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