public static (string, string) Ask()
        {
            var f = new ThemeInputInfo();

            f.ShowDialog();
            return(f.result);
        }
Exemple #2
0
        public static Tuple <string, string, bool> Ask()
        {
            var f = new ThemeInputInfo();

            f.ShowDialog();
            return(f.result);
        }
Exemple #3
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);
            }
        }
Exemple #4
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");
        }
Exemple #5
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);
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
            }
        }
Exemple #8
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);
        }
Exemple #9
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);
            }
        }