From 81898f829c9e5fee5222105823a9ccfae0b2f28e Mon Sep 17 00:00:00 2001 From: nooperation Date: Sun, 10 Dec 2017 15:36:35 -0500 Subject: [PATCH 1/7] Moving ExportView and models out of the BagView namespace (this is to be shared with BagView and ResourceViews) --- SanBag/Commands/CommandCancelExport.cs | 1 + SanBag/SanBag.csproj | 16 ++++++------- .../BagViewModels/GenericBagViewModel.cs | 1 + .../{BagViewModels => }/ExportViewModel.cs | 12 ++++------ .../ManifestResourceViewModel.cs | 1 + SanBag/Views/{BagViews => }/ExportView.xaml | 2 +- .../Views/{BagViews => }/ExportView.xaml.cs | 23 +++---------------- 7 files changed, 20 insertions(+), 36 deletions(-) rename SanBag/ViewModels/{BagViewModels => }/ExportViewModel.cs (98%) rename SanBag/Views/{BagViews => }/ExportView.xaml (97%) rename SanBag/Views/{BagViews => }/ExportView.xaml.cs (57%) diff --git a/SanBag/Commands/CommandCancelExport.cs b/SanBag/Commands/CommandCancelExport.cs index 2ce8032..ce358eb 100644 --- a/SanBag/Commands/CommandCancelExport.cs +++ b/SanBag/Commands/CommandCancelExport.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Input; +using SanBag.ViewModels; using SanBag.ViewModels.BagViewModels; namespace SanBag.Commands diff --git a/SanBag/SanBag.csproj b/SanBag/SanBag.csproj index a169e92..b7d28bb 100644 --- a/SanBag/SanBag.csproj +++ b/SanBag/SanBag.csproj @@ -122,6 +122,9 @@ TextureResourceBagView.xaml + + ExportView.xaml + ResourceView.xaml @@ -150,10 +153,6 @@ MSBuild:Compile Designer - - Designer - MSBuild:Compile - Designer XamlIntelliSenseFileGenerator @@ -166,6 +165,10 @@ Designer XamlIntelliSenseFileGenerator + + Designer + XamlIntelliSenseFileGenerator + MSBuild:Compile Designer @@ -174,10 +177,7 @@ App.xaml Code - - - ExportView.xaml - + MainWindow.xaml Code diff --git a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs index 1b0ee41..1153bda 100644 --- a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs @@ -15,6 +15,7 @@ using System.Windows.Controls; using SanBag.Views.BagViews; using SanBag.Views.ResourceViews; +using ExportView = SanBag.Views.ExportView; namespace SanBag.ViewModels.BagViewModels { diff --git a/SanBag/ViewModels/BagViewModels/ExportViewModel.cs b/SanBag/ViewModels/ExportViewModel.cs similarity index 98% rename from SanBag/ViewModels/BagViewModels/ExportViewModel.cs rename to SanBag/ViewModels/ExportViewModel.cs index 0525c2f..89418a4 100644 --- a/SanBag/ViewModels/BagViewModels/ExportViewModel.cs +++ b/SanBag/ViewModels/ExportViewModel.cs @@ -1,18 +1,16 @@ -using LibSanBag; -using SanBag.Commands; -using SanBag.Models; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.Linq; using System.Runtime.CompilerServices; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; +using LibSanBag; +using SanBag.Commands; +using SanBag.Models; -namespace SanBag.ViewModels.BagViewModels +namespace SanBag.ViewModels { public class ExportViewModel : INotifyPropertyChanged { diff --git a/SanBag/ViewModels/ResourceViewModels/ManifestResourceViewModel.cs b/SanBag/ViewModels/ResourceViewModels/ManifestResourceViewModel.cs index 07d38d6..f26c432 100644 --- a/SanBag/ViewModels/ResourceViewModels/ManifestResourceViewModel.cs +++ b/SanBag/ViewModels/ResourceViewModels/ManifestResourceViewModel.cs @@ -13,6 +13,7 @@ using SanBag.Models; using SanBag.ViewModels.BagViewModels; using SanBag.Views.BagViews; +using ExportView = SanBag.Views.ExportView; namespace SanBag.ViewModels.ResourceViewModels { diff --git a/SanBag/Views/BagViews/ExportView.xaml b/SanBag/Views/ExportView.xaml similarity index 97% rename from SanBag/Views/BagViews/ExportView.xaml rename to SanBag/Views/ExportView.xaml index fecb84e..337257c 100644 --- a/SanBag/Views/BagViews/ExportView.xaml +++ b/SanBag/Views/ExportView.xaml @@ -1,4 +1,4 @@ - /// Interaction logic for ExportWindow.xaml From ed10875a42f4bffaaeed1cb8950458698e513a48 Mon Sep 17 00:00:00 2001 From: nooperation Date: Mon, 11 Dec 2017 19:03:09 -0500 Subject: [PATCH 2/7] removing unnecessary views and just using the generic view --- SanBag/SanBag.csproj | 35 --------------- SanBag/ViewModels/BagViewModel.cs | 12 +++--- SanBag/Views/BagViews/ManifestBagView.xaml | 39 ----------------- SanBag/Views/BagViews/ManifestBagView.xaml.cs | 28 ------------ .../ScriptCompiledBytecodeResourceView.xaml | 33 -------------- ...ScriptCompiledBytecodeResourceView.xaml.cs | 28 ------------ .../ScriptSourceTextResourceBagView.xaml | 39 ----------------- .../ScriptSourceTextResourceBagView.xaml.cs | 28 ------------ .../Views/BagViews/SoundResourceBagView.xaml | 43 ------------------- .../BagViews/SoundResourceBagView.xaml.cs | 28 ------------ .../BagViews/TextureResourceBagView.xaml | 43 ------------------- .../BagViews/TextureResourceBagView.xaml.cs | 33 -------------- 12 files changed, 6 insertions(+), 383 deletions(-) delete mode 100644 SanBag/Views/BagViews/ManifestBagView.xaml delete mode 100644 SanBag/Views/BagViews/ManifestBagView.xaml.cs delete mode 100644 SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml delete mode 100644 SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml.cs delete mode 100644 SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml delete mode 100644 SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml.cs delete mode 100644 SanBag/Views/BagViews/SoundResourceBagView.xaml delete mode 100644 SanBag/Views/BagViews/SoundResourceBagView.xaml.cs delete mode 100644 SanBag/Views/BagViews/TextureResourceBagView.xaml delete mode 100644 SanBag/Views/BagViews/TextureResourceBagView.xaml.cs diff --git a/SanBag/SanBag.csproj b/SanBag/SanBag.csproj index b7d28bb..0962987 100644 --- a/SanBag/SanBag.csproj +++ b/SanBag/SanBag.csproj @@ -113,27 +113,12 @@ - - ScriptSourceTextResourceBagView.xaml - - - SoundResourceBagView.xaml - - - TextureResourceBagView.xaml - ExportView.xaml ResourceView.xaml - - ScriptCompiledBytecodeResourceView.xaml - - - ManifestBagView.xaml - ManifestResourceView.xaml @@ -153,18 +138,6 @@ MSBuild:Compile Designer - - Designer - XamlIntelliSenseFileGenerator - - - Designer - XamlIntelliSenseFileGenerator - - - Designer - XamlIntelliSenseFileGenerator - Designer XamlIntelliSenseFileGenerator @@ -186,14 +159,6 @@ MSBuild:Compile Designer - - Designer - MSBuild:Compile - - - MSBuild:Compile - Designer - Designer MSBuild:Compile diff --git a/SanBag/ViewModels/BagViewModel.cs b/SanBag/ViewModels/BagViewModel.cs index ece3338..785894e 100644 --- a/SanBag/ViewModels/BagViewModel.cs +++ b/SanBag/ViewModels/BagViewModel.cs @@ -108,7 +108,7 @@ private void Init() var textureResourceBagViewModel = new TextureResourceBagViewModel(this); Views.Add(new ViewType { - View = new TextureResourceBagView + View = new GenericBagView { DataContext = textureResourceBagViewModel }, @@ -120,7 +120,7 @@ private void Init() var scriptCompiledBytecodeResourceView = new ScriptCompiledBytecodeResourceViewModel(this); Views.Add(new ViewType { - View = new ScriptCompiledBytecodeResourceView + View = new GenericBagView { DataContext = scriptCompiledBytecodeResourceView }, @@ -131,7 +131,7 @@ private void Init() var scriptSourceTextResourceViewModel = new ScriptSourceTextResourceViewModel(this); Views.Add(new ViewType { - View = new ScriptSourceTextResourceBagView + View = new GenericBagView { DataContext = scriptSourceTextResourceViewModel }, @@ -142,7 +142,7 @@ private void Init() var luaScriptResourceViewModel = new LuaScriptResourceViewModel(this); Views.Add(new ViewType { - View = new ScriptSourceTextResourceBagView + View = new GenericBagView { DataContext = luaScriptResourceViewModel }, @@ -153,7 +153,7 @@ private void Init() var manifestViewModel = new ManifestBagViewModel(this); Views.Add(new ViewType { - View = new ManifestBagView + View = new GenericBagView { DataContext = manifestViewModel }, @@ -164,7 +164,7 @@ private void Init() var soundViewModel = new SoundResourceBagViewModel(this); Views.Add(new ViewType { - View = new SoundResourceBagView + View = new GenericBagView { DataContext = soundViewModel }, diff --git a/SanBag/Views/BagViews/ManifestBagView.xaml b/SanBag/Views/BagViews/ManifestBagView.xaml deleted file mode 100644 index ad27b07..0000000 --- a/SanBag/Views/BagViews/ManifestBagView.xaml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SanBag/Views/BagViews/ManifestBagView.xaml.cs b/SanBag/Views/BagViews/ManifestBagView.xaml.cs deleted file mode 100644 index 02b3e23..0000000 --- a/SanBag/Views/BagViews/ManifestBagView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SanBag.Views.BagViews -{ - /// - /// Interaction logic for ManifestResourceView.xaml - /// - public partial class ManifestBagView : UserControl - { - public ManifestBagView() - { - InitializeComponent(); - } - } -} diff --git a/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml b/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml deleted file mode 100644 index 7066d9f..0000000 --- a/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml.cs b/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml.cs deleted file mode 100644 index 568a3c0..0000000 --- a/SanBag/Views/BagViews/ScriptCompiledBytecodeResourceView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SanBag.Views.BagViews -{ - /// - /// Interaction logic for ScriptCompiledBytecodeResourceView.xaml - /// - public partial class ScriptCompiledBytecodeResourceView : UserControl - { - public ScriptCompiledBytecodeResourceView() - { - InitializeComponent(); - } - } -} diff --git a/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml b/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml deleted file mode 100644 index cbc19b8..0000000 --- a/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml.cs b/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml.cs deleted file mode 100644 index 6d049ea..0000000 --- a/SanBag/Views/BagViews/ScriptSourceTextResourceBagView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SanBag.Views.BagViews -{ - /// - /// Interaction logic for ScriptSourceTextResourceBagView.xaml - /// - public partial class ScriptSourceTextResourceBagView : UserControl - { - public ScriptSourceTextResourceBagView() - { - InitializeComponent(); - } - } -} diff --git a/SanBag/Views/BagViews/SoundResourceBagView.xaml b/SanBag/Views/BagViews/SoundResourceBagView.xaml deleted file mode 100644 index 9e9e48d..0000000 --- a/SanBag/Views/BagViews/SoundResourceBagView.xaml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SanBag/Views/BagViews/SoundResourceBagView.xaml.cs b/SanBag/Views/BagViews/SoundResourceBagView.xaml.cs deleted file mode 100644 index af74004..0000000 --- a/SanBag/Views/BagViews/SoundResourceBagView.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace SanBag.Views.BagViews -{ - /// - /// Interaction logic for SoundResourceBagView.xaml - /// - public partial class SoundResourceBagView : UserControl - { - public SoundResourceBagView() - { - InitializeComponent(); - } - } -} diff --git a/SanBag/Views/BagViews/TextureResourceBagView.xaml b/SanBag/Views/BagViews/TextureResourceBagView.xaml deleted file mode 100644 index cde92ad..0000000 --- a/SanBag/Views/BagViews/TextureResourceBagView.xaml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SanBag/Views/BagViews/TextureResourceBagView.xaml.cs b/SanBag/Views/BagViews/TextureResourceBagView.xaml.cs deleted file mode 100644 index 789e03e..0000000 --- a/SanBag/Views/BagViews/TextureResourceBagView.xaml.cs +++ /dev/null @@ -1,33 +0,0 @@ -using LibSanBag; -using Microsoft.Win32; -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; - -namespace SanBag.Views.BagViews -{ - /// - /// Interaction logic for TextureResourceBagView.xaml - /// - public partial class TextureResourceBagView : UserControl - { - public TextureResourceBagView() - { - InitializeComponent(); - - this.DataContext = this; - } - } -} From e81377afe0da35e3eee2d032b38320c9a7dcae80 Mon Sep 17 00:00:00 2001 From: nooperation Date: Tue, 12 Dec 2017 19:34:54 -0500 Subject: [PATCH 3/7] Added export to texture resource viewer context menu --- .../TextureResourceBagViewModel.cs | 76 ++++++++++--------- .../TextureResourceViewModel.cs | 34 ++++++++- .../ResourceViews/TextureResourceView.xaml | 13 +++- 3 files changed, 81 insertions(+), 42 deletions(-) diff --git a/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs b/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs index 34ac941..f0369ed 100644 --- a/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs @@ -47,46 +47,52 @@ public override bool IsValidRecord(FileRecord record) return record.Info?.Resource == FileRecordInfo.ResourceType.TextureResource; } + public static void Export(TextureResource resource, Stream outStream, string fileExtension) + { + if (string.Equals(fileExtension, ".dds", StringComparison.CurrentCultureIgnoreCase)) + { + var imageBytes = resource.DdsBytes; + outStream.Write(imageBytes, 0, imageBytes.Length); + } + else + { + var codec = LibDDS.ConversionOptions.CodecType.CODEC_JPEG; + switch (fileExtension) + { + case ".png": + codec = LibDDS.ConversionOptions.CodecType.CODEC_PNG; + break; + case ".jpg": + case ".jpeg": + codec = LibDDS.ConversionOptions.CodecType.CODEC_JPEG; + break; + case ".gif": + codec = LibDDS.ConversionOptions.CodecType.CODEC_GIF; + break; + case ".bmp": + codec = LibDDS.ConversionOptions.CodecType.CODEC_BMP; + break; + case ".ico": + codec = LibDDS.ConversionOptions.CodecType.CODEC_ICO; + break; + case ".wmp": + codec = LibDDS.ConversionOptions.CodecType.CODEC_WMP; + break; + } + var imageBytes = resource.ConvertTo(codec); + outStream.Write(imageBytes, 0, imageBytes.Length); + } + } + protected override void CustomFileExport(ExportParameters exportParameters) { var outputPath = Path.GetFullPath(Path.Combine(exportParameters.OutputDirectory, exportParameters.FileRecord.Name + exportParameters.FileExtension)); + + var textureResource = new TextureResource(); + textureResource.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord); using (var outFile = File.OpenWrite(outputPath)) { - var textureResource = new TextureResource(); - textureResource.InitFromRecord(exportParameters.BagStream, exportParameters.FileRecord); - if (string.Equals(exportParameters.FileExtension, ".dds", StringComparison.CurrentCultureIgnoreCase)) - { - var imageBytes = textureResource.DdsBytes; - outFile.Write(imageBytes, 0, imageBytes.Length); - } - else - { - var codec = LibDDS.ConversionOptions.CodecType.CODEC_JPEG; - switch (exportParameters.FileExtension.ToLower()) - { - case ".png": - codec = LibDDS.ConversionOptions.CodecType.CODEC_PNG; - break; - case ".jpg": - case ".jpeg": - codec = LibDDS.ConversionOptions.CodecType.CODEC_JPEG; - break; - case ".gif": - codec = LibDDS.ConversionOptions.CodecType.CODEC_GIF; - break; - case ".bmp": - codec = LibDDS.ConversionOptions.CodecType.CODEC_BMP; - break; - case ".ico": - codec = LibDDS.ConversionOptions.CodecType.CODEC_ICO; - break; - case ".wmp": - codec = LibDDS.ConversionOptions.CodecType.CODEC_WMP; - break; - } - var imageBytes = textureResource.ConvertTo(codec); - outFile.Write(imageBytes, 0, imageBytes.Length); - } + Export(textureResource, outFile, exportParameters.FileExtension); } exportParameters.OnProgressReport?.Invoke(exportParameters.FileRecord, 0); } diff --git a/SanBag/ViewModels/ResourceViewModels/TextureResourceViewModel.cs b/SanBag/ViewModels/ResourceViewModels/TextureResourceViewModel.cs index 015f2ac..e7d13e7 100644 --- a/SanBag/ViewModels/ResourceViewModels/TextureResourceViewModel.cs +++ b/SanBag/ViewModels/ResourceViewModels/TextureResourceViewModel.cs @@ -6,16 +6,23 @@ using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; +using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using LibSanBag.FileResources; using LibSanBag.ResourceUtils; +using Microsoft.Win32; using SanBag.Annotations; +using SanBag.Commands; +using SanBag.ViewModels.BagViewModels; namespace SanBag.ViewModels.ResourceViewModels { - class TextureResourceViewModel : BaseViewModel + class TextureResourceViewModel : BaseViewModel, ISavable { + private TextureResource _currentResource; + public CommandSaveAs CommandSaveAs { get; set; } + private BitmapImage _currentImage; public BitmapImage CurrentImage { @@ -27,12 +34,17 @@ public BitmapImage CurrentImage } } + public TextureResourceViewModel() + { + CommandSaveAs = new CommandSaveAs(this); + } + protected override void LoadFromStream(Stream resourceStream) { - var resource = new TextureResource(); - resource.InitFromStream(resourceStream); + _currentResource = new TextureResource(); + _currentResource.InitFromStream(resourceStream); - var imageBytes = LibDDS.GetImageBytesFromDds(resource.DdsBytes, 256, 256); + var imageBytes = LibDDS.GetImageBytesFromDds(_currentResource.DdsBytes, 256, 256); var newImage = new BitmapImage(); newImage.BeginInit(); newImage.StreamSource = new MemoryStream(imageBytes); @@ -40,5 +52,19 @@ protected override void LoadFromStream(Stream resourceStream) CurrentImage = newImage; } + + public void SaveAs() + { + var dialog = new SaveFileDialog(); + dialog.FileName = Path.GetFileName(Name) + ".dds"; + dialog.Filter = "DDS Source Image|*.dds|PNG Image|*.png|JPG Image|*.jpg|BMP Image|*.bmp|GIF Image|*.gif"; + if (dialog.ShowDialog() == true) + { + using (var outFile = File.OpenWrite(dialog.FileName)) + { + TextureResourceBagViewModel.Export(_currentResource, outFile, Path.GetExtension(dialog.FileName).ToLower()); + } + } + } } } diff --git a/SanBag/Views/ResourceViews/TextureResourceView.xaml b/SanBag/Views/ResourceViews/TextureResourceView.xaml index f33de6a..a536985 100644 --- a/SanBag/Views/ResourceViews/TextureResourceView.xaml +++ b/SanBag/Views/ResourceViews/TextureResourceView.xaml @@ -5,7 +5,14 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> - - - + + + + + + + + + + From ef558d8d64d41759bb78b5ea4a3c10410ec56c1e Mon Sep 17 00:00:00 2001 From: nooperation Date: Wed, 13 Dec 2017 20:21:22 -0500 Subject: [PATCH 4/7] No longer just crashing when loading an invalid resource --- .../BagViewModels/GenericBagViewModel.cs | 11 +++++-- SanBag/ViewModels/ResourceViewModel.cs | 31 ++++++++++++++++--- .../SoundResourceViewModel.cs | 11 ++++--- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs index 1153bda..c0a0c05 100644 --- a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs @@ -43,8 +43,15 @@ public FileRecord SelectedRecord get => _selectedRecord; set { - _selectedRecord = value; - OnSelectedRecordChanged(); + try + { + _selectedRecord = value; + OnSelectedRecordChanged(); + } + catch (Exception ex) + { + MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + } OnPropertyChanged(); } } diff --git a/SanBag/ViewModels/ResourceViewModel.cs b/SanBag/ViewModels/ResourceViewModel.cs index 1822089..58589df 100644 --- a/SanBag/ViewModels/ResourceViewModel.cs +++ b/SanBag/ViewModels/ResourceViewModel.cs @@ -43,6 +43,7 @@ public void OpenFile(string resourcePath) { var fileName = Path.GetFileName(resourcePath); var fileInfo = LibSanBag.FileRecordInfo.Create(fileName); + var isRawView = false; if (fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.TextureResource) { @@ -61,17 +62,39 @@ public void OpenFile(string resourcePath) CurrentViewModel = new SanBag.ViewModels.ResourceViewModels.ScriptSourceTextViewModel(); } else + { + isRawView = true; + } + + if (isRawView == false) + { + try + { + CurrentView.DataContext = CurrentViewModel; + CurrentViewModel.InitFromPath(resourcePath); + return; + } + catch (Exception ex) + { + isRawView = true; + MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + } + } + + try { var view = new RawResourceView(); - var model = new RawResourceViewModel { + var model = new RawResourceViewModel + { HexControl = view.HexEdit }; CurrentView = view; CurrentViewModel = model; } - - CurrentView.DataContext = CurrentViewModel; - CurrentViewModel.InitFromPath(resourcePath); + catch (Exception ex) + { + MessageBox.Show("Failed to load raw view: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + } } public event PropertyChangedEventHandler PropertyChanged; diff --git a/SanBag/ViewModels/ResourceViewModels/SoundResourceViewModel.cs b/SanBag/ViewModels/ResourceViewModels/SoundResourceViewModel.cs index 42d40bf..f4becce 100644 --- a/SanBag/ViewModels/ResourceViewModels/SoundResourceViewModel.cs +++ b/SanBag/ViewModels/ResourceViewModels/SoundResourceViewModel.cs @@ -191,20 +191,21 @@ public void SaveAs() { using (var compressedStream = File.OpenRead(CompressedSoundPath)) { - var soundResource = new SoundResource(); - soundResource.InitFromStream(compressedStream); - - var soundBytes = soundResource.SoundBytes; try { + var soundResource = new SoundResource(); + soundResource.InitFromStream(compressedStream); + + var soundBytes = soundResource.SoundBytes; LibFSB.SaveAs(soundBytes, dialog.FileName); + + MessageBox.Show($"Successfully wrote {soundBytes.Length} byte(s) to {dialog.FileName}"); } catch (Exception ex) { MessageBox.Show("Failed to save audio: " + ex.Message); return; } - MessageBox.Show($"Successfully wrote {soundBytes.Length} byte(s) to {dialog.FileName}"); } } } From 9c0d6f1dff3474eca4962c819adf2777df6f0b1d Mon Sep 17 00:00:00 2001 From: nooperation Date: Wed, 13 Dec 2017 20:22:53 -0500 Subject: [PATCH 5/7] No longer attempting to load non-payload types for sound and texture viewer --- SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs | 3 ++- SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs b/SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs index cf7bd36..4de329a 100644 --- a/SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs @@ -26,7 +26,8 @@ public SoundResourceBagViewModel(BagViewModel parentViewModel) : base(parentView public override bool IsValidRecord(FileRecord record) { - return record.Info?.Resource == FileRecordInfo.ResourceType.SoundResource; + return record.Info?.Resource == FileRecordInfo.ResourceType.SoundResource && + record.Info?.Payload == FileRecordInfo.PayloadType.Payload; } protected override void CustomFileExport(ExportParameters exportParameters) diff --git a/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs b/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs index f0369ed..df2b21a 100644 --- a/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs @@ -44,7 +44,8 @@ public TextureResourceBagViewModel(BagViewModel parentViewModel) public override bool IsValidRecord(FileRecord record) { - return record.Info?.Resource == FileRecordInfo.ResourceType.TextureResource; + return record.Info?.Resource == FileRecordInfo.ResourceType.TextureResource && + record.Info?.Payload == FileRecordInfo.PayloadType.Payload; } public static void Export(TextureResource resource, Stream outStream, string fileExtension) From 2d8f61ec13a81f1041c43455ce998067e488b0ca Mon Sep 17 00:00:00 2001 From: nooperation Date: Thu, 14 Dec 2017 19:14:04 -0500 Subject: [PATCH 6/7] Fixed resource viewer for unknown types and added manifest viewer to resource viewer --- SanBag/ViewModels/ResourceViewModel.cs | 47 ++++++++++++++------------ 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/SanBag/ViewModels/ResourceViewModel.cs b/SanBag/ViewModels/ResourceViewModel.cs index 58589df..19e480f 100644 --- a/SanBag/ViewModels/ResourceViewModel.cs +++ b/SanBag/ViewModels/ResourceViewModel.cs @@ -45,55 +45,58 @@ public void OpenFile(string resourcePath) var fileInfo = LibSanBag.FileRecordInfo.Create(fileName); var isRawView = false; - if (fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.TextureResource) + if (fileInfo?.Payload == LibSanBag.FileRecordInfo.PayloadType.Manifest) { - CurrentView = new SanBag.Views.ResourceViews.TextureResourceView(); - CurrentViewModel = new SanBag.ViewModels.ResourceViewModels.TextureResourceViewModel(); + CurrentView = new ManifestResourceView(); + CurrentViewModel = new ManifestResourceViewModel(); + } + else if (fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.TextureResource) + { + CurrentView = new TextureResourceView(); + CurrentViewModel = new TextureResourceViewModel(); } else if (fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.SoundResource) { - CurrentView = new SanBag.Views.ResourceViews.SoundResourceView(); - CurrentViewModel = new SanBag.ViewModels.ResourceViewModels.SoundResourceViewModel(); + CurrentView = new SoundResourceView(); + CurrentViewModel = new SoundResourceViewModel(); } else if (fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.ScriptSourceTextResource || fileInfo?.Resource == LibSanBag.FileRecordInfo.ResourceType.LuaScriptResource) { - CurrentView = new SanBag.Views.ResourceViews.ScriptSourceTextView(); - CurrentViewModel = new SanBag.ViewModels.ResourceViewModels.ScriptSourceTextViewModel(); + CurrentView = new ScriptSourceTextView(); + CurrentViewModel = new ScriptSourceTextViewModel(); } else { isRawView = true; } - if (isRawView == false) + if (isRawView) { try { - CurrentView.DataContext = CurrentViewModel; - CurrentViewModel.InitFromPath(resourcePath); - return; + var view = new RawResourceView(); + var model = new RawResourceViewModel + { + HexControl = view.HexEdit + }; + CurrentView = view; + CurrentViewModel = model; } catch (Exception ex) { - isRawView = true; - MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + MessageBox.Show("Failed to load raw view: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } } - try { - var view = new RawResourceView(); - var model = new RawResourceViewModel - { - HexControl = view.HexEdit - }; - CurrentView = view; - CurrentViewModel = model; + CurrentView.DataContext = CurrentViewModel; + CurrentViewModel.InitFromPath(resourcePath); + return; } catch (Exception ex) { - MessageBox.Show("Failed to load raw view: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); + MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK); } } From fdd3f4faeac27385f06dcb39801bf5194b3721de Mon Sep 17 00:00:00 2001 From: nooperation Date: Fri, 15 Dec 2017 21:06:02 -0500 Subject: [PATCH 7/7] Re-initiailize controls after opening a new bag --- SanBag/ViewModels/BagViewModel.cs | 2 ++ SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/SanBag/ViewModels/BagViewModel.cs b/SanBag/ViewModels/BagViewModel.cs index 785894e..3e4df0e 100644 --- a/SanBag/ViewModels/BagViewModel.cs +++ b/SanBag/ViewModels/BagViewModel.cs @@ -90,6 +90,7 @@ public BagViewModel() private void Init() { + Views = new List(); CommandOpenBag = new CommandOpenBag(this); var genericBagViewModel = new GenericBagViewModel(this); @@ -196,6 +197,7 @@ public void OnOpenFile() public void OpenBag(string path) { + Init(); BagPath = path; using (var in_stream = File.OpenRead(path)) diff --git a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs index c0a0c05..8a291da 100644 --- a/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs +++ b/SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs @@ -46,7 +46,10 @@ public FileRecord SelectedRecord try { _selectedRecord = value; - OnSelectedRecordChanged(); + if (value != null) + { + OnSelectedRecordChanged(); + } } catch (Exception ex) { @@ -157,6 +160,11 @@ public static void CopyAsUrl(FileRecord fileRecord) protected virtual void OnSelectedRecordChanged() { + if (SelectedRecord == null) + { + return; + } + var view = CurrentResourceView.DataContext as ResourceViewModels.RawResourceViewModel; if (view == null) {