Exemple #1
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 #2
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 #3
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);
            }
        }