Esempio n. 1
0
        /// <summary>
        /// Gets a program's name, copyright and other data by introspection assuming standard ROM layout.
        /// </summary>
        /// <param name="rom">The ROM to inspect.</param>
        /// <returns>An enumeration of strings that contains information about the ROM in a well-ordered format, using the intvname utility.</returns>
        private static string[] GetIntvNameData(INTV.Core.Model.IRom rom)
        {
            var    intvNameData = new string[(int)RomInfoIndex.NumEntries];
            var    jzIntv       = INTV.Shared.Utility.SingleInstanceApplication.Instance.GetConfiguration <JzIntv.Model.Configuration>();
            string intvname     = jzIntv.GetProgramPath(JzIntv.Model.ProgramFile.IntvName);

            if ((intvname != null) && System.IO.File.Exists(intvname))
            {
                var localRomCopy = rom;
                if (rom.RomPath.IsPathOnRemovableDevice())
                {
                    localRomCopy = rom.CopyToLocalRomsDirectory();
                }

                if (localRomCopy.IsUsingStockCfgFilePath())
                {
                    // intvname tool requires .cfg next to .bin, so make a copy of the stock file next to the ROM.
                    var stockCfgFilePath = localRomCopy.ConfigPath;
                    var cfgFilePath      = Path.ChangeExtension(localRomCopy.RomPath, ProgramFileKind.CfgFile.FileExtension());
                    File.Copy(stockCfgFilePath, cfgFilePath, true);
                    localRomCopy.UpdateCfgFile(cfgFilePath);
                }

                var results = INTV.Shared.Utility.RunExternalProgram.CallAndReturnStdOut(intvname, "\"" + localRomCopy.RomPath + "\"", string.Empty);
                if (!string.IsNullOrWhiteSpace(results))
                {
                    intvNameData = System.Text.RegularExpressions.Regex.Split(results, "\r\n|\r|\n");
                    for (int i = 0; i < intvNameData.Length; ++i)
                    {
                        var rawEntry       = intvNameData[i];
                        var unescapedEntry = INTV.Core.Utility.StringUtilities.UnescapeString(rawEntry, null);
                        intvNameData[i] = unescapedEntry;
                    }
                    if (intvNameData.Length > 0)
                    {
                        intvNameData[0] = System.Text.RegularExpressions.Regex.Replace(intvNameData[0], @"\s+", " ").Trim();
                    }
                }
                if (string.IsNullOrEmpty(intvNameData[0]))
                {
                    intvNameData[0] = System.IO.Path.GetFileNameWithoutExtension(rom.RomPath);
                }
                if (string.Equals(intvNameData[0], "IntyBASIC program", System.StringComparison.OrdinalIgnoreCase))
                {
                    // Just use the file name.
                    intvNameData[0] = Path.GetFileNameWithoutExtension(localRomCopy.RomPath);
                }
            }
            return(intvNameData);
        }
Esempio n. 2
0
        /// <summary>
        /// Given a list of files and / or directories, enumerate what appear to be valid program ROM files.
        /// </summary>
        /// <param name="files">A list of files and / or directories to inspect to locate ROM files.</param>
        /// <param name="acceptCancellation">Delegate to call to determine if the operation should accept being cancelled by the user.</param>
        /// <param name="progressFunc">Delegate to call to update progress of the operation.</param>
        /// <returns>An enumerable of valid program ROM files.</returns>
        public static IEnumerable <IRom> IdentifyRomFiles(this IEnumerable <string> files, Func <bool> acceptCancellation, Action <string> progressFunc)
        {
            var potentialRomFilePaths = GetPotentialProgramRomFiles(files, acceptCancellation, progressFunc).Where(f => ProgramFileKind.Rom.IsProgramFile(f));

            foreach (var romFilePath in potentialRomFilePaths)
            {
                if (acceptCancellation())
                {
                    yield break;
                }
                if (progressFunc != null)
                {
                    progressFunc(romFilePath);
                }
                var configFilePath = INTV.Shared.Model.Program.ProgramFileKindHelpers.GetConfigFilePath(romFilePath);
                if (!string.IsNullOrEmpty(configFilePath) && File.Exists(configFilePath))
                {
                    INTV.Core.Model.IRom programRom = null;
                    try
                    {
                        programRom = INTV.Core.Model.Rom.Create(romFilePath, configFilePath);
                    }
                    catch (IOException)
                    {
                        // TODO: Report error here -- this has been found to occur of scanning SkyDrive / OneDrive in Windows 8.1.
                    }
                    if (programRom != null)
                    {
                        yield return(programRom);
                    }
                }
                else
                {
                    INTV.Core.Model.IRom programRom = null;
                    try
                    {
                        programRom = INTV.Core.Model.Rom.Create(romFilePath, null);
                    }
                    catch (IOException)
                    {
                        // TODO: Report error here -- this has been found to occur of scanning SkyDrive / OneDrive in Windows 8.1.
                    }
                    if (programRom != null)
                    {
                        yield return(programRom);
                    }
                    else
                    {
                        // Might be a lone 'bin' file, such as EXEC or GROM. Run a checksum. This will result in a second checksum later, but oh, well.
                        IProgramInformation programInfo = null;
                        try
                        {
                            var crc = INTV.Core.Utility.Crc32.OfFile(romFilePath);
                            programInfo = ProgramInformationTable.Default.FindProgram(crc);
                        }
                        catch (IOException)
                        {
                            // TODO: Report error here -- this has been found to occur of scanning SkyDrive / OneDrive in Windows 8.1.
                        }
                        if (programInfo != null)
                        {
                            if (INTV.Core.Model.Rom.CheckRomFormat(romFilePath) != RomFormat.None)
                            {
                                yield return(INTV.Core.Model.Rom.Create(romFilePath, null));
                            }
                        }
                    }
                }
            }
        }