-
Notifications
You must be signed in to change notification settings - Fork 1
/
sceModule.cs
75 lines (61 loc) · 2.52 KB
/
sceModule.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using StreamFAdd;
using System;
using System.Collections.Generic;
using System.IO;
namespace sceWork
{
internal class sceModule
{
private sceHeader header;
private StreamFunctionAdd mainSfa;
public void Dispose() => this.mainSfa.Dispose();
public int Count => this.header.fileStrings.Count;
internal sceHeader Header { get => header; set => header = value; }
public sceModule(string fileName)
{
this.mainSfa = new StreamFunctionAdd(fileName);
this.header = new sceHeader(this.mainSfa);
}
public byte[] GetBlock(int idx) => this.header.fileStrings[idx].data.ToArray();
public string GetStringBlock(int idx)
{
string str = "";
for (int index = 0; index < this.header.fileStrings[idx].data.Count; ++index)
str += this.header.fileStrings[idx].data[index].ToString("X2");
return str;
}
public void SetBlock(int idx, byte[] data)
{
this.header.fileStrings[idx].data.Clear();
for (int index = 0; index < data.Length; ++index)
this.header.fileStrings[idx].data.Add(data[index]);
}
public void SetBlock(int idx, byte[] data, List<string> plainStringList, List<int> lineNumberList)
{
header.lineNumberList = lineNumberList;
header.plainStringList = plainStringList;
this.header.fileStrings[idx].data.Clear();
for (int index = 0; index < data.Length; ++index)
this.header.fileStrings[idx].data.Add(data[index]);
}
public void SetStringBlock(int idx, string str)
{
List<byte> byteList = new List<byte>();
for (int index = 0; index < str.Length; ++index)
byteList.Add(Convert.ToByte(str[index]));
this.SetBlock(idx, byteList.ToArray());
}
public void Save(bool dedup = false) => header.WriteStrings(mainSfa, dedup);
public bool isHaveText() => mainSfa.LengthStream - header.offsetStrings > 2L;
public void ExtractBlocks()
{
for (int index1 = 0; index1 < header.fileStrings.Count; ++index1)
{
byte[] bytes = new byte[header.fileStrings[index1].data.Count];
for (int index2 = 0; index2 < bytes.Length; ++index2)
bytes[index2] = header.fileStrings[index1].data[index2];
File.WriteAllBytes(index1.ToString(), bytes);
}
}
}
}