public bool Execute(string[] args) { if (args.Length < 1) { Console.WriteLine("Expected at least 1 argument"); return(false); } var inputPath = args[0]; if (!Directory.Exists(inputPath)) { Console.WriteLine("Input directory doesn't exist"); return(false); } var outputPath = Path.ChangeExtension(inputPath, "BIN"); if (args.Length > 1) { outputPath = args[1]; } using (var fs = new SMT1FileSystem()) { foreach (string file in Directory.EnumerateFiles(inputPath, "*.*", SearchOption.AllDirectories)) { var name = Path.GetFileNameWithoutExtension(file); if (!int.TryParse(name, out var handle)) { Console.WriteLine($"Skipping file: {file}; file name not a valid index"); continue; } Console.WriteLine($"Adding file: {file}"); fs.AddFile(handle, file, ConflictPolicy.Replace); } Console.WriteLine("Saving..."); fs.Save(outputPath); } return(true); }
public bool Execute(string[] args) { if (args.Length < 2) { Console.WriteLine("Expected at least 2 arguments."); return(false); } var inputPath = args[0]; if (!File.Exists(inputPath)) { Console.WriteLine("Input file doesn't exist."); return(false); } var fs = new SMT1FileSystem(); try { fs.Load(inputPath); } catch (Exception) { Console.WriteLine("Couldn't load DATA.BIN. Did you make sure to put the game executable in the same directory?"); return(false); } string outputPath = inputPath; if (Directory.Exists(args[1])) { var directoryPath = args[1]; if (args.Length > 2) { outputPath = args[2]; } using ( fs ) { foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*", SearchOption.AllDirectories)) { var name = Path.GetFileName(file); if (int.TryParse(name, out var handle)) { Console.WriteLine($"Replacing file: {file}"); fs.AddFile(handle, file, ConflictPolicy.Replace); } else { Console.WriteLine($"Skipping file: {file}; name does not contain a valid index"); } } Console.WriteLine("Saving..."); fs.Save(outputPath); } } else { if (args.Length > 3) { outputPath = args[3]; } using ( fs ) { var entryName = args[1]; if (int.TryParse(entryName, out var handle)) { if (!fs.Exists(handle)) { Console.WriteLine("Specified entry doesn't exist."); return(false); } var filePath = args[2]; if (!File.Exists(filePath)) { Console.WriteLine("Specified replacement file doesn't exist."); return(false); } Console.WriteLine($"Replacing file: {filePath}"); fs.AddFile(handle, filePath, ConflictPolicy.Replace); Console.WriteLine("Saving..."); fs.Save(outputPath); } else { Console.WriteLine("Specified entry doesn't exist."); return(false); } } } return(true); }
public bool Execute(string[] args) { if (args.Length < 1) { Console.WriteLine("Expected at least 1 argument."); return(false); } var inputPath = args[0]; if (!File.Exists(inputPath)) { Console.WriteLine("Input file doesn't exist."); return(false); } var outputPath = Path.ChangeExtension(inputPath, null); if (args.Length > 1) { outputPath = args[1]; } Directory.CreateDirectory(outputPath); var fs = new SMT1FileSystem(); try { fs.Load(inputPath); } catch (Exception) { Console.WriteLine("Couldn't load DATA.BIN. Did you make sure to put the game executable in the same directory?"); return(false); } using ( fs ) { foreach (int file in fs.EnumerateFiles(SearchOption.AllDirectories)) { var info = fs.GetInfo(file); var extension = ".bin"; switch (info.ContentKind) { case ContentKind.TIM: extension = ".tim"; break; case ContentKind.TIMH: extension = ".timh"; break; case ContentKind.SC02: extension = ".sc02"; break; case ContentKind.Archive: extension = ".arc"; break; } var name = file.ToString("D4") + extension; using (var stream = FileUtils.Create(outputPath + Path.DirectorySeparatorChar + name)) using (var inputStream = fs.OpenFile(file)) { Console.WriteLine($"Extracting: {name}"); inputStream.CopyTo(stream); } } } return(true); }