Esempio n. 1
0
        /// <summary>
        /// Rebuild from TorrentXz to TorrentXz
        /// </summary>
        /// <param name="datFile">Current DatFile object to rebuild from</param>
        /// <param name="datItem">Information for the current file to rebuild from</param>
        /// <param name="file">Name of the file to process</param>
        /// <param name="outDir">Output directory to use to build to</param>
        /// <param name="outputFormat">Output format that files should be written to</param>
        /// <param name="isZip">True if the input file is an archive, false if the file is TXZ, null otherwise</param>
        /// <returns>True if rebuilt properly, false otherwise</returns>
        private static bool RebuildTorrentXz(DatFile datFile, DatItem datItem, string file, string outDir, OutputFormat outputFormat, bool?isZip)
        {
            // If we have a very specific TGZ->TGZ case, just copy it accordingly
            XZArchive txz    = new XZArchive(file);
            BaseFile  txzRom = txz.GetTorrentXZFileInfo();

            if (isZip == false && txzRom != null && (outputFormat == OutputFormat.TorrentXZ || outputFormat == OutputFormat.TorrentXZRomba))
            {
                logger.User($"Matches found for '{Path.GetFileName(datItem.GetName() ?? string.Empty)}', rebuilding accordingly...");

                // Get the proper output path
                string sha1 = (datItem as Rom).SHA1 ?? string.Empty;
                if (outputFormat == OutputFormat.TorrentXZRomba)
                {
                    outDir = Path.Combine(outDir, Utilities.GetDepotPath(sha1, datFile.Header.OutputDepot.Depth)).Replace(".gz", ".xz");
                }
                else
                {
                    outDir = Path.Combine(outDir, sha1 + ".xz");
                }

                // Make sure the output folder is created
                Directory.CreateDirectory(Path.GetDirectoryName(outDir));

                // Now copy the file over
                try
                {
                    File.Copy(file, outDir);
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }

            return(false);
        }