Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();
            PatchLabelText = materialLabel3.Text;

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;

            if (!File.Exists("hactool\\hactool.exe") || !File.Exists("hactool\\keys.dat"))
            {
                materialTabControl1.TabPages.Remove(NCADumpPage);
            }
        }
Exemplo n.º 2
0
 void LayoutPreview(LayoutPatch patch)
 {
     if (patch == null)
     {
         MessageBox.Show("Select a layout first");
     }
     else
     {
         string imagePath = Layouts.FirstOrDefault(x => x.Value == patch).Key;
         if (imagePath == null)
         {
             MessageBox.Show("This theme doesn't have a preview");
             return;
         }
         imagePath = imagePath.Substring(0, imagePath.Length - 5) + ".jpg";
         if (!File.Exists(imagePath))
         {
             MessageBox.Show("This theme doesn't have a preview");
         }
         else
         {
             System.Diagnostics.Process.Start(imagePath);
         }
     }
 }
Exemplo n.º 3
0
        public Form1()
        {
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText   = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text = "(To dump the following files check the guide at https://git.io/fxdyF )\r\n" + LoadFileText;
        }
Exemplo n.º 4
0
        public static void PatchAndSave()
        {
            if (CommonSzs == null)
            {
                Window.Alert("Open an szs first !");
                return;
            }
            if (LoadedDDS == null)
            {
                Window.Alert("Open a DDS first !");
                return;
            }
            DoActionWithloading(() =>
            {
                LayoutPatch targetLayout = null;
                if (LayoutsComboBox.SelectedIndex > 0)
                {
                    targetLayout = layoutPatches[int.Parse(
                                                     ((HTMLOptionElement)LayoutsComboBox.Children[LayoutsComboBox.SelectedIndex]).Value)];
                }

                var yaz0 = Theme.Make(CommonSzs, DDSEncoder.LoadDDS(LoadedDDS), targetPatch, targetLayout);
                if (yaz0 == null)
                {
                    return;
                }
                Uint8Array dwn       = new Uint8Array(yaz0);
                string DownloadFname = targetPatch.szsName;
                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
            });
        }
Exemplo n.º 5
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            LoadFileText    = SwitchThemesCommon.GeneratePatchListString(Templates);
            tbPatches.Text += LoadFileText;
        }
Exemplo n.º 6
0
        private void materialRaisedButton8_Click(object sender, EventArgs e)
        {
            if (CommonSzs == null || targetPatch == null)
            {
                MessageBox.Show("Open a valid SZS first");
                return;
            }
            if (tbImageFile.Text.Trim() == "")
            {
                MessageBox.Show("Select an image first");
                return;
            }

            if (!BgImageCheck(false))
            {
                return;
            }

            var info = ThemeInputInfo.Ask();

            if (info == null)
            {
                return;
            }

            LayoutPatch layout = null;

            if (LayoutPatchList.SelectedIndex != 0)
            {
                layout = LayoutPatchList.SelectedItem as LayoutPatch;
            }
            try
            {
                var builder = new NXThemeBuilder(targetPatch.NXThemeName, info.Item1, info.Item2);

                if (layout != null)
                {
                    builder.AddMainLayout(layout);
                }

                builder.AddMainBg(File.ReadAllBytes(tbImageFile.Text));

                SaveFileDialog sav = new SaveFileDialog()
                {
                    Filter = "Theme pack (*.nxtheme)|*.nxtheme"
                };
                if (sav.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                File.WriteAllBytes(sav.FileName, builder.GetNxtheme());
                MessageBox.Show("Done");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex.Message);
            }
        }
Exemplo n.º 7
0
        private void NnBuilderBuild_Click(object sender, EventArgs e)
        {
            if (tbBntxFile.Text.Trim() == "")
            {
                MessageBox.Show("Select an image first");
                return;
            }
            if (!tbBntxFile.Text.EndsWith(".dds") && !ImageToDDS())
            {
                return;
            }
            var info = ThemeInputInfo.Ask();

            if (info == null)
            {
                return;
            }

            byte[] preview = null;
            if (info.Item3)
            {
                preview = GenerateDDSPreview(tbBntxFile.Text);
            }

            LayoutPatch layout = null;

            if (AllLayoutsBox.SelectedIndex != 0)
            {
                layout = AllLayoutsBox.SelectedItem as LayoutPatch;
            }
            var res = SwitchThemesCommon.GenerateNXTheme(
                new ThemeFileManifest()
            {
                Version    = 3,
                ThemeName  = info.Item1,
                Author     = info.Item2,
                Target     = HomeMenuParts[HomeMenuPartBox.Text],
                LayoutInfo = layout == null ? "" : layout.PatchName + " by " + layout.AuthorName,
            },
                File.ReadAllBytes(tbBntxFile.Text),
                layout?.AsByteArray(),
                new Tuple <string, byte[]> ("preview.png", preview),
                HomeMenuParts[HomeMenuPartBox.Text] == "home" ? new Tuple <string, byte[]>("common.json", ExtraCommonLyt?.AsByteArray()) : null);

            SaveFileDialog sav = new SaveFileDialog()
            {
                Filter = "theme pack (*.nxtheme)|*.nxtheme"
            };

            if (sav.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            File.WriteAllBytes(sav.FileName, res);
            MessageBox.Show("Done");
        }
Exemplo n.º 8
0
 public void LoadAndOptimizeAll()
 {
     // This generates layouts to load for SwitchThemesNXTests::Layouts::LayoutLoading
     foreach (var f in Directory.EnumerateFiles("../../../../../SwitchThemes/layouts").Where(x => x.EndsWith(".json")))
     {
         File.WriteAllText(
             Path.Combine(Util.GetPath("ParsedLayouts"), Path.GetFileName(f)),
             LayoutPatch.Load(File.ReadAllText(f)).AsJson()
             );
     }
 }
Exemplo n.º 9
0
        private void materialRaisedButton6_Click(object sender, EventArgs e)
        {
            if (CommonSzs == null)
            {
                MessageBox.Show("Open the modded file via SZS PATCHING>OPEN SZS first");
                return;
            }
            OpenFileDialog opn = new OpenFileDialog()
            {
                Title  = "Open the original SZS to diff",
                Filter = "SZS file|*.szs"
            };

            if (opn.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var         originalSzs = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(opn.FileName)));
            LayoutPatch res         = null;

#if !DEBUG
            try
            {
#endif
            string msg;
            (res, msg) = LayoutDiff.Diff(originalSzs, CommonSzs);
            if (msg != null)
            {
                MessageBox.Show(msg);
            }
#if !DEBUG
        }

        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
            return;
        }
#endif

            SaveFileDialog sav = new SaveFileDialog()
            {
                Title  = "save the patch file",
                Filter = "json patch file|*.json"
            };
            if (sav.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            File.WriteAllText(sav.FileName, res.AsJson());
        }
Exemplo n.º 10
0
        public static void BuildNxTheme()
        {
            string name = Window.Prompt("Enter a name for the theme");

            LayoutPatch targetLayout = null;

            if (LayoutsComboBox.SelectedIndex > 0)
            {
                targetLayout = layoutPatches[int.Parse(
                                                 ((HTMLOptionElement)LayoutsComboBox.Children[LayoutsComboBox.SelectedIndex]).Value)];
            }

            MakeNxTheme(targetPatch.NXThemeName, name, "", targetLayout);
        }
Exemplo n.º 11
0
        public static void BuildNxThemeNX()
        {
            LayoutPatch targetLayout = null;

            if (LayoutsComboBox_NX.SelectedIndex > 0)
            {
                targetLayout = layoutPatches[int.Parse(
                                                 ((HTMLOptionElement)LayoutsComboBox_NX.Children[LayoutsComboBox_NX.SelectedIndex]).Value)];
            }

            MakeNxTheme(HomePartBox_NX.Value,
                        Document.GetElementById <HTMLInputElement>("NXname").Value,
                        Document.GetElementById <HTMLInputElement>("NXauthor").Value,
                        targetLayout);
        }
Exemplo n.º 12
0
        private void LayoutPatchList_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox comboBox = (ComboBox)sender;

            if (comboBox.SelectedIndex == comboBox.Items.Count - 1)
            {
                OpenFileDialog opn = new OpenFileDialog()
                {
                    Title = "Select a layout", Filter = "Json files|*.json"
                };
                if (opn.ShowDialog() != DialogResult.OK)
                {
                    comboBox.SelectedIndex = 0;
                    return;
                }
                comboBox.Items.Insert(1, LayoutPatch.LoadTemplate(File.ReadAllText(opn.FileName)));
                comboBox.SelectedIndex = 1;
            }
        }
Exemplo n.º 13
0
        private void ProcessSzs(string name)
        {
            SarcData src = SARC.Unpack(ManagedYaz0.Decompress(Util.ReadData($"Source/{name}.szs")));
            SarcData exp = SARC.Unpack(ManagedYaz0.Decompress(Util.ReadData($"Expected/{name}.szs")));

            string lyt = Util.Exists($"Source/{name}.json") ? Util.ReadString($"Source/{name}.json") : null;

            SzsPatcher patcher = new SzsPatcher(src);

            Assert.IsTrue(patcher.PatchMainBG(DDS));

            if (lyt != null)
            {
                var l = LayoutPatch.LoadTemplate(lyt);
                patcher.PatchLayouts(l);
            }

            var final = patcher.GetFinalSarc();

            CompareSarc(final, exp);
        }
Exemplo n.º 14
0
        private void btnOpenCustomLayout_Click(object sender, EventArgs e)
        {
            if (ExtraCommonLyt != null)
            {
                btnOpenCustomLayout.Text = "...";
                lblCustomCommonLyt.Text  = "Custom common layout: Not set";
                ExtraCommonLyt           = null;
                return;
            }
            OpenFileDialog opn = new OpenFileDialog()
            {
                Filter = "json layout|*.json"
            };

            if (opn.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            ExtraCommonLyt           = LayoutPatch.LoadTemplate(File.ReadAllText(opn.FileName));
            lblCustomCommonLyt.Text  = $"Custom common layout: {ExtraCommonLyt.ToString()}";
            btnOpenCustomLayout.Text = "X";
        }
Exemplo n.º 15
0
        static void GetLayoutPart(int i)
        {
            XMLHttpRequest req = new XMLHttpRequest();

            req.ResponseType       = XMLHttpRequestResponseType.String;
            req.OnReadyStateChange = () =>
            {
                if (req.ReadyState != AjaxReadyState.Done)
                {
                    return;
                }
                string DownloadRes = req.Response as string;
                if (DownloadRes == null || DownloadRes.Length == 0)
                {
                    PrintError("Error downloading one of the embedded layouts : " + embedLyouts[i] + ", it won't be available to make themes");
                    return;
                }
                layoutPatches[i] = LayoutPatch.LoadTemplate(DownloadRes);
                DownloadRes      = null;
            };
            req.Open("GET", "layouts/" + embedLyouts[i] + ".json", true);
            req.Send();
        }
Exemplo n.º 16
0
        public Form1()
        {
            MaterialSkin.MaterialSkinManager.Instance.Theme = MaterialSkin.MaterialSkinManager.Themes.DARK;
            InitializeComponent();

            Advanced = Properties.Settings.Default.Adv;
            if (Advanced)
            {
                EnableAdvanced();
            }
            else
            {
                DisableAdvanced();
            }

            //LayoutPatch.CreateTestTemplates();
            //PatchTemplate.BuildTemplateFile();
            Templates.AddRange(DefaultTemplates.templates);
            if (File.Exists("ExtraTemplates.json"))
            {
                Templates.AddRange(PatchTemplate.LoadTemplates());
            }
            if (Directory.Exists("Layouts"))
            {
                foreach (var f in Directory.GetFiles("Layouts").Where(x => x.EndsWith(".json")))
                {
                    Layouts.Add(f, LayoutPatch.LoadTemplate(File.ReadAllText(f)));
                }
            }

            HomeMenuPartBox.Items.AddRange(HomeMenuParts.Keys.ToArray());
            HomeMenuPartBox.SelectedIndex = 0;
            HomeMenuPartBox_SelectedIndexChanged(null, null);

            HomeAppletIcoButtonsInit();
        }
Exemplo n.º 17
0
        static void MakeNxTheme(string partName, string name, string author, LayoutPatch targetLayout)
        {
            if (LoadedDDS == null)
            {
                Window.Alert("Open a DDS first !");
                return;
            }
            if (!ValidAutoThemeParts.Contains(partName))
            {
                Window.Alert("select a valid Home menu part");
                return;
            }
            if (name.Trim() == "")
            {
                Window.Alert("Enter a valid name");
                return;
            }
            DoActionWithloading(() =>
            {
                var dds = DDSEncoder.LoadDDS(LoadedDDS);                 //this will crash if the dds type is wrong

                var meta = new ThemeFileManifest()
                {
                    Version    = 1,
                    Author     = author,
                    LayoutInfo = targetLayout != null ? targetLayout.ToString() : "",
                    ThemeName  = name,
                    Target     = partName,
                };

                var res              = SwitchThemesCommon.GenerateNXTheme(meta, LoadedDDS, targetLayout == null ? null : System.Text.Encoding.UTF8.GetBytes(targetLayout.AsJson()));
                Uint8Array dwn       = new Uint8Array(res);
                string DownloadFname = name + ".nxtheme";
                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
            });
        }
Exemplo n.º 18
0
        static bool NXThemeFromArgs(string[] args)
        {
            if (args.Length < 4)
            {
                return(false);
            }
            string Target = args[1];

            if (!Form1.HomeMenuParts.Values.Contains(Target))
            {
                return(false);
            }

            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 !");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            bool?GetArgBool(string start)
            {
                var a = GetArg(start);

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(bool.Parse(a));
                }
            }

            string Name        = GetArg("name");
            string Author      = GetArg("author");
            string Output      = GetArg("out");
            string ExtraCommon = GetArg("commonlyt");

            if (Output == null || Output == "")
            {
                return(false);
            }

            bool preview = GetArgBool("preview") ?? true;

            if (Name == null || Name.Trim() == "")
            {
                var info = ThemeInputInfo.Ask();
                Name    = info.Item1;
                Author  = info.Item2;
                preview = info.Item3;
            }

            LayoutPatch layout = null;

            if (Layout != null && File.Exists(Layout))
            {
                layout = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
            }

            if (!Image.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(Image, Path.GetTempPath()))
                {
                    Image = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Image) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            var res = SwitchThemesCommon.GenerateNXTheme(
                new ThemeFileManifest()
            {
                Version    = 3,
                ThemeName  = Name,
                Author     = Author,
                Target     = Target,
                LayoutInfo = layout == null ? "" : layout.PatchName + " by " + layout.AuthorName,
            },
                File.ReadAllBytes(Image),
                layout?.AsByteArray(),
                new Tuple <string, byte[]>("preview.png", preview ? Form1.GenerateDDSPreview(Image) : null));

            File.WriteAllBytes(Output, res);

            return(true);
        }
Exemplo n.º 19
0
        public static byte[] Make(SarcData input, DDSLoadResult dds, PatchTemplate targetPatch, LayoutPatch layout)
        {
            if (layout != null)
            {
                var layoutres = SwitchThemesCommon.PatchLayouts(input, layout.Files);
                if (layoutres == BflytFile.PatchResult.Fail)
                {
                    Window.Alert("One of the target files for the selected layout patch is missing in the SZS, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
                else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                {
                    Window.Alert("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS or the wrong layout");
                    return(null);
                }
            }

            if (SwitchThemesCommon.PatchBntx(input, dds, targetPatch) == BflytFile.PatchResult.Fail)
            {
                Window.Alert(
                    "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                    "without this information it is not possible to rebuild the bntx." +
                    "You should use an original or at least working szs");
                return(null);
            }
            var res = SwitchThemesCommon.PatchBgLayouts(input, targetPatch);

            if (res == BflytFile.PatchResult.Fail)
            {
                Window.Alert("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                return(null);
            }
            else if (res == BflytFile.PatchResult.CorruptedFile)
            {
                Window.Alert("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                return(null);
            }
            var sarc = SARC.PackN(input);

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }
Exemplo n.º 20
0
        private void NnBuilderBuild_Click(object sender, EventArgs e)
        {
            if (tbImageFile.Text.Trim() == "")
            {
                if (AllLayoutsBox.SelectedIndex == 0)
                {
                    MessageBox.Show("You need at least a custom image or layout to make a theme.");
                    return;
                }

                if (MessageBox.Show("This will create a theme without any background image, the console default one will be used. Do you want to continue?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            if (!BgImageCheck(false))
            {
                return;
            }

            var info = ThemeInputInfo.Ask();

            if (info == null)
            {
                return;
            }

            string target = HomeMenuParts[HomeMenuPartBox.Text];

            if (target == "home")
            {
                foreach (var k in HomeAppletIcons.Keys.ToArray())
                {
                    string path = HomeAppletIcons[k];
                    if (path != null && !path.EndsWith(".dds") && !IcontoDDS(ref path))
                    {
                        return;
                    }
                    HomeAppletIcons[k] = path;
                }
            }
            else if (target == "lock")
            {
                if (LockCustomIcon != null && !LockCustomIcon.EndsWith(".dds") && !IcontoDDS(ref LockCustomIcon))
                {
                    return;
                }
            }

            LayoutPatch layout = null;

            if (AllLayoutsBox.SelectedIndex != 0)
            {
                layout = AllLayoutsBox.SelectedItem as LayoutPatch;
            }
            try
            {
                var builder = new NXThemeBuilder(target, info.Item1, info.Item2);

                if (layout != null)
                {
                    builder.AddMainLayout(layout);
                }

                if (tbImageFile.Text != "")
                {
                    builder.AddMainBg(File.ReadAllBytes(tbImageFile.Text));
                }

                if (ExtraCommonLyt != null)
                {
                    builder.AddFile("common.json", ExtraCommonLyt.AsByteArray());
                }

                if (target == "home")
                {
                    foreach (var ico in HomeAppletIcons)
                    {
                        if (ico.Value != null)
                        {
                            builder.AddAppletIcon(ico.Key, File.ReadAllBytes(ico.Value));
                        }
                    }
                }
                else if (target == "lock" && LockCustomIcon != null)
                {
                    builder.AddAppletIcon("lock", File.ReadAllBytes(LockCustomIcon));
                }

                SaveFileDialog sav = new SaveFileDialog()
                {
                    Filter = "Theme pack (*.nxtheme)|*.nxtheme"
                };
                if (sav.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                File.WriteAllBytes(sav.FileName, builder.GetNxtheme());
                MessageBox.Show("Done");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex.Message);
            }
        }
Exemplo n.º 21
0
 public ModifyLayoutPatch(LayoutPatch layoutPatch, LayoutView layoutView)
 {
     this.layoutView   = layoutView;
     this.layoutPatch  = layoutPatch;
     base.OnlyThisView = layoutView; // nur für diesen view wird gearbeitet
 }
Exemplo n.º 22
0
        static bool SZSFromArgs(string[] args)
        {
            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            if (args.Length < 2)
            {
                return(false);
            }

            string Target      = args[1];
            var    CommonSzs   = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
            var    targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates);

            if (targetPatch == null)
            {
                Console.WriteLine("Unknown szs file");
                return(false);
            }

            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 !");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            string Output = GetArg("out");

            if (Output == null || Output == "")
            {
                return(false);
            }

            if (!Image.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(Image, Path.GetTempPath()))
                {
                    Image = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Image) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            string album = GetArg("ablum");

            if (album != null && !album.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(album, Path.GetTempPath(), "DXT5", true))
                {
                    album = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(album) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                var res = BflytFile.PatchResult.OK;

                if (Image != null)
                {
                    if (SwitchThemesCommon.PatchBntx(CommonSzs, File.ReadAllBytes(Image), targetPatch) == BflytFile.PatchResult.Fail)
                    {
                        Console.WriteLine(
                            "Can't build this theme: the szs you opened doesn't contain some information needed to patch the bntx," +
                            "without this information it is not possible to rebuild the bntx." +
                            "You should use an original or at least working szs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }

                if (album != null && targetPatch.szsName == "ResidentMenu.szs")
                {
                    SwitchThemesCommon.PatchBntxTexture(CommonSzs, File.ReadAllBytes(album), "RdtIcoPvr_00^s", 0x02000000);
                }

                res = SwitchThemesCommon.PatchBgLayouts(CommonSzs, targetPatch);

                if (res == BflytFile.PatchResult.Fail)
                {
                    Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
                    return(false);
                }
                else if (res == BflytFile.PatchResult.CorruptedFile)
                {
                    Console.WriteLine("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
                    return(false);
                }

                if (Layout != null)
                {
                    var layoutres = SwitchThemesCommon.PatchLayouts(CommonSzs, LayoutPatch.LoadTemplate(File.ReadAllText(Layout)), targetPatch.NXThemeName == "home", true);
                    if (layoutres == BflytFile.PatchResult.Fail)
                    {
                        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");
                        return(false);
                    }
                    else if (layoutres == BflytFile.PatchResult.CorruptedFile)
                    {
                        Console.WriteLine("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS");
                        return(false);
                    }
                }

                var sarc = SARC.PackN(CommonSzs);

                File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
                GC.Collect();

                if (res == BflytFile.PatchResult.AlreadyPatched)
                {
                    Console.WriteLine("Done, This file has already been patched before.\r\nIf you have issues try with an unmodified file");
                }
                else
                {
                    Console.WriteLine("Done");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }

            return(true);
        }
Exemplo n.º 23
0
        static bool NXThemeFromArgs(string[] args)
        {
            if (args.Length < 4)
            {
                return(false);
            }
            string Target = args[1];

            if (!Form1.HomeMenuParts.Values.Contains(Target))
            {
                return(false);
            }

            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 !");
                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");
                return(false);
            }

            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            bool?GetArgBool(string start)
            {
                var a = GetArg(start);

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(bool.Parse(a));
                }
            }

            string Name        = GetArg("name");
            string Author      = GetArg("author");
            string Output      = GetArg("out");
            string ExtraCommon = GetArg("commonlyt");
            string album       = GetArg("album");

            if (Output == null || Output == "")
            {
                Console.WriteLine("Missing out= arg");
                return(false);
            }

            bool preview = GetArgBool("preview") ?? true;

            if (Name == null || Name.Trim() == "")
            {
                var info = ThemeInputInfo.Ask();
                Name    = info.Item1;
                Author  = info.Item2;
                preview = info.Item3;
            }

            LayoutPatch layout = null;

            if (Layout != null && File.Exists(Layout))
            {
                layout = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
            }

            Dictionary <string, string> AppletIcons = new Dictionary <string, string>();

            void PopulateAppletIcons(List <TextureReplacement> l)
            {
                foreach (var a in l)
                {
                    string path = GetArg(a.NxThemeName);
                    AppletIcons.Add(a.NxThemeName, path);
                }
            }

            if (TextureReplacement.NxNameToList.ContainsKey(Target))
            {
                PopulateAppletIcons(TextureReplacement.NxNameToList[Target]);
            }

            try
            {
                var builder = new NXThemeBuilder(Target, Name, Author);

                if (layout != null)
                {
                    builder.AddMainLayout(layout);
                }
                if (Image != null)
                {
                    builder.AddMainBg(File.ReadAllBytes(Image));
                }
                if (ExtraCommon != null)
                {
                    builder.AddFile("common.json", File.ReadAllBytes(ExtraCommon));
                }

                foreach (var i in AppletIcons)
                {
                    if (i.Value != null)
                    {
                        builder.AddAppletIcon(i.Key, File.ReadAllBytes(i.Value));
                    }
                }

                File.WriteAllBytes(Output, builder.GetNxtheme());
                Console.WriteLine("Done !");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                return(false);
            }

            return(true);
        }
Exemplo n.º 24
0
		static bool SZSFromArgs(string[] args)
		{
			string GetArg(string start)
			{
				var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();
				if (a == null) return null;
				else return a.Split('=')[1];
			}

			if (args.Length < 2)
				return false;

			string Target = args[1];
			var	CommonSzs = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
			var targetPatch = SzsPatcher.DetectSarc(CommonSzs, DefaultTemplates.templates);

			if (targetPatch == null)
			{
				Console.WriteLine("Unknown szs file");
				return false;
			}

			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 !");
				return false;
			}
			string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();
			
			string Output = GetArg("out");

			if (Output == null || Output == "")
				return false;

			if (!Image.EndsWith(".dds"))
			{
				if (Form1.ImageToDDS(Image, Path.GetTempPath()))
					Image = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Image) + ".dds");
				else return false;
			}		

			try
			{				
				var res = BflytFile.PatchResult.OK;
				var Patcher = new SzsPatcher(CommonSzs, DefaultTemplates.templates);

				if (Image != null)
				{
					res = Patcher.PatchMainBG(File.ReadAllBytes(Image));
					if (res == BflytFile.PatchResult.Fail)
					{
						Console.WriteLine("Couldn't patch this file, it might have been already modified or it's from an unsupported system version.");
						return false;
					}
					else if (res == BflytFile.PatchResult.CorruptedFile)
					{
						Console.WriteLine("This file has been already patched with another tool and is not compatible, you should get an unmodified layout.");
						return false;
					}
				}				

				if (Layout != null)
				{
					Patcher.EnableAnimations = true;
					var l = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
					var layoutres = Patcher.PatchLayouts(l, targetPatch.NXThemeName, targetPatch.NXThemeName == "home");
					if (layoutres == BflytFile.PatchResult.Fail)
					{
						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");
						return false;
					}
					else if (layoutres == BflytFile.PatchResult.CorruptedFile)
					{
						Console.WriteLine("A layout in this SZS is missing a pane required for the selected layout patch, you are probably using an already patched SZS");
						return false;
					}
					layoutres = Patcher.PatchAnimations(l.Anims);
				}

				void ProcessAppletIcons(List<TextureReplacement> l)
				{
					foreach (var a in l)
					{
						string path = GetArg(a.NxThemeName);
						if (!path.EndsWith(".dds") && !Form1.IcontoDDS(ref path))
							path = null;
						if (path != null)
							Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName);
					}
				}

				if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
					ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);

				CommonSzs = Patcher.GetFinalSarc();
				var sarc = SARC.PackN(CommonSzs);

				File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
				GC.Collect();

				if (res == BflytFile.PatchResult.AlreadyPatched)
					Console.WriteLine("Done, This file has already been patched before.\r\nIf you have issues try with an unmodified file");
				else
					Console.WriteLine("Done");
			}
			catch (Exception ex)
			{
				Console.WriteLine("ERROR: " + ex.Message);
			}

			return true;
		}
Exemplo n.º 25
0
        static bool SZSFromArgs(string[] args)
        {
            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            if (args.Length < 2)
            {
                return(false);
            }

            string Target      = args[1];
            var    CommonSzs   = SARCExt.SARC.UnpackRamN(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
            var    targetPatch = SzsPatcher.DetectSarc(CommonSzs, DefaultTemplates.templates);

            if (targetPatch == null)
            {
                Console.WriteLine("Unknown szs file");
                return(false);
            }

            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 !");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            string Output = GetArg("out");

            if (Output == null || Output == "")
            {
                return(false);
            }

            if (!Image.EndsWith(".dds"))
            {
                if (Form1.ImageToDDS(Image, Path.GetTempPath()))
                {
                    Image = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Image) + ".dds");
                }
                else
                {
                    return(false);
                }
            }

            try
            {
                var res     = true;
                var Patcher = new SzsPatcher(CommonSzs, DefaultTemplates.templates);

                if (Image != null)
                {
                    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.");
                        return(false);
                    }
                }

                void ProcessAppletIcons(List <TextureReplacement> l)
                {
                    foreach (var a in l)
                    {
                        string path = GetArg(a.NxThemeName);
                        if (!path.EndsWith(".dds") && !Form1.IcontoDDS(ref path))
                        {
                            path = null;
                        }
                        if (path != null)
                        {
                            if (!Patcher.PatchAppletIcon(File.ReadAllBytes(path), a.NxThemeName))
                            {
                                Console.WriteLine($"Applet icon patch for {a.NxThemeName} failed");
                            }
                        }
                    }
                }

                if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
                {
                    ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);
                }

                if (Layout != null)
                {
                    Patcher.EnableAnimations = true;
                    var l         = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
                    var layoutres = Patcher.PatchLayouts(l, targetPatch.NXThemeName, targetPatch);
                    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");
                        return(false);
                    }
                    layoutres = Patcher.PatchAnimations(l.Anims);
                }

                CommonSzs = Patcher.GetFinalSarc();
                var sarc = SARC.PackN(CommonSzs);

                File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
                GC.Collect();

                if (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");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            return(true);
        }
Exemplo n.º 26
0
        static void DoAutoTheme(string type, string url, string layout)
        {
            cardLoad = Document.GetElementById <HTMLDivElement>("CardLoad");
            Document.GetElementById <HTMLDivElement>("CardTutorial").Hidden = true;
            string themeTarget = "<br/><br/>This theme is an nxtheme, download NXThemes Installer to install it on your switch.";

            cardLoad.InnerHTML = "Wait while your theme is being generated.... " + themeTarget;
            cardLoad.Hidden    = false;
            StartLoading();

            byte[]      DDS;
            LayoutPatch targetLayout = null;

            void BuildTheme()
            {
                var urlSplit = url.Split("/");
                var meta     = new ThemeFileManifest()
                {
                    Version    = 1,
                    Author     = "Auto-Theme",
                    LayoutInfo = targetLayout != null?targetLayout.ToString() : "",
                                     ThemeName = urlSplit[urlSplit.Length - 1],
                                     Target    = type
                };

                var res = SwitchThemesCommon.GenerateNXTheme(meta, DDS, targetLayout == null ? null : targetLayout.AsJson());

                if (res == null)
                {
                    endWithError("GenerateNXTheme() failed :(");
                    return;
                }
                Uint8Array dwn           = new Uint8Array(res);
                string     DownloadFname = urlSplit[urlSplit.Length - 1] + ".nxtheme";

                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
                Document.GetElementById <HTMLDivElement>("CardLoad").InnerHTML = "Your theme has been generated !" + themeTarget;
                EndLoading();
            }

            void DDSDownloaded(Uint8Array arr)
            {
                DDS = arr.ToArray();

                if (layout == null)
                {
                    BuildTheme();
                }
                else
                {
                    HttpRequest(layout, LayoutDownloaded, "Layout");
                }
            }

            void LayoutDownloaded(string req)
            {
                targetLayout = LayoutPatch.LoadTemplate(req);
                BuildTheme();
            }

            HttpRequest(url, DDSDownloaded, "DDS");
        }
Exemplo n.º 27
0
        static void DoAutoTheme(string type, string url, string layout)
        {
            cardLoad = Document.GetElementById <HTMLDivElement>("CardLoad");
            Document.GetElementById <HTMLDivElement>("CardTutorial").Hidden = true;
            string themeTarget = "<br/><br/>This theme is for " + Window.LocalStorage.GetItem(type + "Name") as string + "<br/>To change the target version upload another szs for Auto-Theme on the <a href=\"index.html\">Home page</a>";

            cardLoad.InnerHTML = "Wait while your theme is being generated.... " + themeTarget;
            cardLoad.Hidden    = false;
            StartLoading();

            DDSEncoder.DDSLoadResult LoadedDDS;
            SarcData      CommonSzs;
            PatchTemplate targetPatch;
            LayoutPatch   targetLayout = null;

            void BuildTheme()
            {
                var yaz0 = Theme.Make(CommonSzs, LoadedDDS, targetPatch, targetLayout);

                if (yaz0 == null)
                {
                    endWithError("Theme.Make() failed :(");
                    return;
                }
                Uint8Array dwn           = new Uint8Array(yaz0);
                string     DownloadFname = targetPatch.szsName;

                Script.Write("downloadBlob(dwn,DownloadFname,'application/octet-stream');");
                Document.GetElementById <HTMLDivElement>("CardLoad").InnerHTML = "Your theme has been generated !" + themeTarget;
                EndLoading();
            }

            void DDSDownloaded(Uint8Array arr)
            {
                LoadedDDS = DDSEncoder.LoadDDS(arr.ToArray());
                arr       = null;
                CommonSzs = SARC.UnpackRamN(
                    ManagedYaz0.Decompress(
                        Convert.FromBase64String(
                            Window.LocalStorage.GetItem(type) as string)));

                targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates);

                if (layout == null)
                {
                    BuildTheme();
                }
                else
                {
                    HttpRequest(layout, LayoutDownloaded, "Layout");
                }
            }

            void LayoutDownloaded(string req)
            {
                targetLayout = LayoutPatch.LoadTemplate(req);
                BuildTheme();
            }

            HttpRequest(url, DDSDownloaded, "DDS");
        }
Exemplo n.º 28
0
        private void NnBuilderBuild_Click(object sender, EventArgs e)
        {
            if (tbBntxFile.Text.Trim() == "")
            {
                if (AllLayoutsBox.SelectedIndex == 0)
                {
                    MessageBox.Show("You need at least a custom image or layout to make a theme.");
                    return;
                }

                if (MessageBox.Show("This will create a theme without any background image, the console default one will be used. Do you want to continue ?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }
            }

            if (!BgImageCheck(false))
            {
                return;
            }

            var info = ThemeInputInfo.Ask();

            if (info == null)
            {
                return;
            }

            byte[] preview = null;
            if (info.Item3 && tbBntxFile.Text.Trim() != "")
            {
                preview = GenerateDDSPreview(tbBntxFile.Text);
            }

            if (AlbumIcon != null && !AlbumIcon.EndsWith(".dds") && !AlbumIcontoDDS())
            {
                return;
            }

            LayoutPatch layout = null;

            if (AllLayoutsBox.SelectedIndex != 0)
            {
                layout = AllLayoutsBox.SelectedItem as LayoutPatch;
            }
            try
            {
                var res = SwitchThemesCommon.GenerateNXTheme(
                    new ThemeFileManifest()
                {
                    Version    = 6,
                    ThemeName  = info.Item1,
                    Author     = info.Item2,
                    Target     = HomeMenuParts[HomeMenuPartBox.Text],
                    LayoutInfo = layout == null ? "" : layout.PatchName + " by " + layout.AuthorName,
                },
                    tbBntxFile.Text != "" ? File.ReadAllBytes(tbBntxFile.Text) : null,
                    layout?.AsByteArray(),
                    new Tuple <string, byte[]>("preview.png", preview),
                    new Tuple <string, byte[]>("common.json", ExtraCommonLyt?.AsByteArray()),
                    new Tuple <string, byte[]>("album.dds", AlbumIcon != null ? File.ReadAllBytes(AlbumIcon) : null));

                SaveFileDialog sav = new SaveFileDialog()
                {
                    Filter = "theme pack (*.nxtheme)|*.nxtheme"
                };
                if (sav.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                File.WriteAllBytes(sav.FileName, res);
                MessageBox.Show("Done");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex.Message);
            }
        }
Exemplo n.º 29
0
        private void materialRaisedButton8_Click(object sender, EventArgs e)
        {
            if (CommonSzs == null || targetPatch == null)
            {
                MessageBox.Show("Open a valid theme first !");
                return;
            }
            if (tbBntxFile.Text.Trim() == "")
            {
                MessageBox.Show("Select an image first");
                return;
            }

            if (!BgImageCheck(false))
            {
                return;
            }

            var info = ThemeInputInfo.Ask();

            if (info == null)
            {
                return;
            }

            byte[] preview = null;
            if (info.Item3)
            {
                preview = GenerateDDSPreview(tbBntxFile.Text);
            }

            LayoutPatch layout = null;

            if (LayoutPatchList.SelectedIndex != 0)
            {
                layout = LayoutPatchList.SelectedItem as LayoutPatch;
            }
            try
            {
                var res = SwitchThemesCommon.GenerateNXTheme(
                    new ThemeFileManifest()
                {
                    Version    = 6,
                    ThemeName  = info.Item1,
                    Author     = info.Item2,
                    Target     = targetPatch.NXThemeName,
                    LayoutInfo = layout == null ? "" : layout.PatchName + " by " + layout.AuthorName,
                },
                    File.ReadAllBytes(tbBntxFile.Text),
                    layout?.AsByteArray(),
                    new Tuple <string, byte[]>("preview.png", preview));

                SaveFileDialog sav = new SaveFileDialog()
                {
                    Filter = "theme pack (*.nxtheme)|*.nxtheme"
                };
                if (sav.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                File.WriteAllBytes(sav.FileName, res);
                MessageBox.Show("Done");
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex.Message);
            }
        }
Exemplo n.º 30
0
        static bool SZSFromArgs(string[] args)
        {
            string GetArg(string start)
            {
                var a = args.Where(x => x.StartsWith(start + "=")).FirstOrDefault();

                if (a == null)
                {
                    return(null);
                }
                else
                {
                    return(a.Split('=')[1]);
                }
            }

            if (args.Length < 2)
            {
                return(false);
            }

            string Target      = args[1];
            var    CommonSzs   = SARCExt.SARC.Unpack(ManagedYaz0.Decompress(File.ReadAllBytes(Target)));
            var    targetPatch = DefaultTemplates.GetFor(CommonSzs);

            if (targetPatch == null)
            {
                Console.WriteLine("Unknown szs file");
                return(false);
            }

            string Image = args.Where(x => x.ToLower().EndsWith(".dds")).FirstOrDefault();

            if (Image == null || !File.Exists(Image))
            {
                Console.WriteLine("No image file !\r\nNote that only dds files are supported for szs themes.");
                return(false);
            }
            string Layout = args.Where(x => x.EndsWith(".json")).FirstOrDefault();

            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");
                }
            }

            try
            {
                var res     = true;
                var Patcher = new SzsPatcher(CommonSzs);

                if (Image != null)
                {
                    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.");
                        return(false);
                    }
                }

                void ProcessAppletIcons(List <TextureReplacement> l)
                {
                    foreach (var a in l)
                    {
                        string path = GetArg(a.NxThemeName);
                        if (!path.EndsWith(".dds"))
                        {
                            Console.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");
                            }
                        }
                    }
                }

                if (TextureReplacement.NxNameToList.ContainsKey(targetPatch.NXThemeName))
                {
                    ProcessAppletIcons(TextureReplacement.NxNameToList[targetPatch.NXThemeName]);
                }

                if (Layout != null)
                {
                    var l         = LayoutPatch.LoadTemplate(File.ReadAllText(Layout));
                    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");
                        return(false);
                    }
                }

                CommonSzs = Patcher.GetFinalSarc();
                var sarc = SARC.Pack(CommonSzs);

                File.WriteAllBytes(Output, ManagedYaz0.Compress(sarc.Item2, 3, (int)sarc.Item1));
                GC.Collect();

                if (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");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }

            return(true);
        }