示例#1
0
        private static void ApplyFixes(SongBrowserSettings settings)
        {
            if (String.Equals(settings.currentLevelPackId, "CustomMaps"))
            {
                settings.currentLevelPackId = "ModdedCustomMaps";
            }

            settings.Save();
        }
        /// <summary>
        /// Load the settings file for this plugin.
        /// If we fail to load return Default settings.
        /// </summary>
        /// <returns>SongBrowserSettings</returns>
        public static SongBrowserSettings Load()
        {
            Logger.Trace("Load()");
            SongBrowserSettings retVal = null;

            // No Settings file.
            String settingsFilePath = SongBrowserSettings.SettingsPath();

            if (File.Exists(settingsFilePath))
            {
                // Deserialization from JSON
                FileStream fs = null;
                try
                {
                    fs = File.OpenRead(settingsFilePath);
                    XmlSerializer serializer = new XmlSerializer(typeof(SongBrowserSettings));
                    retVal = (SongBrowserSettings)serializer.Deserialize(fs);

                    // Success loading, sane time to make a backup
                    retVal.SaveBackup();
                }
                catch (Exception e)
                {
                    Logger.Exception("Unable to deserialize song browser settings file, using default settings: ", e);
                    retVal = new SongBrowserSettings
                    {
                        DisableSavingSettings = true
                    };
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
            else
            {
                Logger.Debug("Settings file does not exist, returning defaults: " + settingsFilePath);
                retVal = new SongBrowserSettings();
            }

            // check if the playlist directory exists, make it otherwise.
            String playlistDirPath = Path.Combine(Environment.CurrentDirectory, "Playlists");

            if (!Directory.Exists(playlistDirPath))
            {
                Directory.CreateDirectory(playlistDirPath);
            }

            MigrateFavorites();
            ApplyFixes(retVal);

            return(retVal);
        }
        /// <summary>
        /// Fix potential breakages in settings.
        /// </summary>
        /// <param name="settings"></param>
        private static void ApplyFixes(SongBrowserSettings settings)
        {
            if (String.Equals(settings.currentLevelPackId, "CustomMaps"))
            {
                settings.currentLevelPackId = "ModdedCustomMaps";
            }
            else if (String.Equals(settings.currentLevelPackId, "ModdedCustomMaps"))
            {
                settings.currentLevelPackId = SongBrowserSettings.CUSTOM_SONG_LEVEL_PACK_ID;
            }

            settings.Save();
        }
        /// <summary>
        /// Fix potential breakages in settings.
        /// </summary>
        /// <param name="settings"></param>
        private static void ApplyFixes(SongBrowserSettings settings)
        {
            if (String.Equals(settings.currentLevelCollectionName, "CustomMaps"))
            {
                settings.currentLevelCollectionName = "ModdedCustomMaps";
            }
            else if (String.Equals(settings.currentLevelCollectionName, "ModdedCustomMaps"))
            {
                settings.currentLevelCollectionName = SongBrowserSettings.CUSTOM_SONGS_LEVEL_COLLECTION_NAME;
            }

            settings.Save();
        }
 /// <summary>
 /// Save a backup.
 /// </summary>
 public void SaveBackup()
 {
     this._Save(SongBrowserSettings.SettingsBackupPath());
 }
 /// <summary>
 /// Save this Settings insance to file.
 /// </summary>
 public void Save()
 {
     this._Save(SongBrowserSettings.SettingsPath());
 }
        /// <summary>
        /// Load the settings file for this plugin.
        /// If we fail to load return Default settings.
        /// </summary>
        /// <returns>SongBrowserSettings</returns>
        public static SongBrowserSettings Load()
        {
            Logger.Trace("Load()");
            SongBrowserSettings retVal = null;

            // No Settings file.
            String settingsFilePath = SongBrowserSettings.SettingsPath();

            if (File.Exists(settingsFilePath))
            {
                // Deserialization from JSON
                FileStream fs = null;
                try
                {
                    fs = File.OpenRead(settingsFilePath);
                    XmlSerializer serializer = new XmlSerializer(typeof(SongBrowserSettings));
                    retVal = (SongBrowserSettings)serializer.Deserialize(fs);

                    // Success loading, sane time to make a backup
                    retVal.SaveBackup();
                }
                catch (Exception e)
                {
                    Logger.Exception("Unable to deserialize song browser settings file, using default settings: ", e);
                    retVal = new SongBrowserSettings
                    {
                        DisableSavingSettings = true
                    };
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
            }
            else
            {
                Logger.Debug("Settings file does not exist, returning defaults: " + settingsFilePath);
                retVal = new SongBrowserSettings();
            }

            // check if the playlist directory exists, make it otherwise.
            String playlistDirPath = Path.Combine(Environment.CurrentDirectory, "Playlists");

            if (!Directory.Exists(playlistDirPath))
            {
                Directory.CreateDirectory(playlistDirPath);
            }

            // Load Downloader favorites but only once, we'll convert them once, empty the song_browser_setting.xml favorites and never load it again.
            String playlistPath = Path.Combine(Environment.CurrentDirectory, "Playlists", DefaultConvertedFavoritesPlaylistName);

            if (!File.Exists(playlistPath))
            {
                if (File.Exists(SongBrowserSettings.DownloaderFavoritesFilePath()))
                {
                    String[] downloaderFavorites = File.ReadAllLines(SongBrowserSettings.DownloaderFavoritesFilePath());
                    retVal.Favorites.UnionWith(downloaderFavorites);
                }

                Playlist p = new Playlist
                {
                    playlistTitle  = "Song Browser Favorites",
                    playlistAuthor = "SongBrowser",
                    fileLoc        = "",
                    image          = Base64Sprites.PlaylistIconB64,
                    songs          = new List <PlaylistSong>(),
                };
                p.CreateNew(playlistPath);
            }

            if (String.IsNullOrEmpty(retVal.currentEditingPlaylistFile))
            {
                retVal.currentEditingPlaylistFile = playlistPath;
            }


            return(retVal);
        }