public virtual void Load() { if (!_file.Exists()) { Save(); } Instance = _file.ReadObject <Type>(); if (Instance == null) { Instance = Activator.CreateInstance <Type>(); Save(); } }
public DynamicConfigFile GetDatafile(string name) { DynamicConfigFile file = this.GetFile(name); if (!file.Exists(null)) { file.Save(null); } else { file.Load(null); } return(file); }
/// <summary> /// Loads the config file for this plugin /// </summary> protected virtual void LoadConfig() { Config = new DynamicConfigFile(Path.Combine(Manager.ConfigPath, $"{Name}.json")); if (!Config.Exists()) { LoadDefaultConfig(); SaveConfig(); } try { Config.Load(); } catch (Exception ex) { RaiseError($"Failed to load config file (is the config file corrupt?) ({ex.Message})"); } }
/// <summary> /// Gets a datafile /// </summary> /// <param name="name"></param> /// <returns></returns> public DynamicConfigFile GetDatafile(string name) { DynamicConfigFile datafile = GetFile(name); // Does it exist? if (datafile.Exists()) { // Load it datafile.Load(); } else { // Just make a new one datafile.Save(); } return(datafile); }
/// <summary> /// Loads the config file for this plugin /// </summary> protected virtual void LoadConfig() { Config = new DynamicConfigFile(Path.Combine(Manager.ConfigPath, string.Format("{0}.json", Name))); if (Config.Exists()) { try { Config.Load(); } catch (Exception ex) { RaiseError(string.Format("Failed to load config file (is the config file corrupt?) ({0})", ex.Message)); } } else { LoadDefaultConfig(); SaveConfig(); } }
public virtual void Load() { if (Compressed) { LoadCompressed(); return; } if (!_file.Exists()) { Save(); } Instance = _file.ReadObject <Type>(); if (Instance == null) { Instance = Activator.CreateInstance <Type>(); Save(); } return; }
protected override void LoadConfig() { string path = $"{Manager.ConfigPath}/MagicPanel/{Name}.json"; DynamicConfigFile newConfig = new DynamicConfigFile(path); if (!newConfig.Exists()) { LoadDefaultConfig(); newConfig.Save(); } try { newConfig.Load(); } catch (Exception ex) { RaiseError("Failed to load config file (is the config file corrupt?) (" + ex.Message + ")"); return; } newConfig.Settings.DefaultValueHandling = DefaultValueHandling.Populate; _pluginConfig = AdditionalConfig(newConfig.ReadObject <PluginConfig>()); newConfig.WriteObject(_pluginConfig); }
void OnServerInitialized() { if (init) { return; } ins = this; LoadMessages(); LoadVariables(); explosionsFile = Interface.Oxide.DataFileSystem.GetFile("RaidTracker"); try { if (explosionsFile.Exists()) { dataExplosions = explosionsFile.ReadObject <List <Dictionary <string, string> > >(); } } catch { } if (dataExplosions == null) { dataExplosions = new List <Dictionary <string, string> >(); explosionsLogChanged = true; } if (wipeData && automateWipes) { int entries = dataExplosions.Count; dataExplosions.Clear(); explosionsLogChanged = true; wipeData = false; SaveExplosionData(); Puts("Wipe detected; wiped {0} entries.", entries); } if (dataExplosions.Count > 0) { foreach (var dict in dataExplosions.ToList()) { if (dict.ContainsKey(szDeleteDate)) // apply retroactive changes { if (applyInactiveChanges) { if (daysBeforeDelete > 0 && dict[szDeleteDate] == DateTime.MinValue.ToString()) { dict[szDeleteDate] = DateTime.UtcNow.AddDays(daysBeforeDelete).ToString(); explosionsLogChanged = true; } if (daysBeforeDelete == 0 && dict[szDeleteDate] != DateTime.MinValue.ToString()) { dict[szDeleteDate] = DateTime.MinValue.ToString(); explosionsLogChanged = true; } } if (applyActiveChanges && daysBeforeDelete > 0 && dict.ContainsKey(szLoggedDate)) { var deleteDate = DateTime.Parse(dict[szDeleteDate]); var loggedDate = DateTime.Parse(dict[szLoggedDate]); int days = deleteDate.Subtract(loggedDate).Days; if (days != daysBeforeDelete) { int daysLeft = deleteDate.Subtract(DateTime.UtcNow).Days; if (daysLeft > daysBeforeDelete) { dict[szDeleteDate] = loggedDate.AddDays(daysBeforeDelete).ToString(); explosionsLogChanged = true; } } } } else { dict.Add(szDeleteDate, daysBeforeDelete > 0 ? DateTime.UtcNow.AddDays(daysBeforeDelete).ToString() : DateTime.MinValue.ToString()); explosionsLogChanged = true; } } } init = true; }