示例#1
0
        public int Step2(out VersionDownload download)
        {
            download = null;

            if (CheckVendor.NotValidResponse(_versionInfo) || _versionInfo.Message != 00_0004)
            {
                return(02_0008);
            }

            var result = ApiCall.VersionDownload.Call(_versionInfo.EligibleBundleKey, null);

            if (!(result.Data is VersionDownload vd))
            {
                return(02_0007);
            }

            if (CheckVendor.NotValidResponse(vd))
            {
                return(vd.Message);
            }

            vd.Argument = UpdateVendor.FormatArgumentString(vd);
            download    = vd;

            return(00_0000);
        }
示例#2
0
        public static DownloadInfo[] DownloadPatches(VersionDownload argument, OnFileDownloadCompleteDelegate handle)
        {
            Directory.CreateDirectory(TempPath);

            var dc = new DownloadClient();

            dc.OnFileDownloadComplete = handle;
            var dic = new Dictionary <string, string>(argument.Files.Length);

            foreach (var file in argument.Files)
            {
                var destFile = Path.Combine(TempPath, Path.GetFileName(file));

                int i = 0;
                while (dic.Values.Contains(destFile, StringComparer.InvariantCultureIgnoreCase))
                {
                    var filename = Path.GetFileName(file);
                    destFile = Path.Combine(TempPath, $"{Path.GetFileNameWithoutExtension(filename)}-{i++}{Path.GetExtension(filename)}");
                }

                dic.Add(argument.FileServer.AppendPathSegment(file), destFile);
            }

            return(dc.StartDownload(dic));
        }
示例#3
0
        public static void InvokeUpdateAndExitProgram(VersionDownload argument, bool restartAfterUpdate)
        {
            var proc = new Process
            {
                StartInfo =
                {
                    FileName               = UpdaterPath,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = false,

                    Arguments              = argument.Argument + (restartAfterUpdate ? " --restart" : "")
                }
            };

            try
            {
                proc.Start();
                Environment.Exit(0);
            }
            catch
            {
                // ignored
            }
        }
示例#4
0
        internal static string FormatArgumentString(VersionDownload argument)
        {
            var method = (argument.BinaryUpdate ? "b" : "") +
                         (argument.DataUpdate ? "d" : "") +
                         (argument.UpdaterUpdate ? "u" : "");

            return(argument.Argument
                   .Replace("<?installdir>", $"\"{ProcessRoot}\"")
                   .Replace("<?datadir>", $"\"{DataRoot}\"")
                   .Replace("<?tempdir>", $"\"{TempPath}\"")
                   .Replace("<?method>", method));
        }
示例#5
0
        public static void UpdateLogic(bool hideNoUpdateMessage = true, bool includeOptional = true)
        {
            var         up         = new UpdateProcedure();
            var         needUpdate = false;
            VersionInfo info       = null;
            int         ret;

            try
            {
                ret = up.Step1(out needUpdate, out info);
            }
            catch (HttpRequestException e)
            {
                ret = 02_0000 + (int)e.Data["StatusCode"];
            }

            if (CheckVendor.NotValidResponseCode(ret))
            {
                MessageBox.Show($"客户端检查更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新");
                return;
            }

            if (!needUpdate)
            {
                if (!hideNoUpdateMessage)
                {
                    MessageBox.Show($"已经是最新版本", "Milvaneth 客户端更新");
                }

                return;
            }

            if (!info.ForceUpdate)
            {
                if (!includeOptional)
                {
                    return;
                }

                var result =
                    MessageBox.Show(
                        $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" +
                        $"版本说明:{info.DisplayMessage}\n" + "是否现在更新?", "Milvaneth 客户端更新", MessageBoxButton.YesNo);

                if (result == MessageBoxResult.No)
                {
                    return;
                }
            }
            else
            {
                Task.Run(() => MessageBox.Show(
                             $"有可用新版本 {info.EligibleMilvanethVersion} (D-{info.EligibleDataVersion} / G-{info.EligibleGameVersion})\n" +
                             $"版本说明:{info.DisplayMessage}\n" + "本版本为必要更新,将自动下载并安装更新\n请不要关闭或退出程序,程序将在更新完成后自动重启", "Milvaneth 客户端更新", MessageBoxButton.OK));
            }

            VersionDownload download = null;

            try
            {
                ret = up.Step2(out download);
            }
            catch (HttpRequestException e)
            {
                ret = 02_0000 + (int)e.Data["StatusCode"];
            }

            if (CheckVendor.NotValidResponseCode(ret))
            {
                MessageBox.Show($"客户端下载更新失败:{MessageVendor.FormatError(ret)}", "Milvaneth 客户端更新");
                return;
            }

            var patches = UpdateVendor.DownloadPatches(download, null);

            UpdateVendor.WaitAllFinish(patches);

            if (!info.ForceUpdate)
            {
                MessageBox.Show($"更新即将开始,请不要关闭或退出程序\n程序将在更新完成后自动重启", "Milvaneth 客户端更新");
            }

            SupportStatic.ExitAll();
            UpdateVendor.InvokeUpdateAndExitProgram(download, true);
        }