Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pull Request] KXP 现在打包 PluginStruct #98

Merged
merged 2 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion KitX Dashboard/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void Main(string[] args)
}
}
}
catch(Exception e)
catch (Exception e)
{
Console.WriteLine(e.Message);
Environment.Exit(1);
Expand Down
28 changes: 23 additions & 5 deletions KitX File Format Helper/KitX.KXP.Helper/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal struct FileMapItem
/// <returns>返回 LoaderStruct 的json文本</returns>
/// <param name="releaseFolder">释放文件的路径</param>
/// <exception cref="Exception">哈希校验错误</exception>
public string Decode(string releaseFolder)
public Tuple<string, string> Decode(string releaseFolder)
{
if (!Directory.Exists(releaseFolder))
Directory.CreateDirectory(releaseFolder);
Expand All @@ -48,7 +48,7 @@ public string Decode(string releaseFolder)

byte[] header = new byte[16];

for(int i = 0; i < 16; ++ i)
for (int i = 0; i < 16; ++i)
header[i] = src[i];

for (int i = 0; i < 16; ++i)
Expand Down Expand Up @@ -132,10 +132,28 @@ public string Decode(string releaseFolder)
for (int i = 0; i < loaderStructLength; ++i, ++cursor)
loaderStructByte[i] = src[cursor];

string result = Encoding.UTF8.GetString(loaderStructByte);
byte[] pluginStructLengthByte = new byte[8];

for (int i = 0; i < 8; ++i, ++cursor)
pluginStructLengthByte[i] = src[cursor];

long pluginStructLength = BitConverter.ToInt64(pluginStructLengthByte, 0); // PluginStruct的长度

#if DEBUG
Console.WriteLine($"Plugin Struct Length: {pluginStructLength}");
#endif

byte[] pluginStructByte = new byte[pluginStructLength]; // Plugin Struct 的 Byte 数组

for (int i = 0; i < pluginStructLength; ++i, ++cursor)
pluginStructByte[i] = src[cursor];

string loaderStruct = Encoding.UTF8.GetString(loaderStructByte);
string pluginStruct = Encoding.UTF8.GetString(pluginStructByte);

#if DEBUG
Console.WriteLine($"Loader Struct: {result}");
Console.WriteLine($"Loader Struct: {loaderStruct}");
Console.WriteLine($"Plugin Struct: {pluginStruct}");
#endif

MD5 md5 = MD5.Create();
Expand All @@ -154,7 +172,7 @@ public string Decode(string releaseFolder)
throw new Exception("MD5 Hash Error.");
}

return result;
return Tuple.Create(loaderStruct, pluginStruct);
}
}
}
19 changes: 16 additions & 3 deletions KitX File Format Helper/KitX.KXP.Helper/Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ namespace KitX.KXP.Helper
{
public class Encoder
{
public Encoder(List<string> files2Include, string loaderStruct)
public Encoder(List<string> files2Include, string loaderStruct, string pluginStruct)
{
Files2Include = files2Include;
LoaderStruct = loaderStruct;
PluginStruct = pluginStruct;
}

public List<string> Files2Include { get; set; }

public string LoaderStruct { get; set; }

public string PluginStruct { get; set; }

/// <summary>
/// 编码包体
/// </summary>
Expand All @@ -34,9 +37,8 @@ public void Encode(string rootDir, string saveFolder, string filename)
files.Add(GetRelativePath(rootDir, item), File.ReadAllBytes(item));
#endregion

#region 所需Loader的LoaderStruct的byte[]
byte[] loaderStruct = Encoding.UTF8.GetBytes(LoaderStruct);
#endregion
byte[] pluginStruct = Encoding.UTF8.GetBytes(PluginStruct);

int fileCount = files.Keys.Count; // 待封装的文件数量

Expand Down Expand Up @@ -96,6 +98,17 @@ public void Encode(string rootDir, string saveFolder, string filename)
all_files.Enqueue(item); // 入队加载器结构
}

EnqueueSingleLong(ref all_files, pluginStruct.LongLength); // 入队插件结构的长度

#if DEBUG
Console.WriteLine($"Plugin Struct Length: {pluginStruct.LongLength}");
#endif

foreach (var item in pluginStruct)
{
all_files.Enqueue(item); // 入队插件结构
}

byte[] filesBytes = all_files.ToArray();

MD5 md5 = MD5.Create(); // 哈希
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Drawing;
using System.IO;
using System.Net;
using System.Reflection;
using System.Security.AccessControl;
using System.Threading;
using System.Windows.Forms;
Expand Down