public void SaveSetting(string settingName, string value) { if (File.Exists(m_pathToSettings) == false) { FactorioXmlHelper.CreateXml(m_pathToSettings, XmlMainElement); } XDocument settings = XDocument.Load(m_pathToSettings); settings.Element(settingName).FirstAttribute.SetValue(value); }
public string LoadSetting(string settingName) { if (File.Exists(m_pathToSettings) == false) { FactorioXmlHelper.CreateXml(m_pathToSettings, XmlMainElement); } XDocument settings = XDocument.Load(m_pathToSettings); if (settings.Element(settingName).FirstAttribute == null) { FactorioXmlHelper.AddAttribute(m_pathToSettings, settingName); } return(settings.Element(settingName).FirstAttribute.ToString()); }
public ObservableCollection <FactorioItem> ReadItems(string path) { // Contains all items that are currently known var knownItems = new List <FactorioItem>(); // Contains items that are found in recipes but aren't loaded yet var unknownItems = new List <FactorioItem>(); try { // Check if file exists, create one if it doesn't if (!File.Exists(path)) { Directory.CreateDirectory(Path.GetDirectoryName(path)); FactorioXmlHelper.CreateXml(path, XmlMainElement); } XDocument itemsFile = XDocument.Load(path); foreach (var xmlItemData in itemsFile.Descendants(XmlItemElement)) { FactorioItem newItem = GetFactorioItemFromXmlData(xmlItemData, knownItems, unknownItems); knownItems.Add(newItem); TryAddRecipeData(newItem, xmlItemData, knownItems, unknownItems); } } catch (FactorioException) { // pass through throw; } catch (Exception ex) { // create a new exception to add the event code throw new FactorioException(DiagnosticEvents.DalXmlRead, "An error occurred while reading a xml file with the message: " + ex.Message, ex); } return(new ObservableCollection <FactorioItem>(knownItems)); }