@@ -96,6 +96,10 @@ private static bool IsAlreadyRunning() {
9696 }
9797
9898 public static bool IsExitingProgram;
99+ #if AllowUpdate
100+ public static bool IsExitingForUpdate;
101+ public static bool IsUpdatingOnAppLaunch;
102+ #endif
99103
100104 public static readonly string CURRENTDIR = AppDomain.CurrentDomain.BaseDirectory;
101105
@@ -416,6 +420,7 @@ public void AddToDbTasksList(Task task, bool runAsync) {
416420 lock (task) {
417421 task.ContinueWith(t => {
418422 lock (this.dbTasks) {
423+ if (IsExitingProgram) return;
419424 this.dbTasks.Remove(t);
420425 }
421426 });
@@ -4793,20 +4798,45 @@ public void SaveWindowState() {
47934798
47944799 public void Stats_ExitProgram(object sender, EventArgs e) {
47954800 try {
4801+ #if AllowUpdate
4802+ if (IsExitingForUpdate) {
4803+ this.trayIcon.Visible = false;
4804+ this.CurrentSettings.ShowChangelog = true;
4805+ }
4806+
4807+ if (!IsUpdatingOnAppLaunch && !this.IsDisposed && !this.Disposing) {
4808+ this.SaveWindowState();
4809+ }
4810+ #else
47964811 if (!this.IsDisposed && !this.Disposing) {
47974812 this.SaveWindowState();
47984813 }
4814+ #endif
47994815 this.SaveUserSettings();
4816+ #if AllowUpdate
4817+ if (IsExitingForUpdate) {
4818+ this.Hide();
4819+ this.overlay?.Hide();
4820+ }
4821+ #endif
48004822 if (this.logFile.logFileWatcher != null) {
48014823 Task.Run(() => this.logFile.Stop()).Wait();
48024824 }
4825+
48034826 lock (this.dbTasks) {
48044827 IsExitingProgram = true;
48054828 Task.WaitAll(this.dbTasks.ToArray());
48064829 }
48074830 this.StatsDB?.Dispose();
4831+ #if AllowUpdate
4832+ if (IsExitingForUpdate) return;
4833+ #endif
48084834 } catch (Exception ex) {
4835+ IsExitingProgram = true;
48094836 MetroMessageBox.Show(this, ex.ToString(), $"{Multilingual.GetWord("message_program_error_caption")}", MessageBoxButtons.OK, MessageBoxIcon.Error);
4837+ #if AllowUpdate
4838+ if (IsExitingForUpdate) return;
4839+ #endif
48104840 }
48114841 this.Close();
48124842 }
@@ -4861,7 +4891,6 @@ private void Stats_Shown(object sender, EventArgs e) {
48614891 this.EnableInfoStrip(false);
48624892 this.EnableMainMenu(false);
48634893 if (this.CheckForUpdate(true)) {
4864- // this.Stats_ExitProgram(this, null);
48654894 return;
48664895 }
48674896 this.EnableInfoStrip(true);
@@ -4892,35 +4921,8 @@ private void Stats_Shown(object sender, EventArgs e) {
48924921 }
48934922 this.RemoveUpdateFiles();
48944923#endif
4895-
4896- this.scrollTimer.Tick += this.scrollTimer_Tick;
4897- if (this.CurrentSettings.Visible) {
4898- this.Show();
4899- this.ShowInTaskbar = true;
4900- this.Opacity = 1;
4901- } else {
4902- this.Hide();
4903- this.ShowInTaskbar = true;
4904- this.Opacity = 1;
4905- }
4906- this.SetMainDataGridViewOrder();
49074924 InstalledEmojiFont = Utils.IsFontInstalled("Segoe UI Emoji");
49084925
4909- if (this.WindowState != FormWindowState.Minimized) {
4910- this.WindowState = this.CurrentSettings.MaximizedWindowState ? FormWindowState.Maximized : FormWindowState.Normal;
4911- }
4912- if (this.CurrentSettings.FormWidth.HasValue) {
4913- this.Size = new Size(this.CurrentSettings.FormWidth.Value, this.CurrentSettings.FormHeight.Value);
4914- }
4915- if (this.CurrentSettings.FormLocationX.HasValue && Utils.IsOnScreen(this.CurrentSettings.FormLocationX.Value, this.CurrentSettings.FormLocationY.Value, this.Width, this.Height)) {
4916- this.Location = new Point(this.CurrentSettings.FormLocationX.Value, this.CurrentSettings.FormLocationY.Value);
4917- }
4918-
4919- this.overlay.UpdateDisplay(true);
4920- if (this.CurrentSettings.OverlayVisible) {
4921- this.ToggleOverlay(this.overlay);
4922- }
4923-
49244926 this.ReloadProfileMenuItems();
49254927
49264928 this.selectedCustomTemplateSeason = this.CurrentSettings.SelectedCustomTemplateSeason;
@@ -4960,10 +4962,11 @@ private void Stats_Shown(object sender, EventArgs e) {
49604962 this.menuStats_Click(this.menuSessionStats, EventArgs.Empty);
49614963 break;
49624964 }
4963-
4964- this.SetWindowCorner();
49654965 this.isStartingUp = false;
49664966
4967+ string logPath = !string.IsNullOrEmpty(this.CurrentSettings.LogPath) && Directory.Exists(this.CurrentSettings.LogPath) ? this.CurrentSettings.LogPath : LOGPATH;
4968+ this.logFile.Start(logPath, LOGFILENAME);
4969+
49674970 if (this.CurrentSettings.AutoLaunchGameOnStartup) {
49684971 this.EnableInfoStrip(false);
49694972 this.EnableMainMenu(false);
@@ -4972,11 +4975,36 @@ private void Stats_Shown(object sender, EventArgs e) {
49724975 this.EnableMainMenu(true);
49734976 }
49744977
4978+ this.scrollTimer.Tick += this.scrollTimer_Tick;
4979+ if (this.CurrentSettings.Visible) {
4980+ this.Show();
4981+ this.Select();
4982+ } else {
4983+ this.Hide();
4984+ }
4985+ this.Opacity = 1;
4986+
4987+ this.SetMainDataGridViewOrder();
4988+
4989+ if (this.WindowState != FormWindowState.Minimized) {
4990+ this.WindowState = this.CurrentSettings.MaximizedWindowState ? FormWindowState.Maximized : FormWindowState.Normal;
4991+ }
4992+ if (this.CurrentSettings.FormWidth.HasValue) {
4993+ this.Size = new Size(this.CurrentSettings.FormWidth.Value, this.CurrentSettings.FormHeight.Value);
4994+ }
4995+ if (this.CurrentSettings.FormLocationX.HasValue && Utils.IsOnScreen(this.CurrentSettings.FormLocationX.Value, this.CurrentSettings.FormLocationY.Value, this.Width, this.Height)) {
4996+ this.Location = new Point(this.CurrentSettings.FormLocationX.Value, this.CurrentSettings.FormLocationY.Value);
4997+ }
4998+
4999+ this.ShowInTaskbar = true;
49755000 this.SetSystemTrayIcon(this.CurrentSettings.SystemTrayIcon);
4976- this.SaveUserSettings();
49775001
4978- string logPath = !string.IsNullOrEmpty(this.CurrentSettings.LogPath) && Directory.Exists(this.CurrentSettings.LogPath) ? this.CurrentSettings.LogPath : LOGPATH;
4979- this.logFile.Start(logPath, LOGFILENAME);
5002+ this.SetWindowCorner();
5003+
5004+ this.overlay.UpdateDisplay(true);
5005+ if (this.CurrentSettings.OverlayVisible) {
5006+ this.ToggleOverlay(this.overlay, false);
5007+ }
49805008 } catch (Exception ex) {
49815009 this.EnableInfoStrip(true);
49825010 this.EnableMainMenu(true);
@@ -5099,13 +5127,13 @@ private void LogFile_OnParsedLogLines(List<RoundInfo> round) {
50995127
51005128 if (info == null && stat.Start > this.lastAddedShow) {
51015129 if (stat.ShowEnd < this.startupTime && this.askedPreviousShows == 0) {
5130+ this.EnableInfoStrip(false);
5131+ this.EnableMainMenu(false);
51025132 IsDisplayOverlayTime = false;
51035133 using (EditShows editShows = new EditShows()) {
51045134 editShows.FunctionFlag = "add";
51055135 editShows.Profiles = this.AllProfiles;
51065136 editShows.StatsForm = this;
5107- this.EnableInfoStrip(false);
5108- this.EnableMainMenu(false);
51095137 if (editShows.ShowDialog(this) == DialogResult.OK) {
51105138 this.askedPreviousShows = 1;
51115139 if (editShows.UseLinkedProfiles) {
@@ -5118,10 +5146,10 @@ private void LogFile_OnParsedLogLines(List<RoundInfo> round) {
51185146 } else {
51195147 this.askedPreviousShows = 2;
51205148 }
5121- this.EnableInfoStrip(true);
5122- this.EnableMainMenu(true);
5123- IsDisplayOverlayTime = true;
51245149 }
5150+ IsDisplayOverlayTime = true;
5151+ this.EnableInfoStrip(true);
5152+ this.EnableMainMenu(true);
51255153 }
51265154
51275155 if (stat.ShowEnd < this.startupTime && this.askedPreviousShows == 2) {
@@ -8278,7 +8306,6 @@ private void menuUpdate_Click(object sender, EventArgs e) {
82788306 this.EnableInfoStrip(false);
82798307 this.EnableMainMenu(false);
82808308 if (this.CheckForUpdate(false)) {
8281- // this.Stats_ExitProgram(this, null);
82828309 return;
82838310 }
82848311 this.EnableInfoStrip(true);
@@ -8387,16 +8414,12 @@ private bool CheckForUpdate(bool isSilent) {
83878414 $"{Multilingual.GetWord("message_update_question_prefix")} [ v{newVersion.ToString(2)} ] {Multilingual.GetWord("message_update_question_suffix")}",
83888415 $"{Multilingual.GetWord("message_update_question_caption")}",
83898416 MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) {
8390- this.trayIcon.Visible = false;
8391- this.CurrentSettings.ShowChangelog = true;
8392- if (!isSilent && !this.IsDisposed && !this.Disposing) {
8393- this.SaveWindowState();
8394- }
8395- this.SaveUserSettings();
8396- IsExitingProgram = true;
8397- this.Hide();
8398- this.overlay?.Dispose();
8399- Task.Run(() => this.UpdateAndExitProgram(web));
8417+ Task.Run(() => {
8418+ IsExitingForUpdate = true;
8419+ IsUpdatingOnAppLaunch = isSilent;
8420+ this.Stats_ExitProgram(this, null);
8421+ this.UpdateProgram(web);
8422+ });
84008423 return true;
84018424 }
84028425 } else if (!isSilent) {
@@ -8423,20 +8446,13 @@ private bool CheckForUpdate(bool isSilent) {
84238446 }
84248447
84258448#if AllowUpdate
8426- public async Task UpdateAndExitProgram(ZipWebClient web) {
8427- if (this.logFile.logFileWatcher != null) {
8428- await this.logFile.Stop();
8449+ public void UpdateProgram(ZipWebClient web) {
8450+ using (DownloadProgress progress = new DownloadProgress()) {
8451+ progress.ZipWebClient = web;
8452+ progress.DownloadUrl = Utils.FALLGUYSSTATS_RELEASES_LATEST_DOWNLOAD_URL;
8453+ progress.FileName = $"{CURRENTDIR}FallGuysStats.zip";
8454+ progress.ShowDialog(this);
84298455 }
8430- await Task.WhenAll(this.dbTasks).ContinueWith(prevTask => {
8431- this.StatsDB?.Dispose();
8432-
8433- using (DownloadProgress progress = new DownloadProgress()) {
8434- progress.ZipWebClient = web;
8435- progress.DownloadUrl = Utils.FALLGUYSSTATS_RELEASES_LATEST_DOWNLOAD_URL;
8436- progress.FileName = $"{CURRENTDIR}FallGuysStats.zip";
8437- progress.ShowDialog(this);
8438- }
8439- });
84408456 }
84418457#endif
84428458
@@ -8558,7 +8574,7 @@ private void menuOverlay_Click(object sender, EventArgs e) {
85588574 this.ToggleOverlay(this.overlay);
85598575 }
85608576
8561- public void ToggleOverlay(Overlay overlay) {
8577+ public void ToggleOverlay(Overlay overlay, bool saveSetting = true ) {
85628578 if (overlay.Visible) {
85638579 IsDisplayOverlayPing = false;
85648580 overlay.Hide();
@@ -8593,8 +8609,10 @@ public void ToggleOverlay(Overlay overlay) {
85938609 this.trayOverlay.Image = Properties.Resources.stat_icon;
85948610 this.trayOverlay.Text = $"{Multilingual.GetWord("main_hide_overlay")}";
85958611 }
8596- this.CurrentSettings.OverlayVisible = overlay.Visible;
8597- this.SaveUserSettings();
8612+ if (saveSetting) {
8613+ this.CurrentSettings.OverlayVisible = overlay.Visible;
8614+ this.SaveUserSettings();
8615+ }
85988616 }
85998617
86008618 private void menuHelp_Click(object sender, EventArgs e) {
0 commit comments