📄 liveupdate.cs
字号:
{
string path = Path.GetDirectoryName(svrConfigName);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
public static void Create(IFrameworkWindow mainWnd)
{
Instance._mainWnd = mainWnd;
Imps.Client.Pc.LiveUpdate instance = Instance;
instance.OnCheckComplete = (EventHandler<UpdateInfo>) Delegate.Combine(instance.OnCheckComplete, new EventHandler<UpdateInfo>(Instance, (IntPtr) this.Update_OnCheckComplete));
Random random = new Random(Environment.TickCount);
Instance._checkSpan = ((random.Next(10, 20) * 60) * 60) * 0x3e8;
GlobalTimer.Register(delegate {
Instance.AsyncCheck(false);
}, 0x1770, TimerHandlerPriority.Lowest);
Instance.AsyncCheck(false);
}
private static void Download()
{
}
private void ForceCheck()
{
this.Check(true);
}
private static void Install()
{
}
private static bool IsDisabledLiveUpdate()
{
return string.Equals(Imps.Client.Core.FixedClientSetting.Instance.Debug_LiveUpdateSwitch, "Off", 5);
}
private void Update_OnCheckComplete(object sender, UpdateInfo e)
{
if ((!string.IsNullOrEmpty(this._liveupdateUrl) && (e != null)) && !string.IsNullOrEmpty(e.DownloadURL))
{
Mutex mutex = null;
bool createdNew = false;
mutex = new Mutex(true, "Imps.pc.client.liveupdate", out createdNew);
if (createdNew)
{
if (this.updateInfo != null)
{
this.updateInfo.Save(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile));
}
try
{
string path = StaticTools.GetFullPath(this.WorkPath.SvrInfoFile + ".target");
bool flag2 = File.Exists(path);
if (_isNotifiedUser)
{
return;
}
try
{
_isNotifiedUser = true;
if (flag2)
{
using (ContinueUpdate update = new ContinueUpdate(e, this._mainWnd))
{
if (update.ShowUpdate() == DialogResult.Yes)
{
goto Label_00ED;
}
return;
}
}
using (PromptLiveUpdate update2 = new PromptLiveUpdate(e, this._mainWnd))
{
if (update2.ShowUpdate() != DialogResult.Yes)
{
return;
}
}
}
finally
{
_isNotifiedUser = false;
}
Label_00ED:
if (!string.IsNullOrEmpty(this._liveupdateUrl))
{
this._mainWnd.HideMainWindow();
this._mainWnd.AccountManager.LogoutForcibly();
string fullPath = StaticTools.GetFullPath(this.WorkPath.ClientUpdateFile);
string downloadUrl = string.Empty;
if (string.IsNullOrEmpty(e.DownloadURL))
{
downloadUrl = "http://www.fetion.com.cn";
}
else
{
try
{
Uri uri = new Uri(new Uri(this._liveupdateUrl), e.DownloadURL);
downloadUrl = uri.AbsoluteUri;
}
catch
{
downloadUrl = "http://www.fetion.com.cn";
}
}
if (flag2)
{
UpdateInfo info = new UpdateInfo(path);
if (((info.TargetVersion != e.TargetVersion) || (info.HashCode != e.HashCode)) || (info.DownloadURL != e.DownloadURL))
{
File.Delete(fullPath);
File.Delete(fullPath + ".Downloading");
}
File.Delete(path);
}
File.Move(StaticTools.GetFullPath(this.WorkPath.SvrInfoFile), path);
do
{
if (!File.Exists(fullPath))
{
using (Downloading downloading = new Downloading(e, downloadUrl))
{
StaticTools.LogMessage(this.WorkPath.LogFile, "开始下载更新包");
if (downloading.ShowDialog(this._mainWnd as Form) != DialogResult.Yes)
{
ShellHelper.ApplicationExit();
return;
}
StaticTools.LogMessage(this.WorkPath.LogFile, "成功下载更新包");
}
}
if (e.HashCode != string.Empty)
{
byte[] buffer = null;
using (FileStream inputStream = new FileStream(StaticTools.GetFullPath(this._workPath.ClientUpdateFile), FileMode.Open))
{
buffer = new MD5CryptoServiceProvider().ComputeHash(inputStream);
}
if (buffer != null)
{
StringBuilder builder = new StringBuilder();
for (int i = 0; i < buffer.Length; i++)
{
builder.Append(buffer[i].ToString("x2"));
}
if (builder.ToString() != e.HashCode)
{
File.Delete(fullPath);
if (MessageBox.Show("下载的文件已经损坏,是否重新下载?\r\n选择“是”重新下载;选择“否”退出应用程序", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1) == DialogResult.No)
{
ShellHelper.ApplicationExit();
return;
}
}
}
}
}
while (!File.Exists(fullPath));
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"Software\Fetion");
key.SetValue("TargetBuildTime", Imps.Client.Core.FixedClientSetting.Instance.BuildDate.ToString("yyyyMMddHHmmss"));
key.SetValue("UpdateString", ImpsPathInfo.StartupPath);
try
{
StaticTools.LogMessage(this.WorkPath.LogFile, "开始安装更新");
Process process = new Process();
process.StartInfo = new ProcessStartInfo(fullPath, string.Empty);
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
process.Start();
}
catch (Win32Exception exception)
{
MessageBox.Show("安装更新失败,安装程序没有获得足够的权限!应用程序将退出。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
StaticTools.LogError(this.WorkPath.LogFile, exception);
}
catch (Exception exception2)
{
MessageBox.Show("安装更新失败,请检查更新文件是否已经损坏!应用程序将退出。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
StaticTools.LogError(this.WorkPath.LogFile, exception2);
}
finally
{
ShellHelper.ApplicationExit();
}
}
}
catch (Exception exception3)
{
StaticTools.LogError(this.WorkPath.LogFile, exception3);
ClientLogger.WriteGeneral("更新失败", exception3.ToString(), 20);
}
finally
{
mutex.ReleaseMutex();
}
}
}
}
private static Imps.Client.Pc.LiveUpdate Instance
{
get
{
if (_instance == null)
{
_instance = new Imps.Client.Pc.LiveUpdate();
}
return _instance;
}
}
public WorkPathInfo WorkPath
{
get
{
return this._workPath;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -