public static void SavePresetCollection(this IEnumerable <Presence> presences, string presetCollectionName,
                                                int active, bool minify, SaveLocations location, string path = null)
        {
            var json = JsonSerializer.Serialize(new PresetCollection
            {
                Presences = presences.ToArray(),
                Active    = active
            }, new JsonSerializerOptions
            {
                WriteIndented = !minify
            });
            var appDataRoot = BuildSavePath(location, path);
            var saveFolder  = Path.Combine(appDataRoot, "Saved Preset Collections");
            var fileName    = Path.Combine(saveFolder, presetCollectionName + ".json");

            Directory.CreateDirectory(saveFolder);

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            var sw = File.CreateText(fileName);

            sw.Write(json);
            sw.Dispose();
        }
Esempio n. 2
0
 public void addSaveLocation(string path)
 {
     if (!this.hasLocation(path))
     {
         SaveLocation location = new SaveLocation(path);
         SaveLocations.Add(location);
     }
 }
        public static string[] GetPresetCollections(SaveLocations location, string path = null)
        {
            var appDataRoot = BuildSavePath(location, path);
            var saveFolder  = Path.Combine(appDataRoot, "Saved Preset Collections");

            return(Directory.Exists(saveFolder)
                                       ? new DirectoryInfo(saveFolder).EnumerateFiles().Select(f => f.Name.Split('.')[0]).ToArray()
                                       : Array.Empty <string>());
        }
Esempio n. 4
0
        internal void setDefaultSaveLocation(SaveLocation selected)
        {
            SaveLocation oldDefault = this.getDefaultLocation();

            if (oldDefault != null)
            {
                oldDefault.IsDefaultLocation = false;
            }

            int          newLocationIndex = SaveLocations.IndexOf(selected);
            SaveLocation newDefault       = SaveLocations[newLocationIndex];

            newDefault.IsDefaultLocation = true;
        }
        public static void SaveOptions(Options options, bool minify, SaveLocations location)
        {
            if (location == SaveLocations.Custom)
            {
                location = SaveLocations.Portable;
            }

            var appDataRoot = BuildSavePath(location);
            var filePath    = Path.Combine(appDataRoot, "settings.json");
            var json        = JsonSerializer.Serialize(options, new JsonSerializerOptions {
                WriteIndented = !minify
            });

            Directory.CreateDirectory(appDataRoot);
            File.WriteAllText(filePath, json);
        }
        private static string BuildSavePath(SaveLocations location, string customDir = null)
        {
            var relativePath = "Cain Atkinson/Discord Rich Presence Presets";

            return(location switch
            {
                SaveLocations.Appdata =>
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), relativePath),
                SaveLocations.Portable =>
                Path.Combine(Environment.CurrentDirectory, "data"),
                SaveLocations.Documents =>
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), relativePath),
                SaveLocations.Custom =>
                customDir ?? throw new ArgumentException("Custom dir was null", nameof(customDir)),
                _ => throw new ArgumentOutOfRangeException(nameof(location), location, null)
            });
        public static List <Presence> LoadPresetCollection(string presetCollectionName, out int active,
                                                           SaveLocations location, string path = null)
        {
            var appDataRoot = BuildSavePath(location, path);
            var saveFolder  = Path.Combine(appDataRoot, "Saved Preset Collections");
            var fileName    = Path.Combine(saveFolder, presetCollectionName + ".json");

            try
            {
                var json             = File.ReadAllText(fileName);
                var presetCollection = JsonSerializer.Deserialize <PresetCollection>(json);
                // ReSharper disable once PossibleNullReferenceException
                active = presetCollection.Active;
                return(presetCollection.Presences.ToList());
            }
            catch (Exception)
            {
                active = 0;
                return(new List <Presence>());
            }
        }
Esempio n. 8
0
 public bool hasLocation(string path)
 {
     return(SaveLocations.Find(location => location.Path == path) != null);
 }
Esempio n. 9
0
 public void removeSaveLocation(SaveLocation location)
 {
     SaveLocations.Remove(location);
 }
Esempio n. 10
0
        public SaveLocation getDefaultLocation()
        {
            SaveLocation oldDefault = SaveLocations.Find(location => location.IsDefaultLocation);

            return(oldDefault);
        }