diff --git a/dlls/sqlite/basic_sql.cpp b/dlls/sqlite/basic_sql.cpp index 9f05cb71..1d926806 100644 --- a/dlls/sqlite/basic_sql.cpp +++ b/dlls/sqlite/basic_sql.cpp @@ -40,22 +40,27 @@ static cell AMX_NATIVE_CALL SQL_MakeDbTuple(AMX *amx, cell *params) SQL_Connection *sql = new SQL_Connection; int len; - char *host = strdup(MF_GetAmxString(amx, params[1], 0, &len)); + sql->port = 0; + sql->host = strdup(""); + sql->user = strdup(""); + sql->pass = strdup(""); - char *p = strchr(host, ':'); - if (p) + char *db = MF_GetAmxString(amx, params[4], 0, &len); + char path[255]; + FILE *fp; + + MF_BuildPathnameR(path, sizeof(path)-1, "%s", db); + if ((fp=fopen(path, "rb"))) { - sql->port = atoi(p+1); - *p = '\0'; + fclose(fp); + sql->db = strdup(path); } else { - sql->port = 0; + MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3/%s.sq3", + MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"), + db); + sql->db = strdup(path); } - sql->host = host; - sql->user = strdup(MF_GetAmxString(amx, params[2], 0, &len)); - sql->pass = strdup(MF_GetAmxString(amx, params[3], 0, &len)); - sql->db = strdup(MF_GetAmxString(amx, params[4], 0, &len)); - unsigned int num = MakeHandle(sql, Handle_Connection, FreeConnection); return num; diff --git a/dlls/sqlite/module.cpp b/dlls/sqlite/module.cpp index fc662764..0074de52 100644 --- a/dlls/sqlite/module.cpp +++ b/dlls/sqlite/module.cpp @@ -19,6 +19,30 @@ int SetMysqlAffinity(AMX *amx) return 0; } +bool DirExists(const char *dir) +{ +#if defined WIN32 || defined _WIN32 + DWORD attr = GetFileAttributes(dir); + + if (attr == INVALID_FILE_ATTRIBUTES) + return false; + + if (attr & FILE_ATTRIBUTE_DIRECTORY) + return true; + +#else + struct stat s; + + if (stat(dir, &s) != 0) + return false; + + if (S_ISDIR(s.st_mode)) + return true; +#endif + + return false; +} + void OnAmxxAttach() { MF_AddNatives(g_BaseSqlNatives); @@ -29,7 +53,18 @@ void OnAmxxAttach() //override any mysqlx old compat stuff MF_AddNatives(g_OldCompatNatives); - MF_OverrideNatives(g_OldCompatNatives); + MF_OverrideNatives(g_OldCompatNatives, MODULE_NAME); + + char path[255]; + MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite3", MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data")); + if (!DirExists(path)) + { + mkdir(path +#if defined __linux__ + , 0775 +#endif + ); + } } void OnAmxxDetach() diff --git a/dlls/sqlite/oldcompat_sql.cpp b/dlls/sqlite/oldcompat_sql.cpp index b62866bd..c621fb87 100644 --- a/dlls/sqlite/oldcompat_sql.cpp +++ b/dlls/sqlite/oldcompat_sql.cpp @@ -50,6 +50,7 @@ static cell AMX_NATIVE_CALL dbi_connect(AMX *amx, cell *params) int len; DatabaseInfo info; char *name = MF_GetAmxString(amx, params[4], 3, &len); + char path[255]; info.host = ""; info.user = ""; @@ -58,6 +59,19 @@ static cell AMX_NATIVE_CALL dbi_connect(AMX *amx, cell *params) int err; char error[512]; + /** if there is an older database, read there instead of the new path */ + MF_BuildPathnameR(path, sizeof(path)-1, "%s", info.database); + FILE *fp = fopen(path, "rb"); + if (fp) + { + fclose(fp); + info.database = path; + } else { + MF_BuildPathnameR(path, sizeof(path)-1, "%s/sqlite/%s.sq3", + MF_GetLocalInfo("amxx_datadir", "addons/amxmodx/data"), + info.database); + info.database = path; + } IDatabase *pDatabase = g_Sqlite.Connect(&info, &err, error, sizeof(error)-1); if (!pDatabase) { diff --git a/dlls/sqlite/sdk/amxxmodule.cpp b/dlls/sqlite/sdk/amxxmodule.cpp index 3492febb..b83c9903 100755 --- a/dlls/sqlite/sdk/amxxmodule.cpp +++ b/dlls/sqlite/sdk/amxxmodule.cpp @@ -2779,7 +2779,7 @@ void ValidateMacros_DontCallThis_Smiley() MF_FindLibrary(NULL, LibType_Class); MF_AddLibraries(NULL, LibType_Class, NULL); MF_RemoveLibraries(NULL); - MF_OverrideNatives(NULL); + MF_OverrideNatives(NULL, NULL); } #endif diff --git a/dlls/sqlite/sdk/amxxmodule.h b/dlls/sqlite/sdk/amxxmodule.h index e74febf4..aec781f1 100755 --- a/dlls/sqlite/sdk/amxxmodule.h +++ b/dlls/sqlite/sdk/amxxmodule.h @@ -2179,7 +2179,7 @@ typedef void (*PFN_UNREG_AUTH_FUNC) (AUTHORIZEFUNC); typedef int (*PFN_FINDLIBRARY) (const char * /*name*/, LibType /*type*/); typedef size_t (*PFN_ADDLIBRARIES) (const char * /*name*/, LibType /*type*/, void * /*parent*/); typedef size_t (*PFN_REMOVELIBRARIES) (void * /*parent*/); -typedef void (*PFN_OVERRIDENATIVES) (AMX_NATIVE_INFO * /*natives*/); +typedef void (*PFN_OVERRIDENATIVES) (AMX_NATIVE_INFO * /*natives*/, const char * /*myname*/); typedef const char * (*PFN_GETLOCALINFO) (const char * /*name*/, const char * /*def*/); typedef int (*PFN_AMX_REREGISTER) (AMX * /*amx*/, AMX_NATIVE_INFO * /*list*/, int /*list*/); typedef void * (*PFN_REGISTERFUNCTIONEX) (void * /*pfn*/, const char * /*desc*/); @@ -2324,7 +2324,7 @@ void MF_UnregAuthFunc (AUTHORIZEFUNC fn) { } int MF_FindLibrary (const char *name, LibType type) { } size_t MF_AddLibraries (const char *name, LibType type, void *parent) { } size_t MF_RemoveLibraries (void *parent) { } -void MF_OverrideNatives (AMX_NATIVE_INFO *natives) { } +void MF_OverrideNatives (AMX_NATIVE_INFO *natives, const char *myname) { } const char * MF_GetLocalInfo (const char *name, const char *def) { } int MF_AmxReRegister (AMX *amx, AMX_NATIVE_INFO *list, int number) { return 0; } void * MF_RegisterFunctionEx (void *pfn, const char *description) { } diff --git a/dlls/sqlite/sdk/moduleconfig.h b/dlls/sqlite/sdk/moduleconfig.h index 5c0c14ed..c3a44ca1 100755 --- a/dlls/sqlite/sdk/moduleconfig.h +++ b/dlls/sqlite/sdk/moduleconfig.h @@ -107,7 +107,7 @@ // #define FN_ServerDeactivate ServerDeactivate /* pfnServerDeactivate() (wd) Server is leaving the map (shutdown or changelevel); SDK2 */ // #define FN_PlayerPreThink PlayerPreThink /* pfnPlayerPreThink() */ // #define FN_PlayerPostThink PlayerPostThink /* pfnPlayerPostThink() */ -// #define FN_StartFrame StartFrame /* pfnStartFrame() */ +#define FN_StartFrame StartFrame /* pfnStartFrame() */ // #define FN_ParmsNewLevel ParmsNewLevel /* pfnParmsNewLevel() */ // #define FN_ParmsChangeLevel ParmsChangeLevel /* pfnParmsChangeLevel() */ // #define FN_GetGameDescription GetGameDescription /* pfnGetGameDescription() Returns string describing current .dll. E.g. "TeamFotrress 2" "Half-Life" */ diff --git a/dlls/sqlite/sqlitepp/SqliteQuery.cpp b/dlls/sqlite/sqlitepp/SqliteQuery.cpp index ca97cdeb..fb7a00ae 100644 --- a/dlls/sqlite/sqlitepp/SqliteQuery.cpp +++ b/dlls/sqlite/sqlitepp/SqliteQuery.cpp @@ -78,7 +78,6 @@ bool SqliteQuery::ExecuteR(QueryInfo *info, char *error, size_t maxlength) data.results = results; SqliteResultSet *pRes = new SqliteResultSet(data); - m_LastRes = pRes; info->rs = static_cast(pRes); } else { info->rs = NULL; diff --git a/dlls/sqlite/thread/WinThreads.cpp b/dlls/sqlite/thread/WinThreads.cpp index 6f3f436f..0d15da9d 100644 --- a/dlls/sqlite/thread/WinThreads.cpp +++ b/dlls/sqlite/thread/WinThreads.cpp @@ -97,7 +97,7 @@ IThreadHandle *WinThreader::MakeThread(IThread *pThread, const ThreadParams *par IEventSignal *WinThreader::MakeEventSignal() { - HANDLE event = CreateEventA(NULL, FALSE, FALSE, NULL); + HANDLE event = CreateEventA(NULL, TRUE, TRUE, NULL); if (!event) return NULL; @@ -275,6 +275,7 @@ WinThreader::WinEvent::~WinEvent() void WinThreader::WinEvent::Wait() { WaitForSingleObject(m_event, INFINITE); + ResetEvent(m_event); } void WinThreader::WinEvent::Signal()