Example #1
0
        // save
        public static void Save()
        {
            if (instance != null)
            {
                Debug.WriteLine("Saving configuration");
                instance.LastVersion = Shared.AppVersion.ToString();
                try
                {
                    string configPath = Shared.PathCombine(Program.BaseDirectoryExternal, ConfigDir, ConfigFile);
                    Directory.CreateDirectory(Path.GetDirectoryName(configPath));
                    File.WriteAllText(configPath, JsonConvert.SerializeObject(instance, Formatting.Indented));

                    string legacyConfigPath = Shared.PathCombine(Program.BaseDirectoryExternal, ConfigDir, LegacyConfigFile);
                    if (File.Exists(legacyConfigPath))
                    {
                        Debug.WriteLine("Legacy configuration file can be removed");
                        //File.Delete(legacyConfigPath);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Unexpected error saving config file : " + ex.Message + ex.StackTrace);
                }
            }
        }
 private void buttonPrepare_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < checkedListBox.Items.Count; ++i)
     {
         var path = Shared.PathCombine(Program.BaseDirectoryExternal, "art", checkedListBox.Items[i] as string);
         if (checkedListBox.GetItemChecked(i))
         {
             Directory.CreateDirectory(path);
         }
         else
         {
             if (Directory.Exists(path))
             {
                 try
                 {
                     // this will only delete empty directories, which is the desired outcome
                     Directory.Delete(path);
                 }
                 catch { }
             }
         }
     }
     if (!ConfigIni.Instance.DisablePopups)
     {
         MessageBox.Show(Resources.Done, Resources.Wow, MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     Close();
 }
Example #3
0
 private void buttonPrepare_Click(object sender, EventArgs e)
 {
     if (Tasks.MessageForm.Show(this, Resources.ApplyChanges, Resources.ApplyChangesQ, Resources.sign_question, new Tasks.MessageForm.Button[] { Tasks.MessageForm.Button.Yes, Tasks.MessageForm.Button.No }, Tasks.MessageForm.DefaultButton.Button1) == Tasks.MessageForm.Button.Yes)
     {
         for (int i = 0; i < checkedListBox.Items.Count; ++i)
         {
             var path = Shared.PathCombine(Program.BaseDirectoryExternal, "art", checkedListBox.Items[i] as string);
             if (checkedListBox.GetItemChecked(i))
             {
                 Directory.CreateDirectory(path);
             }
             else
             {
                 if (Directory.Exists(path))
                 {
                     try
                     {
                         // this will only delete empty directories, which is the desired outcome
                         Directory.Delete(path);
                     }
                     catch { }
                 }
             }
         }
         if (!ConfigIni.Instance.DisablePopups)
         {
             Tasks.MessageForm.Show(Resources.Wow, Resources.Done, Resources.sign_check);
         }
     }
     Close();
 }
Example #4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (comboDriveLetters.SelectedItem == null)
            {
                Tasks.MessageForm.Show(Resources.ExportGames, Resources.NoDriveSelected, Resources.sign_error);
            }
            else
            {
                SelectedDrive = ((DriveLetterItem)comboDriveLetters.SelectedItem).info;
                string systemCode = "";
                if (ConfigIni.Instance.SeparateGameStorage)
                {
                    switch (ConfigIni.Instance.ConsoleType)
                    {
                    case hakchi.ConsoleType.Famicom:
                        systemCode = "nes-jpn";
                        break;

                    case hakchi.ConsoleType.NES:
                        systemCode = "nes-usa";
                        break;

                    case hakchi.ConsoleType.SNES_EUR:
                        systemCode = "snes-eur";
                        break;

                    case hakchi.ConsoleType.SNES_USA:
                        systemCode = "snes-usa";
                        break;

                    case hakchi.ConsoleType.SuperFamicom:
                        systemCode = "snes-jpn";
                        break;

                    default:
                        DialogResult = DialogResult.Abort;
                        this.Close();
                        return;
                    }
                }

                if (ConfigIni.Instance.SeparateGameStorage)
                {
                    ExportPath = Shared.PathCombine(SelectedDrive.RootDirectory.FullName, "hakchi", "games", systemCode);
                }
                else
                {
                    ExportPath = Shared.PathCombine(SelectedDrive.RootDirectory.FullName, "hakchi", "games");
                }

                ConfigIni.Instance.ExportDrive = Path.GetPathRoot(SelectedDrive.RootDirectory.FullName).ToLower();
                LinkedExport = checkLinked.Enabled && checkLinked.Checked;

                DialogResult = DialogResult.OK;
                this.Close();
            }
        }
        private void fillSystems()
        {
            int i = 0;

            foreach (var system in CoreCollection.Systems)
            {
                checkedListBox.Items.Add(system);
                if (Directory.Exists(Shared.PathCombine(Program.BaseDirectoryExternal, "art", system)))
                {
                    checkedListBox.SetItemChecked(i, true);
                }
                ++i;
            }
        }
Example #6
0
        static string getHmodPath(string hmod)
        {
            try
            {
                Dictionary <string, string> readmeData = new Dictionary <string, string>();
                var dir = Shared.PathCombine(Program.BaseDirectoryExternal, "user_mods", hmod + ".hmod");
                if (Directory.Exists(dir))
                {
                    return(dir + Path.DirectorySeparatorChar);
                }
                else if (File.Exists(dir))
                {
                    return(dir);
                }
            }
            catch { }

            return(null);
        }
Example #7
0
        // load
        public static bool Load()
        {
            string configPath = Shared.PathCombine(Program.BaseDirectoryExternal, ConfigDir, ConfigFile);

            if (File.Exists(configPath))
            {
                Trace.WriteLine("Loading configuration");
                try
                {
                    instance = JsonConvert.DeserializeObject <ConfigIni>(File.ReadAllText(configPath));
                    return(true);
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unexpected error loading config file : " + ex.Message + ex.StackTrace);
                    instance = null;
                }
            }
            return(false);
        }
Example #8
0
        // legacy loading code for transition
        public static bool LoadLegacy()
        {
            var fileName = Shared.PathCombine(Program.BaseDirectoryExternal, ConfigDir, LegacyConfigFile);

            if (File.Exists(fileName))
            {
                try
                {
                    Trace.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.DefaultGames[hakchi.ConsoleType.NES].Where(code => !list.Contains(code)).ToList();
                                break;

                            case "hiddengamesfamicom":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.Famicom].OriginalGames = NesApplication.DefaultGames[hakchi.ConsoleType.Famicom].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.DefaultGames[hakchi.ConsoleType.SNES_EUR].Where(code => !list.Contains(code)).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SNES_USA].OriginalGames = NesApplication.DefaultGames[hakchi.ConsoleType.SNES_USA].Where(code => !list.Contains(code)).ToList();
                                break;

                            case "hiddengamessuperfamicom":
                                list = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                                instance.gamesCollectionSettings[hakchi.ConsoleType.SuperFamicom].OriginalGames = NesApplication.DefaultGames[hakchi.ConsoleType.SuperFamicom].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 = UbootType.Normal;
                                }
                                else
                                {
                                    instance.MembootUboot = UbootType.SD;
                                }
                                break;

                            case "hmodlistsort":
                                instance.hmodListSort = (Hmod.ListSort) 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)
                {
                    Trace.WriteLine("Error loading legacy configuration file : " + ex.Message + ex.StackTrace);
                    instance = null;
                }
            }
            // failure
            return(false);
        }
Example #9
0
        public Hmod(string mod, string[] installedHmods = null)
        {
            isInstalled = false;
            if (installedHmods != null)
            {
                isInstalled = installedHmods.Contains(mod);
            }
            RawName       = mod;
            this.HmodPath = null;
            this.isFile   = false;

            string[] readmeFiles       = new string[] { "readme.txt", "readme.md", "readme" };
            string   usermodsDirectory = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
            string   cacheDir          = Shared.PathCombine(Program.BaseDirectoryExternal, "user_mods", "readme_cache");
            string   cacheFile         = Path.Combine(cacheDir, $"{mod}.xml");


            Dictionary <string, string> readmeData = new Dictionary <string, string>();

            try
            {
                var dir = Path.Combine(usermodsDirectory, mod + ".hmod");
                if (Directory.Exists(dir))
                {
                    isFile   = false;
                    HmodPath = dir;
                    foreach (var f in readmeFiles)
                    {
                        var fn = Path.Combine(dir, f);
                        if (File.Exists(fn))
                        {
                            readmeData.Add(f.ToLower(), File.ReadAllText(fn));
                        }
                    }
                }
                else if (File.Exists(dir))
                {
                    isFile   = true;
                    HmodPath = dir;

                    ReadmeCache cache;
                    FileInfo    info = new FileInfo(dir);

                    bool skipExtraction = false;
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            cache = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            if (cache.LastModified == info.LastWriteTimeUtc)
                            {
                                skipExtraction = true;
                                readmeData     = cache.getReadmeDictionary();
                            }
                        } catch { }
                    }


                    if (!skipExtraction)
                    {
                        using (var extractor = ArchiveFactory.Open(dir))
                        {
                            var tar = new MemoryStream();
                            extractor.Entries.First().OpenEntryStream().CopyTo(tar);
                            tar.Seek(0, SeekOrigin.Begin);
                            using (var extractorTar = ArchiveFactory.Open(tar))
                            {
                                foreach (var f in extractorTar.Entries)
                                {
                                    foreach (var readmeFilename in readmeFiles)
                                    {
                                        if (f.Key.ToLower() != readmeFilename && f.Key.ToLower() != $"./{readmeFilename}")
                                        {
                                            continue;
                                        }

                                        var o = new MemoryStream();
                                        f.OpenEntryStream().CopyTo(o);
                                        readmeData.Add(readmeFilename, Encoding.UTF8.GetString(o.ToArray()));
                                    }
                                }
                            }
                        }
                        cache = new ReadmeCache(readmeData, "", info.LastWriteTimeUtc);

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

                        File.WriteAllText(cacheFile, cache.Serialize());
                    }
                }
                else
                {
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            ReadmeCache cache;
                            cache      = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            readmeData = cache.getReadmeDictionary();
                        }
                        catch { }
                    }
                }
            }
            catch
            {
            }

            string readme;
            bool   markdown = false;

            if (readmeData.TryGetValue("readme.md", out readme))
            {
                markdown = true;
            }
            else if (readmeData.TryGetValue("readme.txt", out readme))
            {
            }
            else if (readmeData.TryGetValue("readme", out readme))
            {
            }
            else
            {
                readme = "";
            }

            this.Readme = new HmodReadme(readme, markdown);

            if (!this.Readme.frontMatter.TryGetValue("Name", out this.Name))
            {
                this.Name = mod;
            }
            if (!this.Readme.frontMatter.TryGetValue("Category", out this.Category))
            {
                this.Category = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Creator", out this.Creator))
            {
                this.Creator = Properties.Resources.Unknown;
            }
        }
        public static void Load()
        {
            // try to load from cache
            if (Deserialize())
            {
                return;
            }

            // clear and add default cores
            cores = BuiltInCores.List.ToDictionary(pair => pair.Bin);

            // load info files
            Debug.WriteLine("Loading libretro core info files");
            var whiteList = File.Exists(WhiteListFilename) ? File.ReadAllLines(WhiteListFilename) : Resources.retroarch_whitelist.Split("\n\r".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var regex     = new Regex("(^[^\\s]+)\\s+=\\s+\"?([^\"\\r\\n]*)\"?", RegexOptions.Multiline | RegexOptions.Compiled);
            var infoFiles = Directory.GetFiles(Shared.PathCombine(Program.BaseDirectoryInternal, "data", "libretro_cores"), "*.info");

            foreach (var file in infoFiles)
            {
                Match m = Regex.Match(Path.GetFileNameWithoutExtension(file), "^(.*)_libretro");
                if (m.Success && !string.IsNullOrEmpty(m.Groups[1].ToString()))
                {
                    var bin = m.Groups[1].ToString();
                    if (!whiteList.Contains(bin))
                    {
                        continue;
                    }

                    var f       = File.ReadAllText(file);
                    var matches = regex.Matches(f);
                    if (matches.Count <= 0)
                    {
                        continue;
                    }

                    var    core   = new CoreInfo(bin);
                    string system = null;
                    foreach (Match mm in matches)
                    {
                        if (mm.Success)
                        {
                            switch (mm.Groups[1].ToString().ToLower())
                            {
                            case "corename":
                                core.Name = mm.Groups[2].ToString();
                                break;

                            case "display_name":
                                core.DisplayName = mm.Groups[2].ToString();
                                break;

                            case "systemname":
                                system = mm.Groups[2].ToString();
                                break;

                            case "supported_extensions":
                                core.SupportedExtensions = mm.Groups[2].ToString().Split('|');
                                for (var i = 0; i < core.SupportedExtensions.Length; ++i)
                                {
                                    core.SupportedExtensions[i] = "." + core.SupportedExtensions[i];
                                }
                                break;

                            case "database":
                                core.Systems = mm.Groups[2].ToString().Split('|');
                                break;
                            }
                        }
                    }
                    if (core.Systems == null && system != null)
                    {
                        core.Systems = new string[] { system }
                    }
                    ;
                    core.Kind  = CoreKind.Libretro;
                    cores[bin] = core;
                }
            }
            new Thread(CoreCollection.UpdateWhitelist).Start();

            // cross indexing
            Debug.WriteLine("Building libretro core cross index");
            foreach (var c in cores)
            {
                if (c.Value.SupportedExtensions != null)
                {
                    foreach (var ext in c.Value.SupportedExtensions)
                    {
                        if (!extIndex.ContainsKey(ext))
                        {
                            extIndex[ext] = new List <CoreInfo>();
                        }
                        if (!extIndex[ext].Contains(c.Value))
                        {
                            extIndex[ext].Add(c.Value);
                        }
                    }
                }
                if (c.Value.Systems != null)
                {
                    foreach (var sys in c.Value.Systems)
                    {
                        if (!systemIndex.ContainsKey(sys))
                        {
                            systemIndex[sys] = new List <CoreInfo>();
                        }
                        if (!systemIndex[sys].Contains(c.Value))
                        {
                            systemIndex[sys].Add(c.Value);
                        }
                    }
                }
            }

            // save cache
            Serialize();
        }
Example #11
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (comboDriveLetters.SelectedItem == null)
            {
                MessageBox.Show(this, Properties.Resources.NoDriveSelected, Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                SelectedDrive = ((DriveLetterItem)comboDriveLetters.SelectedItem).info;
                string systemCode = "";
                if (ConfigIni.Instance.SeparateGameStorage)
                {
                    switch (ConfigIni.Instance.ConsoleType)
                    {
                    case MainForm.ConsoleType.Famicom:
                        systemCode = "nes-jpn";
                        break;

                    case MainForm.ConsoleType.NES:
                        systemCode = "nes-usa";
                        break;

                    case MainForm.ConsoleType.SNES:
                        systemCode = "snes";
                        if (radioEUR.Checked)
                        {
                            systemCode += "-eur";
                        }
                        if (radioUSA.Checked)
                        {
                            systemCode += "-usa";
                        }
                        if (radioEUR.Checked == false && radioUSA.Checked == false)
                        {
                            MessageBox.Show(this, Properties.Resources.SelectRegion, Properties.Resources.SelectRegion, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        break;

                    case MainForm.ConsoleType.SuperFamicom:
                        systemCode = "snes-jpn";
                        break;

                    default:
                        DialogResult = DialogResult.Abort;
                        this.Close();
                        return;
                    }
                }

                if (ConfigIni.Instance.SeparateGameStorage)
                {
                    ExportPath = Shared.PathCombine(SelectedDrive.RootDirectory.FullName, "hakchi", "games", systemCode);
                }
                else
                {
                    ExportPath = Shared.PathCombine(SelectedDrive.RootDirectory.FullName, "hakchi", "games");
                }

                LinkedExport = checkLinked.Enabled && checkLinked.Checked;

                DialogResult = DialogResult.OK;
                this.Close();
            }
        }
Example #12
0
        public static void Load()
        {
            cores       = new Dictionary <string, CoreInfo>();
            extIndex    = new SortedDictionary <string, List <CoreInfo> >();
            systemIndex = new SortedDictionary <string, List <CoreInfo> >();

            // try to load from cache
            if (Deserialize())
            {
                return;
            }

            // load info files
            Trace.WriteLine("Loading libretro core info files");
            var regex = new Regex("(^[^\\s]+)\\s+=\\s+\"?([^\"\\r\\n]*)\"?", RegexOptions.Multiline | RegexOptions.Compiled);

            // list base info files present in "libretro_cores.tgz"
            cores = new Dictionary <string, CoreInfo>();
            using (var extractor = ArchiveFactory.Open(Shared.PathCombine(Program.BaseDirectoryInternal, "data", "libretro_cores.tar")))
                using (var reader = extractor.ExtractAllEntries())
                {
                    while (reader.MoveToNextEntry())
                    {
                        var file = reader.Entry.Key;

                        Match m = Regex.Match(file, "^(?:[^/]*/)?(.*)_libretro\\.info");
                        if (m.Success && !string.IsNullOrEmpty(m.Groups[1].ToString()))
                        {
                            var fileStream = reader.OpenEntryStream();
                            var bin        = m.Groups[1].ToString();
                            var core       = parseInfoFile(fileStream, bin);
                            fileStream.Close();
                            if (core != null)
                            {
                                cores[bin] = core;
                            }
                        }
                    }
                }

            // load from hmods
            if (HmodInfo.Length == 0)
            {
                HmodInfo = Hmod.Hmod.GetMods(false, new string[] { }).ToArray();
            }

            foreach (Hmod.Hmod hmod in HmodInfo)
            {
                foreach (string file in hmod.LibretroInfo.Keys)
                {
                    using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(hmod.LibretroInfo[file])))
                    {
                        var filename = Path.GetFileName(file);
                        var bin      = filename.Substring(0, filename.IndexOf("_libretro.info"));
                        var core     = parseInfoFile(stream, bin);
                        if (core != null)
                        {
                            cores[bin] = core;
                        }
                    }
                }
            }

            // list user-added info files present in /info
            if (!Directory.Exists(Path.Combine(Program.BaseDirectoryExternal, "info")))
            {
                Directory.CreateDirectory(Path.Combine(Program.BaseDirectoryExternal, "info"));
            }
            foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.BaseDirectoryExternal, "info"), "*_libretro.info"))
            {
                using (var stream = File.OpenRead(file))
                {
                    var filename = Path.GetFileName(file);
                    var bin      = filename.Substring(0, filename.IndexOf("_libretro.info"));
                    var core     = parseInfoFile(stream, bin);
                    if (core != null)
                    {
                        cores[bin] = core;
                    }
                }
            }

            // add built-in cores
            BuiltInCores.List.ToList().ForEach(c => cores.Add(c.Bin, c));

            // cross indexing
            Trace.WriteLine("Building libretro core cross index");
            foreach (var c in cores)
            {
                if (c.Value.SupportedExtensions != null)
                {
                    foreach (var ext in c.Value.SupportedExtensions)
                    {
                        if (!extIndex.ContainsKey(ext))
                        {
                            extIndex[ext] = new List <CoreInfo>();
                        }
                        if (!extIndex[ext].Contains(c.Value))
                        {
                            extIndex[ext].Add(c.Value);
                        }
                    }
                }
                if (c.Value.Systems != null)
                {
                    foreach (var sys in c.Value.Systems)
                    {
                        if (!systemIndex.ContainsKey(sys))
                        {
                            systemIndex[sys] = new List <CoreInfo>();
                        }
                        if (!systemIndex[sys].Contains(c.Value))
                        {
                            systemIndex[sys].Add(c.Value);
                        }
                    }
                }
            }

            Trace.WriteLine($"Done, {cores.Count()} cores loaded");
            // save cache
            // Serialize();
        }
Example #13
0
        public static void Load()
        {
            // try to load from cache
            if (Deserialize())
            {
                return;
            }

            // load info files
            Trace.WriteLine("Loading libretro core info files");
            var regex = new Regex("(^[^\\s]+)\\s+=\\s+\"?([^\"\\r\\n]*)\"?", RegexOptions.Multiline | RegexOptions.Compiled);

            // list base info files present in "libretro_cores.7z"
            cores = new Dictionary <string, CoreInfo>();
            using (var extractor = ArchiveFactory.Open(Shared.PathCombine(Program.BaseDirectoryInternal, "data", "libretro_cores.7z")))
                using (var reader = extractor.ExtractAllEntries())
                    while (reader.MoveToNextEntry())
                    {
                        string file = reader.Entry.Key;

                        Match m = Regex.Match(Path.GetFileNameWithoutExtension(file), "^(.*)_libretro");
                        if (m.Success && !string.IsNullOrEmpty(m.Groups[1].ToString()))
                        {
                            var bin  = m.Groups[1].ToString();
                            var core = parseInfoFile(reader.OpenEntryStream(), bin);
                            if (core != null)
                            {
                                cores[bin] = core;
                            }
                        }
                    }

            // list user-added info files present in /info
            if (!Directory.Exists(Path.Combine(Program.BaseDirectoryExternal, "info")))
            {
                Directory.CreateDirectory(Path.Combine(Program.BaseDirectoryExternal, "info"));
            }
            foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.BaseDirectoryExternal, "info"), "*_libretro.info"))
            {
                using (var stream = File.OpenRead(file))
                {
                    var filename = Path.GetFileName(file);
                    var bin      = filename.Substring(0, filename.IndexOf("_libretro.info"));
                    var core     = parseInfoFile(stream, bin);
                    if (core != null)
                    {
                        cores[bin] = core;
                    }
                }
            }

            // add built-in cores
            BuiltInCores.List.ToList().ForEach(c => cores.Add(c.Bin, c));

            // cross indexing
            Trace.WriteLine("Building libretro core cross index");
            foreach (var c in cores)
            {
                if (c.Value.SupportedExtensions != null)
                {
                    foreach (var ext in c.Value.SupportedExtensions)
                    {
                        if (!extIndex.ContainsKey(ext))
                        {
                            extIndex[ext] = new List <CoreInfo>();
                        }
                        if (!extIndex[ext].Contains(c.Value))
                        {
                            extIndex[ext].Add(c.Value);
                        }
                    }
                }
                if (c.Value.Systems != null)
                {
                    foreach (var sys in c.Value.Systems)
                    {
                        if (!systemIndex.ContainsKey(sys))
                        {
                            systemIndex[sys] = new List <CoreInfo>();
                        }
                        if (!systemIndex[sys].Contains(c.Value))
                        {
                            systemIndex[sys].Add(c.Value);
                        }
                    }
                }
            }

            // save cache
            // Serialize();
        }
Example #14
0
        public Hmod(string mod)
        {
            RawName       = mod;
            this.HmodPath = null;
            this.isFile   = false;

            string[] readmeFiles       = new string[] { "readme.txt", "readme.md", "readme" };
            string   usermodsDirectory = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
            string   cacheDir          = Shared.PathCombine(Program.BaseDirectoryExternal, "user_mods", "readme_cache");
            string   cacheFile         = Path.Combine(cacheDir, $"{mod}.xml");


            Dictionary <string, string> readmeData = new Dictionary <string, string>();

            try
            {
                var dir = Path.Combine(usermodsDirectory, mod + ".hmod");
                if (Directory.Exists(dir))
                {
                    isFile   = false;
                    HmodPath = dir;
                    foreach (var f in readmeFiles)
                    {
                        var fn = Path.Combine(dir, f);
                        if (File.Exists(fn))
                        {
                            readmeData.Add(f.ToLower(), File.ReadAllText(fn));
                        }
                    }
                }
                else if (File.Exists(dir))
                {
                    isFile   = true;
                    HmodPath = dir;

                    ReadmeCache cache;
                    FileInfo    info = new FileInfo(dir);

                    bool skipExtraction = false;
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            cache = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            if (cache.LastModified == info.LastWriteTimeUtc)
                            {
                                skipExtraction = true;
                                readmeData     = cache.getReadmeDictionary();
                            }
                        } catch { }
                    }


                    if (!skipExtraction)
                    {
                        SevenZipExtractor.SetLibraryPath(Path.Combine(Program.BaseDirectoryInternal, IntPtr.Size == 8 ? @"tools\7z64.dll" : @"tools\7z.dll"));
                        using (var szExtractor = new SevenZipExtractor(dir))
                        {
                            var tar = new MemoryStream();
                            szExtractor.ExtractFile(0, tar);
                            tar.Seek(0, SeekOrigin.Begin);
                            using (var szExtractorTar = new SevenZipExtractor(tar))
                            {
                                foreach (var f in szExtractorTar.ArchiveFileNames)
                                {
                                    if (readmeFiles.Contains(f.ToLower()))
                                    {
                                        var o = new MemoryStream();
                                        szExtractorTar.ExtractFile(f, o);
                                        readmeData.Add(f.ToLower(), Encoding.UTF8.GetString(o.ToArray()));
                                    }
                                }
                            }
                        }
                        cache = new ReadmeCache(readmeData, "", info.LastWriteTimeUtc);

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

                        File.WriteAllText(cacheFile, cache.Serialize());
                    }
                }
                else
                {
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            ReadmeCache cache;
                            cache      = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            readmeData = cache.getReadmeDictionary();
                        }
                        catch { }
                    }
                }
            }
            catch
            {
            }

            string readme;
            bool   markdown = false;

            if (readmeData.TryGetValue("readme.md", out readme))
            {
                markdown = true;
            }
            else if (readmeData.TryGetValue("readme.txt", out readme))
            {
            }
            else if (readmeData.TryGetValue("readme", out readme))
            {
            }
            else
            {
                readme = "";
            }

            this.Readme = new HmodReadme(readme, markdown);

            if (!this.Readme.frontMatter.TryGetValue("Name", out this.Name))
            {
                this.Name = mod;
            }
            if (!this.Readme.frontMatter.TryGetValue("Category", out this.Category))
            {
                this.Category = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Creator", out this.Creator))
            {
                this.Creator = Properties.Resources.Unknown;
            }
        }