internal static void LoadRecipes() { try { XmlDocument document = new XmlDocument(); document.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HunterPie.Resources/Data/CraftingData.xml")); XmlNodeList items = document.SelectNodes("//Crafting/Item"); IEnumerable <Recipe> recipes = items.Cast <XmlNode>() .Select(node => XmlNodeToRecipe(node)); foreach (Recipe recipe in recipes) { AddNewRecipe(recipe.OutputId, recipe); } Debugger.Warn($"Loaded {recipes.Count()} different item crafting recipes!"); document = null; } catch (Exception err) { Debugger.Error($"Failed to load crafting data.\n{err}"); } }
public async void Delete() { try { if (plugin.IsFailed) { // if plugin loading failed, it can already been loaded into AppDomain, so it isn't safe to delete it right away // because dll's may be in use PluginManager.MarkForRemoval(InternalName); } else if (plugin.IsLoaded && plugin.Package.HasValue) { // begin plugin toggle process in other thread await pluginToggleTask; pluginToggleTask = SetPluginEnabled(false); await pluginToggleTask.ConfigureAwait(false); // NOTE: synchronisation might be helpful here, but I don't anticipate multiple calls to this method // in short succession, so it is kept simpler PluginManager.MarkForRemoval(InternalName); } else { try { PluginManager.DeleteNonPreloadedPlugin(InternalName); } catch (Exception ex) { Dispatch(() => MessageBox.Show(ex.Message)); Debugger.Warn(ex); PluginManager.MarkForRemoval(InternalName); } } Dispatch(() => { pluginList.UpdatePluginsArrangement(); OnPropertyChanged(nameof(IsEnabled)); }); } catch (Exception ex) { Dispatch(() => MessageBox.Show(ex.Message)); } }
internal static void LoadRecipes() { try { XmlDocument document = new XmlDocument(); document.Load(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HunterPie.Resources/Data/CraftingData.xml")); XmlNodeList items = document.SelectNodes("//Crafting/Item"); list = items.Cast <XmlNode>() .Select(node => XmlNodeToRecipe(node)) .ToDictionary(m => m.OutputId); Debugger.Warn("Loaded crafting data!"); document = null; } catch (Exception err) { Debugger.Error($"Failed to load crafting data.\n{err}"); } }
public static async Task <UpdateResult> UpdateAllFiles(PluginInformation pInformation, string modPath) { var updateUrl = await PluginRegistryService.Instance.GetModuleUpdateUrl(pInformation); string onlineSerializedInformation = await ReadOnlineModuleJson(updateUrl); if (onlineSerializedInformation is null) { //Debugger.Error($"Failed to update plugin: {pInformation.Name}!"); return(UpdateResult.Failed); } PluginInformation onlineInformation = JsonConvert.DeserializeObject <PluginInformation>(onlineSerializedInformation); if (!IsVersionOk(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 outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync($"{updateUrl}/{filePath}", outputPath, filePath))) { return(UpdateResult.Failed); } result = UpdateResult.Updated; } } else { string outputPath = Path.Combine(modPath, filePath); if (!(await DownloadFileAsync($"{updateUrl}/{filePath}", outputPath, filePath))) { return(UpdateResult.Failed); } result = UpdateResult.Updated; } } return(await DownloadFileAsync($"{updateUrl}/module.json", Path.Combine(modPath, "module.json"), "module.json") ? result : UpdateResult.Failed); }