public UpdateConfig GetUpdateConfig(string appDir) { UpdateConfig config = new UpdateConfig(); config.LocalAppDirectory = appDir + ConfigurationManager.AppSettings[UpdateConfig.KEY_LOCAL_APP_DIRECTORY].ToString(); config.LocalUpdateDirectory = appDir + ConfigurationManager.AppSettings[UpdateConfig.KEY_LOCAL_UPDATE_DIRECTORY].ToString(); config.ServerUpdateUrl = ConfigurationManager.AppSettings[UpdateConfig.KEY_SERVER_UPDATE_URL].ToString(); return(config); }
private int AutoUpdate() { Updater u = new Updater(); UpdateConfig config = u.GetUpdateConfig(Application.StartupPath); ShowMessage("从" + Application.StartupPath + "读取配置文件。"); StepProgress(false); List <FileVersion> serverList = u.ReadServerVersion(config.ServerUpdateUrl); ShowMessage("从服务器读取更新文件列表。"); StepProgress(false); List <FileVersion> localList = u.ReadLocalVersion(config.LocalUpdateDirectory); ShowMessage("从服务器读取文件列表。"); StepProgress(false); List <FileVersion> updateList = u.CompareFileVersionList(serverList, localList); ShowMessage("比较服务器与本地文件列表。"); StepProgress(false); if (updateList.Count <= 0) { return(0); } u.DownloadUpdateList(config.ServerUpdateUrl, config.LocalUpdateDirectory, updateList); ShowMessage("从服务器下载更新文件。"); StepProgress(false); DialogResult dr = MessageBox.Show("主程将退出,以进行更新...", "更新确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (dr != DialogResult.OK) { return(0); } KillProcess(Program.PARENT_PROGRAM_PROCESS_ID); u.CopyFile(config.LocalUpdateDirectory, config.LocalAppDirectory, updateList); ShowMessage("完成文件更新。"); StepProgress(false); return(updateList.Count); }