准备开工script解析

This commit is contained in:
Chenx221 2024-10-13 22:45:24 +08:00
parent b91884b08d
commit 8965c9aacb
2 changed files with 87 additions and 52 deletions

View File

@ -198,72 +198,68 @@ namespace EscudeTools
private static bool SqliteProcess(Sheet[] db, string path)
{
//db含有多个sheet每个sheet中col存放标题对应数据库中应该是字段records存放数据对应数据库中应该是记录
using (SqliteConnection connection = new($"Data Source={path};"))
using SqliteConnection connection = new($"Data Source={path};");
connection.Open();
foreach (var sheet in db)
{
connection.Open();
foreach (var sheet in db)
using (SqliteCommand createTableCommand = connection.CreateCommand())
{
using (SqliteCommand createTableCommand = connection.CreateCommand())
{
StringBuilder createTableQuery = new();
createTableQuery.Append($"CREATE TABLE IF NOT EXISTS {sheet.name} (");
StringBuilder createTableQuery = new();
createTableQuery.Append($"CREATE TABLE IF NOT EXISTS {sheet.name} (");
// Add columns to the create table query
foreach (var column in sheet.col)
{
createTableQuery.Append($"{column.name} {GetSQLiteColumnType(column.type)}, ");
}
createTableQuery.Remove(createTableQuery.Length - 2, 2); // Remove the last comma and space
createTableQuery.Append(");");
createTableCommand.CommandText = createTableQuery.ToString();
createTableCommand.ExecuteNonQuery();
}
using SqliteCommand insertDataCommand = connection.CreateCommand();
StringBuilder insertDataQuery = new();
insertDataQuery.Append($"INSERT INTO {sheet.name} (");
// Add column names to the insert data query
// Add columns to the create table query
foreach (var column in sheet.col)
{
insertDataQuery.Append($"{column.name}, ");
createTableQuery.Append($"{column.name} {GetSQLiteColumnType(column.type)}, ");
}
insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space
insertDataQuery.Append(") VALUES (");
createTableQuery.Remove(createTableQuery.Length - 2, 2); // Remove the last comma and space
createTableQuery.Append(");");
// Add parameter placeholders to the insert data query
for (int i = 0; i < sheet.cols; i++)
createTableCommand.CommandText = createTableQuery.ToString();
createTableCommand.ExecuteNonQuery();
}
using SqliteCommand insertDataCommand = connection.CreateCommand();
StringBuilder insertDataQuery = new();
insertDataQuery.Append($"INSERT INTO {sheet.name} (");
// Add column names to the insert data query
foreach (var column in sheet.col)
{
insertDataQuery.Append($"{column.name}, ");
}
insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space
insertDataQuery.Append(") VALUES (");
// Add parameter placeholders to the insert data query
for (int i = 0; i < sheet.cols; i++)
{
insertDataQuery.Append($"@param{i}, ");
}
insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space
insertDataQuery.Append(");");
insertDataCommand.CommandText = insertDataQuery.ToString();
// Add data parameters to the insert data command
for (int i = 0; i < sheet.records.values.Length; i++)
{
var record = (Record)sheet.records.values[i];
for (int j = 0; j < sheet.cols; j++)
{
insertDataQuery.Append($"@param{i}, ");
var parameter = new SqliteParameter($"@param{j}", record.values[j]);
insertDataCommand.Parameters.Add(parameter);
}
insertDataQuery.Remove(insertDataQuery.Length - 2, 2); // Remove the last comma and space
insertDataQuery.Append(");");
insertDataCommand.CommandText = insertDataQuery.ToString();
// Add data parameters to the insert data command
for (int i = 0; i < sheet.records.values.Length; i++)
{
var record = (Record)sheet.records.values[i];
for (int j = 0; j < sheet.cols; j++)
{
var parameter = new SqliteParameter($"@param{j}", record.values[j]);
insertDataCommand.Parameters.Add(parameter);
}
insertDataCommand.ExecuteNonQuery();
insertDataCommand.Parameters.Clear();
}
insertDataCommand.ExecuteNonQuery();
insertDataCommand.Parameters.Clear();
}
}
return true;
//throw new NotImplementedException();
}
private static string GetSQLiteColumnType(ushort type)
{

View File

@ -0,0 +1,39 @@
namespace EscudeTools
{
public class ScriptMessage
{
public byte[] Data { get; set; } // MESS領域 (消息区域)
public uint Size { get; set; } // MESS領域サイズ (消息区域大小)
public uint[] Offset { get; set; } // MESSオフセット (消息偏移)
public uint Count { get; set; } // MESS数 (消息数量)
}
public class ScriptFile
{
public byte[] Code { get; set; } // CODE領域 (代码区域)
public uint CodeSize { get; set; } // CODE領域サイズ (代码区域大小)
public byte[] Text { get; set; } // TEXT領域 (文本区域)
public uint TextSize { get; set; } // TEXT領域サイズ (文本区域大小)
public uint[] TextOffset { get; set; } // TEXTオフセット (文本偏移)
public uint TextCount { get; set; } // TEXT数 (文本数量)
public uint MessCount { get; set; } // MESS数 (消息数量)
}
public class ScriptManager
{
static readonly byte[] MessHeader = [0x40, 0x6D, 0x65, 0x73, 0x73, 0x3A, 0x5F, 0x5F]; //@mess:__
static readonly byte[] FileHeader = [0x40, 0x63, 0x6F, 0x64, 0x65, 0x3A, 0x5F, 0x5F]; //@code:__
public bool LoadScriptFile(string path)
{
throw new NotImplementedException();
}
public bool LoadScriptMess(string path)
{
throw new NotImplementedException();
}
}
}