Skip to content

Commit

Permalink
only notify about values file update if the format is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
cadon committed Jan 20, 2021
1 parent 95d5dd2 commit 2245bae
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = fal
|| !Version.TryParse(CreatureCollection.CurrentLibraryFormatVersion, out Version currentVersion)
|| ccVersion > currentVersion)
{
throw new FormatException($"Unhandled format version: {(readCollection.FormatVersion ?? "null")}");
throw new FormatException($"Unsupported format version: {(readCollection.FormatVersion ?? "null")}");
}
_creatureCollection = readCollection;
}
Expand Down
5 changes: 2 additions & 3 deletions ARKBreedingStats/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static async Task<string> FetchReleaseFeed()
private static string ParseReleaseInfo(string releaseFeed)
{
var latestRelease = JObject.Parse(releaseFeed);

string tag = latestRelease.Value<string>("tag_name");

Debug.WriteLine("Tag: " + tag);
Expand Down Expand Up @@ -368,8 +368,7 @@ internal static async Task<bool> DownloadModsManifest()

try
{
if ((await DownloadAsync(ObeliskUrl + FileService.ModsManifest,
tempFilePath)).Item1)
if ((await DownloadAsync(ObeliskUrl + FileService.ModsManifest, tempFilePath)).Item1)
{
// if successful downloaded, move tempFile
try
Expand Down
2 changes: 2 additions & 0 deletions ARKBreedingStats/mods/ModInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ModInfo
public string version;
public Version Version;
[JsonProperty]
public string format;
[JsonProperty]
public Mod mod;
/// <summary>
/// Indicates if the according json-file is downloaded.
Expand Down
30 changes: 26 additions & 4 deletions ARKBreedingStats/mods/ModsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ namespace ARKBreedingStats.mods
[JsonObject(MemberSerialization.OptIn)]
public class ModsManifest
{
/// <summary>
/// Default format version, is valid for all entries that have no specific format version.
/// </summary>
[JsonProperty("format")]
public string DefaultFormatVersion;

/// <summary>
/// Dictionary of ModInfos. The key is the mod-filename.
/// </summary>
Expand Down Expand Up @@ -46,11 +52,19 @@ public static async Task<ModsManifest> TryLoadModManifestFile(bool forceDownload
{
while (true)
{
string modsManifestPath = Path.Combine(FileService.ValuesFolder, FileService.ModsManifest);
if (forceDownload || !File.Exists(FileService.GetJsonPath(modsManifestPath))) await TryDownloadFileAsync();
string modsManifestFilePath = FileService.GetJsonPath(FileService.ValuesFolder, FileService.ModsManifest);
if (forceDownload || !File.Exists(modsManifestFilePath)) await TryDownloadFileAsync();

if (FileService.LoadJsonFile(FileService.GetJsonPath(modsManifestPath), out ModsManifest tmpV, out string errorMessage))
if (FileService.LoadJsonFile(modsManifestFilePath, out ModsManifest tmpV, out string errorMessage))
{
// set format versions
// if an entry has no specific format version, it is the general format version of the manifest file
foreach (var mi in tmpV.modsByFiles)
{
if (string.IsNullOrEmpty(mi.Value.format))
mi.Value.format = tmpV.DefaultFormatVersion;
}

return tmpV;
}

Expand Down Expand Up @@ -78,6 +92,14 @@ public static bool TryLoadCustomModManifestFile(out ModsManifest customModsManif

if (FileService.LoadJsonFile(filePath, out ModsManifest tmpV, out string errorMessage))
{
// set format versions
// if an entry has no specific format version, it is the general format version of the manifest file
foreach (var mi in tmpV.modsByFiles)
{
if (string.IsNullOrEmpty(mi.Value.format))
mi.Value.format = tmpV.DefaultFormatVersion;
}

customModsManifest = tmpV;
return true;
}
Expand Down Expand Up @@ -154,8 +176,8 @@ public bool DownloadModFiles(List<string> modValueFiles)
internal static ModsManifest MergeModsManifest(ModsManifest manifest1, ModsManifest manifest2)
=> new ModsManifest()
{
DefaultFormatVersion = manifest1.DefaultFormatVersion,
modsByFiles = manifest2.modsByFiles.Concat(manifest1.modsByFiles.Where(m1 => !manifest2.modsByFiles.ContainsKey(m1.Key))).ToDictionary(m => m.Key, m => m.Value)
};

}
}
19 changes: 12 additions & 7 deletions ARKBreedingStats/values/Values.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private static Values LoadValuesFile(string filePath)
{
if (FileService.LoadJsonFile(filePath, out Values readData, out string errorMessage))
{
if (!IsValidFormatVersion(readData.format)) throw new FormatException("Unhandled format version");
if (!IsValidFormatVersion(readData.format)) throw new FormatException($"Unsupported values format version: {(readData.format ?? "null")}");
return readData;
}
throw new FileLoadException(errorMessage);
Expand Down Expand Up @@ -277,7 +277,7 @@ public bool LoadModValues(List<string> modValueFileNames, bool throwExceptionOnF
sp.Mod = modValues.mod;
speciesAdded++;

if (!blueprintToSpecies.ContainsKey(sp.blueprintPath))
if (!blueprintToSpecies.ContainsKey(sp.blueprintPath))
blueprintToSpecies.Add(sp.blueprintPath, sp);
}
}
Expand Down Expand Up @@ -323,19 +323,24 @@ public bool LoadModValues(List<string> modValueFileNames, bool throwExceptionOnF
foreach (string mf in modValueFileNames)
{
string modFilePath = Path.Combine(valuesFolder, mf);

modsManifest.modsByFiles.TryGetValue(mf, out var modInfo);

if (!File.Exists(modFilePath))
{
if (modsManifest.modsByFiles.ContainsKey(mf)
&& modsManifest.modsByFiles[mf].OnlineAvailable)
if (modInfo != null
&& modInfo.OnlineAvailable
&& IsValidFormatVersion(modInfo.format))
missingModValueFilesOnlineAvailable.Add(mf);
else
missingModValueFilesOnlineNotAvailable.Add(mf);
}
else if (modsManifest.modsByFiles.ContainsKey(mf))
else if (modInfo != null)
{
// check if an update is available
if (modsManifest.modsByFiles[mf].OnlineAvailable
&& modsManifest.modsByFiles[mf].Version != null
if (modInfo.OnlineAvailable
&& IsValidFormatVersion(modInfo.format)
&& modInfo.Version != null
&& TryLoadValuesFile(modFilePath, setModFileName: false, throwExceptionOnFail: false,
out Values modValues, errorMessage: out _)
&& modValues.Version < modsManifest.modsByFiles[mf].Version)
Expand Down

0 comments on commit 2245bae

Please sign in to comment.