コード例 #1
0
            public override bool Execute(IEnumerable <string> arguments)
            {
                if (arguments.Count() < 2)
                {
                    Console.WriteLine("ERROR: Not enough arguments given!");
                    return(false);
                }

                var basePath  = arguments.ElementAt(0);
                var outputDir = arguments.ElementAt(1);

                if (!Directory.Exists(basePath))
                {
                    Console.WriteLine("ERROR: The game base path does not exist!");
                    return(false);
                }

                Directory.CreateDirectory(outputDir);

                var looseFilePath = Path.Combine(basePath, @"France\loosefiles_BinPC.pack");

                if (!File.Exists(looseFilePath))
                {
                    Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!");
                    return(false);
                }

                var looseFile = new LooseFile();

                using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    looseFile.Read(fs);

                var gameTemplatesEntry = looseFile.Files.Where(f => f.Name == "GameTemplates.wsd").FirstOrDefault();

                if (gameTemplatesEntry == null)
                {
                    Console.WriteLine("ERROR: Could not read GameTemplates.wsd from loosefiles!");
                    return(false);
                }

                var gameTemplates = new GameTemplates();

                using (var ms = new MemoryStream(gameTemplatesEntry.Data))
                    gameTemplates.Read(ms);

                return(true);
            }
コード例 #2
0
            public override bool Execute(IEnumerable <string> arguments)
            {
                if (arguments.Count() < 2)
                {
                    Console.WriteLine("ERROR: Not enough arguments given!");
                    return(false);
                }

                var filePath     = arguments.ElementAt(0);
                var outputFolder = arguments.ElementAt(1);

                if (!File.Exists(filePath))
                {
                    Console.WriteLine("ERROR: Loose file doesn't exist!");
                    return(false);
                }

                Directory.CreateDirectory(outputFolder);

                var looseFile = new LooseFile();

                using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    looseFile.Read(fs);

                foreach (var file in looseFile.Files)
                {
                    var outFilePath   = Path.Combine(outputFolder, file.Name);
                    var directoryName = Path.GetDirectoryName(outFilePath);

                    Directory.CreateDirectory(directoryName);

                    Console.WriteLine($"Unpacking {file}...");

                    File.WriteAllBytes(outFilePath, file.Data);
                }

                Console.WriteLine("Files successfully unpacked!");
                return(true);
            }
コード例 #3
0
            public override bool Execute(IEnumerable <string> arguments)
            {
                if (arguments.Count() < 1)
                {
                    Console.WriteLine("ERROR: Not enough arguments given!");
                    return(false);
                }

                var basePathOrFilePath = arguments.ElementAt(0);
                var outputFilePath     = arguments.Count() > 1 ? arguments.ElementAt(1) : null;

                byte[] data = null;

                var attrs = File.GetAttributes(basePathOrFilePath);

                if ((attrs & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    var looseFilePath = Path.Combine(basePathOrFilePath, @"France\loosefiles_BinPC.pack");
                    if (!File.Exists(looseFilePath))
                    {
                        Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!");
                        return(false);
                    }

                    var looseFile = new LooseFile();

                    using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                        looseFile.Read(fs);

                    var gameTemplatesEntry = looseFile.Files.Where(f => f.Name == "GameTemplates.wsd").FirstOrDefault();
                    if (gameTemplatesEntry == null)
                    {
                        Console.WriteLine("ERROR: Could not read GameTemplates.wsd from loosefiles!");
                        return(false);
                    }

                    data = gameTemplatesEntry.Data;
                }
                else
                {
                    data = File.ReadAllBytes(basePathOrFilePath);
                }

                StreamWriter writer = null;

                if (outputFilePath != null)
                {
                    writer = new StreamWriter(new FileStream(outputFilePath, FileMode.Create, FileAccess.Write, FileShare.None));
                }

                var gameTemplates = new GameTemplatesDump(writer);

                using (var ms = new MemoryStream(data))
                    gameTemplates.Read(ms);

                if (writer != null)
                {
                    writer.Flush();
                    writer.Close();
                }

                return(true);
            }
コード例 #4
0
            public override bool Execute(IEnumerable <string> arguments)
            {
                if (arguments.Count() < 2)
                {
                    Console.WriteLine("ERROR: Not enough arguments given!");
                    return(false);
                }

                var basePath  = arguments.ElementAt(0);
                var outputDir = arguments.ElementAt(1);

                if (!Directory.Exists(basePath))
                {
                    Console.WriteLine("ERROR: The game base path does not exist!");
                    return(false);
                }

                Directory.CreateDirectory(outputDir);

                var looseFilePath = Path.Combine(basePath, @"France\loosefiles_BinPC.pack");

                if (!File.Exists(looseFilePath))
                {
                    Console.WriteLine($"ERROR: Loosefile could not be found under \"{looseFilePath}\"!");
                    return(false);
                }

                foreach (var filePath in Megapacks)
                {
                    var fullPath = Path.Combine(basePath, filePath);

                    if (!filePath.Contains("patch") && !File.Exists(fullPath))
                    {
                        Console.WriteLine($"ERROR: Missing non-optional megapack: {filePath}!");
                        return(false);
                    }
                }

                var looseFile = new LooseFile();

                using (var fs = new FileStream(looseFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    looseFile.Read(fs);

                var globalMapEntry = looseFile.Files.Where(f => f.Name == "global.map").FirstOrDefault();

                if (globalMapEntry == null)
                {
                    Console.WriteLine("ERROR: Could not read global.map from loosefiles!");
                    return(false);
                }

                var globalMap = new Map();

                using (var ms = new MemoryStream(globalMapEntry.Data))
                    globalMap.Read(ms);

                var megapacks = new List <Megapack>();

                foreach (var filePath in Megapacks)
                {
                    var fullPath = Path.Combine(basePath, filePath);

                    if (!File.Exists(fullPath))
                    {
                        continue;
                    }

                    var megapack = new Megapack(globalMap);

                    using (var fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        Console.WriteLine($"Reading: {Path.GetFileName(fullPath)}");
                        megapack.Read(fs);
                    }

                    megapacks.Add(megapack);
                }

                foreach (var megapack in megapacks)
                {
                    // TODO: extract when we have the proper file reading methods
                }

                Console.WriteLine("Successfully unpacked the global megapacks!");
                return(true);
            }
コード例 #5
0
            public override bool Execute(IEnumerable <string> arguments)
            {
                if (arguments.Count() < 2)
                {
                    Console.WriteLine("ERROR: Not enough arguments given!");
                    return(false);
                }

                var filePath    = arguments.ElementAt(0);
                var inputFolder = arguments.ElementAt(1);

                if (File.Exists(filePath))
                {
                    Console.WriteLine("ERROR: Loose file already exist!");
                    return(false);
                }

                if (!Directory.Exists(inputFolder))
                {
                    Console.WriteLine("ERROR: Input directory doesn't exist!");
                    return(false);
                }

                var looseFile = new LooseFile();

                if (Path.GetFileName(filePath) == "loosefiles_BinPC.pack")
                {
                    foreach (var pair in LooseFilesBinPCStaticFiles)
                    {
                        var path = Path.Combine(inputFolder, pair.Key);
                        if (!File.Exists(path))
                        {
                            Console.WriteLine($"ERROR: Missing file in input folder: {pair.Key}!");
                            return(false);
                        }

                        var entry = new LooseFileEntry(pair.Value, pair.Key, path);

                        looseFile.AddFile(entry);

                        Console.WriteLine($"Adding: \"{entry}\" to loose file...");
                    }
                }
                else
                {
                    var files = Directory.GetFiles(inputFolder, "*", SearchOption.AllDirectories);

                    if (files.Length == 0)
                    {
                        Console.WriteLine("ERROR: No files found in the input directory!");
                        return(false);
                    }

                    foreach (var file in files)
                    {
                        var entry = new LooseFileEntry(0, file.Substring(inputFolder.Length + 1), file);

                        looseFile.AddFile(entry);

                        Console.WriteLine($"Adding: \"{entry}\" to loose file...");
                    }
                }

                using (var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.None))
                    looseFile.Write(fs);

                Console.WriteLine("Loose file successfully packed! Path: {0}", filePath);
                return(true);
            }