Skip to content

Commit

Permalink
fix: always use latest when updating
Browse files Browse the repository at this point in the history
  • Loading branch information
cengelha committed Jul 22, 2024
1 parent f1c6606 commit e8055a7
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions libNOM.map/Mapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,28 +309,31 @@ private static async Task<bool> GetJsonDownloadAsync()
{
var content = await GithubService.DownloadMappingJsonAsync(Settings.IncludePrerelease);

// Use an existing download file as fallback if it has not been loaded for some reason.
if (string.IsNullOrEmpty(content) && _jsonDownload is null && File.Exists(CombinedPath))
content = File.ReadAllText(CombinedPath);
// Exit if no content found.
if (string.IsNullOrEmpty(content))
return false;

Directory.CreateDirectory(Settings.DownloadDirectory);
try
// Use existing download file as fallback if it has not been loaded for some reason.
if (_jsonDownload is null && File.Exists(CombinedPath) && MappingJson.Deserialize(File.ReadAllText(CombinedPath)) is MappingJson existing && existing.Version > Version)
_jsonDownload = existing;

if (!string.IsNullOrEmpty(content) && MappingJson.Deserialize(content!) is MappingJson download && download.Version > Version)
{
// File does not matter until next startup and therefore no need to wait.
// Write file only if downloaded mapping is newer than current one.
Directory.CreateDirectory(Settings.DownloadDirectory);
try
{
// File does not matter until next startup and therefore no need to wait.
#if NETSTANDARD2_0
_ = Task.Run(() => File.WriteAllText(CombinedPath, content));
_ = Task.Run(() => File.WriteAllText(CombinedPath, content));
#else
_ = File.WriteAllTextAsync(CombinedPath, content);
_ = File.WriteAllTextAsync(CombinedPath, content);
#endif
}
catch (IOException) { } // Try again next time.
}
catch (IOException) { } // Try again next time.

_jsonDownload = download;

_jsonDownload = MappingJson.Deserialize(content!);
return true;
}

return true;
return false;
}

#endregion
Expand Down

0 comments on commit e8055a7

Please sign in to comment.