Пример #1
0
        static bool CheckNeedUpdate(string[] args, UpdateRequest request)
        {
            if (Debugger.IsAttached)
            {
                return(true);
            }
            if (args.Contains("-runnow=1"))
            {
                return(true);
            }
            string programDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Updater\\V1.0.0");

            if (!AppDomain.CurrentDomain.BaseDirectory.StartsWith(programDataPath))
            {
                //不在program data下执行,就不执行升级操作
                Console.WriteLine("正在复制文件到:" + programDataPath);
                UpdateUtils.TryReplaceFile(AppDomain.CurrentDomain.BaseDirectory, programDataPath, new List <string> {
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp"),
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs")
                });
                FileInfo fi          = new FileInfo(Assembly.GetExecutingAssembly().Location);
                string   executePath = Path.Combine(programDataPath, fi.Name);
                //重新组织命令行参数
                var newArgs = args.ToList();
                newArgs.RemoveAll(x => x.StartsWith("-r") || x.StartsWith("-p"));
                newArgs.Add("-r=\"" + request.RootPath + "\"");
                newArgs.Add("-p=\"" + request.PackagePath + "\"");
                ProcessHelper.StartProcess(executePath, String.Join(" ", newArgs));
                return(false);
            }
            return(true);
        }