示例#1
0
        private static string ArchiveFilePath; // 更新压缩包文件路径

        public UpdaterForm()
        {
            Args = Program.Args;

            // 配置文件
            DownloadingText = Utils.GetAppConfig("DownloadingText", "正在下载更新...");
            ExtractingText  = Utils.GetAppConfig("ExtractingText", "正在应用更新...");

            // 升级压缩包文件路径
            ArchiveFilePath = (string.IsNullOrWhiteSpace(Args.SrcLocalFileName))
                ? Utils.GetTempFilePathWithExtension(Path.GetExtension(Args.SrcDownloadUrl)) // 随机临时文件
                : Utils.GetPathBasedOn(Application.StartupPath, Args.SrcLocalFileName);      // 使用参数指定的文件

            // 初始化界面
            InitializeComponent();
            Text = $"{Args.TargetAppName} 升级程序";
        }
示例#2
0
        /// <summary>
        /// Start parameter processing
        /// </summary>
        /// <param name="programArgs"></param>
        private static void ArgsHandle(string[] programArgs)
        {
            // Program startup parameter
            var p = new FluentCommandLineParser <AppArguments>();

            Program.Args = p.Object;

            p.Setup(args => args.TargetAppName)
            .As("name")
            .SetDefault(Utils.GetAppConfig("TargetAppName", ""))
            .WithDescription("Target program name (for display)");

            p.Setup(args => args.TargetAppProcessName)
            .As("process")
            .SetDefault(Utils.GetAppConfig("TargetAppProcessName", ""))
            .WithDescription("Target program process name (used to force the application to close)");

            p.Setup(args => args.TargetAppRootPath)
            .As("root-path")
            .SetDefault(Utils.GetAppConfig("TargetAppRootPath", "./"))
            .WithDescription("Target program root directory (file operations will be performed in this directory)");

            p.Setup(args => args.SrcDownloadUrl)
            .As('u', "url")
            .WithDescription("Remote download upgrade resource file address (online upgrade)");

            p.Setup(args => args.SrcDownloadProxy)
            .As('p', "proxy")
            .SetDefault(Utils.GetAppConfig("DownloadProxy", ""))
            .WithDescription("Remote download agent");

            p.Setup(args => args.SrcFileMD5)
            .As('v', "md5")
            .WithDescription("Download the upgrade resource file MD5 value");

            p.Setup(args => args.SrcLocalFileName)
            .As("local-src")
            .SetDefault("")
            .WithDescription("Local upgrade resource file (offline upgrade)");

            p.Setup(args => args.LauchAppFileName)
            .As("lauch")
            .SetDefault(Utils.GetAppConfig("LauchAppFileName", ""))
            .WithDescription("Files started after the upgrade is completed");

            p.Setup(args => args.LauchAppFileArgs)
            .As("lauch-args")
            .SetDefault(Utils.GetAppConfig("LauchAppFileArgs", ""))
            .WithDescription("Files started after the upgrade is completed");

            p.Setup(args => args.UpdateMode)
            .As('m', "mode")
            .SetDefault(UpdateMode.OverwriteFiles)
            .WithDescription("Upgrade mode");

            p.SetupHelp("?", "help").Callback((text) => {
                MessageBox.Show(text, "Naupdater Startup parameter", MessageBoxButtons.OK);
                ExitApp();
            });

            if (p.Parse(programArgs).HasErrors)
            {
                ReportErrorAndExit("Incorrect startup parameters");
            }

            LauchErrorText = Utils.GetAppConfig("LauchErrorText", "The program can't start, please try to reload");

            // No Args
            if (string.IsNullOrWhiteSpace(Args.SrcDownloadUrl) && string.IsNullOrWhiteSpace(Args.SrcLocalFileName))
            {
                string filename = Utils.GetAppConfig("NoArgsLauchFile", "");
                if (!String.IsNullOrWhiteSpace(filename))
                {
                    Program.LauchProgram(filename, Utils.GetAppConfig("NoArgsLauchFileArgs", ""));
                }

                string msg = Utils.GetAppConfig("NoArgsMsgText", "");
                if (!String.IsNullOrWhiteSpace(msg))
                {
                    MessageBox.Show(Utils.GetAppConfig("NoArgsMsgText", "Please specify the startup parameters"), $"{Args.TargetAppName} Upgrade procedure", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                ExitApp();
            }

            // Path Handle
            Args.TargetAppRootPath = Utils.GetPathBasedOn(Application.StartupPath, Args.TargetAppRootPath);
        }
示例#3
0
        /// <summary>
        /// 启动参数处理
        /// </summary>
        /// <param name="programArgs"></param>
        private static void ArgsHandle(string[] programArgs)
        {
            // 程序启动参数
            var p = new FluentCommandLineParser <AppArguments>();

            Program.Args = p.Object;

            p.Setup(args => args.TargetAppName)
            .As("name")
            .SetDefault(Utils.GetAppConfig("TargetAppName", ""))
            .WithDescription("目标程序名(用于显示)");

            p.Setup(args => args.TargetAppProcessName)
            .As("process")
            .SetDefault(Utils.GetAppConfig("TargetAppProcessName", ""))
            .WithDescription("目标程序进程名(用于强制关闭应用)");

            p.Setup(args => args.TargetAppRootPath)
            .As("root-path")
            .SetDefault(Utils.GetAppConfig("TargetAppRootPath", "./"))
            .WithDescription("目标程序根目录(文件操作将在该目录中进行)");

            p.Setup(args => args.SrcDownloadUrl)
            .As('u', "url")
            .WithDescription("远程下载升级资源文件地址(在线升级)");

            p.Setup(args => args.SrcDownloadProxy)
            .As('p', "proxy")
            .SetDefault(Utils.GetAppConfig("DownloadProxy", ""))
            .WithDescription("远程下载代理");

            p.Setup(args => args.SrcFileMD5)
            .As('v', "md5")
            .WithDescription("下载升级资源文件 MD5 值");

            p.Setup(args => args.SrcLocalFileName)
            .As("local-src")
            .SetDefault("")
            .WithDescription("本地升级资源文件(离线升级)");

            p.Setup(args => args.LauchAppFileName)
            .As("lauch")
            .SetDefault(Utils.GetAppConfig("LauchAppFileName", ""))
            .WithDescription("升级完成后启动的文件");

            p.Setup(args => args.LauchAppFileArgs)
            .As("lauch-args")
            .SetDefault(Utils.GetAppConfig("LauchAppFileArgs", ""))
            .WithDescription("升级完成后启动的文件");

            p.Setup(args => args.UpdateMode)
            .As('m', "mode")
            .SetDefault(UpdateMode.OverwriteFiles)
            .WithDescription("升级模式");

            p.SetupHelp("?", "help").Callback((text) => {
                MessageBox.Show(text, "Naupdater 启动参数", MessageBoxButtons.OK);
                ExitApp();
            });

            if (p.Parse(programArgs).HasErrors)
            {
                ReportErrorAndExit("启动参数有误");
            }

            LauchErrorText = Utils.GetAppConfig("LauchErrorText", "程序无法启动,请尝试重装");

            // No Args
            if (string.IsNullOrWhiteSpace(Args.SrcDownloadUrl) && string.IsNullOrWhiteSpace(Args.SrcLocalFileName))
            {
                string filename = Utils.GetAppConfig("NoArgsLauchFile", "");
                if (!String.IsNullOrWhiteSpace(filename))
                {
                    Program.LauchProgram(filename, Utils.GetAppConfig("NoArgsLauchFileArgs", ""));
                }

                string msg = Utils.GetAppConfig("NoArgsMsgText", "");
                if (!String.IsNullOrWhiteSpace(msg))
                {
                    MessageBox.Show(Utils.GetAppConfig("NoArgsMsgText", "请指定启动参数"), $"{Args.TargetAppName} 升级程序", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                ExitApp();
            }

            // Path Handle
            Args.TargetAppRootPath = Utils.GetPathBasedOn(Application.StartupPath, Args.TargetAppRootPath);
        }