C#: some fixes in the 'UI' part of the program.

This commit is contained in:
barubary 2011-05-15 15:49:21 +00:00
parent 3c0e60d574
commit 441848074d

View File

@ -144,21 +144,21 @@ namespace DSDecmp
Console.WriteLine("Usage:\tDSDecmp (-c FORMAT FORMATOPT*) (-ge) input (output)"); Console.WriteLine("Usage:\tDSDecmp (-c FORMAT FORMATOPT*) (-ge) input (output)");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Without the -c modifier, DSDecmp will decompress the input file to the output"); Console.WriteLine("Without the -c modifier, DSDecmp will decompress the input file to the output");
Console.WriteLine("file. If the output file is a directory, the output file will be placed in that"); Console.WriteLine(" file. If the output file is a directory, the output file will be placed in");
Console.WriteLine("directory with the same filename as the original file. The extension will be"); Console.WriteLine(" that directory with the same filename as the original file. The extension will");
Console.WriteLine("appended with a format-specific extension."); Console.WriteLine(" be appended with a format-specific extension.");
Console.WriteLine("If the output is a nonexistent file or directory, it is assumed to be a");
Console.WriteLine("directory iff there is no '.' in the name.");
Console.WriteLine("The input can also be a directory. In that case, it would be the same as"); Console.WriteLine("The input can also be a directory. In that case, it would be the same as");
Console.WriteLine(" calling DSDecmp for every non-directory in the given directory with the same"); Console.WriteLine(" calling DSDecmp for every non-directory in the given directory with the same");
Console.WriteLine(" options, with one exception; the output is by default the input folder, but"); Console.WriteLine(" options, with one exception; the output is by default the input folder, but");
Console.WriteLine(" with '_dec' appended."); Console.WriteLine(" with '_dec' appended.");
Console.WriteLine("If the output does not exist, it is assumed to be the same type as the input");
Console.WriteLine(" (file or directory).");
Console.WriteLine("If there is no output file given, it is assumed to be the directory of the"); Console.WriteLine("If there is no output file given, it is assumed to be the directory of the");
Console.WriteLine(" input file."); Console.WriteLine(" input file.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("With the -ge option, instead of a format-specific extension, the extension"); Console.WriteLine("With the -ge option, instead of a format-specific extension, the extension");
Console.WriteLine("will be guessed from the first four bytes of the output file. Only non-accented"); Console.WriteLine(" will be guessed from the first four bytes of the output file. Only");
Console.WriteLine("letters or numbers are considered in those four bytes."); Console.WriteLine(" non-accented letters or numbers are considered in those four bytes.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("With the -c option, the input is compressed instead of decompressed. FORMAT"); Console.WriteLine("With the -c option, the input is compressed instead of decompressed. FORMAT");
Console.WriteLine("indicates the desired compression format, and can be one of:"); Console.WriteLine("indicates the desired compression format, and can be one of:");
@ -210,11 +210,12 @@ namespace DSDecmp
{ {
if (Directory.Exists(input)) if (Directory.Exists(input))
{ {
if (!Directory.Exists(input + "_cmp")) string newDir = Path.GetFullPath(input) + "_cmp";
Directory.CreateDirectory(input + "_cmp"); if (!Directory.Exists(newDir))
Directory.CreateDirectory(newDir);
foreach (string file in Directory.GetFiles(input)) foreach (string file in Directory.GetFiles(input))
{ {
Compress(file, input + "_cmp", format, guessExtension); Compress(file, newDir, format, guessExtension);
} }
return; return;
} }
@ -246,15 +247,16 @@ namespace DSDecmp
if (outsize < 0) if (outsize < 0)
return; return;
bool mustAppendExt = !Directory.Exists(output) && !File.Exists(output);
if (Directory.Exists(output)) if (Directory.Exists(output))
{ {
output = CombinePaths(output, Path.GetFileName(input)); output = CombinePaths(output, Path.GetFileName(input));
} }
if (Path.GetExtension(output) == ".dat") if (mustAppendExt && Path.GetExtension(output) == ".dat")
output = RemoveExtension(output); output = RemoveExtension(output);
if (guessExtension) if (guessExtension)
output += "." + compressedFormat.ToString().ToLower(); output += "." + compressedFormat.ToString().ToLower();
else else if (mustAppendExt)
output += ".cdat"; output += ".cdat";
using (FileStream outStream = File.Create(output)) using (FileStream outStream = File.Create(output))
@ -399,11 +401,12 @@ namespace DSDecmp
{ {
if (Directory.Exists(input)) if (Directory.Exists(input))
{ {
if (!Directory.Exists(input + "_dec")) string newDir = Path.GetFullPath(input) + "_dec";
Directory.CreateDirectory(input + "_dec"); if (!Directory.Exists(newDir))
Directory.CreateDirectory(newDir);
foreach (string file in Directory.GetFiles(input)) foreach (string file in Directory.GetFiles(input))
{ {
Decompress(file, input + "_dec", guessExtension); Decompress(file, newDir, guessExtension);
} }
return; return;
} }
@ -432,7 +435,6 @@ namespace DSDecmp
return; return;
} }
byte[] inData; byte[] inData;
using (FileStream inStream = File.OpenRead(input)) using (FileStream inStream = File.OpenRead(input))
{ {
@ -462,11 +464,16 @@ namespace DSDecmp
return; return;
} }
bool mustAppendExt = !Directory.Exists(output) && !File.Exists(output);
if (Directory.Exists(output)) if (Directory.Exists(output))
{ {
output = CombinePaths(output, Path.GetFileName(input)); output = CombinePaths(output, Path.GetFileName(input));
} }
byte[] outData = decompressedData.ToArray();
if (mustAppendExt)
{
switch (Path.GetExtension(output)) switch (Path.GetExtension(output))
{ {
case ".cdat": case ".cdat":
@ -479,7 +486,7 @@ namespace DSDecmp
output = RemoveExtension(output); output = RemoveExtension(output);
break; break;
} }
byte[] outData = decompressedData.ToArray(); }
if (guessExtension) if (guessExtension)
{ {
string ext = ""; string ext = "";
@ -497,13 +504,13 @@ namespace DSDecmp
else else
output += ".dat"; output += ".dat";
} }
else else if(mustAppendExt)
output += ".dat"; output += ".dat";
using (FileStream outStream = File.Create(output)) using (FileStream outStream = File.Create(output))
{ {
outStream.Write(outData, 0, outData.Length); outStream.Write(outData, 0, outData.Length);
Console.WriteLine(usedFormat.ToString() + "-decompressed " + input); Console.WriteLine(usedFormat.ToString() + "-decompressed " + input + " to " + output);
} }
} }