Skip to content

Commit

Permalink
Minor updates + Market Editor
Browse files Browse the repository at this point in the history
  • Loading branch information
iSmokeDrow committed Jun 14, 2021
1 parent 6341f88 commit 91a2b28
Show file tree
Hide file tree
Showing 34 changed files with 2,140 additions and 4,715 deletions.
7 changes: 6 additions & 1 deletion Config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"Styles": [
"RDB",
"DATA",
"HASHER"
"HASHER",
"MARKET"
],
"DefaultStyle": "NONE"
},
Expand Down Expand Up @@ -49,6 +50,10 @@
"AutoConvert": true,
"Type": 0
},
"Market": {
"UseArenaPoint": false,
"SaveToScript": true,
},
"Log": {
"Directory": ".\\Logs",
"DisplayLevel": 0,
Expand Down
10 changes: 6 additions & 4 deletions Configuration/ConfigMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

namespace Grimoire.Configuration
{
//TODO: implement setting call with default value!

/// <summary>
/// Provides configuration storage and real time manipulation
/// </summary>
public class ConfigMan
public class ConfigManager
{
/// <summary>
/// List of Configuration descriptions
Expand Down Expand Up @@ -60,14 +62,14 @@ string confPath
/// <summary>
/// Default constructor which will use default path variables
/// </summary>
public ConfigMan() => parse();
public ConfigManager() => parse();

/// <summary>
/// Constructor for initializing with a directory and file name.
/// </summary>
/// <param name="Directory">Directory holding the configuration .json</param>
/// <param name="FileName">Name of the configuration .json</param>
public ConfigMan(string Directory, string FileName)
public ConfigManager(string Directory, string FileName)
{
confDir = Directory;
confName = FileName;
Expand All @@ -79,7 +81,7 @@ public ConfigMan(string Directory, string FileName)
/// Constructor for initializing with a fully qualified file path to the config .json
/// </summary>
/// <param name="FilePath"></param>
public ConfigMan(string FilePath) => confPath = FilePath;
public ConfigManager(string FilePath) => confPath = FilePath;

public dynamic this[int index] => Options?[index];

Expand Down
106 changes: 87 additions & 19 deletions DB/DBHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Grimoire.DB
public class DBHelper : IDisposable
{
Tabs.Manager TabMan = Tabs.Manager.Instance;
ConfigMan configMan = GUI.Main.Instance.ConfigMan;
ConfigManager configMan = GUI.Main.Instance.ConfigMan;

DbConType connType = DbConType.MsSQL;

Expand Down Expand Up @@ -93,7 +93,7 @@ public ConnectionState State
/// </summary>
/// <param name="configManager"></param>
/// <param name="type"></param>
public DBHelper(ConfigMan configManager, DbConType type = DbConType.MsSQL)
public DBHelper(ConfigManager configManager, DbConType type = DbConType.MsSQL)
{
configMan = configManager;

Expand Down Expand Up @@ -149,12 +149,10 @@ string ConnectionString

}

public async Task<dynamic> Execute(string text, DbParameter parameters, DbCmdType type = DbCmdType.NonQuery)
public async Task<dynamic> Execute(DbCmdType type = DbCmdType.NonQuery)
{
try
{
NewCommand(text, parameters);

return await execute(type);
}
catch (Exception ex)
Expand Down Expand Up @@ -257,6 +255,7 @@ public async Task<dynamic> ReadTable(string table)
{
OnProgressMaxSet(new DBProgressMax(rowCnt));

int prevIdx = 0;
int rowIdx = 0;

if (dbRdr != null)
Expand Down Expand Up @@ -313,6 +312,9 @@ public async Task<dynamic> ReadTable(string table)
break;

case CellType.TYPE_LONG:
goto case CellType.TYPE_INT_64;

case CellType.TYPE_INT_64:
row[i] = (long)iRow[sqlIdx];
break;

Expand All @@ -332,7 +334,7 @@ public async Task<dynamic> ReadTable(string table)
string valStr = iRow[sqlIdx].ToString();

//Got to account for galas fuckery -_-
if (string.IsNullOrEmpty(valStr) || valStr == " " || valStr == "False")
if (string.IsNullOrEmpty(valStr) || valStr == " " || valStr == "False" || valStr == "-")
valStr = "0";
else if (valStr == "True")
valStr = "1";
Expand Down Expand Up @@ -371,6 +373,10 @@ public async Task<dynamic> ReadTable(string table)
row[i] = Convert.ToDouble(iRow[sqlIdx]);
break;

case CellType.TYPE_SID:
row[i] = ++prevIdx;
break;

case CellType.TYPE_STRING:
row[i] = iRow[sqlIdx] as string;
break;
Expand Down Expand Up @@ -440,7 +446,7 @@ public async Task<dynamic> ReadTable(string table)
}
finally
{
CloseConnection(true);
CloseConnection();
OnProgressReset();

actionSW.Stop();
Expand Down Expand Up @@ -612,24 +618,26 @@ public void CloseConnection(bool dispose = false)
}
}

void NewCommand(string text) => NewCommand(text, null);

public void NewCommand(string text, params DbParameter[] parameters)
public void NewCommand(string text)
{
switch (connType)
{
case DbConType.MsSQL:
msSQL_cmd.Connection = msSQL_conn;
msSQL_cmd.CommandText = text;
if (parameters != null)
msSQL_cmd.Parameters.AddRange(parameters);

if (msSQL_cmd.Parameters.Count > 0)
msSQL_cmd.Parameters.Clear();

break;

case DbConType.MySQL:
mySQL_cmd.Connection = mySQL_conn;
mySQL_cmd.CommandText = text;
if (parameters != null)
mySQL_cmd.Parameters.AddRange(parameters);

if (mySQL_cmd.Parameters.Count > 0)
mySQL_cmd.Parameters.Clear();

break;
}
}
Expand All @@ -650,6 +658,46 @@ public void SetCommand(DbCommand dbCmd)
}
}

public void ClearParameters()
{
switch (connType)
{
case DbConType.MsSQL:
msSQL_cmd.Parameters.Clear();
break;

case DbConType.MySQL:
mySQL_cmd.Parameters.Clear();
break;
}
}

public void AddParameter(string name, object value, SqlDbType type)
{
if (msSQL_cmd != null)
{
SqlParameter sqlParam = msSQL_cmd.CreateParameter();
sqlParam.ParameterName = name;
sqlParam.Value = value;
sqlParam.SqlDbType = type;

msSQL_cmd.Parameters.Add(sqlParam);
}
}

public void AddParameter(string name, object value, MySqlDbType type)
{
if (mySQL_cmd != null)
{
MySqlParameter mySQLParam = mySQL_cmd.CreateParameter();
mySQLParam.ParameterName = name;
mySQLParam.Value = value;
mySQLParam.MySqlDbType = type;

mySQL_cmd.Parameters.Add(mySQLParam);
}
}

string generateSelect(string table)
{
string statement = string.Empty;
Expand Down Expand Up @@ -678,11 +726,11 @@ async void clearTable(string table)
if (configMan["Engine", "DB"] == 0) // This feature depends on MsSQL SMO and cannot be used on MySQL/MariaDB!
{
if (configMan["Backup", "DB"])
await Task.Run(() => { scriptTable(table, true); });
await Task.Run(() => { ScriptTable(table, true); });

if (configMan["DropOnExport", "DB"])
{
scriptTable(table, false);
ScriptTable(table, false);

await Execute($"drop table {table}");

Expand All @@ -696,7 +744,7 @@ async void clearTable(string table)
await Execute($"truncate table {table}");
}

void scriptTable(string tableName, bool scriptData)
public void ScriptTable(string tableName, bool scriptData)
{
Microsoft.Data.SqlClient.SqlConnection sqlCon = new Microsoft.Data.SqlClient.SqlConnection(ConnectionString);
ServerConnection svConn = new ServerConnection(sqlCon);
Expand Down Expand Up @@ -753,8 +801,8 @@ async Task<int> executeScript(string filename)
}
catch (Exception ex)
{
OnError(new DBError($"An exception occured during script execution!\nMessage: {ex.Message}\n\nCall-Stack: {ex.StackTrace}"));
}
OnError(new DBError($"An exception occured during script execution!\nMessage: {ex.Message}\n\nCall-Stack: {ex.StackTrace}"));
}
else
OnError(new DBError("Database object is null!"));
}
Expand All @@ -763,6 +811,26 @@ async Task<int> executeScript(string filename)
return -1;
}

public override string ToString()
{
switch (connType)
{
case DbConType.MsSQL:
{
if (msSQL_cmd != null && !string.IsNullOrEmpty(msSQL_cmd.CommandText))
{

}
}
break;

case DbConType.MySQL:
throw new NotImplementedException();
}

return null;
}

object getDefault(Type type)
{
if (type.IsValueType)
Expand Down
2 changes: 1 addition & 1 deletion GUI/BitFlag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public BitFlag(int vector)
#region Properties

readonly Logs.Manager lManager;
readonly ConfigMan configMan;
readonly ConfigManager configMan;

protected bool calculating = false;
public List<string> lists = new List<string>();
Expand Down
2 changes: 1 addition & 1 deletion GUI/DataRebuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class DataRebuild : Form
Logs.Manager lManager = Logs.Manager.Instance;
Core core = null;
XmlManager xMan = XmlManager.Instance;
ConfigMan configMan;
ConfigManager configMan;
public DataRebuild()
{
InitializeComponent();
Expand Down
2 changes: 1 addition & 1 deletion GUI/DumpUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Grimoire.GUI
{
public partial class DumpUpdater : Form
{
ConfigMan configMan = GUI.Main.Instance.ConfigMan;
ConfigManager configMan = GUI.Main.Instance.ConfigMan;

string dumpDir;

Expand Down
22 changes: 10 additions & 12 deletions GUI/Input.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion GUI/Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public InputBox(string description, bool resizable)
{
InitializeComponent();
Text = description;
this.FormBorderStyle = (resizable) ? FormBorderStyle.SizableToolWindow : FormBorderStyle.FixedToolWindow;
this.FormBorderStyle = (resizable) ? FormBorderStyle.Sizable : FormBorderStyle.FixedDialog;
input.Multiline = resizable;
DialogResult = DialogResult.Cancel;
localize();
Expand Down
Loading

0 comments on commit 91a2b28

Please sign in to comment.