示例#1
0
        public static LSSettings load()
        {
            Logger.app.a("Loading LSSettings");
            LSSettings ret;
            XmlSerializer x = new XmlSerializer(typeof(LSSettings));
            if (System.IO.File.Exists("Loopstream.ini"))
            {
                Logger.app.a("Found existing .ini");
                try
                {
                    string str = System.IO.File.ReadAllText("Loopstream.ini", Encoding.UTF8);
                    string ver = str.Substring(0, str.IndexOf('\n'));
                    str = str.Substring(ver.Length + 1);
                    System.IO.MemoryStream s = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(str));

                    int myVer = version();
                    int iniVer = Convert.ToInt32(ver, 16);
                    //if (myVer != iniVer)
                    if (iniVer < 0x01020600)
                    {
                        byte[] bver = BitConverter.GetBytes(iniVer);
                        Array.Reverse(bver);
                        System.Windows.Forms.MessageBox.Show(
                            "Your configuration file is from version " + BitConverter.ToString(bver) + ", which is rather old.\n\n" +
                            "Don't get your hopes up but I'll try to load it...",
                            "Incompatible config file",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    //using (var s = System.IO.File.OpenRead("Loopstream.ini"))
                    {
                        ret = (LSSettings)x.Deserialize(s);
                        //
                        //  Upgrade from v1.2.8.0:
                        //     xRec xMic lim_poor lim_drop
                        //
                        //  Upgrade from v1.3.7.7:
                        //     yRec yMic
                        //
                        if (ret.mixer.xRec < 1) ret.mixer.xRec = 1;
                        if (ret.mixer.xMic < 1) ret.mixer.xMic = 1;
                        if (ret.mixer.yRec < 1) ret.mixer.yRec = -1;
                        if (ret.mixer.yMic < 1) ret.mixer.yMic = -1;
                        foreach (LSSettings.LSPreset pre in ret.presets)
                        {
                            if (pre.xRec < 1) pre.xRec = 1;
                            if (pre.xMic < 1) pre.xMic = 1;
                            if (pre.yRec < 1) pre.yRec = -1;
                            if (pre.yMic < 1) pre.yMic = -1;
                        }
                        if (ret.lim_drop_DEPRECATED <= 0 || ret.lim_poor_DEPRECATED <= 0)
                        {
                            ret.warn_poor_DEPRECATED = ret.warn_drop_DEPRECATED = true;
                            ret.lim_poor_DEPRECATED = 0.9;
                            ret.lim_drop_DEPRECATED = 0.6;
                        }
                        if (ret.reverbS <= 0) ret.reverbS = 90;
                        if (ret.reverbP <= 0) ret.reverbP = 0;
                    }
                }
                catch (Exception e)
                {
                    Logger.app.a("Deserialize failed, fallback to new");
                    ret = new LSSettings();
                    System.Windows.Forms.MessageBox.Show(
                        "Failed to load settings:\n«Loopstream.ini» is probably from an old version of the program.\n\nDetailed information:\n" + e.Message + "\n" + e.StackTrace,
                        "Default settings",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Information);
                }
                try
                {
                    Logger.app.a("Calling init()");
                    ret.init();
                    ret.mp3.FIXME_kbps =
                    ret.ogg.FIXME_kbps = -1;
                    foreach (var v in ret.metas)
                    {
                        if (v.grp != 1)
                        {
                            v.yield = "{" + v.grp + "}";
                            v.grp = 1;
                        }
                    }
                    try
                    {
                        ret.metaDec();
                    }
                    catch { }
                    Logger.app.a("LSSettings deserialize successful");
                    ret.initFinally();
                    return ret;
                }
                catch (Exception e)
                {
                    Logger.app.a("LSSettings deserialize postprocessing failed");
                    System.Windows.Forms.MessageBox.Show(
                        "Failed to initialize settings object:\nPossibly from an outdated version of «Loopstream.ini», though more likely a developer fuckup. Go tell ed this:\n\n" +
                        e.Message + "\n\n" + e.Source + "\n\n" + e.InnerException + "\n\n" + e.StackTrace);
                }
            }
            Logger.app.a("Creating new LSSettings");
            ret = new LSSettings();

            Logger.app.a("LSSettings OK");
            ret.initFinally(); // it is 06:20 am, what are you looking at
            return ret;
        }
示例#2
0
        public static LSSettings load()
        {
            Logger.app.a("Loading LSSettings");
            LSSettings    ret;
            XmlSerializer x = new XmlSerializer(typeof(LSSettings));

            if (System.IO.File.Exists("Loopstream.ini"))
            {
                Logger.app.a("Found existing .ini");
                try
                {
                    string str = System.IO.File.ReadAllText("Loopstream.ini", Encoding.UTF8);
                    string ver = str.Substring(0, str.IndexOf('\n'));
                    str = str.Substring(ver.Length + 1);
                    System.IO.MemoryStream s = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(str));

                    int myVer  = version();
                    int iniVer = Convert.ToInt32(ver, 16);
                    //if (myVer != iniVer)
                    if (iniVer < 0x01020600)
                    {
                        byte[] bver = BitConverter.GetBytes(iniVer);
                        Array.Reverse(bver);
                        System.Windows.Forms.MessageBox.Show(
                            "Your configuration file is from version " + BitConverter.ToString(bver) + ", which is rather old.\n\n" +
                            "Don't get your hopes up but I'll try to load it...",
                            "Incompatible config file",
                            System.Windows.Forms.MessageBoxButtons.OK,
                            System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    //using (var s = System.IO.File.OpenRead("Loopstream.ini"))
                    {
                        ret = (LSSettings)x.Deserialize(s);
                        //
                        //  Upgrade from v1.2.8.0:
                        //     xRec xMic lim_poor lim_drop
                        //
                        //  Upgrade from v1.3.7.7:
                        //     yRec yMic
                        //
                        if (ret.mixer.xRec < 1)
                        {
                            ret.mixer.xRec = 1;
                        }
                        if (ret.mixer.xMic < 1)
                        {
                            ret.mixer.xMic = 1;
                        }
                        if (ret.mixer.yRec < 1)
                        {
                            ret.mixer.yRec = -1;
                        }
                        if (ret.mixer.yMic < 1)
                        {
                            ret.mixer.yMic = -1;
                        }
                        foreach (LSSettings.LSPreset pre in ret.presets)
                        {
                            if (pre.xRec < 1)
                            {
                                pre.xRec = 1;
                            }
                            if (pre.xMic < 1)
                            {
                                pre.xMic = 1;
                            }
                            if (pre.yRec < 1)
                            {
                                pre.yRec = -1;
                            }
                            if (pre.yMic < 1)
                            {
                                pre.yMic = -1;
                            }
                        }
                        if (ret.lim_drop_DEPRECATED <= 0 || ret.lim_poor_DEPRECATED <= 0)
                        {
                            ret.warn_poor_DEPRECATED = ret.warn_drop_DEPRECATED = true;
                            ret.lim_poor_DEPRECATED  = 0.9;
                            ret.lim_drop_DEPRECATED  = 0.6;
                        }
                        if (ret.reverbS <= 0)
                        {
                            ret.reverbS = 90;
                        }
                        if (ret.reverbP <= 0)
                        {
                            ret.reverbP = 0;
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.app.a("Deserialize failed, fallback to new");
                    ret = new LSSettings();
                    System.Windows.Forms.MessageBox.Show(
                        "Failed to load settings:\n«Loopstream.ini» is probably from an old version of the program.\n\nDetailed information:\n" + e.Message + "\n" + e.StackTrace,
                        "Default settings",
                        System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Information);
                }
                try
                {
                    Logger.app.a("Calling init()");
                    ret.init();
                    ret.mp3.FIXME_kbps     =
                        ret.ogg.FIXME_kbps = -1;
                    foreach (var v in ret.metas)
                    {
                        if (v.grp != 1)
                        {
                            v.yield = "{" + v.grp + "}";
                            v.grp   = 1;
                        }
                    }
                    try
                    {
                        ret.metaDec();
                    }
                    catch { }
                    Logger.app.a("LSSettings deserialize successful");
                    ret.initFinally();
                    return(ret);
                }
                catch (Exception e)
                {
                    Logger.app.a("LSSettings deserialize postprocessing failed");
                    System.Windows.Forms.MessageBox.Show(
                        "Failed to initialize settings object:\nPossibly from an outdated version of «Loopstream.ini», though more likely a developer fuckup. Go tell ed this:\n\n" +
                        e.Message + "\n\n" + e.Source + "\n\n" + e.InnerException + "\n\n" + e.StackTrace);
                }
            }
            Logger.app.a("Creating new LSSettings");
            ret = new LSSettings();

            Logger.app.a("LSSettings OK");
            ret.initFinally(); // it is 06:20 am, what are you looking at
            return(ret);
        }