Skip to content

Commit

Permalink
Fix in AutoUpdater
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielefilipp committed Jan 22, 2020
1 parent 542536b commit 305b8a5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 18 deletions.
12 changes: 1 addition & 11 deletions SmartHunter/Core/Config/ConfigContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,7 @@ void Load(bool saveOnLoad = false)
settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
settings.Converters.Add(new StringFloatConverter());

// TODO: Remove this as it is only convient while I'm modifying json classes (to not delete those files every time)
JObject loading = JObject.Parse(contents);
JObject runtime = JObject.Parse(JsonConvert.SerializeObject(Values));

loading.Merge(runtime, new JsonMergeSettings
{
// union array values together to avoid duplicates
MergeArrayHandling = MergeArrayHandling.Union
});

JsonConvert.PopulateObject(loading.ToString(Formatting.None), Values, settings);
JsonConvert.PopulateObject(contents, Values, settings);

Log.WriteLine($"{FileName} loaded");
}
Expand Down
8 changes: 5 additions & 3 deletions SmartHunter/Core/Helpers/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Updater
private List<UpdateNode> NeedUpdates = new List<UpdateNode>();
private string ApiEndpoint = "https://api.github.com/repos/gabrielefilipp/SmartHunter/commits?path=";
private string ApiRaw = "https://github.com/gabrielefilipp/SmartHunter/raw";
private string dummyUserAgent = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";

public bool CheckForUpdates(bool forceCheck = false)
{
Expand All @@ -50,7 +51,7 @@ public bool CheckForUpdates(bool forceCheck = false)
string nameWithNoExtension = Path.GetFileNameWithoutExtension(name);

client.Dispose();
client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
client.Headers["User-Agent"] = dummyUserAgent;

string apiResponseStr = client.DownloadString(apiUrl);
JArray json = JArray.Parse(apiResponseStr);
Expand All @@ -71,6 +72,7 @@ public bool CheckForUpdates(bool forceCheck = false)
}
catch
{
Log.WriteLine($"An error has occured while searching for updates... Resuming the normal flow of the application!");
return false;
}
}
Expand All @@ -91,7 +93,7 @@ public bool DownloadUpdates()
string nameWithNoExtension = Path.GetFileNameWithoutExtension(name);
Log.WriteLine($"Downloading file '{name}'");
client.Dispose();
client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
client.Headers["User-Agent"] = dummyUserAgent;
if (Path.GetExtension(name).Equals(".exe"))
{
client.DownloadFile(url, $"{nameWithNoExtension}_{hash}.exe");
Expand All @@ -103,8 +105,8 @@ public bool DownloadUpdates()

ConfigHelper.Versions.Values.GetType().GetField(nameWithNoExtension).SetValue(ConfigHelper.Versions.Values, hash);
}
NeedUpdates.Clear();
ConfigHelper.Versions.Save();
NeedUpdates.Clear();
}
}
catch
Expand Down
8 changes: 4 additions & 4 deletions SmartHunter/Core/MemoryUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ enum State
CheckingForUpdates,
DownloadingUpdates,
Restarting,
DownloadFailed,
WaitingForProcess,
ProcessFound,
PatternScanning,
Expand Down Expand Up @@ -113,11 +112,12 @@ void CreateStateMachine()
Log.WriteLine("Successfully downloaded all files!");
}),
new StateMachine<State>.Transition(
State.DownloadFailed,
State.WaitingForProcess,
() => !updater.DownloadUpdates(),
() =>
{
Log.WriteLine("Failed to download Updates!");
Log.WriteLine("Failed to download Updates... Resuming the normal flow of the application!");
Initialize();
})
}));

Expand All @@ -134,7 +134,7 @@ void CreateStateMachine()
string file = $".\\SmartHunter_{ConfigHelper.Versions.Values.SmartHunter}.exe";
if (File.Exists(file))
{
Process.Start(file);
Process.Start(file);
}

System.Environment.Exit(1);
Expand Down
Binary file modified SmartHunter/bin/x64/Debug/SmartHunter.exe
Binary file not shown.

0 comments on commit 305b8a5

Please sign in to comment.