Skip to content

Commit 5641698

Browse files
committed
Confirm success before overwriting uasset
Now checks the log to determine if (de)compilation succeeded before proceeding with file deletion
1 parent 6996213 commit 5641698

File tree

4 files changed

+75
-97
lines changed

4 files changed

+75
-97
lines changed

Config.cs

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using Newtonsoft.Json;
2-
using System;
3-
using System.Collections.Generic;
42
using System.IO;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
83

94
namespace AtlusScriptGUI
105
{

Events.cs

-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77
using MetroSet_UI.Forms;
88
using ShrineFox.IO;
99
using System;
10-
using System.Collections;
11-
using System.Collections.Generic;
12-
using System.Diagnostics;
1310
using System.IO;
1411
using System.Linq;
15-
using System.Net.NetworkInformation;
16-
using System.Reflection;
1712
using System.Text;
18-
using System.Threading;
19-
using System.Threading.Tasks;
2013
using System.Windows.Forms;
2114

2215
namespace AtlusScriptGUI

Forms/MainForm.cs

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
using AtlusScriptGUI;
2-
using MetroSet_UI.Forms;
1+
using MetroSet_UI.Forms;
32
using ShrineFox.IO;
43
using System;
5-
using System.IO;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading;
9-
using System.Windows.Forms;
104

115
namespace AtlusScriptGUI
126
{
137
public partial class MainForm : MetroSetForm
148
{
15-
public static Version version = new Version(3, 4, 1);
9+
public static Version version = new Version(3, 4, 2);
1610
public Config settings = new Config();
1711

1812
public MainForm(string[] args)

GUI.cs

+73-77
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
using MetroSet_UI.Forms;
22
using ShrineFox.IO;
33
using System;
4-
using System.Collections;
54
using System.Collections.Generic;
65
using System.Diagnostics;
76
using System.IO;
87
using System.Linq;
9-
using System.Net.NetworkInformation;
10-
using System.Reflection;
118
using System.Text;
129
using System.Threading;
13-
using System.Threading.Tasks;
14-
using System.Windows.Forms;
1510

1611
namespace AtlusScriptGUI
1712
{
@@ -168,101 +163,102 @@ public void Compile(string[] fileList, bool decompile = false)
168163
return;
169164

170165
Exe.Run(Path.GetFullPath(settings.CompilerPath), args, redirectStdOut: true);
166+
if (CheckIfTaskSucceeded())
167+
{
168+
ProcessUassetOutput(fileList[i], decompile);
169+
DeleteHeaderFiles(fileList[i]);
170+
}
171171
}
172-
ProcessUassetOutput(fileList, decompile);
173-
DeleteHeaderFiles(fileList);
174172
}).Start();
175173
}
176174

177-
private void ProcessUassetOutput(string[] fileList, bool decompile)
175+
private bool CheckIfTaskSucceeded()
176+
{
177+
var logLines = new string[0];
178+
rtb_Log.Invoke((Action)(() => logLines = rtb_Log.Text.Split('\n')));
179+
if (logLines[logLines.Length - 2].Contains("Info: Task completed successfully!"))
180+
return true;
181+
return false;
182+
}
183+
184+
private void ProcessUassetOutput(string file, bool decompile)
178185
{
179-
if (settings.Game != "Persona 3 Reload")
186+
if (settings.Game != "Persona 3 Reload" || !settings.Overwrite)
180187
return;
181188

182-
foreach (var file in fileList)
189+
if (decompile && Path.GetExtension(file).ToUpper() == ".UASSET")
183190
{
184-
if (decompile && chk_Overwrite.Checked && Path.GetExtension(file).ToUpper() == ".UASSET")
185-
{
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;
197-
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);
216-
}
217-
else if (chk_Overwrite.Checked)
218-
{
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";
225-
string newUassetDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".uasset");
191+
string bfFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bf");
192+
string bmdFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd");
193+
string flowFile = bfFile + ".flow";
194+
string msgFile = bmdFile + ".msg";
195+
string newFlowDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".flow");
196+
string newMsgDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg");
197+
string hFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
198+
string newHFileDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".msg.h");
199+
200+
if (File.Exists(bfFile))
201+
File.Delete(bfFile);
202+
if (File.Exists(bmdFile))
203+
File.Delete(bmdFile);
204+
205+
if (File.Exists(newFlowDest))
206+
File.Delete(newFlowDest);
207+
if (File.Exists(newMsgDest))
208+
File.Delete(newMsgDest);
209+
if (File.Exists(newHFileDest))
210+
File.Delete(newHFileDest);
211+
212+
if (File.Exists(flowFile))
213+
File.Move(flowFile, newFlowDest);
214+
if (File.Exists(msgFile))
215+
File.Move(msgFile, newMsgDest);
216+
if (File.Exists(hFile))
217+
File.Move(hFile, newHFileDest);
218+
}
219+
else if (chk_Overwrite.Checked)
220+
{
221+
string extension = ".bf";
222+
if (Path.GetFileName(file).ToLower().Contains("bmd"))
223+
extension = ".bmd";
226224

227-
if (!File.Exists(uassetFile))
228-
return;
225+
string scriptFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + extension);
226+
string uassetFile = scriptFile + ".uasset";
227+
string newUassetDest = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + ".uasset");
229228

230-
if (File.Exists(scriptFile))
231-
File.Delete(scriptFile);
229+
if (File.Exists(scriptFile))
230+
File.Delete(scriptFile);
232231

233-
if (File.Exists(newUassetDest))
234-
File.Delete(newUassetDest);
232+
if (File.Exists(newUassetDest))
233+
File.Delete(newUassetDest);
235234

235+
if (File.Exists(uassetFile))
236236
File.Move(uassetFile, newUassetDest);
237-
}
238237
}
239238
}
240239

241-
private void DeleteHeaderFiles(string[] fileList)
240+
private void DeleteHeaderFiles(string file)
242241
{
243242
if (!chk_DeleteHeader.Checked)
244243
return;
245244

246-
foreach (var file in fileList)
245+
if (Path.GetExtension(file).ToUpper() == ".BMD")
247246
{
248-
if (Path.GetExtension(file).ToUpper() == ".BMD")
249-
{
250-
string headerFile = file + ".msg.h";
251-
if (chk_Overwrite.Checked)
252-
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
247+
string headerFile = file + ".msg.h";
248+
if (chk_Overwrite.Checked)
249+
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
253250

254-
if (File.Exists(headerFile))
255-
File.Delete(headerFile);
256-
}
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";
251+
if (File.Exists(headerFile))
252+
File.Delete(headerFile);
253+
}
254+
else if (Path.GetExtension(file).ToUpper() == ".UASSET" && Path.GetFileName(file).ToLower().Contains("bmd"))
255+
{
256+
string headerFile = Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) + "_unwrapped.bmd.msg.h");
257+
if (chk_Overwrite.Checked)
258+
headerFile = FileSys.GetExtensionlessPath(file) + ".msg.h";
262259

263-
if (File.Exists(headerFile))
264-
File.Delete(headerFile);
265-
}
260+
if (File.Exists(headerFile))
261+
File.Delete(headerFile);
266262
}
267263
}
268264

0 commit comments

Comments
 (0)