diff options
Diffstat (limited to 'src/file-utils.c')
-rw-r--r-- | src/file-utils.c | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/file-utils.c b/src/file-utils.c index 239cc5f..3f8f721 100644 --- a/src/file-utils.c +++ b/src/file-utils.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2023 Robin Haberkorn + * Copyright (C) 2012-2024 Robin Haberkorn * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,6 +28,7 @@ #ifdef HAVE_WINDOWS_H #define WIN32_LEAN_AND_MEAN +#define UNICODE #include <windows.h> #endif @@ -36,7 +37,6 @@ #include "sciteco.h" #include "qreg.h" -#include "glob.h" #include "interface.h" #include "string-utils.h" #include "file-utils.h" @@ -56,26 +56,35 @@ G_STATIC_ASSERT(INVALID_FILE_ATTRIBUTES == TECO_FILE_INVALID_ATTRIBUTES); teco_file_attributes_t teco_file_get_attributes(const gchar *filename) { - return GetFileAttributes((LPCTSTR)filename); + g_autofree gunichar2 *filename_utf16 = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); + return filename_utf16 ? GetFileAttributesW(filename_utf16) + : TECO_FILE_INVALID_ATTRIBUTES; } void teco_file_set_attributes(const gchar *filename, teco_file_attributes_t attrs) { - SetFileAttributes((LPCTSTR)filename, attrs); + g_autofree gunichar2 *filename_utf16 = g_utf8_to_utf16(filename, -1, NULL, NULL, NULL); + if (filename_utf16) + SetFileAttributesW(filename_utf16, attrs); } gchar * teco_file_get_absolute_path(const gchar *path) { + if (!path) + return NULL; + g_autofree gunichar2 *path_utf16 = g_utf8_to_utf16(path, -1, NULL, NULL, NULL); TCHAR buf[MAX_PATH]; - return path && GetFullPathName(path, sizeof(buf), buf, NULL) ? g_strdup(buf) : NULL; + return path_utf16 && GetFullPathNameW(path_utf16, G_N_ELEMENTS(buf), buf, NULL) + ? g_utf16_to_utf8(buf, -1, NULL, NULL, NULL) : NULL; } gboolean teco_file_is_visible(const gchar *path) { - return !(GetFileAttributes((LPCTSTR)path) & FILE_ATTRIBUTE_HIDDEN); + g_autofree gunichar2 *path_utf16 = g_utf8_to_utf16(path, -1, NULL, NULL, NULL); + return path_utf16 && !(GetFileAttributesW(path_utf16) & FILE_ATTRIBUTE_HIDDEN); } #else /* !G_OS_WIN32 */ @@ -83,7 +92,7 @@ teco_file_is_visible(const gchar *path) teco_file_attributes_t teco_file_get_attributes(const gchar *filename) { - struct stat buf; + GStatBuf buf; return g_stat(filename, &buf) ? TECO_FILE_INVALID_ATTRIBUTES : buf.st_mode; } @@ -204,7 +213,7 @@ teco_file_expand_path(const gchar *path) * but it may have been changed later on. */ g_auto(teco_string_t) home = {NULL, 0}; - if (!qreg->vtable->get_string(qreg, &home.data, &home.len, NULL) || + if (!qreg->vtable->get_string(qreg, &home.data, &home.len, NULL, NULL) || teco_string_contains(&home, '\0')) return g_strdup(path); g_assert(home.data != NULL); @@ -227,9 +236,6 @@ teco_file_auto_complete(const gchar *filename, GFileTest file_test, teco_string_ { memset(insert, 0, sizeof(*insert)); - if (teco_globber_is_pattern(filename)) - return FALSE; - g_autofree gchar *filename_expanded = teco_file_expand_path(filename); gsize filename_len = strlen(filename_expanded); |