|
1 | 1 | using MetroSet_UI.Forms;
|
2 | 2 | using ShrineFox.IO;
|
3 | 3 | using System;
|
4 |
| -using System.Collections; |
5 | 4 | using System.Collections.Generic;
|
6 | 5 | using System.Diagnostics;
|
7 | 6 | using System.IO;
|
8 | 7 | using System.Linq;
|
9 |
| -using System.Net.NetworkInformation; |
10 |
| -using System.Reflection; |
11 | 8 | using System.Text;
|
12 | 9 | using System.Threading;
|
13 |
| -using System.Threading.Tasks; |
14 |
| -using System.Windows.Forms; |
15 | 10 |
|
16 | 11 | namespace AtlusScriptGUI
|
17 | 12 | {
|
@@ -168,101 +163,102 @@ public void Compile(string[] fileList, bool decompile = false)
|
168 | 163 | return;
|
169 | 164 |
|
170 | 165 | Exe.Run(Path.GetFullPath(settings.CompilerPath), args, redirectStdOut: true);
|
| 166 | + if (CheckIfTaskSucceeded()) |
| 167 | + { |
| 168 | + ProcessUassetOutput(fileList[i], decompile); |
| 169 | + DeleteHeaderFiles(fileList[i]); |
| 170 | + } |
171 | 171 | }
|
172 |
| - ProcessUassetOutput(fileList, decompile); |
173 |
| - DeleteHeaderFiles(fileList); |
174 | 172 | }).Start();
|
175 | 173 | }
|
176 | 174 |
|
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) |
178 | 185 | {
|
179 |
| - if (settings.Game != "Persona 3 Reload") |
| 186 | + if (settings.Game != "Persona 3 Reload" || !settings.Overwrite) |
180 | 187 | return;
|
181 | 188 |
|
182 |
| - foreach (var file in fileList) |
| 189 | + if (decompile && Path.GetExtension(file).ToUpper() == ".UASSET") |
183 | 190 | {
|
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"; |
226 | 224 |
|
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"); |
229 | 228 |
|
230 |
| - if (File.Exists(scriptFile)) |
231 |
| - File.Delete(scriptFile); |
| 229 | + if (File.Exists(scriptFile)) |
| 230 | + File.Delete(scriptFile); |
232 | 231 |
|
233 |
| - if (File.Exists(newUassetDest)) |
234 |
| - File.Delete(newUassetDest); |
| 232 | + if (File.Exists(newUassetDest)) |
| 233 | + File.Delete(newUassetDest); |
235 | 234 |
|
| 235 | + if (File.Exists(uassetFile)) |
236 | 236 | File.Move(uassetFile, newUassetDest);
|
237 |
| - } |
238 | 237 | }
|
239 | 238 | }
|
240 | 239 |
|
241 |
| - private void DeleteHeaderFiles(string[] fileList) |
| 240 | + private void DeleteHeaderFiles(string file) |
242 | 241 | {
|
243 | 242 | if (!chk_DeleteHeader.Checked)
|
244 | 243 | return;
|
245 | 244 |
|
246 |
| - foreach (var file in fileList) |
| 245 | + if (Path.GetExtension(file).ToUpper() == ".BMD") |
247 | 246 | {
|
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"; |
253 | 250 |
|
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"; |
262 | 259 |
|
263 |
| - if (File.Exists(headerFile)) |
264 |
| - File.Delete(headerFile); |
265 |
| - } |
| 260 | + if (File.Exists(headerFile)) |
| 261 | + File.Delete(headerFile); |
266 | 262 | }
|
267 | 263 | }
|
268 | 264 |
|
|
0 commit comments