fix(platform,core,test): fix Windows compatibility issues
- platform_mkdir now checks if directory exists before creating - Add FILE_ATTRIBUTE_HIDDEN for dot-prefixed directories on Windows - Create parent mods directory before temp directory - Move module unload before copy in reload sequence to fix issue on Windows - Force CMD shell in test makefile on Windows Test makefile now uses cmd.exe instead of bash on Windows, fixing syntax errors when running via build.bat.
This commit is contained in:
+22
-2
@@ -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
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user