private static void LaunchWorker_DoWork(object sender, DoWorkEventArgs e) { Launcher.Invoke(delegate { Launcher.LauncherWindow.Show(); Launcher.LauncherWindow.LogoRing.IsActive = true; Launcher.LauncherWindow.Status = "Check update folder"; }); Thread.Sleep(Config.ThreadLongSleepTimeout); if (Directory.Exists(Config.UpdateFolderName)) { Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "Install new files"; }); Thread.Sleep(Config.ThreadSleepTimeout); List <string> filePaths = Directory.GetFiles(Config.UpdateFolderName).ToList(); int removed = filePaths.RemoveAll(x => Path.GetFileName(x) == Config.LauncherAppName); foreach (string path in filePaths) { string fileName = Path.GetFileName(path); if (File.Exists(fileName)) { File.Delete(fileName); } File.Move(path, fileName); } if (removed == 0) { Directory.Delete(Config.UpdateFolderName, true); } } else { Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "There is nothing to update"; }); Thread.Sleep(Config.ThreadSleepTimeout); Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "Start 'bayoen-star'"; }); Thread.Sleep(Config.ThreadLongSleepTimeout); Launcher.StartMainApp(); return; } Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "Start 'bayoen-star'"; }); Thread.Sleep(Config.ThreadLongSleepTimeout); Launcher.StartMainApp(); }
private static void StartMainApp() { Launcher.Invoke(delegate { Launcher.LauncherWindow.LogoRing.IsActive = false; }); if (File.Exists(Config.MainAppName)) { Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "bayoen~"; }); Thread.Sleep(Config.ThreadLongSleepTimeout); bool isMainAppBroken = false; try { Process.Start(Config.MainAppName); } catch (Exception e) { isMainAppBroken = true; System.Media.SystemSounds.Hand.Play(); Launcher.Invoke(async delegate { MessageDialogResult result = await Launcher.LauncherWindow.ShowMessageAsync("ERROR", $"{Config.LauncherAppName} is broken, '{e.Message}'", MessageDialogStyle.Affirmative); if (result == MessageDialogResult.Affirmative) { Application.Current.Shutdown(); } }); } if (!isMainAppBroken) { Launcher.Invoke(delegate { Application.Current.Shutdown(); }); } } else { Launcher.Invoke(delegate { Launcher.LauncherWindow.Status = "???"; }); Thread.Sleep(Config.ThreadSleepTimeout); System.Media.SystemSounds.Hand.Play(); Launcher.Invoke(async delegate { MessageDialogResult result = await Launcher.LauncherWindow.ShowMessageAsync("ERROR", $"'{Config.MainAppName}' is missing. Please check the directory and contact us!", MessageDialogStyle.Affirmative); if (result == MessageDialogResult.Affirmative) { Process.Start(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); Application.Current.Shutdown(); } }); } }