@@ -10,32 +10,76 @@ public static class Program
10
10
{
11
11
private static readonly Dictionary < ulong , string > HashNameDictionary = new Dictionary < ulong , string > ( ) ;
12
12
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
+
13
33
private static void Main ( string [ ] args )
14
34
{
15
- if ( args . Length != 2 )
35
+ if ( args . Length == 1 )
16
36
{
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
+ }
19
59
}
20
-
21
- switch ( args [ 0 ] )
60
+ else if ( args . Length == 2 )
22
61
{
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
+ }
32
75
}
76
+ ShowUsageInfo ( ) ;
33
77
}
34
78
35
79
private static void CompileFile ( string path )
36
80
{
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 ) ;
39
83
using ( FileStream input = new FileStream ( path , FileMode . Open ) )
40
84
using ( FileStream output = new FileStream ( outFileName , FileMode . Create ) )
41
85
{
@@ -54,38 +98,28 @@ private static void CompileFile(string path)
54
98
private static void ShowUsageInfo ( )
55
99
{
56
100
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 " +
58
102
"Information:\n " +
59
103
" Compiled XML files have these file extensions:\n " +
60
104
" BND CLO DES EVF FOX2 FSD LAD PARTS PH PHSD SDF SIM TGT VDP VEH VFXLF\n " +
61
105
"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" ) ;
65
114
}
66
115
67
- private static void DecompileFile ( string path )
116
+ private static bool IsDecompilable ( string fileExtension )
68
117
{
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
+ }
88
120
121
+ private static void DecompileFile ( string path )
122
+ {
89
123
try
90
124
{
91
125
Console . WriteLine ( "Reading Dictionary.txt" ) ;
@@ -99,9 +133,9 @@ private static void DecompileFile(string path)
99
133
100
134
if ( File . Exists ( path ) )
101
135
{
102
- if ( decompilableExtensions . Contains ( Path . GetExtension ( path ) . ToLower ( ) ) == false )
136
+ if ( IsDecompilable ( Path . GetExtension ( path ) ) == false )
103
137
{
104
- Console . WriteLine ( "The provided file is not decompilable. \n " ) ;
138
+ ShowNotDecompilableError ( ) ;
105
139
return ;
106
140
}
107
141
@@ -118,7 +152,7 @@ private static void DecompileFile(string path)
118
152
}
119
153
else if ( Directory . Exists ( path ) )
120
154
{
121
- foreach ( var file in GetFileList ( new DirectoryInfo ( path ) , true , decompilableExtensions ) )
155
+ foreach ( var file in GetFileList ( new DirectoryInfo ( path ) , true , DecompilableExtensions ) )
122
156
{
123
157
Console . WriteLine ( "Decompiling {0}" , file . FullName ) ;
124
158
try
@@ -137,10 +171,14 @@ private static void DecompileFile(string path)
137
171
}
138
172
}
139
173
174
+ private static void ShowNotDecompilableError ( )
175
+ {
176
+ Console . WriteLine ( "The provided file is not decompilable." ) ;
177
+ }
178
+
140
179
private static void DecompileFile ( FileInfo file )
141
180
{
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 ) ) ;
144
182
string outputName = Path . Combine ( file . DirectoryName , fileName ) ;
145
183
using ( FileStream input = new FileStream ( file . FullName , FileMode . Open ) )
146
184
using ( FileStream output = new FileStream ( outputName , FileMode . Create ) )
0 commit comments