Skip to content

Commit

Permalink
Prevent most if not all startup hanging
Browse files Browse the repository at this point in the history
IT'S TIME TO STOP hanging on startup if there is an error. Now we should show an error popup and also still try to show the main window.
  • Loading branch information
Vermintide-Analytics committed Aug 26, 2022
1 parent 6af3d88 commit 77a7940
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Vermintide Analyzer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.10.0")]
[assembly: AssemblyFileVersion("1.1.10.0")]
[assembly: AssemblyVersion("1.1.11.0")]
[assembly: AssemblyFileVersion("1.1.11.0")]
105 changes: 62 additions & 43 deletions Vermintide Analyzer/StartupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,53 +57,72 @@ public void NotifyPropertyChanged([CallerMemberName] string propertyName = "")

private void Startup()
{
BeginStep("Checking directories...");
if(!GameRepository.Instance.CheckDirectories())
try
{
BeginStep("Creating directories...");
GameRepository.Instance.CreateDirectories();
BeginStep("Checking directories...");
if (!GameRepository.Instance.CheckDirectories())
{
BeginStep("Creating directories...");
GameRepository.Instance.CreateDirectories();
}

BeginStep("Loading user settings...");
Settings.Load();

BeginStep("Gathering latest console logs...");
GameRepository.Instance.ReadAndMoveNewGameLogs();

BeginStep("Reading old games...");
var existingGameHeaders = GameRepository.Instance.ReadExistingGameHeaders();
var previouslyInvalidGameHeaders = GameRepository.Instance.ReadPreviouslyInvalidGameHeaders();
LogDetail($"Found {existingGameHeaders.Count() + previouslyInvalidGameHeaders.Count()} old games.");

BeginStep("Reading new games...");
// Temporary bandaid for some mistakes I make in the mod output
GameRepository.Instance.FixNewGameData();
var newGameHeaders = GameRepository.Instance.ReadAndMoveNewGameHeaders();
LogDetail($"Found {newGameHeaders.Count()} new games.");

LogDetail($"Found {GameRepository.Instance.InvalidGames.Count} invalid games.");

BeginStep("Finishing up...");
GameRepository.Instance.GameHeaders.Sort((gh1, gh2) => gh2.GameStart.CompareTo(gh1.GameStart));
GameRepository.Instance.ReadGameNotesFromDisk();
GameRepository.Instance.ReadGameFiltersFromDisk();

// Delete and recreate the temp dir to clear it out
try
{
Directory.Delete(GameRepository.TempDir, true);
}
catch { }
Directory.CreateDirectory(GameRepository.TempDir);
GameRepository.Instance.RemoveTemporaryGameNotes();

Thread.Sleep(STARTUP_DELAY);
}

BeginStep("Loading user settings...");
Settings.Load();

BeginStep("Gathering latest console logs...");
GameRepository.Instance.ReadAndMoveNewGameLogs();

BeginStep("Reading old games...");
var existingGameHeaders = GameRepository.Instance.ReadExistingGameHeaders();
var previouslyInvalidGameHeaders = GameRepository.Instance.ReadPreviouslyInvalidGameHeaders();
LogDetail($"Found {existingGameHeaders.Count() + previouslyInvalidGameHeaders.Count()} old games.");

BeginStep("Reading new games...");
// Temporary bandaid for some mistakes I make in the mod output
GameRepository.Instance.FixNewGameData();
var newGameHeaders = GameRepository.Instance.ReadAndMoveNewGameHeaders();
LogDetail($"Found {newGameHeaders.Count()} new games.");

LogDetail($"Found {GameRepository.Instance.InvalidGames.Count} invalid games.");

BeginStep("Finishing up...");
GameRepository.Instance.GameHeaders.Sort((gh1, gh2) => gh2.GameStart.CompareTo(gh1.GameStart));
GameRepository.Instance.ReadGameNotesFromDisk();
GameRepository.Instance.ReadGameFiltersFromDisk();

// Delete and recreate the temp dir to clear it out
try
catch(Exception e)
{
Directory.Delete(GameRepository.TempDir, true);
MessageBox.Show($"{e.Message}\n{e.StackTrace}", "An error occurred during startup, the app may not function correctly", MessageBoxButton.OK, MessageBoxImage.Error);
}
catch { }
Directory.CreateDirectory(GameRepository.TempDir);
GameRepository.Instance.RemoveTemporaryGameNotes();

Thread.Sleep(STARTUP_DELAY);

Util.SafeInvoke(() =>
finally
{
new MainWindow().Show();
Close();
});
Util.SafeInvoke(() =>
{
try
{
new MainWindow().Show();
}
catch
{
MainWindow.Instance?.Close();
}
finally
{
Close();
}
});
}
}

private void BeginStep(string step)
Expand All @@ -122,7 +141,7 @@ private void Window_ContentRendered(object sender, EventArgs e)
// It became visible
if (!HasSetup)
{
new Task(Startup).Start();
Task.Run(Startup);
HasSetup = true;
}
}
Expand Down

0 comments on commit 77a7940

Please sign in to comment.