Simplified code

This commit is contained in:
ZestyTS 2022-08-24 00:01:35 -07:00
parent 94bfdde67e
commit 2857dca029

View file

@ -1617,37 +1617,28 @@ namespace UWUVCI_AIO_WPF
int i = 0; int i = 0;
while (Directory.Exists(outputPath)) while (Directory.Exists(outputPath))
{ {
outputPath = Path.Combine(Properties.Settings.Default.OutPath, $"[WUP]{reg.Replace(gameName, "").Replace("|", " ")}_{i}"); outputPath = Path.Combine(Settings.Default.OutPath, $"[WUP]{reg.Replace(gameName, "").Replace("|", " ")}_{i}");
mvvm.foldername = $"[WUP]{reg.Replace(gameName, "").Replace("|", " ")}_{i}"; mvvm.foldername = $"[WUP]{reg.Replace(gameName, "").Replace("|", " ")}_{i}";
i++; i++;
} }
var oldpath = Directory.GetCurrentDirectory();
mvm.Progress = 40; mvm.Progress = 40;
mvm.msg = "Packing..."; mvm.msg = "Packing...";
try
{
Directory.Delete(Environment.GetEnvironmentVariable("LocalAppData") + @"\temp\.net\CNUSPACKER", true);
}
catch { }
if (Environment.Is64BitOperatingSystem) if (Environment.Is64BitOperatingSystem)
CNUSPACKER.Program.Main(new string[] { "-in", baseRomPath, "-out", outputPath, "-encryptKeyWidth", Settings.Default.Ckey }); CNUSPACKER.Program.Main(new string[] { "-in", baseRomPath, "-out", outputPath, "-encryptKeyWidth", Settings.Default.Ckey });
else else
{ {
using (Process cnuspacker = new Process()) using var cnuspacker = new Process();
{
if (!mvm.debug) if (!mvm.debug)
{ {
cnuspacker.StartInfo.UseShellExecute = false; cnuspacker.StartInfo.UseShellExecute = false;
cnuspacker.StartInfo.CreateNoWindow = true; cnuspacker.StartInfo.CreateNoWindow = true;
} }
cnuspacker.StartInfo.FileName = "java"; cnuspacker.StartInfo.FileName = "java";
cnuspacker.StartInfo.Arguments = $"-jar \"{Path.Combine(toolsPath, "NUSPacker.jar")}\" -in \"{baseRomPath}\" -out \"{outputPath}\" -encryptKeyWith {Properties.Settings.Default.Ckey}"; cnuspacker.StartInfo.Arguments = $"-jar \"{Path.Combine(toolsPath, "NUSPacker.jar")}\" -in \"{baseRomPath}\" -out \"{outputPath}\" -encryptKeyWith {Settings.Default.Ckey}";
cnuspacker.Start(); cnuspacker.Start();
cnuspacker.WaitForExit(); cnuspacker.WaitForExit();
} }
}
mvm.Progress = 90; mvm.Progress = 90;
mvm.msg = "Cleaning..."; mvm.msg = "Cleaning...";
Clean(); Clean();
@ -1678,7 +1669,7 @@ namespace UWUVCI_AIO_WPF
if (mvm.GameConfiguration.Console == GameConsoles.WII || mvm.GameConfiguration.Console == GameConsoles.GCN) if (mvm.GameConfiguration.Console == GameConsoles.WII || mvm.GameConfiguration.Console == GameConsoles.GCN)
{ {
mvm.Progress += 10; mvm.Progress += 10;
foreach (string sFile in Directory.GetFiles(Path.Combine(Properties.Settings.Default.BasePath, $"{b.Name.Replace(":", "")} [{b.Region}]", "content"), "*.nfs")) foreach (string sFile in Directory.GetFiles(Path.Combine(Settings.Default.BasePath, $"{b.Name.Replace(":", "")} [{b.Region}]", "content"), "*.nfs"))
File.Delete(sFile); File.Delete(sFile);
mvm.Progress += 15; mvm.Progress += 15;
@ -1710,7 +1701,7 @@ namespace UWUVCI_AIO_WPF
{ {
string gameName = string.Empty; string gameName = string.Empty;
//This line of code gives me cancer //This line of code gives me cancer
if (gameNameOr != null || !String.IsNullOrWhiteSpace(gameNameOr)) if (gameNameOr != null || !string.IsNullOrWhiteSpace(gameNameOr))
{ {
gameName = gameNameOr; gameName = gameNameOr;
@ -1725,12 +1716,12 @@ namespace UWUVCI_AIO_WPF
string metaXml = Path.Combine(baseRomPath, "meta", "meta.xml"); string metaXml = Path.Combine(baseRomPath, "meta", "meta.xml");
string appXml = Path.Combine(baseRomPath, "code", "app.xml"); string appXml = Path.Combine(baseRomPath, "code", "app.xml");
Random random = new Random(); Random random = new();
string ID = $"{random.Next(0x3000, 0x10000):X4}{random.Next(0x3000, 0x10000):X4}"; string ID = $"{random.Next(0x3000, 0x10000):X4}{random.Next(0x3000, 0x10000):X4}";
string ID2 = $"{random.Next(0x3000, 0x10000):X4}"; string ID2 = $"{random.Next(0x3000, 0x10000):X4}";
mvvm.prodcode = ID2; mvvm.prodcode = ID2;
XmlDocument doc = new XmlDocument(); XmlDocument doc = new();
try try
{ {
doc.Load(metaXml); doc.Load(metaXml);
@ -1861,8 +1852,7 @@ namespace UWUVCI_AIO_WPF
else else
{ {
//creating pkg file including the TG16 rom //creating pkg file including the TG16 rom
using (Process TurboInject = new Process()) using Process TurboInject = new Process();
{
mvvm.msg = "Creating Turbo16 Pkg..."; mvvm.msg = "Creating Turbo16 Pkg...";
TurboInject.StartInfo.UseShellExecute = false; TurboInject.StartInfo.UseShellExecute = false;
TurboInject.StartInfo.CreateNoWindow = true; TurboInject.StartInfo.CreateNoWindow = true;
@ -1872,7 +1862,6 @@ namespace UWUVCI_AIO_WPF
TurboInject.WaitForExit(); TurboInject.WaitForExit();
mvvm.Progress = 70; mvvm.Progress = 70;
} }
}
mvvm.msg = "Injecting ROM..."; mvvm.msg = "Injecting ROM...";
//replacing tg16 rom //replacing tg16 rom
File.Delete(Path.Combine(baseRomPath, "content", "pceemu", "pce.pkg")); File.Delete(Path.Combine(baseRomPath, "content", "pceemu", "pce.pkg"));
@ -1889,8 +1878,7 @@ namespace UWUVCI_AIO_WPF
mvvm.Progress = 20; mvvm.Progress = 20;
if (mvvm.pixelperfect) if (mvvm.pixelperfect)
{ {
using (Process retroinject = new Process()) using Process retroinject = new Process();
{
mvvm.msg = "Applying Pixel Perfect Patches..."; mvvm.msg = "Applying Pixel Perfect Patches...";
retroinject.StartInfo.UseShellExecute = false; retroinject.StartInfo.UseShellExecute = false;
retroinject.StartInfo.CreateNoWindow = true; retroinject.StartInfo.CreateNoWindow = true;
@ -1902,9 +1890,6 @@ namespace UWUVCI_AIO_WPF
retroinject.Start(); retroinject.Start();
retroinject.WaitForExit(); retroinject.WaitForExit();
mvvm.Progress = 30; mvvm.Progress = 30;
}
} }
using (Process retroinject = new Process()) using (Process retroinject = new Process())
{ {
@ -1939,7 +1924,7 @@ namespace UWUVCI_AIO_WPF
if (!new FileInfo(injectRomPath).Extension.Contains("gba")) if (!new FileInfo(injectRomPath).Extension.Contains("gba"))
{ {
//it's a GBC or GB rom so it needs to be copied into goomba.gba and then padded to 32Mb (16 would work too but just ot be save) //it's a GBC or GB rom so it needs to be copied into goomba.gba and then padded to 32Mb (16 would work too but just ot be save)
using (Process goomba = new Process()) using (Process goomba = new())
{ {
mvvm.msg = "Injecting GB/GBC ROM into goomba..."; mvvm.msg = "Injecting GB/GBC ROM into goomba...";
goomba.StartInfo.UseShellExecute = false; goomba.StartInfo.UseShellExecute = false;
@ -1975,7 +1960,7 @@ namespace UWUVCI_AIO_WPF
} }
using (Process psb = new Process()) using (Process psb = new())
{ {
mvvm.msg = "Injecting ROM..."; mvvm.msg = "Injecting ROM...";
psb.StartInfo.UseShellExecute = false; psb.StartInfo.UseShellExecute = false;
@ -2153,8 +2138,8 @@ namespace UWUVCI_AIO_WPF
} }
File.Copy(Path.Combine(tempPath, "tempd", "code", "font.bin"), Path.Combine(Properties.Settings.Default.BasePath, $"vwiisys", "code", "font.bin")); File.Copy(Path.Combine(tempPath, "tempd", "code", "font.bin"), Path.Combine(Settings.Default.BasePath, $"vwiisys", "code", "font.bin"));
File.Copy(Path.Combine(tempPath, "tempd", "code", "deint.txt"), Path.Combine(Properties.Settings.Default.BasePath, $"vwiisys", "code", "deint.txt")); File.Copy(Path.Combine(tempPath, "tempd", "code", "deint.txt"), Path.Combine(Settings.Default.BasePath, $"vwiisys", "code", "deint.txt"));
File.Delete(Path.Combine(Properties.Settings.Default.BasePath, $"vwiisys", "code", "app.xml")); File.Delete(Path.Combine(Properties.Settings.Default.BasePath, $"vwiisys", "code", "app.xml"));
} }
} }
@ -2191,7 +2176,7 @@ namespace UWUVCI_AIO_WPF
{ {
string mainRomPath = Directory.GetFiles(Path.Combine(baseRomPath, "content", "rom"))[0]; string mainRomPath = Directory.GetFiles(Path.Combine(baseRomPath, "content", "rom"))[0];
string mainIni = Path.Combine(baseRomPath, "content", "config", $"{Path.GetFileName(mainRomPath)}.ini"); string mainIni = Path.Combine(baseRomPath, "content", "config", $"{Path.GetFileName(mainRomPath)}.ini");
using (Process n64convert = new Process()) using (Process n64convert = new())
{ {
mvvm.msg = "Injecting ROM..."; mvvm.msg = "Injecting ROM...";
n64convert.StartInfo.UseShellExecute = false; n64convert.StartInfo.UseShellExecute = false;
@ -2326,17 +2311,13 @@ namespace UWUVCI_AIO_WPF
mvvm.msg = "Copying INI..."; mvvm.msg = "Copying INI...";
if (config.INIBin == null) if (config.INIBin == null)
{ {
File.Delete(mainIni);
if (config.INIPath == null) if (config.INIPath == null)
{
File.Delete(mainIni);
File.Copy(Path.Combine(toolsPath, "blank.ini"), mainIni); File.Copy(Path.Combine(toolsPath, "blank.ini"), mainIni);
}
else else
{
File.Delete(mainIni);
File.Copy(config.INIPath, mainIni); File.Copy(config.INIPath, mainIni);
} }
}
else else
{ {
ReadFileFromBin(config.INIBin, "custom.ini"); ReadFileFromBin(config.INIBin, "custom.ini");
@ -2366,8 +2347,7 @@ namespace UWUVCI_AIO_WPF
private static void RPXcomp(string rpxpath) private static void RPXcomp(string rpxpath)
{ {
using (Process rpxtool = new Process()) using Process rpxtool = new Process();
{
rpxtool.StartInfo.UseShellExecute = false; rpxtool.StartInfo.UseShellExecute = false;
rpxtool.StartInfo.CreateNoWindow = true; rpxtool.StartInfo.CreateNoWindow = true;
rpxtool.StartInfo.FileName = Path.Combine(toolsPath, "wiiurpxtool.exe"); rpxtool.StartInfo.FileName = Path.Combine(toolsPath, "wiiurpxtool.exe");
@ -2376,7 +2356,6 @@ namespace UWUVCI_AIO_WPF
rpxtool.Start(); rpxtool.Start();
rpxtool.WaitForExit(); rpxtool.WaitForExit();
} }
}
private static void ReadFileFromBin(byte[] bin, string output) private static void ReadFileFromBin(byte[] bin, string output)
{ {
@ -2388,8 +2367,6 @@ namespace UWUVCI_AIO_WPF
bool readbin = false; bool readbin = false;
try try
{ {
//is an image embedded? yes => export them and check for issues //is an image embedded? yes => export them and check for issues
//no => using path //no => using path
if (Directory.Exists(imgPath)) // sanity check if (Directory.Exists(imgPath)) // sanity check
@ -2409,17 +2386,11 @@ namespace UWUVCI_AIO_WPF
} }
else else
{ {
if (File.Exists(Path.Combine(toolsPath, "iconTex.tga"))) var fileExists = File.Exists(Path.Combine(toolsPath, "iconTex.tga"));
{ if (fileExists)
CopyAndConvertImage(Path.Combine(toolsPath, "iconTex.tga"), Path.Combine(imgPath), false, 128, 128, 32, "iconTex.tga"); CopyAndConvertImage(Path.Combine(toolsPath, "iconTex.tga"), Path.Combine(imgPath), false, 128, 128, 32, "iconTex.tga");
Images.Add(true); Images.Add(fileExists);
}
else
{
Images.Add(false);
}
} }
} }
else else
@ -2439,17 +2410,13 @@ namespace UWUVCI_AIO_WPF
} }
else else
{ {
if (File.Exists(Path.Combine(toolsPath, "bootTvTex.png"))) var fileExists = File.Exists(Path.Combine(toolsPath, "bootTvTex.png");
if (fileExists)
{ {
CopyAndConvertImage(Path.Combine(toolsPath, "bootTvTex.png"), Path.Combine(imgPath), false, 1280, 720, 24, "bootTvTex.tga"); CopyAndConvertImage(Path.Combine(toolsPath, "bootTvTex.png"), Path.Combine(imgPath), false, 1280, 720, 24, "bootTvTex.tga");
usetemp = true; usetemp = true;
Images.Add(true);
}
else
{
Images.Add(false);
} }
Images.Add(fileExists);
} }
} }
else else
@ -2474,8 +2441,7 @@ namespace UWUVCI_AIO_WPF
{ {
if (Images[1]) if (Images[1])
{ {
using (Process conv = new Process()) using Process conv = new Process();
{
if (!mvvm.debug) if (!mvvm.debug)
{ {
@ -2514,20 +2480,16 @@ namespace UWUVCI_AIO_WPF
} }
File.Copy(Path.Combine(tempPath, "bootTvTex.png"), Path.Combine(tempPath, "bootDrcTex.png")); File.Copy(Path.Combine(tempPath, "bootTvTex.png"), Path.Combine(tempPath, "bootDrcTex.png"));
if (File.Exists(Path.Combine(tempPath, "bootTvTex.png"))) File.Delete(Path.Combine(tempPath, "bootTvTex.png"));
if (File.Exists($"bootTvTex.{config.TGATv.extension}")) File.Delete($"bootTvTex.{config.TGATv.extension}"); if (File.Exists(Path.Combine(tempPath, "bootTvTex.png")))
File.Delete(Path.Combine(tempPath, "bootTvTex.png"));
if (File.Exists($"bootTvTex.{config.TGATv.extension}"))
File.Delete($"bootTvTex.{config.TGATv.extension}");
} }
CopyAndConvertImage(Path.Combine(tempPath, "bootDrcTex.png"), Path.Combine(imgPath), false, 854, 480, 24, "bootDrcTex.tga"); CopyAndConvertImage(Path.Combine(tempPath, "bootDrcTex.png"), Path.Combine(imgPath), false, 854, 480, 24, "bootDrcTex.tga");
Images.Add(true);
} }
} Images.Add(Images[1]);
else
{
Images.Add(false);
}
} }
} }
else else
@ -2542,30 +2504,26 @@ namespace UWUVCI_AIO_WPF
//logo //logo
var addBool = true;
if (config.TGALog.ImgBin == null) if (config.TGALog.ImgBin == null)
{ {
//use path //use path
if (config.TGALog.ImgPath != null) if (config.TGALog.ImgPath != null)
{
Images.Add(true);
CopyAndConvertImage(config.TGALog.ImgPath, Path.Combine(imgPath), false, 170, 42, 32, "bootLogoTex.tga"); CopyAndConvertImage(config.TGALog.ImgPath, Path.Combine(imgPath), false, 170, 42, 32, "bootLogoTex.tga");
}
else else
{ addBool = false;
Images.Add(false);
}
} }
else else
{ {
ReadFileFromBin(config.TGALog.ImgBin, $"bootLogoTex.{config.TGALog.extension}"); ReadFileFromBin(config.TGALog.ImgBin, $"bootLogoTex.{config.TGALog.extension}");
CopyAndConvertImage($"bootLogoTex.{config.TGALog.extension}", Path.Combine(imgPath), true, 170, 42, 32, "bootLogoTex.tga"); CopyAndConvertImage($"bootLogoTex.{config.TGALog.extension}", Path.Combine(imgPath), true, 170, 42, 32, "bootLogoTex.tga");
Images.Add(true);
} }
Images.Add(addBool);
//Fixing Images + Injecting them //Fixing Images + Injecting them
if (Images[0] || Images[1] || Images[2] || Images[3]) if (Images[0] || Images[1] || Images[2] || Images[3])
{ {
using (Process checkIfIssue = new Process()) using (Process checkIfIssue = new())
{ {
checkIfIssue.StartInfo.UseShellExecute = false; checkIfIssue.StartInfo.UseShellExecute = false;
checkIfIssue.StartInfo.CreateNoWindow = false; checkIfIssue.StartInfo.CreateNoWindow = false;
@ -2647,18 +2605,13 @@ namespace UWUVCI_AIO_WPF
png2tga.StartInfo.UseShellExecute = false; png2tga.StartInfo.UseShellExecute = false;
png2tga.StartInfo.CreateNoWindow = true; png2tga.StartInfo.CreateNoWindow = true;
var extension = new FileInfo(inputPath).Extension; var extension = new FileInfo(inputPath).Extension;
if (extension.Contains("png")) if (extension.Contains("png"))
{
png2tga.StartInfo.FileName = Path.Combine(toolsPath, "png2tga.exe"); png2tga.StartInfo.FileName = Path.Combine(toolsPath, "png2tga.exe");
}
else if (extension.Contains("jpg") || extension.Contains("jpeg")) else if (extension.Contains("jpg") || extension.Contains("jpeg"))
{
png2tga.StartInfo.FileName = Path.Combine(toolsPath, "jpg2tga.exe"); png2tga.StartInfo.FileName = Path.Combine(toolsPath, "jpg2tga.exe");
}
else if (extension.Contains("bmp")) else if (extension.Contains("bmp"))
{
png2tga.StartInfo.FileName = Path.Combine(toolsPath, "bmp2tga.exe"); png2tga.StartInfo.FileName = Path.Combine(toolsPath, "bmp2tga.exe");
}
png2tga.StartInfo.Arguments = $"-i \"{inputPath}\" -o \"{outputPath}\" --width={widht} --height={height} --tga-bpp={bit} --tga-compression=none"; png2tga.StartInfo.Arguments = $"-i \"{inputPath}\" -o \"{outputPath}\" --width={widht} --height={height} --tga-bpp={bit} --tga-compression=none";
@ -2691,10 +2644,8 @@ namespace UWUVCI_AIO_WPF
return filePath; return filePath;
string newFilePath = Path.Combine(tempPath, Path.GetFileName(filePath)); string newFilePath = Path.Combine(tempPath, Path.GetFileName(filePath));
using (FileStream outStream = new FileStream(newFilePath, FileMode.OpenOrCreate)) using (FileStream outStream = new(newFilePath, FileMode.OpenOrCreate))
{
inStream.CopyTo(outStream); inStream.CopyTo(outStream);
}
return newFilePath; return newFilePath;
} }