mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-24 03:44:13 +08:00
implemented non-encrypted INT archives creation.
This commit is contained in:
parent
cfd71f5519
commit
8fc34f9161
@ -70,6 +70,9 @@
|
||||
<Compile Include="CreateAMIWidget.xaml.cs">
|
||||
<DependentUpon>CreateAMIWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CreateINTWidget.xaml.cs">
|
||||
<DependentUpon>CreateINTWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="CreateONSWidget.xaml.cs">
|
||||
<DependentUpon>CreateONSWidget.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -139,6 +142,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="CreateINTWidget.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="CreateONSWidget.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
@ -48,6 +48,7 @@ namespace GameRes.Formats
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable()]
|
||||
public class IntEncryptionInfo
|
||||
{
|
||||
public uint? Key { get; set; }
|
||||
@ -85,6 +86,7 @@ namespace GameRes.Formats
|
||||
public override string Description { get { return arcStrings.INTDescription; } }
|
||||
public override uint Signature { get { return 0x0046494b; } }
|
||||
public override bool IsHierarchic { get { return false; } }
|
||||
public override bool CanCreate { get { return true; } }
|
||||
|
||||
public override ArcFile TryOpen (ArcView file)
|
||||
{
|
||||
@ -103,7 +105,7 @@ namespace GameRes.Formats
|
||||
}
|
||||
|
||||
long current_offset = 8;
|
||||
var dir = new List<Entry>();
|
||||
var dir = new List<Entry> ((int)entry_count);
|
||||
for (uint i = 0; i < entry_count; ++i)
|
||||
{
|
||||
string name = file.View.ReadString (current_offset, 0x40);
|
||||
@ -135,7 +137,7 @@ namespace GameRes.Formats
|
||||
Array.Reverse (blowfish_key);
|
||||
|
||||
var blowfish = new Blowfish (blowfish_key);
|
||||
var dir = new List<Entry>();
|
||||
var dir = new List<Entry> ((int)entry_count-1);
|
||||
byte[] name_info = new byte[0x40];
|
||||
for (uint i = 1; i < entry_count; ++i)
|
||||
{
|
||||
@ -332,10 +334,92 @@ namespace GameRes.Formats
|
||||
return new GUI.WidgetINT ();
|
||||
}
|
||||
|
||||
public override object GetCreationWidget ()
|
||||
{
|
||||
return new GUI.CreateINTWidget();
|
||||
}
|
||||
|
||||
uint? QueryEncryptionInfo ()
|
||||
{
|
||||
var options = Query<IntOptions> (arcStrings.INTNotice);
|
||||
return options.EncryptionInfo.GetKey();
|
||||
}
|
||||
|
||||
public override void Create (Stream output, IEnumerable<Entry> list, ResourceOptions options,
|
||||
EntryCallback callback)
|
||||
{
|
||||
int file_count = list.Count();
|
||||
if (null != callback)
|
||||
callback (file_count+2, null, null);
|
||||
int callback_count = 0;
|
||||
using (var writer = new BinaryWriter (output, Encoding.ASCII, true))
|
||||
{
|
||||
writer.Write (Signature);
|
||||
writer.Write (file_count);
|
||||
long dir_offset = output.Position;
|
||||
|
||||
var encoding = Encodings.cp932.WithFatalFallback();
|
||||
byte[] name_buf = new byte[0x40];
|
||||
int previous_size = 0;
|
||||
|
||||
if (null != callback)
|
||||
callback (callback_count++, null, arcStrings.MsgWritingIndex);
|
||||
|
||||
// first, write names only
|
||||
foreach (var entry in list)
|
||||
{
|
||||
string name = Path.GetFileName (entry.Name);
|
||||
try
|
||||
{
|
||||
int size = encoding.GetBytes (name, 0, name.Length, name_buf, 0);
|
||||
for (int i = size; i < previous_size; ++i)
|
||||
name_buf[i] = 0;
|
||||
previous_size = size;
|
||||
}
|
||||
catch (EncoderFallbackException X)
|
||||
{
|
||||
throw new InvalidFileName (entry.Name, arcStrings.MsgIllegalCharacters, X);
|
||||
}
|
||||
catch (ArgumentException X)
|
||||
{
|
||||
throw new InvalidFileName (entry.Name, arcStrings.MsgFileNameTooLong, X);
|
||||
}
|
||||
writer.Write (name_buf);
|
||||
writer.BaseStream.Seek (8, SeekOrigin.Current);
|
||||
}
|
||||
|
||||
// now, write files and remember offset/sizes
|
||||
long current_offset = output.Position;
|
||||
foreach (var entry in list)
|
||||
{
|
||||
if (null != callback)
|
||||
callback (callback_count++, entry, arcStrings.MsgAddingFile);
|
||||
|
||||
entry.Offset = current_offset;
|
||||
using (var input = File.OpenRead (entry.Name))
|
||||
{
|
||||
var size = input.Length;
|
||||
if (size > uint.MaxValue || current_offset + size > uint.MaxValue)
|
||||
throw new FileSizeException();
|
||||
current_offset += (uint)size;
|
||||
entry.Size = (uint)size;
|
||||
input.CopyTo (output);
|
||||
}
|
||||
}
|
||||
|
||||
if (null != callback)
|
||||
callback (callback_count++, null, arcStrings.MsgUpdatingIndex);
|
||||
|
||||
// at last, go back to directory and write offset/sizes
|
||||
dir_offset += 0x40;
|
||||
foreach (var entry in list)
|
||||
{
|
||||
writer.BaseStream.Position = dir_offset;
|
||||
writer.Write ((uint)entry.Offset);
|
||||
writer.Write (entry.Size);
|
||||
dir_offset += 0x48;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
6
ArcFormats/CreateINTWidget.xaml
Normal file
6
ArcFormats/CreateINTWidget.xaml
Normal file
@ -0,0 +1,6 @@
|
||||
<Grid x:Class="GameRes.Formats.GUI.CreateINTWidget"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:GameRes.Formats.Strings">
|
||||
<TextBlock Text="{x:Static s:arcStrings.INTCreationNotice}" Margin="5"/>
|
||||
</Grid>
|
15
ArcFormats/CreateINTWidget.xaml.cs
Normal file
15
ArcFormats/CreateINTWidget.xaml.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace GameRes.Formats.GUI
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for CreateINTWidget.xaml
|
||||
/// </summary>
|
||||
public partial class CreateINTWidget : Grid
|
||||
{
|
||||
public CreateINTWidget ()
|
||||
{
|
||||
InitializeComponent ();
|
||||
}
|
||||
}
|
||||
}
|
9
ArcFormats/Strings/arcStrings.Designer.cs
generated
9
ArcFormats/Strings/arcStrings.Designer.cs
generated
@ -142,6 +142,15 @@ namespace GameRes.Formats.Strings {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Encrypted archives creation is not implemented..
|
||||
/// </summary>
|
||||
public static string INTCreationNotice {
|
||||
get {
|
||||
return ResourceManager.GetString("INTCreationNotice", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to FrontWing game resource archive.
|
||||
/// </summary>
|
||||
|
@ -145,6 +145,9 @@ Choose appropriate encryption scheme.</value>
|
||||
<data name="GSCDescription" xml:space="preserve">
|
||||
<value>Liar-soft proprietary script format</value>
|
||||
</data>
|
||||
<data name="INTCreationNotice" xml:space="preserve">
|
||||
<value>Encrypted archives creation is not implemented.</value>
|
||||
</data>
|
||||
<data name="INTDescription" xml:space="preserve">
|
||||
<value>FrontWing game resource archive</value>
|
||||
</data>
|
||||
|
@ -136,6 +136,9 @@
|
||||
<data name="ArcNoEncryption" xml:space="preserve">
|
||||
<value>без шифрования</value>
|
||||
</data>
|
||||
<data name="INTCreationNotice" xml:space="preserve">
|
||||
<value>Создание зашифрованных архивов не реализовано.</value>
|
||||
</data>
|
||||
<data name="INTKeyRequirement" xml:space="preserve">
|
||||
<value>Цифровой ключ должен быть 32-битным шестнадцатиричным числом</value>
|
||||
</data>
|
||||
|
Loading…
x
Reference in New Issue
Block a user