Skip to content

Commit

Permalink
Merge pull request #35 from nooperation/develop
Browse files Browse the repository at this point in the history
Develop into master
  • Loading branch information
nooperation authored Dec 16, 2017
2 parents ff2229f + b01e7ab commit 10697fb
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 481 deletions.
1 change: 1 addition & 0 deletions SanBag/Commands/CommandCancelExport.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Windows.Input;
using SanBag.ViewModels;
using SanBag.ViewModels.BagViewModels;

namespace SanBag.Commands
Expand Down
43 changes: 4 additions & 39 deletions SanBag/SanBag.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,12 @@
</Compile>
<Compile Include="Converters\SizeToStringConverter.cs" />
<Compile Include="Converters\TimestampNsConverter.cs" />
<Compile Include="Views\BagViews\ScriptSourceTextResourceBagView.xaml.cs">
<DependentUpon>ScriptSourceTextResourceBagView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BagViews\SoundResourceBagView.xaml.cs">
<DependentUpon>SoundResourceBagView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BagViews\TextureResourceBagView.xaml.cs">
<DependentUpon>TextureResourceBagView.xaml</DependentUpon>
<Compile Include="Views\ExportView.xaml.cs">
<DependentUpon>ExportView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ResourceView.xaml.cs">
<DependentUpon>ResourceView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BagViews\ScriptCompiledBytecodeResourceView.xaml.cs">
<DependentUpon>ScriptCompiledBytecodeResourceView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\BagViews\ManifestBagView.xaml.cs">
<DependentUpon>ManifestBagView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ResourceViews\ManifestResourceView.xaml.cs">
<DependentUpon>ManifestResourceView.xaml</DependentUpon>
</Compile>
Expand All @@ -150,19 +138,7 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\BagViews\ExportView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\BagViews\ScriptSourceTextResourceBagView.xaml">
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
</Page>
<Page Include="Views\BagViews\SoundResourceBagView.xaml">
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
</Page>
<Page Include="Views\BagViews\TextureResourceBagView.xaml">
<Page Include="Views\ExportView.xaml">
<SubType>Designer</SubType>
<Generator>XamlIntelliSenseFileGenerator</Generator>
</Page>
Expand All @@ -174,10 +150,7 @@
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="ViewModels\BagViewModels\ExportViewModel.cs" />
<Compile Include="Views\BagViews\ExportView.xaml.cs">
<DependentUpon>ExportView.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\ExportViewModel.cs" />
<Compile Include="Views\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
Expand All @@ -186,14 +159,6 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\BagViews\ScriptCompiledBytecodeResourceView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\BagViews\ManifestBagView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\ResourceViews\ManifestResourceView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
14 changes: 8 additions & 6 deletions SanBag/ViewModels/BagViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public BagViewModel()

private void Init()
{
Views = new List<ViewType>();
CommandOpenBag = new CommandOpenBag(this);

var genericBagViewModel = new GenericBagViewModel(this);
Expand All @@ -108,7 +109,7 @@ private void Init()
var textureResourceBagViewModel = new TextureResourceBagViewModel(this);
Views.Add(new ViewType
{
View = new TextureResourceBagView
View = new GenericBagView
{
DataContext = textureResourceBagViewModel
},
Expand All @@ -120,7 +121,7 @@ private void Init()
var scriptCompiledBytecodeResourceView = new ScriptCompiledBytecodeResourceViewModel(this);
Views.Add(new ViewType
{
View = new ScriptCompiledBytecodeResourceView
View = new GenericBagView
{
DataContext = scriptCompiledBytecodeResourceView
},
Expand All @@ -131,7 +132,7 @@ private void Init()
var scriptSourceTextResourceViewModel = new ScriptSourceTextResourceViewModel(this);
Views.Add(new ViewType
{
View = new ScriptSourceTextResourceBagView
View = new GenericBagView
{
DataContext = scriptSourceTextResourceViewModel
},
Expand All @@ -142,7 +143,7 @@ private void Init()
var luaScriptResourceViewModel = new LuaScriptResourceViewModel(this);
Views.Add(new ViewType
{
View = new ScriptSourceTextResourceBagView
View = new GenericBagView
{
DataContext = luaScriptResourceViewModel
},
Expand All @@ -153,7 +154,7 @@ private void Init()
var manifestViewModel = new ManifestBagViewModel(this);
Views.Add(new ViewType
{
View = new ManifestBagView
View = new GenericBagView
{
DataContext = manifestViewModel
},
Expand All @@ -164,7 +165,7 @@ private void Init()
var soundViewModel = new SoundResourceBagViewModel(this);
Views.Add(new ViewType
{
View = new SoundResourceBagView
View = new GenericBagView
{
DataContext = soundViewModel
},
Expand Down Expand Up @@ -196,6 +197,7 @@ public void OnOpenFile()

public void OpenBag(string path)
{
Init();
BagPath = path;

using (var in_stream = File.OpenRead(path))
Expand Down
20 changes: 18 additions & 2 deletions SanBag/ViewModels/BagViewModels/GenericBagViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -42,8 +43,18 @@ public FileRecord SelectedRecord
get => _selectedRecord;
set
{
_selectedRecord = value;
OnSelectedRecordChanged();
try
{
_selectedRecord = value;
if (value != null)
{
OnSelectedRecordChanged();
}
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
}
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -149,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)
{
Expand Down
3 changes: 2 additions & 1 deletion SanBag/ViewModels/BagViewModels/SoundResourceBagViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
79 changes: 43 additions & 36 deletions SanBag/ViewModels/BagViewModels/TextureResourceBagViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,49 +44,56 @@ 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)
{
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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
56 changes: 41 additions & 15 deletions SanBag/ViewModels/ResourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,61 @@ 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)
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
{
var view = new RawResourceView();
var model = new RawResourceViewModel {
HexControl = view.HexEdit
};
CurrentView = view;
CurrentViewModel = model;
isRawView = true;
}

CurrentView.DataContext = CurrentViewModel;
CurrentViewModel.InitFromPath(resourcePath);
if (isRawView)
{
try
{
var view = new RawResourceView();
var model = new RawResourceViewModel
{
HexControl = view.HexEdit
};
CurrentView = view;
CurrentViewModel = model;
}
catch (Exception ex)
{
MessageBox.Show("Failed to load raw view: " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
}
}
try
{
CurrentView.DataContext = CurrentViewModel;
CurrentViewModel.InitFromPath(resourcePath);
return;
}
catch (Exception ex)
{
MessageBox.Show($"Failed to load resource: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
}
}

public event PropertyChangedEventHandler PropertyChanged;
Expand Down
Loading

0 comments on commit 10697fb

Please sign in to comment.