diff --git a/src/platform.c b/src/platform.c index 6b01dee..3137935 100644 --- a/src/platform.c +++ b/src/platform.c @@ -107,9 +107,29 @@ typedef struct { unsigned char platform_mkdir(const char *path) { #ifdef _WIN32 - return CreateDirectoryA(path, NULL) ? STK_PLATFORM_OPERATION_SUCCESS - : STK_PLATFORM_MKDIR_ERROR; + DWORD attrib; + + attrib = GetFileAttributesA(path); + + if (attrib != INVALID_FILE_ATTRIBUTES && + (attrib & FILE_ATTRIBUTE_DIRECTORY)) + return STK_PLATFORM_OPERATION_SUCCESS; + + if (!CreateDirectoryA(path, NULL)) + return STK_PLATFORM_MKDIR_ERROR; + + if (strrchr(path, '\\') && *(strrchr(path, '\\') + 1) == '.') + SetFileAttributesA(path, FILE_ATTRIBUTE_HIDDEN); + else if (!strrchr(path, '\\') && path[0] == '.') + SetFileAttributesA(path, FILE_ATTRIBUTE_HIDDEN); + + return STK_PLATFORM_OPERATION_SUCCESS; #else + struct stat st; + + if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) + return STK_PLATFORM_OPERATION_SUCCESS; + return mkdir(path, 0755) == 0 ? STK_PLATFORM_OPERATION_SUCCESS : STK_PLATFORM_MKDIR_ERROR; #endif diff --git a/src/stk.c b/src/stk.c index 7fcde51..0317845 100644 --- a/src/stk.c +++ b/src/stk.c @@ -19,7 +19,7 @@ unsigned char stk_flags = STK_FLAG_LOGGING_ENABLED; static char stk_mod_dir[STK_PATH_MAX_OS] = "mods"; static char stk_tmp_name[STK_MOD_ID_BUFFER] = ".tmp"; -static char stk_tmp_dir[STK_PATH_MAX_OS] = "mods/.tmp"; +static char stk_tmp_dir[STK_PATH_MAX_OS] = ""; static void *watch_handle = NULL; char (*platform_directory_init_scan(const char *path, @@ -77,6 +77,8 @@ unsigned char stk_init(void) char tmp_path[STK_PATH_MAX_OS]; int load_result; + platform_mkdir(stk_mod_dir); + build_path(stk_tmp_dir, sizeof(stk_tmp_dir), stk_mod_dir, stk_tmp_name); if (platform_mkdir(stk_tmp_dir) != STK_PLATFORM_OPERATION_SUCCESS) { char (*test_scan)[STK_PATH_MAX]; size_t test_count; @@ -263,6 +265,8 @@ begin_operations: build_path(tmp_path, sizeof(tmp_path), stk_tmp_dir, file_list[file_index]); + stk_module_unload(mod_index); + if (platform_copy_file(full_path, tmp_path) != STK_PLATFORM_OPERATION_SUCCESS) { stk_log(STK_LOG_ERROR, "Failed to copy %s for reload", @@ -270,8 +274,6 @@ begin_operations: continue; } - stk_module_unload(mod_index); - load_result = stk_module_load(tmp_path, mod_index); if (load_result != STK_MOD_INIT_SUCCESS) { stk_log(STK_LOG_ERROR, "Failed to reload module %s: %s", diff --git a/test/gmake.mk b/test/gmake.mk index cb9c5a2..5bf3f03 100644 --- a/test/gmake.mk +++ b/test/gmake.mk @@ -3,6 +3,8 @@ CFLAGS = -Wall -Wpedantic -I../include -std=c89 LDFLAGS = -L../bin/debug -lstk ifeq ($(OS),Windows_NT) + SHELL := cmd.exe + .SHELLFLAGS := /c MODULE_EXT = .dll EXE_EXT = .exe else