mirror of
https://github.com/claunia/Claunia.RsrcFork.git
synced 2025-12-16 19:24:46 +00:00
Code refactor.
This commit is contained in:
@@ -23,10 +23,11 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork.CLI
|
namespace Claunia.RsrcFork.CLI
|
||||||
{
|
{
|
||||||
@@ -68,20 +69,17 @@ namespace Claunia.RsrcFork.CLI
|
|||||||
typeBytes = typeBytes.Reverse().ToArray();
|
typeBytes = typeBytes.Reverse().ToArray();
|
||||||
string typeName = Types.GetName(type);
|
string typeName = Types.GetName(type);
|
||||||
if(typeName != null)
|
if(typeName != null)
|
||||||
Console.WriteLine("\"{0}\" (0x{1:X8}) - {2}", Encoding.ASCII.GetString(typeBytes), type, typeName);
|
Console.WriteLine("\"{0}\" (0x{1:X8}) - {2}", Encoding.ASCII.GetString(typeBytes), type,
|
||||||
else
|
typeName);
|
||||||
Console.WriteLine("\"{0}\" (0x{1:X8})", Encoding.ASCII.GetString(typeBytes), type);
|
else Console.WriteLine("\"{0}\" (0x{1:X8})", Encoding.ASCII.GetString(typeBytes), type);
|
||||||
|
|
||||||
Resource rez = rsrc.GetResource(type);
|
Resource rez = rsrc.GetResource(type);
|
||||||
Console.WriteLine("{0,6}{1,8}\t{2}", "ID", "Length", "Name");
|
Console.WriteLine("{0,6}{1,8}\t{2}", "ID", "Length", "Name");
|
||||||
Console.WriteLine("{0,6}{1,8}--{2}", "------", "--------", "----------------");
|
Console.WriteLine("{0,6}{1,8}--{2}", "------", "--------", "----------------");
|
||||||
foreach(short id in rez.GetIds())
|
foreach(short id in rez.GetIds())
|
||||||
{
|
|
||||||
if(rez.GetName(id) != null)
|
if(rez.GetName(id) != null)
|
||||||
Console.WriteLine("{0,6}{1,8}\t\"{2}\"", id, rez.GetLength(id), rez.GetName(id));
|
Console.WriteLine("{0,6}{1,8}\t\"{2}\"", id, rez.GetLength(id), rez.GetName(id));
|
||||||
else
|
else Console.WriteLine("{0,6}{1,8}", id, rez.GetLength(id));
|
||||||
Console.WriteLine("{0,6}{1,8}", id, rez.GetLength(id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
@@ -130,14 +128,15 @@ namespace Claunia.RsrcFork.CLI
|
|||||||
Resource rez = rsrc.GetResource(type);
|
Resource rez = rsrc.GetResource(type);
|
||||||
foreach(short id in rez.GetIds())
|
foreach(short id in rez.GetIds())
|
||||||
{
|
{
|
||||||
outStream = new FileStream(Path.Combine(args[2], Encoding.ASCII.GetString(typeBytes), string.Format("{0}", id)), FileMode.Create, FileAccess.ReadWrite);
|
outStream =
|
||||||
|
new
|
||||||
|
FileStream(Path.Combine(args[2], Encoding.ASCII.GetString(typeBytes), string.Format("{0}", id)),
|
||||||
|
FileMode.Create, FileAccess.ReadWrite);
|
||||||
byte[] rez_b = rez.GetResource(id);
|
byte[] rez_b = rez.GetResource(id);
|
||||||
outStream.Write(rez_b, 0, rez_b.Length);
|
outStream.Write(rez_b, 0, rez_b.Length);
|
||||||
outStream.Close();
|
outStream.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
// Information about this assembly is defined by the following attributes.
|
// Information about this assembly is defined by the following attributes.
|
||||||
// Change them to the values specific to your project.
|
// Change them to the values specific to your project.
|
||||||
@@ -49,4 +49,3 @@ using System.Runtime.CompilerServices;
|
|||||||
|
|
||||||
//[assembly: AssemblyDelaySign(false)]
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
//[assembly: AssemblyKeyFile("")]
|
//[assembly: AssemblyKeyFile("")]
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,12 @@ namespace Claunia.RsrcFork.Test
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class Test
|
public class Test
|
||||||
{
|
{
|
||||||
readonly byte[] DC42_Vers = { 0x06, 0x40, 0x80, 0x00, 0x00, 0x00, 0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79, 0x1C, 0x34, 0x2E, 0x32, 0x2C,
|
readonly byte[] DC42_Vers =
|
||||||
0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6B, 0x73, 0x75, 0x6D, 0x3D, 0x24, 0x41, 0x35, 0x31, 0x34, 0x37, 0x46, 0x37, 0x45 };
|
{
|
||||||
|
0x06, 0x40, 0x80, 0x00, 0x00, 0x00, 0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79, 0x1C,
|
||||||
|
0x34, 0x2E, 0x32, 0x2C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x20, 0x63, 0x68, 0x65, 0x63, 0x6B, 0x73, 0x75,
|
||||||
|
0x6D, 0x3D, 0x24, 0x41, 0x35, 0x31, 0x34, 0x37, 0x46, 0x37, 0x45
|
||||||
|
};
|
||||||
readonly byte[] DC42_Str = {0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79};
|
readonly byte[] DC42_Str = {0x09, 0x44, 0x69, 0x73, 0x6B, 0x20, 0x43, 0x6F, 0x70, 0x79};
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -225,4 +229,3 @@ namespace Claunia.RsrcFork.Test
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,10 @@
|
|||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -39,8 +41,7 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="PStr">The ASCII Pascal string.</param>
|
/// <param name="PStr">The ASCII Pascal string.</param>
|
||||||
public static string GetString(byte[] PStr)
|
public static string GetString(byte[] PStr)
|
||||||
{
|
{
|
||||||
if(PStr == null || PStr[0] >= PStr.Length)
|
if(PStr == null || PStr[0] >= PStr.Length) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
return Encoding.ASCII.GetString(PStr, 1, PStr[0]);
|
return Encoding.ASCII.GetString(PStr, 1, PStr[0]);
|
||||||
}
|
}
|
||||||
@@ -52,16 +53,13 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="str">The .NET string.</param>
|
/// <param name="str">The .NET string.</param>
|
||||||
public static byte[] GetBytes(string str)
|
public static byte[] GetBytes(string str)
|
||||||
{
|
{
|
||||||
if(str == null)
|
if(str == null) return new byte[1];
|
||||||
return new byte[1];
|
|
||||||
|
|
||||||
byte[] str_b = Encoding.ASCII.GetBytes(str);
|
byte[] str_b = Encoding.ASCII.GetBytes(str);
|
||||||
byte[] PStr;
|
byte[] PStr;
|
||||||
|
|
||||||
if(str_b.Length >= 256)
|
if(str_b.Length >= 256) PStr = new byte[256];
|
||||||
PStr = new byte[256];
|
else PStr = new byte[str_b.Length + 1];
|
||||||
else
|
|
||||||
PStr = new byte[str_b.Length + 1];
|
|
||||||
|
|
||||||
Array.Copy(str_b, 0, PStr, 1, PStr.Length - 1);
|
Array.Copy(str_b, 0, PStr, 1, PStr.Length - 1);
|
||||||
PStr[0] = (byte)(PStr.Length - 1);
|
PStr[0] = (byte)(PStr.Length - 1);
|
||||||
@@ -70,4 +68,3 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,17 +37,11 @@ namespace Claunia.RsrcFork
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Resource
|
public class Resource
|
||||||
{
|
{
|
||||||
|
readonly List<short> ids;
|
||||||
|
readonly Dictionary<short, byte[]> resourceCache;
|
||||||
readonly Dictionary<short, string> resourceNames;
|
readonly Dictionary<short, string> resourceNames;
|
||||||
readonly Dictionary<short, ResourceData> resources;
|
readonly Dictionary<short, ResourceData> resources;
|
||||||
readonly Dictionary<short, byte[]> resourceCache;
|
|
||||||
readonly Stream rsrcStream;
|
readonly Stream rsrcStream;
|
||||||
readonly List<short> ids;
|
|
||||||
|
|
||||||
struct ResourceData
|
|
||||||
{
|
|
||||||
public long offset;
|
|
||||||
public long length;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializates the specified resource type.
|
/// Initializates the specified resource type.
|
||||||
@@ -58,10 +52,12 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="resourceNameOffset">Offset from start of stream to resource name list.</param>
|
/// <param name="resourceNameOffset">Offset from start of stream to resource name list.</param>
|
||||||
/// <param name="resourceDataOffset">Offset from start of stream to resource data.</param>
|
/// <param name="resourceDataOffset">Offset from start of stream to resource data.</param>
|
||||||
/// <param name="OSType">Resource type.</param>
|
/// <param name="OSType">Resource type.</param>
|
||||||
internal Resource(Stream stream, ushort resources, long referenceListOff, long resourceNameOffset, long resourceDataOffset, uint OSType)
|
internal Resource(Stream stream, ushort resources, long referenceListOff, long resourceNameOffset,
|
||||||
|
long resourceDataOffset, uint OSType)
|
||||||
{
|
{
|
||||||
rsrcStream = stream;
|
rsrcStream = stream;
|
||||||
Dictionary<short, ResourceTypeReferenceListItem> referenceLists = new Dictionary<short, ResourceTypeReferenceListItem>();
|
Dictionary<short, ResourceTypeReferenceListItem> referenceLists =
|
||||||
|
new Dictionary<short, ResourceTypeReferenceListItem>();
|
||||||
resourceNames = new Dictionary<short, string>();
|
resourceNames = new Dictionary<short, string>();
|
||||||
this.resources = new Dictionary<short, ResourceData>();
|
this.resources = new Dictionary<short, ResourceData>();
|
||||||
ids = new List<short>();
|
ids = new List<short>();
|
||||||
@@ -93,8 +89,7 @@ namespace Claunia.RsrcFork
|
|||||||
string name;
|
string name;
|
||||||
ResourceData data = new ResourceData();
|
ResourceData data = new ResourceData();
|
||||||
|
|
||||||
if(item.nameOff == -1)
|
if(item.nameOff == -1) name = null;
|
||||||
name = null;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rsrcStream.Seek(resourceNameOffset + item.nameOff, SeekOrigin.Begin);
|
rsrcStream.Seek(resourceNameOffset + item.nameOff, SeekOrigin.Begin);
|
||||||
@@ -138,13 +133,11 @@ namespace Claunia.RsrcFork
|
|||||||
{
|
{
|
||||||
byte[] resource;
|
byte[] resource;
|
||||||
|
|
||||||
if(resourceCache.TryGetValue(id, out resource))
|
if(resourceCache.TryGetValue(id, out resource)) return resource;
|
||||||
return resource;
|
|
||||||
|
|
||||||
ResourceData data;
|
ResourceData data;
|
||||||
|
|
||||||
if(!resources.TryGetValue(id, out data))
|
if(!resources.TryGetValue(id, out data)) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
resource = new byte[data.length];
|
resource = new byte[data.length];
|
||||||
rsrcStream.Seek(data.offset, SeekOrigin.Begin);
|
rsrcStream.Seek(data.offset, SeekOrigin.Begin);
|
||||||
@@ -170,20 +163,19 @@ namespace Claunia.RsrcFork
|
|||||||
/// Gets the IDs of all the resources contained by this instance.
|
/// Gets the IDs of all the resources contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The identifiers.</returns>
|
/// <returns>The identifiers.</returns>
|
||||||
public short[] GetIds()
|
public short[] GetIds() => ids.ToArray();
|
||||||
{
|
|
||||||
return ids.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the resource specified by ID is contained by this instance.
|
/// Checks if the resource specified by ID is contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns><c>true</c>, if the resource is contained in this instance, <c>false</c> otherwise.</returns>
|
/// <returns><c>true</c>, if the resource is contained in this instance, <c>false</c> otherwise.</returns>
|
||||||
/// <param name="id">Resource identifier.</param>
|
/// <param name="id">Resource identifier.</param>
|
||||||
public bool ContainsId(short id)
|
public bool ContainsId(short id) => ids.Contains(id);
|
||||||
{
|
|
||||||
return ids.Contains(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
struct ResourceData
|
||||||
|
{
|
||||||
|
public long offset;
|
||||||
|
public long length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,12 +35,12 @@ namespace Claunia.RsrcFork
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ResourceFork
|
public class ResourceFork
|
||||||
{
|
{
|
||||||
Stream rsrcStream;
|
|
||||||
ResourceHeader header;
|
ResourceHeader header;
|
||||||
ResourceMap map;
|
ResourceMap map;
|
||||||
Dictionary<uint, ResourceTypeListItem> resourceTypeList;
|
|
||||||
Dictionary<uint, Resource> resourceCache;
|
|
||||||
List<uint> osTypes;
|
List<uint> osTypes;
|
||||||
|
Dictionary<uint, Resource> resourceCache;
|
||||||
|
Dictionary<uint, ResourceTypeListItem> resourceTypeList;
|
||||||
|
readonly Stream rsrcStream;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializates a resource fork using a byte array as backend.
|
/// Initializates a resource fork using a byte array as backend.
|
||||||
@@ -67,8 +67,7 @@ namespace Claunia.RsrcFork
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
~ResourceFork()
|
~ResourceFork()
|
||||||
{
|
{
|
||||||
if(rsrcStream != null)
|
if(rsrcStream != null) rsrcStream.Dispose();
|
||||||
rsrcStream.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -88,8 +87,8 @@ namespace Claunia.RsrcFork
|
|||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
header.resourceMapLen = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
header.resourceMapLen = BitConverter.ToInt32(tmp.Reverse().ToArray(), 0);
|
||||||
|
|
||||||
if(header.resourceDataOff <= 0 || header.resourceMapOff <= 0 || header.resourceDataLen <= 0 || header.resourceMapLen <= 0)
|
if(header.resourceDataOff <= 0 || header.resourceMapOff <= 0 || header.resourceDataLen <= 0 ||
|
||||||
throw new InvalidCastException("Not a resource fork");
|
header.resourceMapLen <= 0) throw new InvalidCastException("Not a resource fork");
|
||||||
|
|
||||||
if(header.resourceDataOff + header.resourceDataLen > rsrcStream.Length ||
|
if(header.resourceDataOff + header.resourceDataLen > rsrcStream.Length ||
|
||||||
header.resourceMapOff + header.resourceMapLen > rsrcStream.Length)
|
header.resourceMapOff + header.resourceMapLen > rsrcStream.Length)
|
||||||
@@ -134,7 +133,8 @@ namespace Claunia.RsrcFork
|
|||||||
resourceTypeList = new Dictionary<uint, ResourceTypeListItem>();
|
resourceTypeList = new Dictionary<uint, ResourceTypeListItem>();
|
||||||
osTypes = new List<uint>();
|
osTypes = new List<uint>();
|
||||||
|
|
||||||
for(int i = 0; i <= map.numberOfTypes; i++) {
|
for(int i = 0; i <= map.numberOfTypes; i++)
|
||||||
|
{
|
||||||
ResourceTypeListItem typeList = new ResourceTypeListItem();
|
ResourceTypeListItem typeList = new ResourceTypeListItem();
|
||||||
tmp = new byte[4];
|
tmp = new byte[4];
|
||||||
rsrcStream.Read(tmp, 0, 4);
|
rsrcStream.Read(tmp, 0, 4);
|
||||||
@@ -161,14 +161,15 @@ namespace Claunia.RsrcFork
|
|||||||
{
|
{
|
||||||
Resource rsrc;
|
Resource rsrc;
|
||||||
|
|
||||||
if(resourceCache.TryGetValue(OSType, out rsrc))
|
if(resourceCache.TryGetValue(OSType, out rsrc)) return rsrc;
|
||||||
return rsrc;
|
|
||||||
|
|
||||||
ResourceTypeListItem typeList;
|
ResourceTypeListItem typeList;
|
||||||
if(!resourceTypeList.TryGetValue(OSType, out typeList))
|
if(!resourceTypeList.TryGetValue(OSType, out typeList)) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
rsrc = new Resource(rsrcStream, (ushort)(typeList.resources + 1), header.resourceMapOff + map.typeListOff + typeList.referenceOff - 2, header.resourceMapOff + map.nameListOff, header.resourceDataOff, OSType);
|
rsrc = new Resource(rsrcStream, (ushort)(typeList.resources + 1),
|
||||||
|
header.resourceMapOff + map.typeListOff + typeList.referenceOff - 2,
|
||||||
|
header.resourceMapOff + map.nameListOff,
|
||||||
|
header.resourceDataOff, OSType);
|
||||||
|
|
||||||
resourceCache.Add(OSType, rsrc);
|
resourceCache.Add(OSType, rsrc);
|
||||||
|
|
||||||
@@ -179,19 +180,12 @@ namespace Claunia.RsrcFork
|
|||||||
/// Gets all OSTypes stored in this resource fork
|
/// Gets all OSTypes stored in this resource fork
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The types.</returns>
|
/// <returns>The types.</returns>
|
||||||
public uint[] GetTypes()
|
public uint[] GetTypes() => osTypes.ToArray();
|
||||||
{
|
|
||||||
return osTypes.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns true if the specified OSType is present in this resource fork.
|
/// Returns true if the specified OSType is present in this resource fork.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="OSType">OSType.</param>
|
/// <param name="OSType">OSType.</param>
|
||||||
public bool ContainsKey(uint OSType)
|
public bool ContainsKey(uint OSType) => resourceTypeList.ContainsKey(OSType);
|
||||||
{
|
|
||||||
return resourceTypeList.ContainsKey(OSType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,39 +35,6 @@ namespace Resources
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Version
|
public class Version
|
||||||
{
|
{
|
||||||
static uint ostype = 0x76657273;
|
|
||||||
|
|
||||||
#region On-disk structure
|
|
||||||
/// <summary>
|
|
||||||
/// Major version.
|
|
||||||
/// </summary>
|
|
||||||
public byte MajorVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Minor version.
|
|
||||||
/// </summary>
|
|
||||||
public byte MinorVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Development stage.
|
|
||||||
/// </summary>
|
|
||||||
public DevelopmentStage DevStage;
|
|
||||||
/// <summary>
|
|
||||||
/// Pre-release version.
|
|
||||||
/// </summary>
|
|
||||||
public byte PreReleaseVersion;
|
|
||||||
/// <summary>
|
|
||||||
/// Region code.
|
|
||||||
/// </summary>
|
|
||||||
public ushort RegionCode;
|
|
||||||
/// <summary>
|
|
||||||
/// Version string.
|
|
||||||
/// </summary>
|
|
||||||
public string VersionString;
|
|
||||||
/// <summary>
|
|
||||||
/// Version message.
|
|
||||||
/// </summary>
|
|
||||||
public string VersionMessage;
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Known development stages
|
/// Known development stages
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -115,6 +82,12 @@ namespace Resources
|
|||||||
VersionMessage = PascalString.GetString(tmpMsg);
|
VersionMessage = PascalString.GetString(tmpMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the OSTYPE of this resource.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The OSTYPE.</value>
|
||||||
|
public static uint OSType { get; } = 0x76657273;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a byte array with the "VERS" resource contained by this instance.
|
/// Gets a byte array with the "VERS" resource contained by this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -139,28 +112,44 @@ namespace Resources
|
|||||||
return vers;
|
return vers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
byte BCDToNumber(byte bcd) => Convert.ToByte(string.Format("{0:X2}", bcd), 10);
|
||||||
/// Gets the OSTYPE of this resource.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The OSTYPE.</value>
|
|
||||||
public static uint OSType {
|
|
||||||
get {
|
|
||||||
return ostype;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
byte BCDToNumber(byte bcd)
|
|
||||||
{
|
|
||||||
return Convert.ToByte(string.Format("{0:X2}", bcd), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte NumberToBCD(byte number)
|
byte NumberToBCD(byte number)
|
||||||
{
|
{
|
||||||
if(number >= 100)
|
if(number >= 100) number = 99;
|
||||||
number = 99;
|
|
||||||
|
|
||||||
return Convert.ToByte(string.Format("{0:D2}", number), 16);
|
return Convert.ToByte(string.Format("{0:D2}", number), 16);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#region On-disk structure
|
||||||
|
/// <summary>
|
||||||
|
/// Major version.
|
||||||
|
/// </summary>
|
||||||
|
public byte MajorVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Minor version.
|
||||||
|
/// </summary>
|
||||||
|
public byte MinorVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Development stage.
|
||||||
|
/// </summary>
|
||||||
|
public DevelopmentStage DevStage;
|
||||||
|
/// <summary>
|
||||||
|
/// Pre-release version.
|
||||||
|
/// </summary>
|
||||||
|
public byte PreReleaseVersion;
|
||||||
|
/// <summary>
|
||||||
|
/// Region code.
|
||||||
|
/// </summary>
|
||||||
|
public ushort RegionCode;
|
||||||
|
/// <summary>
|
||||||
|
/// Version string.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionString;
|
||||||
|
/// <summary>
|
||||||
|
/// Version message.
|
||||||
|
/// </summary>
|
||||||
|
public string VersionMessage;
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -118,4 +118,3 @@ namespace Claunia.RsrcFork
|
|||||||
public uint handle;
|
public uint handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Claunia.RsrcFork
|
namespace Claunia.RsrcFork
|
||||||
{
|
{
|
||||||
@@ -42,7 +42,8 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="OSType">The OSTYPE.</param>
|
/// <param name="OSType">The OSTYPE.</param>
|
||||||
public static string GetName(uint OSType)
|
public static string GetName(uint OSType)
|
||||||
{
|
{
|
||||||
switch(OSType) {
|
switch(OSType)
|
||||||
|
{
|
||||||
case 0x2E58534C: // ".XSL"
|
case 0x2E58534C: // ".XSL"
|
||||||
return "XML style sheet";
|
return "XML style sheet";
|
||||||
case 0x33444D46: // "3DMF"
|
case 0x33444D46: // "3DMF"
|
||||||
@@ -683,8 +684,7 @@ namespace Claunia.RsrcFork
|
|||||||
return "MC680x0 Code";
|
return "MC680x0 Code";
|
||||||
case 0x5F505043: // "_PPC"
|
case 0x5F505043: // "_PPC"
|
||||||
return "PowerPC Code";
|
return "PowerPC Code";
|
||||||
default:
|
default: return null;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,8 +695,7 @@ namespace Claunia.RsrcFork
|
|||||||
/// <param name="OSType">The OSTYPE.</param>
|
/// <param name="OSType">The OSTYPE.</param>
|
||||||
public static string GetName(string OSType)
|
public static string GetName(string OSType)
|
||||||
{
|
{
|
||||||
if(OSType.Length != 4)
|
if(OSType.Length != 4) return null;
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] typB = Encoding.ASCII.GetBytes(OSType);
|
byte[] typB = Encoding.ASCII.GetBytes(OSType);
|
||||||
uint type = BitConverter.ToUInt32(typB.Reverse().ToArray(), 0);
|
uint type = BitConverter.ToUInt32(typB.Reverse().ToArray(), 0);
|
||||||
@@ -705,4 +704,3 @@ namespace Claunia.RsrcFork
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user