Overwrite now accounts for extracting too

This commit is contained in:
Villermen 2014-11-21 19:14:30 +01:00
parent e93ea24283
commit 8b6fe66102

View file

@ -20,18 +20,19 @@ namespace RSCacheTool
{ {
bool error = false; bool error = false;
bool help = false, extract = false, combine = false, combineOverwrite = false, combineMergeIncomplete = false; bool help = false, extract = false, combine = false, overwrite = false, combineMergeIncomplete = false;
int extractArchive = -1, combineArchive = 40, combineStartFile = 0; int extractArchive = -1, combineArchive = 40, combineStartFile = 0;
OptionSet argsParser = new OptionSet() { OptionSet argsParser = new OptionSet() {
{ "h", "show this message", val => { help = true; } }, { "h", "show this message", val => { help = true; } },
{ "o", "overwrite existing files, for all actions", val => { overwrite = true; } },
{ "e", "extract files from cache", val => { extract = true; } }, { "e", "extract files from cache", val => { extract = true; } },
{ "a=", "single archive to extract, if not given all archives will be extracted", val => { extractArchive = Convert.ToInt32(val); } }, { "a=", "single archive to extract, if not given all archives will be extracted", val => { extractArchive = Convert.ToInt32(val); } },
{ "c", "combine sound", val => { combine = true; } }, { "c", "combine sound", val => { combine = true; } },
{ "s=", "archive to combine sounds of, defaults to 40", val => { combineArchive = Convert.ToInt32(val); } }, { "s=", "archive to combine sounds of, defaults to 40", val => { combineArchive = Convert.ToInt32(val); } },
{ "o", "overwrite existing soundfiles", val => { combineOverwrite = true; } },
{ "i", "merge incomplete files (into special directory)", val => { combineMergeIncomplete = true; } }, { "i", "merge incomplete files (into special directory)", val => { combineMergeIncomplete = true; } },
}; };
@ -77,10 +78,10 @@ namespace RSCacheTool
else if (!error) else if (!error)
{ {
if (extract) if (extract)
ExtractFiles(extractArchive); ExtractFiles(extractArchive, overwrite);
if (combine) if (combine)
CombineSounds(combineArchive, combineStartFile, combineOverwrite, combineMergeIncomplete); CombineSounds(combineArchive, combineStartFile, overwrite, combineMergeIncomplete);
} }
return 0; return 0;
@ -89,7 +90,7 @@ namespace RSCacheTool
/// <summary> /// <summary>
/// Rips all files from the cachefile and puts them (structured and given a fitting extension where possible) in the fileDir. /// Rips all files from the cachefile and puts them (structured and given a fitting extension where possible) in the fileDir.
/// </summary> /// </summary>
static void ExtractFiles(int archive) static void ExtractFiles(int archive, bool overwriteExisting)
{ {
int startArchive = 0, endArchive = 255; int startArchive = 0, endArchive = 255;
@ -294,11 +295,17 @@ namespace RSCacheTool
if (!Directory.Exists(outFileDir)) if (!Directory.Exists(outFileDir))
Directory.CreateDirectory(outFileDir); Directory.CreateDirectory(outFileDir);
using (FileStream outFile = File.Open(outFileDir + outFileName, FileMode.Create, FileAccess.Write)) //(over)write file
if (!File.Exists(outFileDir + outFileName) || overwriteExisting)
{ {
outFile.Write(buffer, 0, buffer.Length); using (FileStream outFile = File.Open(outFileDir + outFileName, FileMode.Create, FileAccess.Write))
Console.WriteLine(outFileDir + outFileName); {
outFile.Write(buffer, 0, buffer.Length);
Console.WriteLine(outFileDir + outFileName);
}
} }
else
Console.WriteLine("Skipping file because it already exists.");
} }
} }
else else
@ -316,7 +323,7 @@ namespace RSCacheTool
/// <summary> /// <summary>
/// Combines the sound files (.jag &amp; .ogg) in the specified archive (40 for the build it was made on), and puts them into the soundtracks directory. /// Combines the sound files (.jag &amp; .ogg) in the specified archive (40 for the build it was made on), and puts them into the soundtracks directory.
/// </summary> /// </summary>
static void CombineSounds(int archive = 40, int startFile = 0, bool overwriteExisting = false, bool mergeIncomplete = false) static void CombineSounds(int archive, int startFile, bool overwriteExisting, bool mergeIncomplete)
{ {
string archiveDir = outDir + archive + "\\"; string archiveDir = outDir + archive + "\\";
string soundDir = outDir + "sound\\"; string soundDir = outDir + "sound\\";