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