public virtual T Load <T, U>(IExposedMod mod) where T : U, new()
            {
                ModEntry modEntry = mod as ModEntry;
                var      t        = new T();
                var      filepath = GetSettingsPath(modEntry);

                if (File.Exists(filepath))
                {
                    try
                    {
                        using (var stream = File.OpenRead(filepath))
                        {
                            var serializer = new XmlSerializer(typeof(T));
                            var result     = (T)serializer.Deserialize(stream);
                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        LoggerDelegates.LogError($"Can't read {filepath}.", e);
                    }
                }

                return(t);
            }
Exemple #2
0
        public bool ParseManifest(string strManifestPath)
        {
            string dirPath  = Path.GetDirectoryName(strManifestPath);
            string fileName = Path.GetFileName(strManifestPath);

            try
            {
                if (!File.Exists(strManifestPath))
                {
                    fileName        = fileName.ToLower();
                    strManifestPath = Path.Combine(dirPath, fileName);
                }
                string  json    = File.ReadAllText(strManifestPath);
                UMMData modData = JsonConvert.DeserializeObject <UMMData>(json);
                if (modData.Base_Id != null)
                {
                    AssignBaseData(modData);
                    m_strAssemblyName = modData.AssemblyName;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception exc) {
                bool isParserError = (exc is JsonException) ? true : false;
                if (!isParserError)
                {
                    LoggerDelegates.LogError("Failed to parse mod data", exc);
                }

                return(false);
            }
        }
Exemple #3
0
 public static void LoadVortexUI(List <IExposedMod> exposedMods)
 {
     try
     {
         VortexUI.Load(exposedMods);
     }
     catch (Exception exc)
     {
         LoggerDelegates.LogError(exc);
     }
 }
Exemple #4
0
        public static ModEntry FindMod(string id)
        {
            IExposedMod mod = BaseModType.ExposedMods
                              .Where(entry => ((entry as ModEntry) != null) && (entry.GetModName() == id))
                              .SingleOrDefault();

            if (mod == null)
            {
                LoggerDelegates.LogError($"Unable to find mod: {id}");
            }

            return(mod as ModEntry);
        }
 static public void TryDelete(string strFilePath)
 {
     if (!File.Exists(strFilePath))
     {
         return; // No file, no problems.
     }
     try
     {
         File.Delete(strFilePath);
     }
     catch (Exception e)
     {
         LoggerDelegates.LogError("Unable to delete file", e);
         return;
     }
 }
            public static void Save <T>(T data, ModEntry mod) where T : ModSettings, new()
            {
                var filepath = data.GetSettingsPath(mod);

                try
                {
                    using (var writer = new StreamWriter(filepath))
                    {
                        var serializer = new XmlSerializer(typeof(T));
                        serializer.Serialize(writer, data);
                    }
                }
                catch (Exception e)
                {
                    LoggerDelegates.LogError($"Can't save {filepath}.", e);
                }
            }
Exemple #7
0
        public T Load <T, U>(IExposedMod mod) where T : U, new()
        {
            string strSettingsPath = GetSettingsPath(mod);

            if (File.Exists(strSettingsPath))
            {
                try
                {
                    T deserialized = JsonConvert.DeserializeObject <T>(strSettingsPath);
                    return(deserialized);
                }
                catch (Exception e)
                {
                    LoggerDelegates.LogError($"Can't read {strSettingsPath}.", e);
                }
            }

            return(new T());
        }
Exemple #8
0
        public static T Load <T>(VortexMod mod) where T : VortexModSettings, new()
        {
            T      t = new T();
            string strSettingsPath = t.GetSettingsPath(mod);

            if (File.Exists(strSettingsPath))
            {
                try
                {
                    string fileContents = File.ReadAllText(strSettingsPath);
                    T      deserialized = JsonConvert.DeserializeObject <T>(fileContents);
                    return(deserialized);
                }
                catch (Exception e)
                {
                    LoggerDelegates.LogError($"Can't read {strSettingsPath}.", e);
                }
            }

            return(t);
        }
            public static T Load <T>(ModEntry modEntry) where T : ModSettings, new()
            {
                var t        = new T();
                var filepath = t.GetSettingsPath(modEntry);

                if (File.Exists(filepath))
                {
                    try
                    {
                        using (var stream = File.OpenRead(filepath))
                        {
                            var serializer = new XmlSerializer(typeof(T));
                            var result     = (T)serializer.Deserialize(stream);
                            return(result);
                        }
                    }
                    catch (Exception e)
                    {
                        LoggerDelegates.LogError($"Can't read {filepath}.", e);
                    }
                }

                return(t);
            }
Exemple #10
0
 public void Critical(string str)
 {
     LoggerDelegates.LogError(m_modId + str);
 }
Exemple #11
0
 public void LogException(Exception e)
 {
     LoggerDelegates.LogError(m_modId, e);
 }
Exemple #12
0
 public void LogException(string key, Exception e)
 {
     LoggerDelegates.LogError(m_modId + key, e);
 }