src/GlobalSettings.cs
/// <summary>
/// Creates a singleton settings object and loads parameters from file, if it exists.
/// </summary>
Creates a singleton settings object and loads parameters from file, if it exists.
Creates a singleton settings object and loads parameters from file if it exists .
public static void GlobalSettingsInit()
        {
            Settings = new GlobalSettings();
            appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            settingsFN = Path.Combine(appDataPath, "furdown\\furdown.conf");
            if (File.Exists("./furdown-portable.conf"))
            {
                settingsFN = "./furdown-portable.conf";
            }
            bool needToSetDefaults = false;
            if (File.Exists(settingsFN))
            {
                using (Stream stream = File.Open(settingsFN, FileMode.Open))
                {
                    var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    try
                    {
                        Settings = (GlobalSettings)bformatter.Deserialize(stream);
                    }
                    catch
                    {
                        needToSetDefaults = true;
                        Console.WriteLine("Settings file is incompatible or corrupted, restoring defaults.");
                    }
                }
            }
            else
            {
                needToSetDefaults = true;
            }
            if (needToSetDefaults)
            {
                Settings.downloadPath = Path.Combine(appDataPath, "furdown\\downloads");
                Settings.systemPath = Path.Combine(appDataPath, "furdown\\system");
                Settings.filenameTemplate = "%ARTIST%%SCRAPS%\\%SUBMID%.%FILEPART%";
                Settings.descrFilenameTemplate = "%ARTIST%%SCRAPS%\\%SUBMID%.%FILEPART%.dsc.htm";
                Settings.downloadOnlyOnce = true;
                Settings.scrapsTemplateActive = ".scraps";
                Settings.scrapsTemplateActive = "";
                try
                {
                    Directory.CreateDirectory(Settings.downloadPath);
                    Directory.CreateDirectory(Settings.systemPath);
                }
                catch
                {
                    Console.WriteLine("[Error] Default paths are invalid!");
                }
            }
            else
            {
                if (!Directory.Exists(Settings.downloadPath))
                    Directory.CreateDirectory(Settings.downloadPath);
                if (!Directory.Exists(Settings.systemPath))
                    Directory.CreateDirectory(Settings.systemPath);
            }
            SubmissionsDB.Load();
        }
public static void GlobalSettingsInit ( ) { Settings = new GlobalSettings ( ) ; appDataPath = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) ; settingsFN = Path . Combine ( appDataPath , " \\ " ) ; if ( File . Exists ( " " ) ) { settingsFN = " " ; } bool needToSetDefaults = false ; if ( File . Exists ( settingsFN ) ) { using ( Stream stream = File . Open ( settingsFN , FileMode . Open ) ) { var bformatter = new System . Runtime . Serialization . Formatters . Binary . BinaryFormatter ( ) ; try { Settings = ( GlobalSettings ) bformatter . Deserialize ( stream ) ; } catch { needToSetDefaults = true ; Console . WriteLine ( " " ) ; } } } else { needToSetDefaults = true ; } if ( needToSetDefaults ) { Settings . downloadPath = Path . Combine ( appDataPath , " \\ " ) ; Settings . systemPath = Path . Combine ( appDataPath , " \\ " ) ; Settings . filenameTemplate = " \\ " ; Settings . descrFilenameTemplate = " \\ " ; Settings . downloadOnlyOnce = true ; Settings . scrapsTemplateActive = " " ; Settings . scrapsTemplateActive = " " ; try { Directory . CreateDirectory ( Settings . downloadPath ) ; Directory . CreateDirectory ( Settings . systemPath ) ; } catch { Console . WriteLine ( " " ) ; } } else { if ( ! Directory . Exists ( Settings . downloadPath ) ) Directory . CreateDirectory ( Settings . downloadPath ) ; if ( ! Directory . Exists ( Settings . systemPath ) ) Directory . CreateDirectory ( Settings . systemPath ) ; } SubmissionsDB . Load ( ) ; }
Creates a singleton settings object and loads parameters from file, if it exists.
Creates a singleton settings object and loads parameters from file if it exists .
// true portable mode // if settings file exists, load it // settings file is present, but failed to be loaded // set defaults, if settings file does not exist or otherwise not loaded