(NPK2): added GUI widget.

This commit is contained in:
morkt 2016-07-10 12:21:38 +04:00
parent ebb6c91a73
commit 9a94416f23
7 changed files with 88 additions and 5 deletions

View File

@ -133,6 +133,9 @@
<Compile Include="MnoViolet\ImageDIF.cs" />
<Compile Include="Nexas\ImageGRP.cs" />
<Compile Include="NitroPlus\ArcNPK.cs" />
<Compile Include="NitroPlus\WidgetNPK.xaml.cs">
<DependentUpon>WidgetNPK.xaml</DependentUpon>
</Compile>
<Compile Include="NonColor\ArcDAT.cs" />
<Compile Include="Crc64.cs" />
<Compile Include="NonColor\WidgetNCARC.xaml.cs">
@ -593,6 +596,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="NitroPlus\WidgetNPK.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="NonColor\WidgetNCARC.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -28,8 +28,9 @@ using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Security.Cryptography;
using GameRes.Formats.Properties;
using GameRes.Formats.Strings;
namespace GameRes.Formats.NitroPlus
{
@ -47,6 +48,11 @@ namespace GameRes.Formats.NitroPlus
public bool IsCompressed { get { return Size < UnpackedSize; } }
}
public class Npk2Options : ResourceOptions
{
public byte[] Key;
}
internal class NpkArchive : ArcFile
{
public readonly Aes Encryption;
@ -141,8 +147,14 @@ namespace GameRes.Formats.NitroPlus
entry.UnpackedSize = index.ReadUInt32();
index.Read (name_buffer, 0, 0x20); // skip
int segment_count = index.ReadInt32();
if (segment_count <= 0)
if (segment_count < 0)
return null;
if (0 == segment_count)
{
entry.Offset = 0;
dir.Add (entry);
continue;
}
entry.Segments.Capacity = segment_count;
uint packed_size = 0;
bool is_packed = false;
@ -169,6 +181,8 @@ namespace GameRes.Formats.NitroPlus
public override Stream OpenEntry (ArcFile arc, Entry entry)
{
if (0 == entry.Size)
return Stream.Null;
var narc = arc as NpkArchive;
var nent = entry as NpkEntry;
if (null == narc || null == nent)
@ -183,11 +197,28 @@ namespace GameRes.Formats.NitroPlus
return new NpkStream (narc, nent);
}
public override ResourceOptions GetDefaultOptions ()
{
return new Npk2Options { Key = GetKey (Settings.Default.NPKScheme) };
}
public override object GetAccessWidget ()
{
return new GUI.WidgetNPK();
}
byte[] QueryEncryption ()
{
if (0 == KnownKeys.Count)
return null;
return KnownKeys.Values.First();
var options = Query<Npk2Options> (arcStrings.ArcEncryptedNotice);
return options.Key;
}
byte[] GetKey (string title)
{
byte[] key;
if (KnownKeys.TryGetValue (title, out key))
return key;
return key;
}
}

View File

@ -0,0 +1,9 @@
<Grid x:Class="GameRes.Formats.GUI.WidgetNPK"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:p="clr-namespace:GameRes.Formats.Properties"
MaxWidth="250">
<ComboBox Name="Scheme" Width="180"
ItemsSource="{Binding}"
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=NPKScheme, Mode=TwoWay}"/>
</Grid>

View File

@ -0,0 +1,18 @@
using System.Windows.Controls;
using System.Linq;
using GameRes.Formats.NitroPlus;
namespace GameRes.Formats.GUI
{
/// <summary>
/// Interaction logic for WidgetNPK.xaml
/// </summary>
public partial class WidgetNPK : Grid
{
public WidgetNPK ()
{
InitializeComponent();
Scheme.ItemsSource = NpkOpener.KnownKeys.Keys.OrderBy (x => x);
}
}
}

View File

@ -585,5 +585,17 @@ namespace GameRes.Formats.Properties {
this["BELLTitle"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string NPKScheme {
get {
return ((string)(this["NPKScheme"]));
}
set {
this["NPKScheme"] = value;
}
}
}
}

View File

@ -143,5 +143,8 @@
<Setting Name="BELLTitle" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="NPKScheme" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

View File

@ -145,6 +145,9 @@
<setting name="BELLTitle" serializeAs="String">
<value />
</setting>
<setting name="NPKScheme" serializeAs="String">
<value />
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>