Exemple #1
0
        private RomType[] LoadRoms(string folder, bool skipZip)
        {
            string[] roms = System.IO.Directory.GetFiles(folder, "*.*", System.IO.SearchOption.AllDirectories);
            Dictionary <string, RomType> typesToImport = new Dictionary <string, RomType>();
            int           zipcount   = 0;
            List <string> compressed = new List <string>();

            foreach (String r in roms)
            {
                string ext = System.IO.Path.GetExtension(r).ToLower();
                if (!typesToImport.ContainsKey(ext))
                {
                    typesToImport[ext]           = new RomType();
                    typesToImport[ext].extension = ext;
                    typesToImport[ext].import    = true;
                }
                typesToImport[ext].romsPath.Add(r);
                if (ext == ".zip" || ext == ".7z" || ext == ".rar")
                {
                    zipcount++;
                    compressed.Add(r);
                }
            }
            if (!skipZip && !_InfoOnly)
            {
                /*Check if unzip required*/
                if (zipcount > 0)
                {
                    if (MessageBox.Show("It appears you are importing compressed files (" + zipcount.ToString() + "), uncompressing them will allow better emulator detection.\r\nDo you want to automatically extract them? \r\nClicking No will keep them as is.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        if (System.IO.Directory.Exists(".\\RomsTemp\\"))
                        {
                            System.IO.Directory.Delete(".\\RomsTemp\\", true);
                        }
                        System.IO.Directory.CreateDirectory(".\\RomsTemp\\");
                        Dictionary <string, string> fToDir = new Dictionary <string, string>();

                        foreach (string f in compressed)
                        {
                            string filename = System.IO.Path.GetFileName(f);
                            string tf       = System.IO.Path.Combine(".\\RomsTemp\\", filename + "\\");
                            fToDir[f] = tf;
                        }
                        AsyncTask at = new AsyncTask(new Tooling.Tasks.ExtractFiles(fToDir));
                        at.ShowDialog();
                        RomType[] added = LoadRoms(".\\RomsTemp\\", true);
                        foreach (RomType rt in added)
                        {
                            if (!typesToImport.ContainsKey(rt.extension))
                            {
                                typesToImport[rt.extension] = rt;
                            }
                            else
                            {
                                typesToImport[rt.extension].romsPath.AddRange(rt.romsPath);
                            }
                        }
                        typesToImport.Remove(".zip");
                        typesToImport.Remove(".7z");
                        typesToImport.Remove(".rar");
                    }
                }
            }
            return(typesToImport.Values.ToArray());
        }