示例#1
0
        public bool Execute(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Expected at least 1 argument.");
                return(false);
            }

            var inputPath = args[1];

            if (!File.Exists(inputPath))
            {
                Console.WriteLine("Input file doesn't exist.");
                return(false);
            }

            var outputPath = Path.ChangeExtension(inputPath, null);

            if (args.Length > 2)
            {
                outputPath = args[2];
            }

            Directory.CreateDirectory(outputPath);

            DDS3FileSystem fs = new DDS3FileSystem();

            try
            {
                fs.Load(inputPath);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid ddt/img file.");
                return(false);
            }

            using ( fs )
            {
                foreach (string file in fs.EnumerateFiles(SearchOption.AllDirectories))
                {
                    using (var stream = FileUtils.Create(outputPath + Path.DirectorySeparatorChar + file))
                        using (var inputStream = fs.OpenFile(file))
                        {
                            Console.WriteLine($"Extracting: {file}");
                            inputStream.CopyTo(stream);
                        }
                }
            }

            return(true);
        }
示例#2
0
        public bool Execute(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("Expected at least 2 arguments.");
                return(false);
            }

            var inputPath = args[1];

            if (!File.Exists(inputPath))
            {
                Console.WriteLine("Input file doesn't exist.");
                return(false);
            }

            DDS3FileSystem fs = new DDS3FileSystem();

            try
            {
                fs.Load(inputPath);
            }
            catch (Exception e)
            {
                Console.WriteLine("Invalid ddt/img file");
                return(false);
            }

            string outputPath = inputPath;

            if (Directory.Exists(args[2]))
            {
                var directoryPath = args[2];

                if (args.Length > 3)
                {
                    outputPath = args[3];
                }

                using ( fs )
                {
                    foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories))
                    {
                        var filePath = file.Substring(directoryPath.Length)
                                       .Trim(Path.DirectorySeparatorChar)
                                       .Replace("\\", "/");

                        bool exists = fs.Exists(filePath);
                        Console.WriteLine($"{(exists? "Replacing" : "Adding")} file: {filePath}");

                        fs.AddFile(filePath, file, ConflictPolicy.Replace);
                    }

                    Console.WriteLine("Saving ddt/img...");
                    fs.Save(outputPath);
                }
            }
            else
            {
                if (args.Length > 4)
                {
                    outputPath = args[4];
                }

                using ( fs )
                {
                    var entryName = args[2];

                    if (!fs.Exists(entryName))
                    {
                        Console.WriteLine("Specified entry doesn't exist.");
                        return(false);
                    }

                    var filePath = args[3];
                    if (!File.Exists(filePath))
                    {
                        Console.WriteLine("Specified replacement file doesn't exist.");
                        return(false);
                    }

                    Console.WriteLine($"Replacing file: {filePath}");
                    fs.AddFile(entryName, filePath, ConflictPolicy.Replace);

                    Console.WriteLine("Saving ddt/img...");
                    fs.Save(outputPath);
                }
            }

            return(true);
        }