public ThemeViewModel(Theme model, SMDH info = null) : base(model, Guid.NewGuid().ToString())
        {
            Flags    = new FlagsViewModel(model.Flags, Tag);
            Colors   = new ColorsViewModel(model.Colors, Tag);
            Textures = new TexturesViewModel(model.Textures, Tag);

            Info = new ThemeInfoViewModel(info ?? new SMDH(), Tag);

            SetupRules();
        }
 public SMDHViewer(SMDH Icon)
 {
     this.icn = Icon;
     InitializeComponent();
     typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
                                       dataGridView1, new object[] { true });
     typeof(TabControl).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
                                     tabControl1, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
                                  tabPage1, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
                                  tabPage2, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
                                  tabPage3, new object[] { true });
 }
Esempio n. 3
0
 public SMDHViewer(SMDH Icon)
 {
     this.icn = Icon;
     InitializeComponent();
     typeof(DataGridView).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
         dataGridView1, new object[] { true });
     typeof(TabControl).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
         tabControl1, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
         tabPage1, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
         tabPage2, new object[] { true });
     typeof(TabPage).InvokeMember("DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetProperty, null,
         tabPage3, new object[] { true });
 }
Esempio n. 4
0
        private void importSMDH(byte[] data, bool prompt = false)
        {
            if (prompt && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, "Replace SMDH?"))
            {
                return;
            }

            SMDH newSMDH = new SMDH(data);

            if (newSMDH.LargeIcon.Icon == null)
            {
                return;
            }

            SMDH  = newSMDH;
            entry = -1; // allow proper refreshing
            LoadSMDH();
        }
Esempio n. 5
0
        public ThemeInfoViewModel(SMDH model, string tag) : base(model, tag)
        {
            SmallIcon = new TextureViewModel(model.SmallIcon, Tag);
            LargeIcon = new TextureViewModel(model.LargeIcon, Tag);

            SmallIcon.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(TextureViewModel.Bitmap))
                {
                    RaiseViewModelChanged(nameof(SmallIcon), null, null);
                }
            };
            LargeIcon.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(TextureViewModel.Bitmap))
                {
                    RaiseViewModelChanged(nameof(LargeIcon), null, null);
                }
            };
        }
Esempio n. 6
0
        public static Bitmap CreateBitmap(Stream stream)
        {
            // Read the header
            CXIHeader header = Helpers.ReadCXIHeader(stream);

            header.ExeFSOffset *= BlockSize;
            header.ExeFSLength *= BlockSize;

            // Now read the ExeFS header
            ExeFsHeader exefs_header = ReadExeFSHeader(stream, header.ExeFSOffset);

            ExeFSSectionHeader?icon_section = FindExeFSSection(exefs_header, "icon");

            if (icon_section != null && icon_section.Value.Size != 0)
            {
                SMDH icon = ReadExeFSSection <SMDH>(stream, icon_section.Value, header.ExeFSOffset);
                return(DecodeMortonImage(icon.Graphics.Large, 48));
            }

            return(new Bitmap(100, 100));
        }
Esempio n. 7
0
        public Icon()
        {
            InitializeComponent();
            SMDH = Main.SMDH;
            if (SMDH?.AppSettings == null || SMDH.LargeIcon.Bytes == null)
            {
                byte[] data = new byte[0x3C0];                          // Feed a blank SMDH
                Array.Copy(BitConverter.GetBytes(0x48444D53), data, 4); // SMDH header
                SMDH           = new SMDH(data);
                B_Save.Enabled = false;
            }
            for (int i = 0; i < 16; i++)
            {
                CB_AppInfo.Items.Add(i);
            }

            LoadSMDH();

            AllowDrop  = true;
            DragEnter += tabMain_DragEnter;
            DragDrop  += tabMain_DragDrop;
        }
Esempio n. 8
0
        private Task <LoadThemeResults> LoadTheme_Execute(string path, bool start)
        {
            var busyPickingFile  = MainResources.Busy_PickingFile;
            var busyLoadingTheme = MainResources.Busy_LoadingTheme;
            var task             = new Task <LoadThemeResults>(() =>
            {
                var result = new LoadThemeResults
                {
                    Loaded = false,
                    Path   = path,
                };

                if (string.IsNullOrEmpty(result.Path))
                {
                    BusyText = busyPickingFile;
                    var opfl = new OpenFileDialog
                    {
                        Filter      = "3DS Theme File|*.bin",
                        Multiselect = false
                    };
                    var dlg = opfl.ShowDialog();
                    if (dlg.HasValue && dlg.Value)
                    {
                        result.Path = opfl.FileName;
                    }
                }

                if (string.IsNullOrEmpty(result.Path))
                {
                    return(result);
                }

                var themeDir = Path.GetDirectoryName(result.Path) ?? ".";

                BusyText = busyLoadingTheme;
                using (var fs = File.OpenRead(result.Path))
                    using (var ms = new MemoryStream())
                    {
                        try
                        {
                            LZ11.Decompress(fs, fs.Length, ms);
                            ms.Position  = 0;
                            result.Theme = Theme.Read(ms);
#if DEBUG
                            ms.Seek(0, SeekOrigin.Begin);
                            File.WriteAllBytes("dump.bin", ms.ToArray());
#endif
                            result.Loaded = true;
                        }
                        catch
                        {
                            // Ignore
                        }
                    }

                var smdhPath = Path.Combine(themeDir, "info.smdh");
                if (result.Loaded && File.Exists(smdhPath))
                {
                    using (var fs = File.OpenRead(smdhPath))
                    {
                        try
                        {
                            result.Info = SMDH.Read(fs);
                        }
                        catch
                        {
                            result.Info = null;
                        }
                    }
                }
                return(result);
            });

            if (start)
            {
                task.Start();
            }
            return(task);
        }
Esempio n. 9
0
 public void Save(Stream s)
 {
     SMDH.Write(Model, s);
 }