Skip to content

Commit 74a7e9e

Browse files
committed
Overwrite/delete .uasset header files
Also attempt to prevent deletion of original input files if decompilation fails (this only checks if the expected output file doesn't exist, so if it's overwriting an existing output it may still not be enough to prevent the original file being deleted)
1 parent 8eb0f7e commit 74a7e9e

File tree

1 file changed

+55
-20
lines changed

1 file changed

+55
-20
lines changed

GUI.cs

+55-20
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ public void Compile(string[] fileList, bool decompile = false)
169169

170170
Exe.Run(Path.GetFullPath(settings.CompilerPath), args, redirectStdOut: true);
171171
}
172-
DeleteHeaderFiles(fileList);
173172
ProcessUassetOutput(fileList, decompile);
173+
DeleteHeaderFiles(fileList);
174174
}).Start();
175175
}
176176

@@ -183,43 +183,69 @@ private void ProcessUassetOutput(string[] fileList, bool decompile)
183183
{
184184
if (decompile && chk_Overwrite.Checked && Path.GetExtension(file).ToUpper() == ".UASSET")
185185
{
186+
string bfFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bf");
187+
string bmdFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd");
188+
string flowFile = bfFile + ".flow";
189+
string msgFile = bmdFile + ".msg";
190+
string newFlowDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".flow");
191+
string newMsgDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg");
192+
string hFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
193+
string newHFileDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg.h");
194+
195+
if (!File.Exists(flowFile) && !File.Exists(msgFile))
196+
return;
186197

187-
string bfFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bf");
188-
string flowFile = bfFile + ".flow";
189-
string newFlowDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".flow");
190-
191-
if (File.Exists(bfFile))
192-
File.Delete(bfFile);
193-
194-
if (File.Exists(newFlowDest))
195-
File.Delete(newFlowDest);
196-
197-
if (File.Exists(flowFile))
198-
File.Move(flowFile, newFlowDest);
198+
if (File.Exists(bfFile))
199+
File.Delete(bfFile);
200+
if (File.Exists(bmdFile))
201+
File.Delete(bmdFile);
202+
203+
if (File.Exists(newFlowDest))
204+
File.Delete(newFlowDest);
205+
if (File.Exists(newMsgDest))
206+
File.Delete(newMsgDest);
207+
if (File.Exists(newHFileDest))
208+
File.Delete(newHFileDest);
209+
210+
if (File.Exists(flowFile))
211+
File.Move(flowFile, newFlowDest);
212+
if (File.Exists(msgFile))
213+
File.Move(msgFile, newMsgDest);
214+
if (File.Exists(hFile))
215+
File.Move(hFile, newHFileDest);
199216
}
200217
else if (chk_Overwrite.Checked)
201218
{
202-
string bfFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".bf");
203-
string uassetFile = bfFile + ".uasset";
219+
string extension = ".bf";
220+
if (Path.GetFileName(file).ToLower().Contains("bmd"))
221+
extension = ".bmd";
222+
223+
string scriptFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + extension);
224+
string uassetFile = scriptFile + ".uasset";
204225
string newUassetDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".uasset");
205226

206-
if (File.Exists(bfFile))
207-
File.Delete(bfFile);
227+
if (!File.Exists(uassetFile))
228+
return;
229+
230+
if (File.Exists(scriptFile))
231+
File.Delete(scriptFile);
208232

209233
if (File.Exists(newUassetDest))
210234
File.Delete(newUassetDest);
211235

212-
if (File.Exists(uassetFile))
213-
File.Move(uassetFile, newUassetDest);
236+
File.Move(uassetFile, newUassetDest);
214237
}
215238
}
216239
}
217240

218241
private void DeleteHeaderFiles(string[] fileList)
219242
{
243+
if (!chk_DeleteHeader.Checked)
244+
return;
245+
220246
foreach (var file in fileList)
221247
{
222-
if (chk_DeleteHeader.Checked && Path.GetExtension(file).ToUpper() == ".BMD")
248+
if (Path.GetExtension(file).ToUpper() == ".BMD")
223249
{
224250
string headerFile = file + ".msg.h";
225251
if (chk_Overwrite.Checked)
@@ -228,6 +254,15 @@ private void DeleteHeaderFiles(string[] fileList)
228254
if (File.Exists(headerFile))
229255
File.Delete(headerFile);
230256
}
257+
else if (Path.GetExtension(file).ToUpper() == ".UASSET" && Path.GetFileName(file).ToLower().Contains("bmd"))
258+
{
259+
string headerFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
260+
if (chk_Overwrite.Checked)
261+
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
262+
263+
if (File.Exists(headerFile))
264+
File.Delete(headerFile);
265+
}
231266
}
232267
}
233268

0 commit comments

Comments
 (0)