public static async Task <bool> UpdateAllFiles(PluginInformation pInformation, string modPath) { string onlineSerializedInformation = await ReadOnlineModuleJson(pInformation.Update.UpdateUrl); if (onlineSerializedInformation is null) { //Debugger.Error($"Failed to update plugin: {pInformation.Name}!"); return(false); } PluginInformation onlineInformation = JsonConvert.DeserializeObject <PluginInformation>(onlineSerializedInformation); if (!(Hunterpie.ParseVersion(Hunterpie.HUNTERPIE_VERSION) >= Hunterpie.ParseVersion(onlineInformation.Update.MinimumVersion))) { return(false); } foreach (string filePath in onlineInformation.Update.FileHashes.Keys) { string onlineHash = onlineInformation.Update.FileHashes[filePath]; if (onlineHash.ToLower() == "installonly" && File.Exists(Path.Combine(modPath, filePath))) { continue; } if (pInformation.Update.FileHashes.ContainsKey(filePath)) { string localHash = pInformation.Update.FileHashes[filePath]; if (onlineHash.ToLower() != localHash.ToLower() || !File.Exists(Path.Combine(modPath, filePath))) { string updateurl = $"{pInformation.Update.UpdateUrl}/{filePath}"; string outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync(updateurl, outputPath, filePath))) { return(false); } } } else { string updateurl = $"{pInformation.Update.UpdateUrl}/{filePath}"; string outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync(updateurl, outputPath, filePath))) { return(false); } } } return(await DownloadFileAsync($"{pInformation.Update.UpdateUrl}/module.json", Path.Combine(modPath, "module.json"), "module.json")); }
public static bool IsVersionOk(string minimumVersion) => Hunterpie.AssemblyVersion >= Hunterpie.ParseVersion(minimumVersion);
public static async Task <UpdateResult> UpdateAllFiles(PluginInformation pInformation, string modPath) { string onlineSerializedInformation = await ReadOnlineModuleJson(pInformation.Update.UpdateUrl); if (onlineSerializedInformation is null) { //Debugger.Error($"Failed to update plugin: {pInformation.Name}!"); return(UpdateResult.Failed); } PluginInformation onlineInformation = JsonConvert.DeserializeObject <PluginInformation>(onlineSerializedInformation); if (!(Hunterpie.AssemblyVersion >= Hunterpie.ParseVersion(onlineInformation.Update.MinimumVersion))) { Debugger.Warn($"Newest version of {pInformation.Name} requires HunterPie v{onlineInformation.Update.MinimumVersion}!"); return(UpdateResult.Skipped); } UpdateResult result = UpdateResult.UpToDate; foreach (string filePath in onlineInformation.Update.FileHashes.Keys) { string onlineHash = onlineInformation.Update.FileHashes[filePath]; if (onlineHash.ToLower() == "installonly" && File.Exists(Path.Combine(modPath, filePath))) { continue; } if (pInformation.Update.FileHashes.ContainsKey(filePath)) { string localHash = pInformation.Update.FileHashes[filePath]; if (onlineHash.ToLower() != localHash.ToLower() || !File.Exists(Path.Combine(modPath, filePath))) { string updateurl = $"{pInformation.Update.UpdateUrl}/{filePath}"; string outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync(updateurl, outputPath, filePath))) { return(UpdateResult.Failed); } result = UpdateResult.Updated; } } else { string updateurl = $"{pInformation.Update.UpdateUrl}/{filePath}"; string outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync(updateurl, outputPath, filePath))) { return(UpdateResult.Failed); } result = UpdateResult.Updated; } } return(await DownloadFileAsync($"{pInformation.Update.UpdateUrl}/module.json", Path.Combine(modPath, "module.json"), "module.json") ? result : UpdateResult.Failed); }