Exemplo n.º 1
0
        public override void ProcessFeatures(Dictionary <string, Feature> features)
        {
            base.ProcessFeatures(features);

            // Get feature flags
            bool   copy   = GetBoolean(features, CopyValue);
            string outdat = GetString(features, OutStringValue);

            // Verify the filenames
            Dictionary <string, string> foundDats = GetValidDats(Inputs);

            // Ensure the output directory is set
            if (string.IsNullOrWhiteSpace(outdat))
            {
                outdat = "out";
            }

            // Now that we have the dictionary, we can loop through and output to a new folder for each
            foreach (string key in foundDats.Keys)
            {
                // Get the DAT file associated with the key
                DatFile datFile = DatFile.CreateAndParse(Path.Combine(_dats, foundDats[key]));

                // Set the depot values
                datFile.Header.InputDepot  = new DepotInformation(true, 4);
                datFile.Header.OutputDepot = new DepotInformation(true, 4);

                // Create the new output directory if it doesn't exist
                string outputFolder = Path.Combine(outdat, Path.GetFileNameWithoutExtension(foundDats[key]));
                DirectoryExtensions.Ensure(outputFolder, create: true);

                // Get all online depots
                List <string> onlineDepots = _depots.Where(d => d.Value.Item2).Select(d => d.Key).ToList();

                // Now scan all of those depots and rebuild
                datFile.RebuildDepot(
                    onlineDepots,
                    outDir: outputFolder,
                    outputFormat: (copy ? OutputFormat.TorrentGzipRomba : OutputFormat.TorrentZip));
            }
        }
Exemplo n.º 2
0
        public override void ProcessFeatures(Dictionary <string, Feature> features)
        {
            base.ProcessFeatures(features);

            // Get feature flags
            string name        = GetString(features, NameStringValue);
            string description = GetString(features, DescriptionStringValue);
            string newdat      = GetString(features, NewStringValue);
            string olddat      = GetString(features, OldStringValue);
            string outdat      = GetString(features, OutStringValue);

            // Ensure the output directory
            DirectoryExtensions.Ensure(outdat, create: true);

            // Check that all required files exist
            if (!File.Exists(olddat))
            {
                logger.Error($"File '{olddat}' does not exist!");
                return;
            }

            if (!File.Exists(newdat))
            {
                logger.Error($"File '{newdat}' does not exist!");
                return;
            }

            // Create the encapsulating datfile
            DatFile datfile = DatFile.Create();

            datfile.Header.Name        = name;
            datfile.Header.Description = description;
            datfile.Parse(olddat);

            // Diff against the new datfile
            DatFile intDat = DatFile.CreateAndParse(newdat);

            datfile.DiffAgainst(intDat, false);
            intDat.Write(outdat);
        }
Exemplo n.º 3
0
        public override void ProcessFeatures(Dictionary <string, Feature> features)
        {
            base.ProcessFeatures(features);

            // Verify the filenames
            Dictionary <string, string> foundDats = GetValidDats(Inputs);

            // Create the new output directory if it doesn't exist
            DirectoryExtensions.Ensure(Path.Combine(Globals.ExeDir, "out"), create: true);

            // Now that we have the dictionary, we can loop through and output to a new folder for each
            foreach (string key in foundDats.Keys)
            {
                // Get the DAT file associated with the key
                DatFile datFile = DatFile.CreateAndParse(Path.Combine(_dats, foundDats[key]));

                // Now loop through and see if all of the hash combinations exist in the database
                /* ended here */
            }

            logger.Error("This feature is not yet implemented: miss");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add a new DAT to the database
        /// </summary>
        /// <param name="dat">DatFile hash information to add</param>
        /// <param name="dbc">Database connection to use</param>
        internal void AddDatToDatabase(Rom dat, SqliteConnection dbc)
        {
            // Get the dat full path
            string fullpath = Path.Combine(_dats, (dat.Machine.Name == "dats" ? string.Empty : dat.Machine.Name), dat.Name);

            // Parse the Dat if possible
            logger.User($"Adding from '{dat.Name}'");
            DatFile tempdat = DatFile.CreateAndParse(fullpath);

            // If the Dat wasn't empty, add the information
            SqliteCommand slc          = null;
            string        crcquery     = "INSERT OR IGNORE INTO crc (crc) VALUES";
            string        md5query     = "INSERT OR IGNORE INTO md5 (md5) VALUES";
            string        sha1query    = "INSERT OR IGNORE INTO sha1 (sha1) VALUES";
            string        crcsha1query = "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES";
            string        md5sha1query = "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES";

            // Loop through the parsed entries
            bool hasItems = false;

            foreach (string romkey in tempdat.Items.Keys)
            {
                foreach (DatItem datItem in tempdat.Items[romkey])
                {
                    logger.Verbose($"Checking and adding file '{datItem.GetName() ?? string.Empty}'");

                    if (datItem.ItemType == ItemType.Disk)
                    {
                        Disk disk = (Disk)datItem;
                        hasItems = true;

                        if (!string.IsNullOrWhiteSpace(disk.MD5))
                        {
                            md5query += $" (\"{disk.MD5}\"),";
                        }

                        if (!string.IsNullOrWhiteSpace(disk.SHA1))
                        {
                            sha1query += $" (\"{disk.SHA1}\"),";

                            if (!string.IsNullOrWhiteSpace(disk.MD5))
                            {
                                md5sha1query += $" (\"{disk.MD5}\", \"{disk.SHA1}\"),";
                            }
                        }
                    }
                    else if (datItem.ItemType == ItemType.Media)
                    {
                        Media media = (Media)datItem;
                        hasItems = true;

                        if (!string.IsNullOrWhiteSpace(media.MD5))
                        {
                            md5query += $" (\"{media.MD5}\"),";
                        }

                        if (!string.IsNullOrWhiteSpace(media.SHA1))
                        {
                            sha1query += $" (\"{media.SHA1}\"),";

                            if (!string.IsNullOrWhiteSpace(media.MD5))
                            {
                                md5sha1query += $" (\"{media.MD5}\", \"{media.SHA1}\"),";
                            }
                        }
                    }
                    else if (datItem.ItemType == ItemType.Rom)
                    {
                        Rom rom = (Rom)datItem;
                        hasItems = true;

                        if (!string.IsNullOrWhiteSpace(rom.CRC))
                        {
                            crcquery += $" (\"{rom.CRC}\"),";
                        }

                        if (!string.IsNullOrWhiteSpace(rom.MD5))
                        {
                            md5query += $" (\"{rom.MD5}\"),";
                        }

                        if (!string.IsNullOrWhiteSpace(rom.SHA1))
                        {
                            sha1query += $" (\"{rom.SHA1}\"),";

                            if (!string.IsNullOrWhiteSpace(rom.CRC))
                            {
                                crcsha1query += $" (\"{rom.CRC}\", \"{rom.SHA1}\"),";
                            }

                            if (!string.IsNullOrWhiteSpace(rom.MD5))
                            {
                                md5sha1query += $" (\"{rom.MD5}\", \"{rom.SHA1}\"),";
                            }
                        }
                    }
                }
            }

            // Now run the queries after fixing them
            if (crcquery != "INSERT OR IGNORE INTO crc (crc) VALUES")
            {
                slc = new SqliteCommand(crcquery.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
            }

            if (md5query != "INSERT OR IGNORE INTO md5 (md5) VALUES")
            {
                slc = new SqliteCommand(md5query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
            }

            if (sha1query != "INSERT OR IGNORE INTO sha1 (sha1) VALUES")
            {
                slc = new SqliteCommand(sha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
            }

            if (crcsha1query != "INSERT OR IGNORE INTO crcsha1 (crc, sha1) VALUES")
            {
                slc = new SqliteCommand(crcsha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
            }

            if (md5sha1query != "INSERT OR IGNORE INTO md5sha1 (md5, sha1) VALUES")
            {
                slc = new SqliteCommand(md5sha1query.TrimEnd(','), dbc);
                slc.ExecuteNonQuery();
            }

            // Only add the DAT if it's non-empty
            if (hasItems)
            {
                string datquery = $"INSERT OR IGNORE INTO dat (hash) VALUES (\"{dat.SHA1}\")";
                slc = new SqliteCommand(datquery, dbc);
                slc.ExecuteNonQuery();
            }

            slc?.Dispose();
        }