private void StartDownload(List <DownloadFileInfo> downloadList) { DownloadProgress dp = new DownloadProgress(downloadList); if (dp.ShowDialog() == DialogResult.OK) { //更新成功 updateconfig.SaveConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FILENAME)); if (updateconfig.UpdateFileList.Count <= 0) { return; } // /// <param name="unRarPath">文件夹路径</param> string unRarPath = AppDomain.CurrentDomain.BaseDirectory + "TEMP"; // /// <param name="rarPath">压缩文件的路径</param> string rarPath = AppDomain.CurrentDomain.BaseDirectory; // /// <param name="rarName">压缩文件的文件名</param> string rarName = updateconfig.UpdateFileList[0].Path; unRarPath = UnCompressRar(unRarPath, rarPath, rarName); if (unRarPath.Trim().Length <= 0) { MessageBox.Show("未安装WinRar压缩软件,会更新失败,请安装软件后再试"); return; } if (bNeedRestart) { File.Delete(unRarPath + rarName); MessageBox.Show("程序需要重新启动才能应用更新,请点击确定重新启动程序。", "自动更新", MessageBoxButtons.OK, MessageBoxIcon.Information); string batstr = @"xcopy TEMP\* * /s /f /h /y" + "\r\n" + "rd /s /q TEMP" + "\r\n" + "del " + rarName + "\r\n" + "start " + Application.ExecutablePath + "\r\n" + "del %0 "; StreamWriter sw = new StreamWriter(rarPath + "\\update.bat", false); sw.WriteLine(batstr); sw.Close(); //写入 Process.Start(rarPath + "\\update.bat"); //启动新程式 // Process.Start(Application.ExecutablePath); Environment.Exit(0); } } }
private void StartDownload(List <DownloadFileInfo> downloadList) { DownloadProgress dp = new DownloadProgress(downloadList); if (dp.ShowDialog() == DialogResult.OK) { updateconfig.SaveConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, FILENAME)); if (updateconfig.UpdateFileList.Count <= 0) { return; } string unRarPath = AppDomain.CurrentDomain.BaseDirectory + "TEMP"; string rarPath = AppDomain.CurrentDomain.BaseDirectory; string rarName = updateconfig.UpdateFileList[0].Path; unRarPath = UnCompressRar(unRarPath, rarPath, rarName); if (unRarPath.Trim().Length <= 0) { MessageBox.Show("rterte"); return; } if (bNeedRestart) { File.Delete(unRarPath + rarName); MessageBox.Show("Download Success", "Download Success", MessageBoxButtons.OK, MessageBoxIcon.Information); string batstr = @"xcopy TEMP\* * /s /f /h /y" + "\r\n" + "rd /s /q TEMP" + "\r\n" + "del " + rarName + "\r\n" + "start " + Application.ExecutablePath + "\r\n" + "del %0 "; StreamWriter sw = new StreamWriter(rarPath + "\\update.bat", false); sw.WriteLine(batstr); sw.Close();//迡 Process.Start(rarPath + "\\update.bat"); Environment.Exit(0); } } }