Beispiel #1
0
        public static byte[] GenerateNXTheme(ThemeFileManifest info, byte[] image, byte[] layout = null, params Tuple <string, byte[]>[] ExtraFiles)
        {
            Dictionary <string, byte[]> Files = new Dictionary <string, byte[]>();

            Files.Add("info.json", Encoding.UTF8.GetBytes(info.Serialize()));
            Files.Add("image.dds", image);
            if (layout != null)
            {
                Files.Add("layout.json", layout);
            }

            foreach (var f in ExtraFiles)
            {
                if (f != null && f.Item1 != null && f.Item2 != null)
                {
                    Files.Add(f.Item1, f.Item2);
                }
            }

            var sarc = SARCExt.SARC.PackN(new SARCExt.SarcData()
            {
                endianness = ByteOrder.LittleEndian, Files = Files, HashOnly = false
            });

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }
 public NXThemeBuilder(string target, string name, string author)
 {
     info = new ThemeFileManifest()
     {
         Version   = SwitchThemesCommon.NxThemeFormatVersion,
         ThemeName = name,
         Author    = author,
         Target    = target,
     };
 }
Beispiel #3
0
        public static byte[] GenerateNXTheme(ThemeFileManifest info, byte[] image, byte[] layout = null, params Tuple <string, byte[]>[] _ExtraFiles)
        {
            Dictionary <string, byte[]> ExtFiles = new Dictionary <string, byte[]>();

            foreach (var f in _ExtraFiles)
            {
                if (f != null && f.Item1 != null && f.Item2 != null)
                {
                    ExtFiles.Add(f.Item1, f.Item2);
                }
            }

            if (image == null && layout == null)
            {
                throw new Exception("You need at least an image or a layout to make a theme");
            }

            if (image != null)
            {
                var img = DDSEncoder.LoadDDS(image);
                if (img.width != 1280 || img.height != 720 || img.Format != "DXT1")
                {
                    throw new Exception("The background image must be 1280x720 and (if you're using a DDS) DXT1 encoded ");
                }
            }

            if (info.Target != "home")
            {
                if (ExtFiles.ContainsKey("album.dds"))
                {
                    ExtFiles.Remove("album.dds");
                }
                if (ExtFiles.ContainsKey("common.json"))
                {
                    ExtFiles.Remove("common.json");
                }
            }

            {
                byte[] album_img = null;
                ExtFiles.TryGetValue("album.dds", out album_img);
                if (album_img != null)
                {
                    var img = DDSEncoder.LoadDDS(album_img);
                    if (img.width != 64 || img.height != 56)
                    {
                        throw new Exception("The custom album image must be 64x56");
                    }
                }
            }

            Dictionary <string, byte[]> Files = new Dictionary <string, byte[]>();

            Files.Add("info.json", Encoding.UTF8.GetBytes(info.Serialize()));
            if (image != null)
            {
                Files.Add("image.dds", image);
            }
            if (layout != null)
            {
                Files.Add("layout.json", layout);
            }

            foreach (var f in ExtFiles)
            {
                Files.Add(f.Key, f.Value);
            }

            var sarc = SARCExt.SARC.PackN(new SARCExt.SarcData()
            {
                endianness = ByteOrder.LittleEndian, Files = Files, HashOnly = false
            });

            return(ManagedYaz0.Compress(sarc.Item2, 1, (int)sarc.Item1));
        }