Ejemplo n.º 1
0
        // legacy loading code for transition
        public static bool LoadLegacy()
        {
            var fileName = Shared.PathCombine(Program.BaseDirectoryExternal, ConfigDir, LegacyConfigFile);

            if (File.Exists(fileName))
            {
                try
                {
                    Debug.WriteLine("Loading legacy configuration file");
                    instance = new ConfigIni();

                    var           configLines = File.ReadAllLines(fileName);
                    List <string> list;
                    string        section = "";
                    foreach (var line in configLines)
                    {
                        var l = line.Trim();
                        if (l.StartsWith("[") && l.EndsWith("]"))
                        {
                            section = l.Substring(1, l.Length - 2).ToLower();
                        }
                        int pos = l.IndexOf('=');
                        if (pos <= 0)
                        {
                            continue;
                        }
                        var param = l.Substring(0, pos).Trim();
                        var value = l.Substring(pos + 1).Trim();
                        switch (section)
                        {
                        case "config":
                            param = param.ToLower();
                            switch (param)
                            {
                            case "lastversion":
                                instance.LastVersion = value;
                                break;

                            case "language":
                                instance.Language = value;
                                break;

                            case "selectedgames":
                            case "selectedgamesnes":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.NES].SelectedGames = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                if (instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].SelectedGames.Count == 0)
                                {
                                    instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].SelectedGames = instance.gamesCollectionSettings[hakchi.ConsoleType.NES].SelectedGames.ToList();
                                }
                                break;

                            case "selectedgamesfamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].SelectedGames = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                break;

                            case "selectedgamessnes":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].SelectedGames = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].SelectedGames = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                if (instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].SelectedGames.Count == 0)
                                {
                                    instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].SelectedGames = instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].SelectedGames.ToList();
                                }
                                break;

                            case "selectedgamessuperfamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].SelectedGames = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                break;

                            case "hiddengames":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.NES].OriginalGames = NesApplication.defaultNesGames.Select(game => game.Code).Where(code => !list.Contains(code)).ToList();
                                break;

                            case "hiddengamesfamicom":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].OriginalGames = NesApplication.defaultFamicomGames.Select(game => game.Code).Where(code => !list.Contains(code)).ToList();
                                break;

                            case "hiddengamessnes":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].OriginalGames = NesApplication.defaultSnesGames.Select(game => game.Code).Where(code => !list.Contains(code)).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].OriginalGames = NesApplication.defaultSnesGames.Select(game => game.Code).Where(code => !list.Contains(code)).ToList();
                                break;

                            case "hiddengamessuperfamicom":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].OriginalGames =
                                    NesApplication.defaultSuperFamicomGames.Select(game => game.Code).Where(code => !list.Contains(code)).ToList();
                                break;

                            case "originalgamesposition":
                                instance.OriginalGamesPosition = (MainForm.OriginalGamesPosition) byte.Parse(value);
                                break;

                            case "groupgamesbyapptype":
                                instance.GamesSorting = !value.ToLower().Equals("false") ? MainForm.GamesSorting.System : MainForm.GamesSorting.Name;
                                break;

                            case "customflashednes":
                            case "customflashedfamicom":
                            case "customflashedsnes":
                            case "customflashedsuperfamicom":
                            case "usefont":
                            case "usefontfamicom":
                            case "usefontsnes":
                            case "usefontsuperfamicom":
                            case "antiarmetlevel":
                            case "resethack":
                            case "cloverconhack":
                            case "resethacksnes":
                            case "autofirehack":
                            case "autofirehacksnes":
                            case "autofirexyhack":
                            case "resetcombination":
                            case "resetcombinationsnes":
                            case "usbhostnes":
                            case "usbhostfamicom":
                            case "usbhostsnes":
                            case "usbhostsuperfamicom":
                                // ignoring these settings, using defaults
                                break;

                            case "runcount":
                                instance.RunCount = int.Parse(value);
                                break;

                            case "consoletype":
                                instance.ConsoleType = (hakchi.ConsoleType) byte.Parse(value);
                                if (instance.ConsoleType == hakchi.ConsoleType.SNES_USA)         // compensate for new 5th console type
                                {
                                    instance.ConsoleType = hakchi.ConsoleType.SuperFamicom;
                                }
                                break;

                            case "extracommandlinearguments":
                                instance.consoleSettings[0].ExtraCommandLineArguments[ExtraCmdLineTypes.Kachikachi] = value;
                                break;

                            case "extracommandlineargumentssnes":
                                instance.consoleSettings[0].ExtraCommandLineArguments[ExtraCmdLineTypes.Canoe] = value;
                                break;

                            case "fcstart":
                                instance.consoleSettings[0].FcStart = !value.ToLower().Equals("false");
                                break;

                            case "maxgamesperfolder":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.NES].MaxGamesPerFolder = byte.Parse(value);
                                break;

                            case "maxgamesperfolderfamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].MaxGamesPerFolder = byte.Parse(value);
                                break;

                            case "maxgamesperfoldersnes":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].MaxGamesPerFolder     =
                                    instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].MaxGamesPerFolder =
                                        byte.Parse(value);
                                break;

                            case "maxgamesperfoldersuperfamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].MaxGamesPerFolder = byte.Parse(value);
                                break;

                            case "foldersmode":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.NES].FoldersMode = (NesMenuCollection.SplitStyle) byte.Parse(value);
                                break;

                            case "foldersmodefamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].FoldersMode = (NesMenuCollection.SplitStyle) byte.Parse(value);
                                break;

                            case "foldersmodesnes":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].FoldersMode     =
                                    instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].FoldersMode =
                                        (NesMenuCollection.SplitStyle) byte.Parse(value);
                                break;

                            case "foldersmodesuperfamicom":
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].FoldersMode = (NesMenuCollection.SplitStyle) byte.Parse(value);
                                break;

                            case "usesfromtool":
                                instance.UseSFROMTool = !value.ToLower().Equals("false");
                                break;

                            case "usepcmpatch":
                                instance.UsePCMPatch = !value.ToLower().Equals("false");
                                break;

                            case "compress":
                                instance.Compress = !value.ToLower().Equals("false");
                                break;

                            case "compresscover":
                                instance.CompressCover = !value.ToLower().Equals("false");
                                break;

                            case "centerthumbnail":
                                instance.CenterThumbnail = !value.ToLower().Equals("false");
                                break;

                            case "disablepopups":
                                instance.DisablePopups = !value.ToLower().Equals("false");
                                break;

                            case "ftpserver":
                                instance.FtpServer = !value.ToLower().Equals("false");
                                break;

                            case "ftpcommand":
                                instance.FtpCommand = value;
                                break;

                            case "ftparguments":
                                instance.FtpArguments = value;
                                break;

                            case "telnetserver":
                                instance.TelnetServer = !value.ToLower().Equals("false");
                                break;

                            case "telnetcommand":
                                instance.TelnetCommand = value;
                                break;

                            case "telnetarguments":
                                instance.TelnetArguments = value;
                                break;

                            case "separategamestorage":
                                instance.SeparateGameStorage = !value.ToLower().Equals("false");
                                break;

                            case "exportlinked":
                                instance.ExportLinked = !value.ToLower().Equals("false");
                                break;

                            case "synclinked":
                                instance.SyncLinked = !value.ToLower().Equals("false");
                                break;

                            case "exportregion":
                                //instance.ExportRegion = value;
                                break;

                            case "membootuboot":
                                if (value == "uboot.bin")
                                {
                                    instance.MembootUboot = FelLib.Fel.UbootType.Normal;
                                }
                                else
                                {
                                    instance.MembootUboot = FelLib.Fel.UbootType.SD;
                                }
                                break;

                            case "hmodlistsort":
                                instance.hmodListSort = (HmodListSort)byte.Parse(value);
                                break;
                            }
                            break;

                        case "presets":
                            instance.gamesCollectionSettings[hakchi.ConsoleType.NES].Presets[param]          = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].Presets[param]      = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_EUR].Presets[param]     = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].Presets[param]     = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].Presets[param] = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                            break;
                        }
                    }

                    // cleanup
                    instance.gamesCollectionSettings.ToList().ForEach(pair => pair.Value.SelectedGames.Remove("default"));

                    // success
                    return(true);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error loading legacy configuration file : " + ex.Message + ex.StackTrace);
                    instance = null;
                }
            }
            // failure
            return(false);
        }