Exemple #1
0
 /** Loads item from store, throws error if not found. */
 private T loadFromStore <T>(string key) where T : DataObject
 {
     if (StateStorage.HasData(key))
     {
         return(StateStorage.LoadData <T>(key));
     }
     else
     {
         throw new Exception(String.Format("Error reading from save file, expecting file {0} but it wasn't found.", key));
     }
 }
Exemple #2
0
 /** Loads item from store, or creates a new default instance if not found. */
 private T loadFromStoreDefault <T>(string key) where T : DataObject, new()
 {
     if (StateStorage.HasData(key))
     {
         return(StateStorage.LoadData <T>(key));
     }
     else
     {
         return(new T());
     }
 }
Exemple #3
0
 /** Returns true only if all the requied static game files are present.  */
 public static bool HasAllStaticData()
 {
     foreach (var file in RequiredStaticData)
     {
         if (!StateStorage.HasData(file))
         {
             Trace.LogDebug("Missing file {0}", file);
             return(false);
         }
     }
     return(true);
 }
Exemple #4
0
    /**
     * Loads a file from storage and returns it.
     * Provides validiation and logging.
     * If the type is a library the library will be set as the global library for that type.
     * If min version is set an exception will be thrown if data doesn't meet minimum version.
     */
    private static T LoadData <T>(string source, float minVersion = 0.0f, bool silent = false) where T : DataObject
    {
        if (!StateStorage.HasData(source))
        {
            throw new Exception("Source not found [" + source + "]");
        }

        T result = StateStorage.LoadData <T>(source);

        if (result.Version < minVersion)
        {
            throw new Exception(String.Format("File {0} has an old version, expecting {1} but found {2}", source, minVersion, result.Version));
        }

        if (!silent)
        {
            Trace.Log(" - Loaded [" + source + "] (v" + result.Version.ToString("0.0") + ")");
        }

        return(result);
    }
Exemple #5
0
    /** Reads all settings from XML file */
    public static void ReadSettings()
    {
        bool hasSettingsFile = StateStorage.HasData("Settings");

        General     = new GeneralSettings();
        Advanced    = new AdvancedSettings();
        Information = new InformationSettings();

        try {
            if (hasSettingsFile)
            {
                XElement rootNode = StateStorage.LoadXML("Settings");
                if (rootNode == null)
                {
                    Trace.LogWarning("No settings in file, resetting to default");
                    ResetSettings();
                }
                else
                {
                    Trace.Log("Reading settings");
                    General.Load(rootNode.Element("General"));
                    Advanced.Load(rootNode.Element("Advanced"));
                }
            }
            else
            {
                Trace.Log("No settings file present, setting to default");
                ResetSettings();
            }
        } catch (Exception e) {
            Trace.LogWarning("Error while reading settings file:" + e.Message);
            ResetSettings();
        }

        IsLoaded = true;
    }