Skip to content

Commit

Permalink
Minor auto-update code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ShikenNuggets committed Aug 28, 2021
1 parent 9a4ac25 commit 44edca1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 1 addition & 5 deletions ArkhamDisplay/BaseWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ protected virtual void UpdatePreferences(object sender = null, RoutedEventArgs e
}

protected void CheckForUpdatedRoutes(object sender = null, RoutedEventArgs e = null){
string routesWithUpdatesStr = "";
List<string> routesWithUpdates = new List<string>();
Dictionary<string, string> routeFileData = new Dictionary<string, string>();

Expand All @@ -400,22 +399,19 @@ protected void CheckForUpdatedRoutes(object sender = null, RoutedEventArgs e = n

if(!Data.HasRouteFile(r.Name)){
routesWithUpdates.Add(r.Name);
routesWithUpdatesStr += "\n" + r.Name;
continue;
}

if(r.Name.Contains("json")){
if(Utils.GetSHA1Hash("Routes/" + r.Name) != Utils.GetSHA1Hash(split)){
routesWithUpdates.Add(r.Name);
routesWithUpdatesStr += "\n" + r.Name;
continue;
}
}else{
Route r1 = new Route("Routes/" + r.Name);
Route r2 = new Route(null, split);
if(r1.IsEqual(r2) == false){
routesWithUpdates.Add(r.Name);
routesWithUpdatesStr += "\n" + r.Name;
continue;
}
}
Expand All @@ -429,7 +425,7 @@ protected void CheckForUpdatedRoutes(object sender = null, RoutedEventArgs e = n

MessageBoxResult result = MessageBoxResult.No;
if(routesWithUpdates.Count > 0){
result = MessageBox.Show("The following routes have updates. Would you like to download? Any custom changes will be lost.\n" + routesWithUpdatesStr, "Updates Available", MessageBoxButton.YesNo);
result = MessageBox.Show("The following routes have updates. Would you like to download? Any custom changes will be lost.\n" + Utils.ListToNewlinedString(routesWithUpdates), "Updates Available", MessageBoxButton.YesNo);
}else{
MessageBox.Show("Routes are already up to date.");
}
Expand Down
10 changes: 10 additions & 0 deletions ArkhamDisplay/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public static string GetSHA1Hash(byte[] data){
using var cryptoProvider = new SHA1CryptoServiceProvider();
return BitConverter.ToString(cryptoProvider.ComputeHash(data));
}

public static string ListToNewlinedString(List<string> list){
string final = "";

foreach(string s in list){
final += "\n" + s;
}

return final;
}
}
}

0 comments on commit 44edca1

Please sign in to comment.