// Start ROM scan and import process for specific system public void BeginRomImport(int _systemId, ProgressDialogController _dialog) { allowedFiles = new List <string>(); dialog = _dialog; systemId = _systemId; Common.Eventing.Listeners.ProgressDialogListener l = new Common.Eventing.Listeners.ProgressDialogListener(dialog, SignatureType.Archive); l.Subscribe(archive); // get path to ROM folder romFolderPath = GetPath(systemId); // get allowed file types for this particular system HashSet <string> exts = GSystem.GetAllowedFileExtensions(systemId); // get a list of games for this system currently already in the database presentGames = (from g in Games where g.systemId == systemId select g).ToList(); // get all files from romfolderpath and sub directories that have an allowed extension IEnumerable <string> romFiles = FileAndFolder.GetFiles(romFolderPath, true); // if romfiles is null break if (romFiles == null) { return; } // populate list of allowed file paths foreach (string s in exts) { foreach (string p in romFiles) { if (p.EndsWith(s)) { //MessageBoxResult result5 = MessageBox.Show(p); allowedFiles.Add(p); } } } // calculate the number of files to be processed numFiles = allowedFiles.Count; progress = 0; // set base dialog message strBase = "Scanning: "; // now we have a list of allowed files, loop through them foreach (string file in allowedFiles) { if (_dialog.IsCanceled) { return; } ProcessFile(file); } // whatever games are left in the presentGames list should be marked as hidden as they have not been found if (presentGames.Count > 0) { foreach (Game g in presentGames) { g.hidden = true; RomsToUpdate.Add(g); HiddenStats++; } } //GameListBuilder.UpdateFlag(); }
public void ProcessFile(string file) { // get the relative path string relPath = PathUtil.GetRelativePath(romFolderPath, file); // get just the filename string fileName = System.IO.Path.GetFileName(file); // get just the extension string extension = System.IO.Path.GetExtension(file).ToLower(); // get rom name wihout extension string romName = fileName.Replace(extension, ""); // update UI progress++; string uiUpdate = strBase + fileName + "\n(" + progress + " of " + numFiles + ")"; dialog.SetMessage(uiUpdate); string hash = String.Empty; // inspect archive files if (extension == ".zip" || extension == ".7z") { //bool isAllowed = false; try { archive.ArchivePath = file; var results = archive.ProcessArchive(GSystem.GetAllowedFileExtensions(systemId).ToArray()); if (archive.AllowedFilesDetected == 0) { // no files returned return; } else { // check how many allowed files are in the archive int alcnt = archive.AllowedFilesDetected; if (alcnt == 0) { // no allowed files return; } else if (alcnt == 1 && extension == ".zip") { // 1 allowed file and 1 total files in a zip file - use the zip file rather than the embedded rom var result = results.Results.First(); if (result.Extension == ".zip" || result.Extension == ".7z") { return; } //ArchiveFiles.Add(a); // actual rom extension - not archive extension string romExtension = result.Extension; // generate relative path (normal archive path) string romRelPath = relPath; // get romname without extension string name = result.RomName; ProcessGame(name, result.MD5, romRelPath, result.FileName, romExtension); } else { // either multiple allowed files or // 7zip archive // - Add the individual embedded rom(s) IsSingleRomInArchive = false; foreach (var r in results.Results) { //ArchiveFiles.Add(a); // actual rom extension - not archive extension string romExtension = r.Extension; // generate relative path (normal archive path + "*") string romRelPath = relPath + "*/" + r.InternalPath; // get romname without extension string name = r.RomName; ProcessGame(name, r.MD5, romRelPath, r.FileName, romExtension); } } } /* * * // retrieve the list of archive objects retrieved * if (Archiving.ArchiveMultiple.Count == 1) * { * IsSingleRomInArchive = true; * // single allowed rom file in archive detected - parse the archive as a normal game * hash = Archiving.ArchiveMultiple[0].MD5Hash; * isAllowed = Archiving.ArchiveMultiple[0].IsAllowed; * if (hash == null) * { * // hash could not be calculated - skip on general principle * return; * } * * if (isAllowed == false) * return; * * ProcessGame(romName, hash, relPath, fileName, extension); * } * else if (Archiving.ArchiveMultiple.Count == 0) * { * // no files returned * return; * } * else * { * IsSingleRomInArchive = false; * // multiple allowed rom files in archive detected - add to list to process later * foreach (var a in Archiving.ArchiveMultiple.Where(i => i.IsAllowed == true)) * { * //ArchiveFiles.Add(a); * // actual rom extension - not archive extension * string romExtension = "." + (a.FileName.Split('.').Last()); * // generate relative path (normal archive path + "*") * string romRelPath = relPath + "*" + a.FileName; * // get romname without extension * string name = a.FileName.Replace(romExtension, ""); * * ProcessGame(name, a.MD5Hash, romRelPath, a.FileName, romExtension); * } * } * */ } catch (System.IO.InvalidDataException ex) { // problem with the archive file Console.WriteLine(ex); } finally { } //if (isAllowed == false) { return; } } else { // file is not an archive - calculate md5 //hash = Crypto.Crc32.ComputeFileHash(file); hash = Crypto.checkMD5(file); /* process single game (no archive) */ if (extension.ToLower().Contains("7z") || extension.ToLower().Contains("zip")) { return; } ProcessGame(romName, hash, relPath, fileName, extension); } }