Skip to content

Commit fe0e642

Browse files
committed
Simplified usage of the command line arguments.
1 parent e687c8c commit fe0e642

File tree

2 files changed

+85
-47
lines changed

2 files changed

+85
-47
lines changed

FoxTool/Program.cs

Lines changed: 83 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,76 @@ public static class Program
1010
{
1111
private static readonly Dictionary<ulong, string> HashNameDictionary = new Dictionary<ulong, string>();
1212

13+
private static readonly List<string> DecompilableExtensions = new List<string>
14+
{
15+
".bnd",
16+
".clo",
17+
".des",
18+
".evf",
19+
".fox2",
20+
".fsd",
21+
".lad",
22+
".parts",
23+
".ph",
24+
".phsd",
25+
".sdf",
26+
".sim",
27+
".tgt",
28+
".vdp",
29+
".veh",
30+
".vfxlf"
31+
};
32+
1333
private static void Main(string[] args)
1434
{
15-
if (args.Length != 2)
35+
if (args.Length == 1)
1636
{
17-
ShowUsageInfo();
18-
return;
37+
string path = args[0];
38+
if (File.Exists(path))
39+
{
40+
string fileExtension = Path.GetExtension(path);
41+
if (fileExtension.Equals(".xml", StringComparison.OrdinalIgnoreCase))
42+
{
43+
CompileFile(path);
44+
return;
45+
}
46+
if (IsDecompilable(fileExtension))
47+
{
48+
DecompileFile(path);
49+
return;
50+
}
51+
ShowNotDecompilableError();
52+
return;
53+
}
54+
if (Directory.Exists(path))
55+
{
56+
DecompileFile(path);
57+
return;
58+
}
1959
}
20-
21-
switch (args[0])
60+
else if (args.Length == 2)
2261
{
23-
case "-c":
24-
CompileFile(args[1]);
25-
break;
26-
case "-d":
27-
DecompileFile(args[1]);
28-
break;
29-
default:
30-
ShowUsageInfo();
31-
return;
62+
string option = args[0];
63+
switch (option)
64+
{
65+
case "-c":
66+
CompileFile(args[1]);
67+
return;
68+
case "-d":
69+
DecompileFile(args[1]);
70+
return;
71+
default:
72+
Console.WriteLine("Unknown option: {0}", option);
73+
return;
74+
}
3275
}
76+
ShowUsageInfo();
3377
}
3478

3579
private static void CompileFile(string path)
3680
{
37-
string outFileName = Path.Combine(Path.GetDirectoryName(path),
38-
string.Format("{0}.bin", Path.GetFileNameWithoutExtension(path)));
81+
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
82+
string outFileName = Path.Combine(Path.GetDirectoryName(path), fileNameWithoutExtension);
3983
using (FileStream input = new FileStream(path, FileMode.Open))
4084
using (FileStream output = new FileStream(outFileName, FileMode.Create))
4185
{
@@ -54,38 +98,28 @@ private static void CompileFile(string path)
5498
private static void ShowUsageInfo()
5599
{
56100
Console.WriteLine("FoxTool by Atvaark\n" +
57-
" A tool for compiling and decompiling Fox Engine XML files." +
101+
" A tool for compiling and decompiling Fox Engine XML files.\n" +
58102
"Information:\n" +
59103
" Compiled XML files have these file extensions:\n" +
60104
" BND CLO DES EVF FOX2 FSD LAD PARTS PH PHSD SDF SIM TGT VDP VEH VFXLF\n" +
61105
"Usage:\n" +
62-
" FoxTool -d file_path - Decompile the file to .fox\n" +
63-
" FoxTool -d folder_path - Decompile all decompilable files in the folder to .fox\n" +
64-
" FoxTool -c file_path - Compile the file to .bin");
106+
" FoxTool [-d|-c] file_path|folder_path\n" +
107+
"Examples:\n" +
108+
" FoxTool file_path.xml - Compile the XML file\n" +
109+
" FoxTool -c file_path - Compile the XML file\n" +
110+
" FoxTool file_path - Decompile the file to XML\n" +
111+
" FoxTool -d file_path - Decompile the file to XML\n" +
112+
" FoxTool folder_path - Decompile all suitable files in the folder to XML\n" +
113+
" FoxTool -d folder_path - Decompile all suitable files in the folder to XML");
65114
}
66115

67-
private static void DecompileFile(string path)
116+
private static bool IsDecompilable(string fileExtension)
68117
{
69-
List<string> decompilableExtensions = new List<string>
70-
{
71-
".bnd",
72-
".clo",
73-
".des",
74-
".evf",
75-
".fox2",
76-
".fsd",
77-
".lad",
78-
".parts",
79-
".ph",
80-
".phsd",
81-
".sdf",
82-
".sim",
83-
".tgt",
84-
".vdp",
85-
".veh",
86-
".vfxlf"
87-
};
118+
return DecompilableExtensions.Contains(fileExtension, StringComparer.OrdinalIgnoreCase);
119+
}
88120

121+
private static void DecompileFile(string path)
122+
{
89123
try
90124
{
91125
Console.WriteLine("Reading Dictionary.txt");
@@ -99,9 +133,9 @@ private static void DecompileFile(string path)
99133

100134
if (File.Exists(path))
101135
{
102-
if (decompilableExtensions.Contains(Path.GetExtension(path).ToLower()) == false)
136+
if (IsDecompilable(Path.GetExtension(path)) == false)
103137
{
104-
Console.WriteLine("The provided file is not decompilable.\n");
138+
ShowNotDecompilableError();
105139
return;
106140
}
107141

@@ -118,7 +152,7 @@ private static void DecompileFile(string path)
118152
}
119153
else if (Directory.Exists(path))
120154
{
121-
foreach (var file in GetFileList(new DirectoryInfo(path), true, decompilableExtensions))
155+
foreach (var file in GetFileList(new DirectoryInfo(path), true, DecompilableExtensions))
122156
{
123157
Console.WriteLine("Decompiling {0}", file.FullName);
124158
try
@@ -137,10 +171,14 @@ private static void DecompileFile(string path)
137171
}
138172
}
139173

174+
private static void ShowNotDecompilableError()
175+
{
176+
Console.WriteLine("The provided file is not decompilable.");
177+
}
178+
140179
private static void DecompileFile(FileInfo file)
141180
{
142-
string fileName = string.Format("{0}_{1}.fox", Path.GetFileNameWithoutExtension(file.Name),
143-
Path.GetExtension(file.Name).Replace(".", ""));
181+
string fileName = string.Format("{0}.xml", Path.GetFileName(file.Name));
144182
string outputName = Path.Combine(file.DirectoryName, fileName);
145183
using (FileStream input = new FileStream(file.FullName, FileMode.Open))
146184
using (FileStream output = new FileStream(outputName, FileMode.Create))

FoxTool/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
[assembly: AssemblyCulture("")]
1212
[assembly: ComVisible(false)]
1313
[assembly: Guid("561aab12-c53d-4a0e-bac5-0efc04a54618")]
14-
[assembly: AssemblyVersion("0.1.1.0")]
15-
[assembly: AssemblyFileVersion("0.1.1.0")]
14+
[assembly: AssemblyVersion("0.1.3.0")]
15+
[assembly: AssemblyFileVersion("0.1.3.0")]

0 commit comments

Comments
 (0)