using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; using System.Windows; namespace Vinno.FIS.Sonopost.Upgrade { /// /// App.xaml 的交互逻辑 /// public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); if (e.Args.Length == 3) { var upgradePath = e.Args[0]; var targetPath = e.Args[1]; var deleteAllFiles = false; bool.TryParse(e.Args[2], out deleteAllFiles); StartUpgradeThread(upgradePath, targetPath, deleteAllFiles); } else { Process.GetCurrentProcess().Kill(); } } private void StartUpgradeThread(string upgradePath, string targetPath, bool deleteAllFiles) { Task.Run(() => { var upgrade = new UpgradeOperator(upgradePath, targetPath, deleteAllFiles); try { upgrade.StartUpgrade(); } catch (Exception ex) { File.AppendAllText("UpgradeLog.txt", ex.ToString()); upgrade.InstallSonopostTask(); } finally { Process.GetCurrentProcess().Kill(); } }); } } }