daily update on 20240508 by nitload youmu, partical added
This commit is contained in:
@@ -49,7 +49,7 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
|
||||
public const string FileType = "ssdraw";
|
||||
public const int SegmentCapacity = 16 * 16;
|
||||
public const int SegmentCapacity = 16 * (StgSharp.ssdSegmentLength - 1);
|
||||
|
||||
private Area home;
|
||||
private int previousHash;
|
||||
@@ -62,7 +62,6 @@ namespace StgSharp.Data.FileIO
|
||||
internal SSDraw()
|
||||
{
|
||||
segments = new List<SSDSegment>();
|
||||
|
||||
}
|
||||
|
||||
public SSDraw(string name)
|
||||
@@ -79,24 +78,11 @@ namespace StgSharp.Data.FileIO
|
||||
|
||||
internal SSDrawHead Head => _head;
|
||||
|
||||
//TODO 分析头,加载文件头,进一步加载全部的数据块
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="head"></param>
|
||||
/// <returns></returns>
|
||||
public static SSDraw AnalyzeHead(SSDrawHead head)
|
||||
public SSDSegment[] GetSegments()
|
||||
{
|
||||
if (head._head.globalID == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SSDraw ret = new SSDraw();
|
||||
foreach ((int, int) item in head)
|
||||
{
|
||||
|
||||
}
|
||||
SSDSegment[] ret = segments.ToArray();
|
||||
Array.Resize(ref ret, ret.Length + 1);
|
||||
ret[ret.Length - 1] = Head.Data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -118,7 +104,7 @@ namespace StgSharp.Data.FileIO
|
||||
f.Close();
|
||||
}
|
||||
|
||||
//TODO read raw 没写完
|
||||
|
||||
public static SSDraw readRaw(string route)
|
||||
{
|
||||
string[] routeFolders = route.Split('\\');
|
||||
@@ -126,9 +112,20 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
throw new Exception($"File to open is not a {FileType} file.");
|
||||
}
|
||||
FileStream stream = File.Open(route, FileMode.Open);
|
||||
return new SSDraw(string.Empty);
|
||||
|
||||
byte[] dataStream= new byte[16 * StgSharp.ssdSegmentLength];
|
||||
SSDraw ret = new SSDraw();
|
||||
using (FileStream stream = File.Open(route, FileMode.Open))
|
||||
{
|
||||
int offset = 0;
|
||||
offset += stream.Read(dataStream,offset,16);
|
||||
ret._head = new SSDrawHead(dataStream);
|
||||
while (offset < stream.Length)
|
||||
{
|
||||
offset += stream.Read(dataStream, offset, 16);
|
||||
ret.segments.Add(SSDSegment.FromStream(dataStream));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void WriteRaw(byte[] dataStream)
|
||||
@@ -170,9 +167,26 @@ namespace StgSharp.Data.FileIO
|
||||
public unsafe class SSDrawHead : IEnumerable<(int, int)>
|
||||
{
|
||||
|
||||
private SSDSegment segmentRange;
|
||||
private SSDSegment segmentData;
|
||||
private string name;
|
||||
|
||||
internal SSDrawHead(byte[] data)
|
||||
{
|
||||
if (data.Length != 16* StgSharp.ssdSegmentLength)
|
||||
{
|
||||
throw new ArgumentException();
|
||||
}
|
||||
segmentData = new SSDSegment();
|
||||
fixed (byte* bptr = data)
|
||||
{
|
||||
segmentData.Head.data = *(M128*)bptr;
|
||||
for (int i = 1; i < StgSharp.ssdSegmentLength; i++)
|
||||
{
|
||||
segmentData.WriteData<M128>(i - 1,*(M128*)(bptr + 16 * i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal SSDrawHead(string name)
|
||||
{
|
||||
int hash;
|
||||
@@ -190,16 +204,43 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
}
|
||||
|
||||
public (int begin, int end) this[byte index]
|
||||
internal SSDSegment Data
|
||||
{
|
||||
get => segmentRange.ReadData<(int, int)>(index);
|
||||
set => segmentRange.WriteData<(int, int)>(index, value);
|
||||
get => segmentData;
|
||||
}
|
||||
|
||||
public byte DiscIndex
|
||||
public (int begin, int end) this[byte index]
|
||||
{
|
||||
get => _head.selfDefine_2;
|
||||
internal set => _head.selfDefine_2 = value;
|
||||
get => segmentData.ReadData<(int, int)>(index);
|
||||
set => segmentData.WriteData<(int, int)>(index, value);
|
||||
}
|
||||
|
||||
public unsafe string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] bytes = new byte[15 * 16];
|
||||
fixed (byte* bptr = segmentData.Data)
|
||||
{
|
||||
Marshal.Copy(
|
||||
source: (IntPtr)bptr,
|
||||
destination: bytes,
|
||||
256, 15 * 16);
|
||||
}
|
||||
return Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
set
|
||||
{
|
||||
byte[] namecode = Encoding.UTF8.GetBytes(value);
|
||||
fixed (byte* bptr = segmentData.Data)
|
||||
{
|
||||
Marshal.Copy(
|
||||
source: namecode,
|
||||
startIndex: 0,
|
||||
destination: (IntPtr)(bptr + 256),
|
||||
length: 15 * 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public byte TypeCode
|
||||
@@ -210,7 +251,7 @@ namespace StgSharp.Data.FileIO
|
||||
|
||||
internal ref SSDSegmentHead _head
|
||||
{
|
||||
get => ref segmentRange.Head;
|
||||
get => ref segmentData.Head;
|
||||
}
|
||||
|
||||
internal byte pairCount
|
||||
@@ -226,10 +267,9 @@ namespace StgSharp.Data.FileIO
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public unsafe byte[] GetBytes()
|
||||
{
|
||||
return segmentRange.GetBytes();
|
||||
return segmentData.GetBytes();
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +277,7 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
for (int i = 0; i < pairCount; i++)
|
||||
{
|
||||
yield return segmentRange.ReadData<(int, int)>(i);
|
||||
yield return segmentData.ReadData<(int, int)>(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +285,7 @@ namespace StgSharp.Data.FileIO
|
||||
{
|
||||
for (int i = 0; i < pairCount; i++)
|
||||
{
|
||||
yield return segmentRange.ReadData<(int, int)>(i);
|
||||
yield return segmentData.ReadData<(int, int)>(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user