(OGG): added fix checksums setting.

This commit is contained in:
morkt 2018-01-30 09:30:34 +04:00
parent 0a702c5c5d
commit ebbac01c40
10 changed files with 137 additions and 1 deletions

View File

@ -27,6 +27,7 @@ using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
using GameRes.Utility;
using NVorbis;
namespace GameRes.Formats
@ -124,16 +125,19 @@ namespace GameRes.Formats
}
[Export(typeof(AudioFormat))]
public class OggAudio : AudioFormat
public sealed class OggAudio : AudioFormat
{
public override string Tag { get { return "OGG"; } }
public override string Description { get { return "Ogg/Vorbis audio format"; } }
public override uint Signature { get { return 0x5367674f; } } // 'OggS'
public override bool CanWrite { get { return false; } }
LocalResourceSetting FixCrc = new LocalResourceSetting ("OGGFixCrc");
public OggAudio ()
{
Signatures = new uint[] { 0x5367674F, 0 };
Settings = new[] { FixCrc };
}
public override SoundInput TryOpen (IBinaryStream file)
@ -169,6 +173,8 @@ namespace GameRes.Formats
}
else if (file.Signature != this.Signature)
return null;
if (FixCrc.Get<bool>())
input = new SeekableStream (new OggRestoreStream (input));
return new OggInput (input);
}
@ -176,4 +182,89 @@ namespace GameRes.Formats
static readonly ResourceInstance<AudioFormat> s_OggFormat = new ResourceInstance<AudioFormat> ("OGG");
}
/// <summary>
/// Restore CRC checksums of the OGG stream pages.
/// </summary>
internal class OggRestoreStream : InputProxyStream
{
bool m_eof;
bool m_ogg_ended;
byte[] m_page = new byte[0x10000];
int m_page_pos = 0;
int m_page_length = 0;
public override bool CanSeek { get { return false; } }
public OggRestoreStream (Stream input) : base (input)
{
}
public override int Read (byte[] buffer, int offset, int count)
{
int total_read = 0;
while (count > 0 && !m_eof)
{
if (m_page_pos == m_page_length)
{
if (m_ogg_ended)
{
int read = BaseStream.Read (buffer, offset, count);
total_read += read;
m_eof = 0 == read;
break;
}
NextPage();
}
if (m_eof)
break;
int available = Math.Min (m_page_length - m_page_pos, count);
Buffer.BlockCopy (m_page, m_page_pos, buffer, offset, available);
m_page_pos += available;
offset += available;
count -= available;
total_read += available;
}
return total_read;
}
void NextPage ()
{
m_page_pos = 0;
m_page_length = BaseStream.Read (m_page, 0, 0x1B);
if (0 == m_page_length)
{
m_eof = true;
return;
}
if (m_page_length < 0x1B || !m_page.AsciiEqual ("OggS"))
{
m_ogg_ended = true;
return;
}
int segment_count = m_page[0x1A];
m_page[0x16] = 0;
m_page[0x17] = 0;
m_page[0x18] = 0;
m_page[0x19] = 0;
if (segment_count != 0)
{
int table_length = BaseStream.Read (m_page, 0x1B, segment_count);
m_page_length += table_length;
if (table_length != segment_count)
{
m_ogg_ended = true;
return;
}
int segments_length = 0;
int segment_table = 0x1B;
for (int i = 0; i < segment_count; ++i)
segments_length += m_page[segment_table++];
m_page_length += BaseStream.Read (m_page, 0x1B+segment_count, segments_length);
}
uint crc = Crc32Normal.UpdateCrc (0, m_page, 0, m_page_length);
LittleEndian.Pack (crc, m_page, 0x16);
}
}
}

View File

@ -729,5 +729,17 @@ namespace GameRes.Formats.Properties {
this["ZIPPassword"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("False")]
public bool OGGFixCrc {
get {
return ((bool)(this["OGGFixCrc"]));
}
set {
this["OGGFixCrc"] = value;
}
}
}
}

View File

@ -179,5 +179,8 @@
<Setting Name="ZIPPassword" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="OGGFixCrc" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -606,6 +606,15 @@ namespace GameRes.Formats.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Fix Ogg files checksums.
/// </summary>
public static string OGGFixCrc {
get {
return ResourceManager.GetString("OGGFixCrc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Archive type.
/// </summary>

View File

@ -491,4 +491,8 @@ Choose encryption scheme or enter a passphrase.</comment>
<value>アーカイブコンテンツは暗号化されています。</value>
<comment>Archive content is encrypted.</comment>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Fix Ogg files checksums</value>
<comment>Translation pending</comment>
</data>
</root>

View File

@ -391,4 +391,8 @@
<data name="ZIPEncryptedNotice" xml:space="preserve">
<value>아카이브 내용이 암호화됨.</value>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Fix Ogg files checksums</value>
<comment>Translation pending</comment>
</data>
</root>

View File

@ -392,4 +392,7 @@ Choose encryption scheme or enter a passphrase.</value>
<data name="ZIPEncryptedNotice" xml:space="preserve">
<value>Archive content is encrypted.</value>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Fix Ogg files checksums</value>
</data>
</root>

View File

@ -276,6 +276,9 @@
<value>Ключи шифрования
(требуются даже если содержимое не шифруется)</value>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Исправлять контрольные суммы в Ogg аудио файлах</value>
</data>
<data name="ONSArchiveType" xml:space="preserve">
<value>Тип архива</value>
</data>

View File

@ -392,4 +392,8 @@
<data name="ZIPEncryptedNotice" xml:space="preserve">
<value>压缩文件的内容已被加密。</value>
</data>
<data name="OGGFixCrc" xml:space="preserve">
<value>Fix Ogg files checksums</value>
<comment>Translation pending</comment>
</data>
</root>

View File

@ -181,6 +181,9 @@
<setting name="ZIPPassword" serializeAs="String">
<value />
</setting>
<setting name="OGGFixCrc" serializeAs="String">
<value>False</value>
</setting>
</GameRes.Formats.Properties.Settings>
</userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" /></startup>