Only print out files that were named

Instead of almost all of them.
Major convention changes too.
main
Villermen 10 years ago
parent ae662cad8a
commit 99fa58f31a

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;
@ -14,8 +15,8 @@ namespace RSCacheTool
{
static class Program
{
static string cacheDir = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\jagexcache\runescape\LIVE\");
static string outDir = "cache\\";
static string _cacheDir = Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\jagexcache\runescape\LIVE\");
static string _outDir = "cache\\";
static int Main(string[] args)
{
@ -25,7 +26,7 @@ namespace RSCacheTool
int extractArchive = -1, combineArchive = 40;
string combineFile = "", nameFile = "";
OptionSet argsParser = new OptionSet() {
OptionSet argsParser = new OptionSet {
{ "h", "show this message", val => { help = true; } },
{ "o", "overwrite existing files, for all actions", val => { overwrite = true; } },
@ -68,10 +69,15 @@ namespace RSCacheTool
if (Directory.Exists(parsedPath))
{
if (i == 0)
outDir = parsedPath;
else if (i == 1)
cacheDir = parsedPath;
switch (i)
{
case 0:
_outDir = parsedPath;
break;
case 1:
_cacheDir = parsedPath;
break;
}
}
else
{
@ -100,8 +106,8 @@ namespace RSCacheTool
else if (!error)
{
//create outdir
if (!Directory.Exists(outDir))
Directory.CreateDirectory(outDir);
if (!Directory.Exists(_outDir))
Directory.CreateDirectory(_outDir);
if (extract)
ExtractFiles(extractArchive, overwrite);
@ -132,14 +138,15 @@ namespace RSCacheTool
endArchive = archive;
}
using (FileStream cacheFile = File.Open(cacheDir + "main_file_cache.dat2", FileMode.Open, FileAccess.Read))
using (FileStream cacheFile = File.Open(_cacheDir + "main_file_cache.dat2", FileMode.Open, FileAccess.Read))
{
for (int archiveIndex = startArchive; archiveIndex <= endArchive; archiveIndex++)
{
string indexFileString = cacheDir + "main_file_cache.idx" + archiveIndex.ToString();
string indexFileString = _cacheDir + "main_file_cache.idx" + archiveIndex;
if (!File.Exists(indexFileString))
continue;
if (File.Exists(indexFileString))
{
FileStream indexFile = File.Open(indexFileString, FileMode.Open, FileAccess.Read);
int fileCount = (int)indexFile.Length / 6;
@ -204,11 +211,12 @@ namespace RSCacheTool
}
}
if (!fileError)
{
if (fileError)
continue;
//process file
string outFileDir = outDir + archiveIndex + "\\";
string outFileName = fileIndex.ToString();
string outFileDir = _outDir + archiveIndex + "\\";
string outFileName = fileIndex.ToString(CultureInfo.InvariantCulture);
//remove the first 5 bytes because they are not part of the file
byte[] tempBuffer = new byte[fileSize - 5];
@ -253,7 +261,7 @@ namespace RSCacheTool
tempBuffer = new byte[fileSize - 4];
Array.Copy(buffer, 4, tempBuffer, 0, fileSize - 4);
buffer = tempBuffer;
fileSize -= 4;
//fileSize -= 4;
//prepend file header
byte[] magic = {
@ -316,7 +324,6 @@ namespace RSCacheTool
else
Console.WriteLine("Skipping file because it already exists.");
}
}
else
{
Console.WriteLine("Ignoring file because of size or offset.");
@ -324,7 +331,6 @@ namespace RSCacheTool
}
}
}
}
Console.WriteLine("Done extracting files.");
}
@ -334,8 +340,8 @@ namespace RSCacheTool
/// </summary>
static void CombineSounds(int archive, string file, bool overwriteExisting, bool mergeIncomplete)
{
string archiveDir = outDir + archive + "\\";
string soundDir = outDir + "sound\\";
string archiveDir = _outDir + archive + "\\";
string soundDir = _outDir + "sound\\";
//gather all index files
string[] indexFiles = Directory.GetFiles(archiveDir, "*.jaga", SearchOption.TopDirectoryOnly);
@ -406,7 +412,7 @@ namespace RSCacheTool
StartInfo = {FileName = "sox.exe", Arguments = "--combine concatenate ~index.ogg"}
};
chunkFiles.ForEach((str) =>
chunkFiles.ForEach(str =>
{
soxProcess.StartInfo.Arguments += " " + str;
});
@ -450,7 +456,7 @@ namespace RSCacheTool
//the following is based on even more assumptions than normal made while comparing 2 extracted caches, it's therefore probably the first thing to break
//4B magic number (0x00016902) - 2B a file id? - 2B amount of files (higher than actual entries sometimes) - 2B amount of files
string resolveFileName = outDir + "17\\5";
string resolveFileName = _outDir + "17\\5";
if (File.Exists(resolveFileName))
{
@ -511,10 +517,10 @@ namespace RSCacheTool
}
//let's do this!
if (!Directory.Exists(outDir + "sound\\named\\"))
Directory.CreateDirectory(outDir + "sound\\named\\");
if (!Directory.Exists(_outDir + "sound\\named\\"))
Directory.CreateDirectory(_outDir + "sound\\named\\");
foreach (string soundFile in Directory.GetFiles(outDir + "sound\\"))
foreach (string soundFile in Directory.GetFiles(_outDir + "sound\\"))
{
string fileIdString = Path.GetFileNameWithoutExtension(soundFile);
@ -522,32 +528,33 @@ namespace RSCacheTool
continue;
uint fileId;
if (uint.TryParse(fileIdString, out fileId))
{
if (fileIdTracks.ContainsKey(fileId))
{
if (!uint.TryParse(fileIdString, out fileId))
continue;
if (!fileIdTracks.ContainsKey(fileId))
continue;
int trackId = fileIdTracks[fileId];
if (trackIdNames.ContainsKey(trackId))
{
if (!trackIdNames.ContainsKey(trackId))
continue;
string trackName = trackIdNames[trackId];
string destFile = outDir + "sound\\named\\" + trackName + ".ogg";
string destFile = _outDir + "sound\\named\\" + trackName + ".ogg";
if (!File.Exists(destFile) || overwrite)
File.Copy(soundFile, destFile, true);
if (File.Exists(destFile) && !overwrite)
continue;
File.Copy(soundFile, destFile, true);
Console.WriteLine(destFile);
}
}
}
}
//redundancy, whatever
if (incomplete)
{
if (!Directory.Exists(outDir + "sound\\named\\incomplete\\"))
Directory.CreateDirectory(outDir + "sound\\named\\incomplete");
if (!Directory.Exists(_outDir + "sound\\named\\incomplete\\"))
Directory.CreateDirectory(_outDir + "sound\\named\\incomplete");
foreach (string soundFile in Directory.GetFiles(outDir + "sound\\incomplete\\"))
foreach (string soundFile in Directory.GetFiles(_outDir + "sound\\incomplete\\"))
{
string fileIdString = Path.GetFileNameWithoutExtension(soundFile);
@ -555,26 +562,27 @@ namespace RSCacheTool
continue;
uint fileId;
if (uint.TryParse(fileIdString, out fileId))
{
if (fileIdTracks.ContainsKey(fileId))
{
if (!uint.TryParse(fileIdString, out fileId))
continue;
if (!fileIdTracks.ContainsKey(fileId))
continue;
int trackId = fileIdTracks[fileId];
if (trackIdNames.ContainsKey(trackId))
{
if (!trackIdNames.ContainsKey(trackId))
continue;
string trackName = trackIdNames[trackId];
string destFile = outDir + "sound\\named\\incomplete\\" + trackName + ".ogg";
string destFile = _outDir + "sound\\named\\incomplete\\" + trackName + ".ogg";
if (!File.Exists(destFile) || overwrite)
File.Copy(soundFile, destFile, true);
if (File.Exists(destFile) && !overwrite)
continue;
File.Copy(soundFile, destFile, true);
Console.WriteLine(destFile);
}
}
}
}
}
}
else
Console.WriteLine("Entry points within resolving file could not be found.");
}

Loading…
Cancel
Save