From be03cc956498f7b29b7412897f0dd12e4c6d133e Mon Sep 17 00:00:00 2001 From: RamonUnch <74856804+RamonUnch@users.noreply.github.com> Date: Sun, 19 May 2024 22:07:22 +0200 Subject: [PATCH 1/2] Add support for non-portable mode --- altsnap.c | 17 +++++++++++++++-- hooks.c | 9 ++++----- hooks.h | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/altsnap.c b/altsnap.c index 4f72f3b2..fc3ee939 100644 --- a/altsnap.c +++ b/altsnap.c @@ -85,9 +85,9 @@ int HookSystem() return 1; } } - HWND (WINAPI *Load)(HWND) = (HWND (WINAPI *)(HWND))GetProcAddress(hinstDLL, LOAD_PROC); + HWND (WINAPI *Load)(HWND, const TCHAR *) = (HWND (WINAPI *)(HWND, const TCHAR*))GetProcAddress(hinstDLL, LOAD_PROC); if(Load) { - g_dllmsgHKhwnd = Load(g_hwnd); + g_dllmsgHKhwnd = Load(g_hwnd, inipath); } LOG("HOOKS.DLL Loaded"); @@ -438,6 +438,19 @@ int WINAPI tWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, TCHAR *params, int GetModuleFileName(NULL, inipath, ARR_SZ(inipath)); inipath[MAX_PATH-1] = '\0'; lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("ini")); + if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(inipath) + && GetEnvironmentVariable(TEXT("APPDATA"), NULL, 0)) { + // .ini file is not in current directorry, and APPDATA exists + // we should look for %APPDATA%\AltSnap\AltSnap.ini + GetEnvironmentVariable(TEXT("APPDATA"), inipath, ARR_SZ(inipath)); + lstrcat_s(inipath, ARR_SZ(inipath), TEXT("\\AltSnap")); + if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(inipath)) { + CreateDirectory(inipath, NULL); + } + lstrcat_s(inipath, ARR_SZ(inipath), TEXT("\\AltSnap.ini")); + } + MessageBox(NULL, inipath, NULL, 0); + LOG("ini file: %S", inipath); // Read parameters on command line diff --git a/hooks.c b/hooks.c index 8709c591..36f441b6 100644 --- a/hooks.c +++ b/hooks.c @@ -6153,7 +6153,7 @@ static void readblacklist(const TCHAR *section, struct blacklist *blacklist, con } // Read all the blacklitsts #define blacklist_section_length 32767 -void readallblacklists(TCHAR *inipath) +void readallblacklists(const TCHAR *inipath) { mem00(&BlkLst, sizeof(BlkLst)); @@ -6376,13 +6376,12 @@ static void freeallinputSequences(void) #ifdef __cplusplus extern "C" #endif -__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd) +__declspec(dllexport) HWND WINAPI Load(HWND mainhwnd, const TCHAR inipath[AT_LEAST MAX_PATH]) { #if defined(_MSC_VER) && _MSC_VER > 1300 #pragma comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__) #endif // Load settings - TCHAR inipath[MAX_PATH]; unsigned i; state.action = AC_NONE; state.shift = 0; @@ -6405,8 +6404,8 @@ __declspec(dllexport) HWND WINAPI Load(HWND mainhwnd) // Get ini path - GetModuleFileName(NULL, inipath, ARR_SZ(inipath)); - lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini")); +// GetModuleFileName(NULL, inipath, ARR_SZ(inipath)); +// lstrcpy(&inipath[lstrlen(inipath)-3], TEXT("ini")); TCHAR stk_inisection[1420], *inisection; // Stack buffer. size_t inisectionlen = 8192; diff --git a/hooks.h b/hooks.h index 0342337d..39314fa7 100644 --- a/hooks.h +++ b/hooks.h @@ -15,7 +15,7 @@ #define UNLOAD_PROC "Unload" #else #define LOW_LEVEL_KB_PROC "_LowLevelKeyboardProc@12" - #define LOAD_PROC "_Load@4" + #define LOAD_PROC "_Load@8" #define UNLOAD_PROC "_Unload@0" #endif #endif From ba04c858807e412564e0f360ad5778070ebaf925 Mon Sep 17 00:00:00 2001 From: RamonUnch <74856804+RamonUnch@users.noreply.github.com> Date: Sat, 25 May 2024 08:15:44 +0200 Subject: [PATCH 2/2] copy altsnap.dni if no ini file found in user's folder --- altsnap.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/altsnap.c b/altsnap.c index fc3ee939..6fd57840 100644 --- a/altsnap.c +++ b/altsnap.c @@ -442,15 +442,24 @@ int WINAPI tWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, TCHAR *params, int && GetEnvironmentVariable(TEXT("APPDATA"), NULL, 0)) { // .ini file is not in current directorry, and APPDATA exists // we should look for %APPDATA%\AltSnap\AltSnap.ini - GetEnvironmentVariable(TEXT("APPDATA"), inipath, ARR_SZ(inipath)); - lstrcat_s(inipath, ARR_SZ(inipath), TEXT("\\AltSnap")); - if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(inipath)) { - CreateDirectory(inipath, NULL); + TCHAR userini[MAX_PATH]; + GetEnvironmentVariable(TEXT("APPDATA"), userini, ARR_SZ(userini)); + lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap")); + if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) { + CreateDirectory(userini, NULL); + LOG("CreateDirectory(%S)", userini); + } + // Full user ini name. + lstrcat_s(userini, ARR_SZ(userini), TEXT("\\AltSnap.ini")); + if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(userini)) { + // Copy AltSnap.dni (Default ini file) if no ini present + lstrcpy_s(&inipath[lstrlen(inipath)-3], 4, TEXT("dni")); + CopyFile(inipath, userini, FALSE); // AltSnap.dni -> AltSnap.ini + LOG("CopyFile(%S -> %S)", inipath, userini); } - lstrcat_s(inipath, ARR_SZ(inipath), TEXT("\\AltSnap.ini")); - } - MessageBox(NULL, inipath, NULL, 0); + lstrcpy_s(inipath, ARR_SZ(inipath), userini); + } LOG("ini file: %S", inipath); // Read parameters on command line