Skip to content

Commit

Permalink
Force FirstRun to run again if last ran version is below specified one
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotrekol committed Oct 30, 2016
1 parent 5873580 commit c0b55eb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
27 changes: 25 additions & 2 deletions osu!StreamCompanion/Code/Core/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,31 @@ public void Start()
_msn = new Msn(MsnGetters);

#region First run
if (Settings.Get<bool>(_names.FirstRun))

bool shouldForceFirstRun=false;
var lastVersionStr = Settings.Get<string>(_names.LastRunVersion);
if (lastVersionStr == _names.LastRunVersion.Default<string>())
{
shouldForceFirstRun = true;
}
else
{
try
{
var lastVersion = Helpers.Helpers.GetDateFromVersionString(lastVersionStr);
var versionToResetOn = Helpers.Helpers.GetDateFromVersionString("v161030.20");
shouldForceFirstRun = lastVersion < versionToResetOn;
}
catch (Exception e)
{
if (e is FormatException || e is ArgumentNullException)
shouldForceFirstRun = true;
else
throw;
}
}

if (Settings.Get<bool>(_names.FirstRun) || shouldForceFirstRun)
{
var firstRunModule = new FirstRun(delegate()
{
Expand Down Expand Up @@ -117,7 +141,6 @@ public void Start()
_started = true;
_logger.Log("Started!", LogLevel.Basic);
}

public void StartModules()
{
AddModule(new OsuPathResolver());
Expand Down
5 changes: 5 additions & 0 deletions osu!StreamCompanion/Code/Helpers/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ public static T[] SubArray<T>(this T[] data, int index, int length)
Array.Copy(data, index, result, 0, length);
return result;
}

public static DateTime GetDateFromVersionString(string version)
{
return DateTime.ParseExact(version.TrimStart('v'), "yyMMdd.HH", System.Globalization.CultureInfo.InvariantCulture);
}
}
}

0 comments on commit c0b55eb

Please sign in to comment.