Daily update 2 on 20240228 by nitload youmu

This commit is contained in:
Nitload
2025-03-01 04:58:46 +08:00
parent 90d5f76511
commit f22862dfc4
983 changed files with 180004 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="root.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
public static unsafe partial class StgSharp
{
private static byte leastUnusedArea;
private static List<Area> root = new List<Area>();
private static SSD defaultIdProvider = new SSD();
public static byte NewArea()
{
byte ret = leastUnusedArea;
leastUnusedArea++;
return ret;
}
}//------------------ end of class ---------------------
}
+169
View File
@@ -0,0 +1,169 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="RandomGenerator.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.HighPerformance;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Serialization;
namespace StgSharp.Data
{
public class RandomGenerator
{
private byte[] currentKey;
private readonly byte[] originKey;
private int cycleCount;
private SHA512 hash;
public RandomGenerator() : this( DateTime.UtcNow.ToBinary() ) { }
public RandomGenerator( object source )
{
try {
if( source == null ) {
throw new ArgumentNullException( nameof( source ) );
}
XmlSerializer s = new XmlSerializer( source.GetType() );
using( StringWriter sw = new StringWriter() ) {
s.Serialize( sw, source );
string data = sw.ToString();
originKey = Encoding.UTF8.GetBytes( data );
}
}
catch( Exception ) {
throw;
}
hash = SHA512.Create();
originKey = hash.ComputeHash( originKey );
currentKey = originKey;
cycleCount = 0;
}
public int TotalGeneratedRandom
{
get => cycleCount;
}
public unsafe int GenRandomInt()
{
M128 source = PrivateRand();
cycleCount++;
/*
float d0 = MathF.Sin(1 / source.Read<float>(0));
float d1 = MathF.Sin(1 / source.Read<float>(1));
float d2 = MathF.Sin(1 / source.Read<float>(2));
float d3 = MathF.Sin(1 / source.Read<float>(3));
source.Write<short>(0, *( short*)&d3);
source.Write<short>(2, *((short*)&d2+1));
source.Write<short>(4, *( short*)&d1);
source.Write<short>(6, *((short*)&d0+1));
/**/
return source.Read<int>( cycleCount % 4 );
}
public byte GenRandomInt8()
{
cycleCount++;
if( cycleCount % 64 == 0 ) {
PrivateRand();
}
return currentKey[ cycleCount % 64 ];
}
public float GenRandomSingle()
{
cycleCount++;
while( true ) {
M128 source = PrivateRand();
uint
temp0 = source.Read<uint>( 0 ),
temp1 = source.Read<uint>( 2 );
if( temp0 * temp1 != 0 ) {
float ret = ( ( temp0 % temp1 ) * 1.0f ) / temp1;
if( ret < 0.335f ) {
ret = ret * ( ( ret * ( -0.7811934f ) ) + 1.4489113f );
} else {
ret = ( ret * ( ( ret * ( -0.1158368f ) ) + 1.0580600f ) ) + 0.0590584f;
}
if( ret > 1 ) {
continue;
}
return ret;
}
}
}
public void Reset()
{
currentKey = originKey;
cycleCount = 0;
}
private unsafe M128 PrivateRand()
{
currentKey = hash.ComputeHash( currentKey );
M128 ret;
fixed( byte* bptr = currentKey ) {
switch( ( cycleCount % 16 ) / 4 ) {
case 0:
ret = *( ( ( M128* )bptr ) + 0 );
break;
case 1:
ret = *( ( ( M128* )bptr ) + 1 );
break;
case 2:
ret = *( ( ( M128* )bptr ) + 2 );
break;
case 3:
ret = *( ( ( M128* )bptr ) + 3 );
break;
default:
throw new InvalidOperationException();
}
}
//Console.WriteLine(ret.ToString(16));
return ret;
}
}
}
+47
View File
@@ -0,0 +1,47 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Area.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal.FileIO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Internal
{
/// <summary>
/// An independent storage area, used as the only folder type in root folder. Contains several
/// <see cref="SSD" /> files reference as virtual disc. Data is actually stored in <see
/// cref="SSD" />s in certain RAID mode.
/// </summary>
public partial class Area { }
}
+79
View File
@@ -0,0 +1,79 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DataHead.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.HighPerformance;
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace StgSharp.Internal
{
[StructLayout( LayoutKind.Explicit, Size = 16 )]
public struct SSDSegmentHead
{
[FieldOffset( 12 )] internal byte size;
[FieldOffset( 0 )] internal M128 data;
[FieldOffset( 13 )] public byte selfDefine_1;
[FieldOffset( 14 )] public byte selfDefine_2;
[FieldOffset( 15 )] public byte selfDefine_3;
[FieldOffset( 0 )] public int globalID;
[FieldOffset( 4 )] public int nextID;
[FieldOffset( 8 )] public int previousHash;
public int Size
{
get => ( ( int )size ) + 1;
set
{
if( ( value > 256 ) || ( value < 0 ) ) {
throw new ArgumentOutOfRangeException();
}
size = ( byte )( value - 1 );
}
}
public unsafe byte[] GetBytes()
{
byte[] ret = new byte[16];
fixed( Vector4* vptr = &data.Vec ) {
byte* bptr = ( byte* )vptr;
for( int i = 0; i < 15; i++ ) {
ret[ i ] = *bptr;
}
}
return ret;
}
}
}
+184
View File
@@ -0,0 +1,184 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="DataSegment.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.HighPerformance;
using StgSharp.HighPerformance;
using StgSharp.Internal.Intrinsic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Internal
{
[StructLayout( LayoutKind.Explicit, Size = StgSharp.ssdSegmentLength * 16 )]
public unsafe struct SSDSegment : IComparable<int>, IComparable<SSDSegment>
{
[FieldOffset( 16 )] public fixed byte Data[
16 * ( StgSharp.ssdSegmentLength - 1 ) ];
[FieldOffset( 12 )] public int DataHash;
[FieldOffset( 8 )] public int PreviousHash;
[FieldOffset( 0 * 16 )] public SSDSegmentHead Head;
public SSDSegment( int previousHash )
{
this.PreviousHash = previousHash;
}
public byte this[ int index ]
{
get
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
return Data[ index ];
}
set
{
if( index > ( 16 * ( StgSharp.ssdSegmentLength - 1 ) ) - 1 ) {
throw new IndexOutOfRangeException();
}
Data[ index ] = value;
}
}
public int ID
{
get { return Head.globalID; }
set { Head.globalID = value; }
}
public short Size => Head.size;
public void FillRandomBytes( int begin )
{
if( begin > 255 ) {
return;
}
for( int i = begin; i < 255; i++ ) {
Data[ i ] = Scaler.Random<byte>();
}
}
public static SSDSegment FromStream( byte[] stream )
{
if( stream.Length != 16 * StgSharp.ssdSegmentLength ) {
throw new ArgumentException();
}
SSDSegment ret = new SSDSegment();
fixed( byte* bptr = stream ) {
ret.Head.data = *( M128* )bptr;
for( int i = 1; i < StgSharp.ssdSegmentLength; i++ ) {
ret.WriteData<M128>(
i - 1, *( M128* )( bptr + ( 16 * i ) ) );
}
}
return ret;
}
public byte[] GetBytes()
{
byte[] ret = new byte[16 * StgSharp.ssdSegmentLength];
fixed( M128* mptr = &Head.data ) {
fixed( byte* aptr = ret ) {
Vector4* vsptr = ( Vector4* )mptr;
Vector4* vtptr = ( Vector4* )aptr;
for( int i = 0; i < 18; i++ ) {
*( vtptr + i ) = *( vsptr + i );
}
}
}
return ret;
}
public int GetDataHash()
{
Vector4 v = Vector4.One;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength - 1; i += 1 ) {
v += ( *vptr ) * 31;
}
}
M128 m = new M128( v );
DataHash = m.Vec.GetHashCode();
return DataHash;
}
public override int GetHashCode()
{
int ret = 17;
fixed( M128* mptr = &Head.data ) {
Vector4* vptr = ( Vector4* )mptr;
for( int i = 0; i < StgSharp.ssdSegmentLength; i++ ) {
ret = ( ret + ( *vptr ).GetHashCode() ) * 31;
}
}
return ret;
}
public unsafe T ReadData<T>( int index ) where T: struct
{
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
return *( tptr + index );
}
}
public unsafe void WriteData<T>( int index, T value ) where T: struct
{
fixed( byte* bptr = Data ) {
T* tptr = ( T* )bptr;
*( tptr + index ) = value;
}
}
int IComparable<int>.CompareTo( int other )
{
return ID.CompareTo( other );
}
int IComparable<SSDSegment>.CompareTo( SSDSegment other )
{
return ID.CompareTo( other.ID );
}
}
}
+68
View File
@@ -0,0 +1,68 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSD.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace StgSharp.Internal
{
public partial class SSD
{
private Dictionary<string, SSDraw> fileList;
private FileStream file;
private SSDrawHead head;
public SSD()
{
fileList = new Dictionary<string, SSDraw>();
}
public SSD( FileStream fileStream )
{
fileList = new Dictionary<string, SSDraw>();
file = fileStream;
}
public static SSD FromFile( string fileRoute )
{
return new SSD(
new FileStream( fileRoute, FileMode.Open, FileAccess.Read ) )
{
};
}
}
}
@@ -0,0 +1,80 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSDVirtualFolder.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Internal.FileIO;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Internal
{
public class SSDFolder : ISSDSerializable
{
internal Dictionary<string, SSDFolder> folders;
internal int _folderID;
internal string _name;
internal SSDFolder()
{
folders = new Dictionary<string, SSDFolder>();
}
internal SSDFolder( string name )
{
if( name == "root" ) {
throw new ArgumentException(
"Name cannot be root," + "it is preserved for root file indexer." );
}
if( name == "default" ) {
throw new ArgumentException(
"Name cannot be default," + "it is preserved for default file id provider." );
}
_name = name;
folders = new Dictionary<string, SSDFolder>();
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.VirtualFolder;
public void FromBytes( byte[] stream )
{
throw new NotImplementedException();
}
//TODO 虚拟文件夹的GetBytes好难写
public byte[] GetBytes()
{
throw new NotImplementedException();
}
}
}
+79
View File
@@ -0,0 +1,79 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SSDraw.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics.ShaderEdit;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Xml.Serialization;
namespace StgSharp.Internal.FileIO
{
public class SSDraw
{
private byte[] data;
public SSDraw( string name, Stream streamSource )
{
if( ( streamSource == null ) || ( streamSource.Length == 0 ) ) {
throw new ArgumentNullException( nameof( streamSource ) );
}
Name = name;
data = new byte[streamSource.Length];
streamSource.Read( data.AsSpan() );
}
public SSDrawHead Head
{
get;
set;
}
public string Name
{
get;
set;
}
}
[StructLayout( LayoutKind.Explicit, Size = 32 * 16 )]
public unsafe struct SSDrawHead { }
}
+41
View File
@@ -0,0 +1,41 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Define.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Internal
{
/// <summary>
/// A class contains a sets of methods to serialize several types
/// </summary>
public static partial class Serializer { }
}
@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ISSDSerializable.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Internal
{
public interface ISSDSerializable
{
public SerializableTypeCode SSDTypeCode
{
get;
}
public byte[] GetBytes();
internal void FromBytes( byte[] stream );
}
public enum SerializableTypeCode
{
Unknown = 0,
IndexTable = 1,
PixelImage = 2,
VectorImage = 3,
Audio = 4,
Shader = 5,
Text = 6,
RawData = 7,
VirtualFolder = int.MaxValue,
}
public static partial class Serializer
{
public static T Deserialize<T>( byte[] stream )
where T: ISSDSerializable
{
T serializableObject = Activator.CreateInstance<T>();
serializableObject.FromBytes( stream );
return serializableObject;
}
public static string GetNameTail( SerializableTypeCode typeCode )
{
switch( typeCode ) {
case SerializableTypeCode.IndexTable:
return "_idt";
case SerializableTypeCode.PixelImage:
return "_pim";
case SerializableTypeCode.VectorImage:
return "_vim";
case SerializableTypeCode.Audio:
return "_wav";
case SerializableTypeCode.Shader:
return "_gls";
case SerializableTypeCode.Text:
return "_txt";
case SerializableTypeCode.RawData:
return "_raw";
case SerializableTypeCode.VirtualFolder:
return "_fod";
default:
throw new ArgumentException( "Unknown file type" );
}
}
public static byte[] Serialize( ISSDSerializable serializableObject )
{
return serializableObject.GetBytes();
}
}
}
+101
View File
@@ -0,0 +1,101 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ValueBox.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER 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 THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data
{
public interface IValueBox
{
ref object ValueReference
{
get;
}
static virtual IValueBox<T> AsGeneric<T>( IValueBox box )
where T: struct
{
if( box is not IValueBox<T> genericBox ) {
return null;
}
return genericBox;
}
static virtual bool IsGeneric<T>( IValueBox box ) where T: struct
{
return box is IValueBox<T>;
}
}
public interface IValueBox<T> where T: struct
{
T Value
{
get;
set;
}
}
/// <summary>
/// A class attempt to reduce cost of boxing, though still a bit slower than direct access to
/// origin value type instance.
/// </summary>
/// <typeparam name="T"> Type of instance to be boxed. </typeparam>
public class ValueBox<T> : IValueBox, IValueBox<T> where T: struct
{
private T _value;
public ValueBox( T value )
{
_value = value;
}
public ref object ValueReference => ref Unsafe.As<T, object>(
ref _value );
public T Value
{
get => _value;
set => _value = value;
}
}
}