Exemplo n.º 1
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 source      = GetString(features, SourceStringValue);
            string outdat      = GetString(features, OutStringValue);

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

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

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

            datfile.Header.Name        = string.IsNullOrWhiteSpace(name) ? "untitled" : name;
            datfile.Header.Description = description;
            datfile.PopulateFromDir(source, asFiles: TreatAsFile.NonArchive);
            datfile.ApplyCleaning(new Cleaner()
            {
                ExcludeFields = Hash.DeepHashes.AsFields()
            });
            datfile.Write(outdat);
        }
Exemplo n.º 2
0
        public override void ProcessFeatures(Dictionary <string, Feature> features)
        {
            base.ProcessFeatures(features);

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

            // 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.CreateAndParse(olddat);

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

            datfile.DiffAgainst(intDat, false);
            intDat.Write(outdat);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Detect header skipper compliance and create an output file
        /// </summary>
        /// <param name="file">Name of the file to be parsed</param>
        /// <param name="outDir">Output directory to write the file to, empty means the same directory as the input file</param>
        /// <param name="nostore">True if headers should not be stored in the database, false otherwise</param>
        /// <returns>True if the output file was created, false otherwise</returns>
        public static bool DetectTransformStore(string file, string outDir, bool nostore)
        {
            // Create the output directory if it doesn't exist
            DirectoryExtensions.Ensure(outDir, create: true);

            logger.User($"\nGetting skipper information for '{file}'");

            // Get the skipper rule that matches the file, if any
            SkipperRule rule = GetMatchingRule(file, string.Empty);

            // If we have an empty rule, return false
            if (rule.Tests == null || rule.Tests.Count == 0 || rule.Operation != HeaderSkipOperation.None)
                return false;

            logger.User("File has a valid copier header");

            // Get the header bytes from the file first
            string hstr;
            try
            {
                // Extract the header as a string for the database
#if NET_FRAMEWORK
                using (var fs = FileExtensions.TryOpenRead(file))
                {
#else
                using var fs = FileExtensions.TryOpenRead(file);
#endif
                byte[] hbin = new byte[(int)rule.StartOffset];
                fs.Read(hbin, 0, (int)rule.StartOffset);
                hstr = Utilities.ByteArrayToString(hbin);
#if NET_FRAMEWORK
                }
#endif
            }
            catch
            {
                return false;
            }

            // Apply the rule to the file
            string newfile = (string.IsNullOrWhiteSpace(outDir) ? Path.GetFullPath(file) + ".new" : Path.Combine(outDir, Path.GetFileName(file)));
            rule.TransformFile(file, newfile);

            // If the output file doesn't exist, return false
            if (!File.Exists(newfile))
                return false;

            // Now add the information to the database if it's not already there
            if (!nostore)
            {
                BaseFile baseFile = FileExtensions.GetInfo(newfile, hashes: Hash.SHA1, asFiles: TreatAsFile.NonArchive);
                DatabaseTools.AddHeaderToDatabase(hstr, Utilities.ByteArrayToString(baseFile.SHA1), rule.SourceFile);
            }

            return true;
        }
Exemplo n.º 4
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.º 5
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.º 6
0
        /// <summary>
        /// Transform an input file using the given rule
        /// </summary>
        /// <param name="input">Input file name</param>
        /// <param name="output">Output file name</param>
        /// <returns>True if the file was transformed properly, false otherwise</returns>
        public bool TransformFile(string input, string output)
        {
            // If the input file doesn't exist, fail
            if (!File.Exists(input))
            {
                logger.Error($"I'm sorry but '{input}' doesn't exist!");
                return(false);
            }

            // Create the output directory if it doesn't already
            DirectoryExtensions.Ensure(Path.GetDirectoryName(output));

            logger.User($"Attempting to apply rule to '{input}'");
            bool success = TransformStream(FileExtensions.TryOpenRead(input), FileExtensions.TryCreate(output));

            // If the output file has size 0, delete it
            if (new FileInfo(output).Length == 0)
            {
                FileExtensions.TryDelete(output);
                success = false;
            }

            return(success);
        }