예제 #1
0
        public static bool SaveSettings(Shrek2MMSettings settings)
        {
            try
            {
                Shrek2Utils.EnsureDataFolderExists();

                var json = SettingsToJSON(settings);
                File.WriteAllText(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_SETTINGS), json);
                return(true);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }
예제 #2
0
        public static bool SaveMods(List <Shrek2ModListItem> items)
        {
            try
            {
                Shrek2Utils.EnsureDataFolderExists();

                var json = ListToJSON(items);
                File.WriteAllText(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_ADDED_MODS), json);
                return(true);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }
예제 #3
0
        public static List <Shrek2ModListItem>?LoadMods()
        {
            try
            {
                Shrek2Utils.EnsureDataFolderExists();

                if (File.Exists(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_ADDED_MODS)) == false)
                {
                    return(new List <Shrek2ModListItem>());
                }

                var json = File.ReadAllText(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_ADDED_MODS));
                return(JSONToList(json));
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(null);
            }
        }
예제 #4
0
        public static Shrek2MMSettings?LoadSettings()
        {
            try
            {
                Shrek2Utils.EnsureDataFolderExists();

                if (File.Exists(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_SETTINGS)) == false)
                {
                    return(new Shrek2MMSettings());
                }

                var json = File.ReadAllText(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_SETTINGS));
                return(JSONToSettings(json));
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(null);
            }
        }
예제 #5
0
        public static async Task <bool> ExtractModLoader()
        {
            try
            {
                Shrek2Utils.EnsureDataFolderExists();

                var assembly     = Assembly.GetExecutingAssembly();
                var resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(Shrek2Utils.SHREK2MM_FILE_MOD_LOADER_ZIP));

                if (string.IsNullOrEmpty(resourceName))
                {
                    return(false);
                }

                using (var resStream = assembly.GetManifestResourceStream(resourceName))
                {
                    var ms = new MemoryStream();

                    if (resStream != null)
                    {
                        await resStream.CopyToAsync(ms);

                        var bytes = ms.ToArray();

                        File.WriteAllBytes(Path.Combine(Shrek2Utils.GetDataFolderPath(), Shrek2Utils.SHREK2MM_FILE_MOD_LOADER_ZIP), bytes);

                        return(true);
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                Shrek2Utils.LogError(ex);
                return(false);
            }
        }