示例#1
0
        static bool OpenArchive(string archiveLoc, out CCDFileManager fileManager, bool verbose)
        {
            var fileInfo = new FileInfo(archiveLoc);

            if (!fileInfo.Exists)
            {
                Console.WriteLine($"Unable to locate file: {fileInfo.Name}!");
                fileManager = null;
                return(false);
            }

            try
            {
                fileManager = new CCDFileManager(fileInfo.FullName);
                if (verbose)
                {
                    Console.WriteLine("=== Archive Header ===");
                    Console.WriteLine(fileManager.Header + "\n");

                    foreach (CcdFileInfo cfi in fileManager.FileList)
                    {
                        Console.WriteLine("File Header:\n" + cfi);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine($"ERROR: {e.Message} - {fileInfo.FullName}");
                fileManager = null;
                return(false);
            }
        }
示例#2
0
        static void ExtractFiles(CCDFileManager fileManager, string outputDir, string mask = "")
        {
            bool   skipMask  = string.IsNullOrEmpty(mask);
            string maskRegex = "^" + Regex.Escape(mask).Replace("\\*", ".*") + "$";

            foreach (CcdFileInfo cfi in fileManager.FileList)
            {
                if (!skipMask && !Regex.IsMatch(cfi.Name, maskRegex))
                {
                    continue;
                }
                if (verbose)
                {
                    Console.WriteLine($"Extracting: {cfi.Name}");
                }
                string outputPath = Path.Combine(outputDir, cfi.Name);
                fileManager.ExtractFile(cfi.Name, outputPath);
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            bool           list        = false;
            bool           showHelp    = false;
            string         fileName    = string.Empty;
            string         folderName  = string.Empty;
            string         searchQuery = string.Empty;
            string         gameDir     = null;
            string         outputDir   = string.Empty;
            CCDFileManager ccdFile;

            if (args.Length == 0)
            {
                Console.WriteLine("Missing arguments, type '--help' for more information'");
                return;
            }

            var options = new OptionSet {
                { "e|extract=", "File to extract", n => fileName = n },
                { "c|compress=", "Folder to compress", c => folderName = c },
                { "l", "List file instead of extraction", l => list = (l != null) },
                { "v", "increase debug message verbosity", v => verbose = (v != null) },
                { "s|search=", "search query through cli files", s => searchQuery = s },
                { "o|out=", "output directory", o => outputDir = o },
                { "d|dir=", "Game Directory, defaults to registry location", d => gameDir = d },
                { "h|help", "show this message and exit", v => showHelp = v != null },
            };

            List <string> extra;

            try
            {
                extra = options.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write(e.Message);
                Console.WriteLine("Try '--help' for more information.");
            }

            if (showHelp)
            {
                options.WriteOptionDescriptions(Console.Out);
                return;
            }

            if (fileName != string.Empty && searchQuery != string.Empty && folderName != string.Empty)
            {
                Console.WriteLine("Entry only one of -s, -e or -c options.");
                return;
            }

            if (fileName != string.Empty)
            {
                if (!OpenArchive(fileName, out ccdFile, verbose))
                {
                    return;
                }

                string dirName = "";
                if (!list)
                {
                    if (string.IsNullOrEmpty(outputDir))
                    {
                        outputDir = Path.GetDirectoryName(fileName);
                    }
                    dirName = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(fileName));
                    if (!Directory.Exists(dirName))
                    {
                        Directory.CreateDirectory(dirName);
                    }
                    try
                    {
                        ExtractFiles(ccdFile, dirName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Error Processing file => {fileName}: {e.Message}");
                        return;
                    }
                }
            }
            else if (folderName != string.Empty)
            {
                if (string.IsNullOrEmpty(outputDir))
                {
                    outputDir =
                        Path.Combine(Path.GetDirectoryName(folderName), Path.GetDirectoryName(outputDir) + ".ccd");
                }
                CCDFileManager.CompressDirectory(folderName, outputDir);
            }
            else
            {
                gameDir = gameDir ?? GetRegistryInstallDir();
                if (gameDir == string.Empty)
                {
                    Console.WriteLine("Error: Failed to obtain install directory via registry.");
                    return;
                }

                gameDir = Path.GetFullPath(gameDir);
                if (verbose)
                {
                    Console.WriteLine($"Game Directory: {gameDir}");
                }
                ScanFiles(gameDir, searchQuery, verbose);
            }

            Console.WriteLine("Operations complete!");
            Console.ReadKey();
        }