Skip to content

Commit

Permalink
fix(IO): previous version file path handling
Browse files Browse the repository at this point in the history
closes #147
  • Loading branch information
DorielRivalet committed Jul 31, 2023
1 parent 283d747 commit 0daa24d
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions MHFZ_Overlay/Services/DatabaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ public bool SetupLocalDatabase(DataLoader dataLoader)
this.CreateDatabaseIndexes(conn);
this.CreateDatabaseTriggers(conn);
this.CheckDatabaseVersion(conn, dataLoader);

// TODO: avoid using version files. find alternatives to IO.
WriteNewVersionToFile();
}

Expand Down Expand Up @@ -14811,7 +14813,25 @@ private void CheckPreviousVersionFile()
{
logger.Info(CultureInfo.InvariantCulture, "previousVersionFilePath found, reading version number.");
previousVersion = File.ReadAllText(previousVersionFilePath).Trim();
logger.Info(CultureInfo.InvariantCulture, "previousVersionFilePath version number {0}", previousVersion);
if (string.IsNullOrEmpty(previousVersion))
{
logger.Info(CultureInfo.InvariantCulture, "previousVersionFilePath contents are empty, writing to file");
if (App.CurrentProgramVersion == null)
{
logger.Fatal(CultureInfo.InvariantCulture, "CurrentProgramVersion does not exist");
MessageBox.Show("Current Program Version not found.");
LoggingService.WriteCrashLog(new Exception("CurrentProgramVersion not found."), logMessage);
return;
}

previousVersion = App.CurrentProgramVersion.Trim();
File.WriteAllText(previousVersionFilePath, previousVersion);
logger.Info(CultureInfo.InvariantCulture, "Writing previous version {0} to file {1}", previousVersion, previousVersionFilePath);
}
else
{
logger.Info(CultureInfo.InvariantCulture, "previousVersionFilePath version number {0}", previousVersion);
}
}
else
{
Expand Down Expand Up @@ -14848,9 +14868,8 @@ private void WriteNewVersionToFile()
var versionInFile = File.ReadAllText(previousVersionFilePath).Trim();
if (string.IsNullOrEmpty(versionInFile))
{
logger.Fatal(CultureInfo.InvariantCulture, "previousVersionFilePath file is empty");
MessageBox.Show("previous-version.txt is empty.");
LoggingService.WriteCrashLog(new Exception("previous-version.txt is empty."), logMessage);
logger.Warn(CultureInfo.InvariantCulture, "previousVersionFilePath file is empty");
versionInFile = "Fresh Install";
}

if (App.CurrentProgramVersion == null)
Expand Down

0 comments on commit 0daa24d

Please sign in to comment.