bug修复+sqlite导出性能优化
This commit is contained in:
parent
cd926e361e
commit
abb3d6c2ef
@ -146,14 +146,19 @@ namespace EscudeTools
|
||||
public static string SetCommandStr(Command c, ScriptFile sf, ScriptMessage sm, ref int messIndex)
|
||||
{
|
||||
//__cdecl
|
||||
//todo
|
||||
//可考虑对pop进行进一步处理
|
||||
switch (c.Instruction)
|
||||
{
|
||||
case INST_POP:
|
||||
return "Pop a value";
|
||||
{
|
||||
Mark(sf, 1);
|
||||
return "Pop a value";
|
||||
}
|
||||
|
||||
case INST_POP_N:
|
||||
return $"Pop multiple values";
|
||||
{
|
||||
Mark(sf, (uint)c.Parameter);
|
||||
return $"Pop multiple values";
|
||||
}
|
||||
case INST_POP_RET:
|
||||
return $"Pop a return value";
|
||||
case INST_PUSH_INT:
|
||||
@ -250,6 +255,18 @@ namespace EscudeTools
|
||||
}
|
||||
}
|
||||
|
||||
private static void Mark(ScriptFile sf, uint j)
|
||||
{
|
||||
int k = sf.Commands.Count - 1;
|
||||
for (int i = 0; i < j; i++)
|
||||
{
|
||||
if (sf.Commands[k].Instruction <= 10 && sf.Commands[k].Instruction >= 4 && !sf.Commands[k].IsProcSet)
|
||||
{
|
||||
sf.Commands[k--].IsProcSet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string SetExtStr(Command c, ScriptFile sf)
|
||||
{
|
||||
switch ((uint)c.Parameter)
|
||||
@ -810,6 +827,7 @@ namespace EscudeTools
|
||||
private static void SetExtStr1(string[] ps, ScriptFile sf)
|
||||
{
|
||||
int i = sf.Commands.Count - 2;
|
||||
sf.Commands[i + 1].IsProcSet = true;
|
||||
for (int k = 0; k < ps.Length; k++)
|
||||
{
|
||||
if (sf.Commands[i].IsProcSet || sf.Commands[i].Instruction < 4 || sf.Commands[i].Instruction > 10)
|
||||
|
@ -266,65 +266,63 @@ namespace EscudeTools
|
||||
connection.Open();
|
||||
|
||||
string checkTableExistsQuery = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{name}';";
|
||||
|
||||
using (var checkTableCmd = new SqliteCommand(checkTableExistsQuery, connection))
|
||||
{
|
||||
var result = checkTableCmd.ExecuteScalar();
|
||||
if (result != null)
|
||||
return true;
|
||||
if (result != null) return true;
|
||||
}
|
||||
|
||||
string createTableQuery = $@"
|
||||
CREATE TABLE {name} (
|
||||
Offset INTEGER,
|
||||
Instruction INTEGER,
|
||||
InstructionString TEXT,
|
||||
Parameter TEXT,
|
||||
Helper TEXT
|
||||
);";
|
||||
|
||||
CREATE TABLE {name} (
|
||||
Offset INTEGER,
|
||||
Instruction INTEGER,
|
||||
InstructionString TEXT,
|
||||
Parameter TEXT,
|
||||
Helper TEXT
|
||||
);";
|
||||
using (var createTableCmd = new SqliteCommand(createTableQuery, connection))
|
||||
{
|
||||
createTableCmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
string insertQuery = $"INSERT INTO {name} (Offset, Instruction, InstructionString,Parameter, Helper) VALUES (@Offset, @Instruction, @InstructionString,@Parameter, @Helper);";
|
||||
string insertQuery = $"INSERT INTO {name} (Offset, Instruction, InstructionString, Parameter, Helper) VALUES (@Offset, @Instruction, @InstructionString, @Parameter, @Helper);";
|
||||
|
||||
using var transaction = connection.BeginTransaction();
|
||||
using var insertCmd = new SqliteCommand(insertQuery, connection, transaction);
|
||||
|
||||
using var insertCmd = new SqliteCommand(insertQuery, connection);
|
||||
foreach (var command in sf.Commands)
|
||||
{
|
||||
insertCmd.Parameters.Clear();
|
||||
insertCmd.Parameters.AddWithValue("@Offset", command.Offset);
|
||||
insertCmd.Parameters.AddWithValue("@Instruction", command.Instruction);
|
||||
insertCmd.Parameters.AddWithValue("@InstructionString", command.InstructionString);
|
||||
insertCmd.Parameters.AddWithValue("@Parameter", command.Parameter == null ? "" : command.Parameter.ToString());
|
||||
insertCmd.Parameters.AddWithValue("@Parameter", command.Parameter ?? "");
|
||||
insertCmd.Parameters.AddWithValue("@Helper", command.Helper ?? "");
|
||||
|
||||
insertCmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private bool SqliteProcess(ScriptMessage sm, string path)
|
||||
{
|
||||
using SqliteConnection connection = new($"Data Source={path};");
|
||||
connection.Open();
|
||||
|
||||
string checkTableExistsQuery = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{name}';";
|
||||
|
||||
using (var checkTableCmd = new SqliteCommand(checkTableExistsQuery, connection))
|
||||
{
|
||||
var result = checkTableCmd.ExecuteScalar();
|
||||
if (result != null)
|
||||
return true;
|
||||
if (result != null) return true;
|
||||
}
|
||||
|
||||
string createTableQuery = $@"
|
||||
CREATE TABLE {name} (
|
||||
DataString TEXT
|
||||
);";
|
||||
|
||||
CREATE TABLE {name} (
|
||||
DataString TEXT
|
||||
);";
|
||||
using (var createTableCmd = new SqliteCommand(createTableQuery, connection))
|
||||
{
|
||||
createTableCmd.ExecuteNonQuery();
|
||||
@ -332,7 +330,9 @@ namespace EscudeTools
|
||||
|
||||
string insertQuery = $"INSERT INTO {name} (DataString) VALUES (@DataString);";
|
||||
|
||||
using var insertCmd = new SqliteCommand(insertQuery, connection);
|
||||
using var transaction = connection.BeginTransaction();
|
||||
using var insertCmd = new SqliteCommand(insertQuery, connection, transaction);
|
||||
|
||||
foreach (var ds in sm.DataString)
|
||||
{
|
||||
insertCmd.Parameters.Clear();
|
||||
@ -340,9 +340,11 @@ namespace EscudeTools
|
||||
insertCmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static string GetSQLiteColumnType(ushort type)
|
||||
{
|
||||
return type switch
|
||||
|
Loading…
Reference in New Issue
Block a user