示例#1
0
        private void LoadTheme_PostExecute(LoadThemeResults result)
        {
            if (result.Loaded)
            {
                ViewModel = new ThemeViewModel(result.Theme, result.Info);

                var path = result.Path;
                UpdateRecentsList(path);

                if (result.Info == null)
                {
                    IconExtension icex  = new IconExtension(@"/ThemeEditor.WPF;component/Resources/Icons/app_icn.ico", 48);
                    var           large = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(48, 48);
                    icex.Size = 24;
                    var small = ((BitmapSource)icex.ProvideValue(null)).CreateResizedImage(24, 24);

                    ViewModel.Info.LargeIcon.Bitmap = large;
                    ViewModel.Info.SmallIcon.Bitmap = small;
                }

                ThemePath = result.Path;

                if (ReloadBGMCommand.CanExecute(null))
                {
                    ReloadBGMCommand.Execute(null);
                }
            }
            IsBusy = false;
        }
        private Task<LoadThemeResults> LoadNullTheme_Execute(bool start)
        {
            var busyLoadingTheme = MainResources.Busy_LoadingTheme;
            var task = new Task<LoadThemeResults>(() =>
            {
                var result = new LoadThemeResults
                {
                    Loaded = false,
                    Path = null,
                };

                BusyText = busyLoadingTheme;
                var res = Extensions.GetResources("body_lz\\.bin");
                using (var fs = (Stream) res.Values.First())
                using (var ms = new MemoryStream())
                {
                    try
                    {
                        LZ11.Decompress(fs, fs.Length, ms);
                        ms.Position = 0;
                        result.Theme = Theme.Read(ms);
                        result.Loaded = true;
                    }
                    catch
                    {
                        return result;
                    }
                }

                return result;
            });
            if (start)
                task.Start();
            return task;
        }
示例#3
0
        private Task <LoadThemeResults> LoadNullTheme_Execute(bool start)
        {
            var busyLoadingTheme = MainResources.Busy_LoadingTheme;
            var task             = new Task <LoadThemeResults>(() =>
            {
                var result = new LoadThemeResults
                {
                    Loaded = false,
                    Path   = null,
                };

                BusyText = busyLoadingTheme;
                Stream fs;
                if (!File.Exists("default_body_lz.bin"))
                {
                    var res = Extensions.GetResources("body_lz\\.bin");
                    fs      = (Stream)res.Values.First();
                }
                else
                {
                    fs = File.OpenRead("default_body_lz.bin");
                }
                using (fs)
                    using (var ms = new MemoryStream())
                    {
                        try
                        {
                            LZ11.Decompress(fs, fs.Length, ms);
                            ms.Position   = 0;
                            result.Theme  = Theme.Read(ms);
                            result.Loaded = true;
                        }
                        catch
                        {
                            return(result);
                        }
                    }

                return(result);
            });

            if (start)
            {
                task.Start();
            }
            return(task);
        }
示例#4
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);
        }
        private void LoadTheme_PostExecute(LoadThemeResults result)
        {
            if (result.Loaded)
            {
                ViewModel = new ThemeViewModel(result.Theme);
                ThemePath = result.Path;

                if (ReloadBGMCommand.CanExecute(null))
                    ReloadBGMCommand.Execute(null);
            }
            IsBusy = false;
        }
        private Task<LoadThemeResults> LoadTheme_Execute(string path)
        {
            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|body_LZ.bin",
                        Multiselect = false
                    };
                    var dlg = opfl.ShowDialog();
                    if (dlg.HasValue && dlg.Value)
                        result.Path = opfl.FileName;
                }

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

                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);
                        result.Loaded = true;
                    }
                    catch
                    {
                        return result;
                    }
                }

                return result;
            });
            task.Start();
            return task;
        }
        private void LoadTheme_PostExecute(LoadThemeResults result)
        {
            if (result.Loaded)
            {
                ViewModel = new ThemeViewModel(result.Theme, result.Info);

                var path = result.Path;
                UpdateRecentsList(path);

                if (result.Info == null)
                {
                    IconExtension icex = new IconExtension(@"/ThemeEditor.WPF;component/Resources/Icons/app_icn.ico", 48);
                    var large = ((BitmapSource) icex.ProvideValue(null)).CreateResizedImage(48, 48);
                    icex.Size = 24;
                    var small = ((BitmapSource) icex.ProvideValue(null)).CreateResizedImage(24, 24);

                    ViewModel.Info.LargeIcon.Bitmap = large;
                    ViewModel.Info.SmallIcon.Bitmap = small;
                }

                ThemePath = result.Path;

                if (ReloadBGMCommand.CanExecute(null))
                    ReloadBGMCommand.Execute(null);
            }
            IsBusy = false;
        }
        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;
        }