Make dds argument for szs command optional (#86)

* Make image file optional in szs cli command

* Use stderr for cli command errors
This commit is contained in:
Migush 2021-05-24 21:58:21 +02:00 committed by GitHub
parent 6fb1e1fa4d
commit 173f220e08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 42 deletions

View File

@ -7,7 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwitchThemesWin", "SwitchTh
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SwitchThemesCommon", "SwitchThemesCommon\SwitchThemesCommon.shproj", "{11174F92-402D-4064-B278-F52842A48251}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SwitchThemesOnline", "SwitchThemesOnline\SwitchThemesOnline.csproj", "{3EE76B71-422A-4E80-8F17-63DA105BB4BC}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwitchThemesOnline", "SwitchThemesOnline\SwitchThemesOnline.csproj", "{3EE76B71-422A-4E80-8F17-63DA105BB4BC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SwitchThemesNX", "SwitchThemesNX\SwitchThemesNX.vcxproj", "{B6DA9247-8ED4-44D7-9FD3-6EAB523FC003}"
EndProject

View File

@ -64,7 +64,7 @@ namespace SwitchThemes
"Build an nxtheme file : SwitchThemes.exe buildNX home \"<your image.jpg/dds>\" \"<json layout file, optional>\" \"name=<theme name>\" \"author=<author name>\" \"commonlyt=<custom common.szs layout>\" \"out=<OutputPath>.nxtheme\"\r\n" +
" instead of home you can use: lock for lockscreen, apps for the all apps screen, set for the settings applet, user for the user page applet and news for the news applet.\r\n" +
" Only the image and out file are needed.\r\n" +
"Patch an SZS: SwitchThemes.exe szs \"<input file>\" \"<your image.dds>\" \"<json layout file, optional>\" \"out=<OutputPath>.szs\"\r\n" +
"Patch an SZS: SwitchThemes.exe szs \"<input file>\" \"<your image.dds, optional>\" \"<json layout file, optional>\" \"out=<OutputPath>.szs\"\r\n" +
"Extract an nxtheme: Switchthemes.exe extract \"<input file>\" \"<target oath>\" \r\n" +
"Remote install to NXTheme installer: SwitchThemes.exe install 192.168.X.Y \"<your nxtheme/szs file>\"\r\n" +
"Diff szs files: SwitchThemes.exe diff <original szs file> <modified szs file> <output json path>\r\n");
@ -81,7 +81,7 @@ namespace SwitchThemes
if (IsMono)
{
Console.WriteLine("The ui is not supported with mono, use the command line args.\r\nRun \"mono SwitchThemes.exe help\"");
Console.Error.WriteLine("The ui is not supported with mono, use the command line args.\r\nRun \"mono SwitchThemes.exe help\"");
return;
}
@ -94,7 +94,7 @@ namespace SwitchThemes
{
if (args.Length != 3)
{
Console.WriteLine("Error: Wrong number of arguments.");
Console.Error.WriteLine("Error: Wrong number of arguments.");
return false;
}
@ -102,7 +102,11 @@ namespace SwitchThemes
byte[] Theme = File.ReadAllBytes(args[2]);
var res = RemoteInstallForm.DoRemoteInstall(Ip, Theme);
Console.WriteLine(res == null ? "Done !" : res);
if (res == null) {
Console.WriteLine("Done!");
} else {
Console.Error.WriteLine(res);
}
return true;
}
@ -111,7 +115,7 @@ namespace SwitchThemes
{
if (args.Length != 4)
{
Console.WriteLine("Error: Wrong number of arguments.");
Console.Error.WriteLine("Error: Wrong number of arguments.");
return false;
}
@ -137,7 +141,7 @@ namespace SwitchThemes
}
catch (Exception ex)
{
Console.WriteLine($"There was an error:\r\n{ex}");
Console.Error.WriteLine($"There was an error:\r\n{ex}");
}
return true;
@ -147,7 +151,7 @@ namespace SwitchThemes
{
if (args.Length != 3)
{
Console.WriteLine("Error: Wrong number of arguments.");
Console.Error.WriteLine("Error: Wrong number of arguments.");
return false;
}
@ -158,7 +162,7 @@ namespace SwitchThemes
}
catch (Exception ex)
{
Console.WriteLine($"There was an error:\r\n{ex}");
Console.Error.WriteLine($"There was an error:\r\n{ex}");
}
return true;
@ -178,45 +182,57 @@ namespace SwitchThemes
return false;
string Target = args[1];
var CommonSzs = SARCExt.SARC.Unpack(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
var targetPatch = DefaultTemplates.GetFor(CommonSzs);
var TargetSzs = SARCExt.SARC.Unpack(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
var targetPatch = DefaultTemplates.GetFor(TargetSzs);
if (targetPatch == null)
{
Console.WriteLine("Unknown szs file");
Console.Error.WriteLine("Unknown SZS file.");
return false;
}
string Image = args.Where(x => x.ToLower().EndsWith(".dds")).FirstOrDefault();
if (Image == null || !File.Exists(Image))
if (Image != null && !File.Exists(Image))
{
Console.WriteLine("No image file !\r\nNote that only dds files are supported for szs themes.");
Console.Error.WriteLine("DDS image not found!\r\nNote that only DDS files are supported for szs themes.");
return false;
}
string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();
if (Layout != null && !File.Exists(Layout)) {
Console.Error.WriteLine("JSON layout not found!");
return false;
}
string Output = GetArg("out");
if (Output == null || Output == "")
return false;
{
var dds = Common.Images.Util.ParseDds(File.ReadAllBytes(Image));
if (dds.Encoding != "DXT1") Console.WriteLine("WARNING: the encoding of the selected DDS is not DXT1, it may crash on the switch");
if (dds.Size.Width != 1280 || dds.Size.Height != 720) Console.WriteLine("WARNING: the selected image is not 720p (1280x720), it may crash on the swtich");
Console.Error.WriteLine("No output path supplied! Example: 'out=file.szs'");
return false;
}
try
if (Image == null && Layout == null)
{
Console.Error.WriteLine("Nothing to do! An image (DDS), layout (JSON), or both should be supplied.");
return false;
}
try {
var res = true;
var Patcher = new SzsPatcher(CommonSzs);
var Patcher = new SzsPatcher(TargetSzs);
if (Image != null)
{
{
var dds = Common.Images.Util.ParseDds(File.ReadAllBytes(Image));
if (dds.Encoding != "DXT1") Console.WriteLine("WARNING: the encoding of the selected DDS is not DXT1, it may crash on the switch");
if (dds.Size.Width != 1280 || dds.Size.Height != 720) Console.WriteLine("WARNING: the selected image is not 720p (1280x720), it may crash on the switch");
}
res = Patcher.PatchMainBG(File.ReadAllBytes(Image));
if (!res)
{
Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
Console.Error.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
return false;
}
}
@ -226,14 +242,14 @@ namespace SwitchThemes
foreach (var a in l)
{
string path = GetArg(a.NxThemeName);
if (!path.EndsWith(".dds"))
if (path != null && !path.EndsWith(".dds"))
{
Console.WriteLine($"{path} is not supported, only dds files can be used for szs themes");
Console.Error.WriteLine($"{path} is not supported, only dds files can be used for szs themes");
path = null;
}
if (path != null)
if (!Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName))
Console.WriteLine($"Applet icon patch for {a.NxThemeName} failed");
Console.Error.WriteLine($"Applet icon patch for {a.NxThemeName} failed");
}
}
@ -246,25 +262,25 @@ namespace SwitchThemes
var layoutres = Patcher.PatchLayouts(l);
if (!layoutres)
{
Console.WriteLine("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS");
Console.Error.WriteLine("One or more of the target files for the selected layout patch is missing in the SZS. Either this layout it not meant for this menu or you are using an already patched SZS.");
return false;
}
}
CommonSzs = Patcher.GetFinalSarc();
var sarc = SARC.Pack(CommonSzs);
TargetSzs = Patcher.GetFinalSarc();
var sarc = SARC.Pack(TargetSzs);
File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
GC.Collect();
if (Patcher.PatchTemplate.RequiresCodePatch)
if (Image != null && Patcher.PatchTemplate.RequiresCodePatch)
Console.WriteLine("The file has been patched successfully but due to memory limitations this szs requires an extra code patch to be applied to the home menu, if you use NXThemesInstaller to install this it will be done automatically, otherwise you need to manually copy the patches from https://github.com/exelix11/SwitchThemeInjector/tree/master/SwitchThemesNX/romfs to the exefs patches directory of your cfw");
else
Console.WriteLine("Done");
Console.WriteLine("Done!");
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.Error.WriteLine("Error: " + ex.Message);
}
return true;
@ -281,14 +297,14 @@ namespace SwitchThemes
string Image = args.Where(x => x.EndsWith(".dds") || x.EndsWith(".jpg") || x.EndsWith(".png") || x.EndsWith("jpeg")).FirstOrDefault();
if (Image != null && !File.Exists(Image))
{
Console.WriteLine("No image file !");
Console.Error.WriteLine("No image file!");
return false;
}
string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();
if (Image == null && Layout == null)
{
Console.WriteLine("You need at least an image or a layout to make a theme");
Console.Error.WriteLine("You need at least an image or a layout to make a theme.");
return false;
}
@ -307,7 +323,7 @@ namespace SwitchThemes
if (Output == null || Output == "")
{
Console.WriteLine("Missing out= arg");
Console.Error.WriteLine("Missing out= arg");
return false;
}
@ -354,7 +370,7 @@ namespace SwitchThemes
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
Console.Error.WriteLine("Error: " + ex.Message);
return false;
}