summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-02-20 00:09:23 +0000
committerDarkvater <darkvater@openttd.org>2007-02-20 00:09:23 +0000
commit92bbe45dd031c7a14b9ba55a77a27d66cf07b876 (patch)
tree2597b59d39104907743caf0340df546274f0b559
parent5b237758aaf4ba5d646ccfad2129312f30bfcfb2 (diff)
downloadopenttd-92bbe45dd031c7a14b9ba55a77a27d66cf07b876.tar.xz
(svn r8821) -Regression: Unable to browse directories on *nix if the filesystem is not in UTF-8 charset and special characters are used. The string passed to opendir() which is UTF-8 was not parsed back to the filesystem format. Use a wrapper called ttd_opendir() instead of redefining opendir itself.
-rw-r--r--src/fios.cpp4
-rw-r--r--src/fios.h15
-rw-r--r--src/newgrf_config.cpp2
-rw-r--r--src/strings.cpp2
-rw-r--r--src/win32.cpp10
5 files changed, 22 insertions, 11 deletions
diff --git a/src/fios.cpp b/src/fios.cpp
index 615570742..c8d7fdf8d 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -224,7 +224,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
}
/* Show subdirectories */
- if (mode != SLD_NEW_GAME && (dir = opendir(_fios_path)) != NULL) {
+ if (mode != SLD_NEW_GAME && (dir = ttd_opendir(_fios_path)) != NULL) {
while ((dirent = readdir(dir)) != NULL) {
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
@@ -254,7 +254,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
sort_start = _fios_count;
/* Show files */
- dir = opendir(_fios_path);
+ dir = ttd_opendir(_fios_path);
if (dir != NULL) {
while ((dirent = readdir(dir)) != NULL) {
char fios_title[64];
diff --git a/src/fios.h b/src/fios.h
index 85d0b6041..0663b781b 100644
--- a/src/fios.h
+++ b/src/fios.h
@@ -77,10 +77,21 @@ struct DIR {
bool at_first_entry;
};
-DIR *opendir(const char *path);
+DIR *opendir(const wchar_t *path);
struct dirent *readdir(DIR *d);
int closedir(DIR *d);
-
#endif /* defined(WIN32) */
+/**
+ * A wrapper around opendir() which will convert the string from
+ * OPENTTD encoding to that of the filesystem. For all purposes this
+ * function behaves the same as the original opendir function
+ * @param path string to open directory of
+ * @return DIR pointer
+ */
+static inline DIR *ttd_opendir(const char *path)
+{
+ return opendir(OTTD2FS(path));
+}
+
#endif /* FIOS_H */
diff --git a/src/newgrf_config.cpp b/src/newgrf_config.cpp
index 583b4773b..6b13ecc2e 100644
--- a/src/newgrf_config.cpp
+++ b/src/newgrf_config.cpp
@@ -274,7 +274,7 @@ static uint ScanPath(const char *path)
struct dirent *dirent;
DIR *dir;
- if ((dir = opendir(path)) == NULL) return 0;
+ if ((dir = ttd_opendir(path)) == NULL) return 0;
while ((dirent = readdir(dir)) != NULL) {
const char *d_name = FS2OTTD(dirent->d_name);
diff --git a/src/strings.cpp b/src/strings.cpp
index d794e9c97..d1ab5df0c 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1164,7 +1164,7 @@ static int GetLanguageList(char **languages, int max)
struct dirent *dirent;
int num = 0;
- dir = opendir(_paths.lang_dir);
+ dir = ttd_opendir(_paths.lang_dir);
if (dir != NULL) {
while ((dirent = readdir(dir)) != NULL) {
const char *d_name = FS2OTTD(dirent->d_name);
diff --git a/src/win32.cpp b/src/win32.cpp
index a79fda13a..017d62a2c 100644
--- a/src/win32.cpp
+++ b/src/win32.cpp
@@ -653,19 +653,19 @@ static inline void dir_free(DIR *d)
}
}
-DIR *opendir(const char *path)
+DIR *opendir(const wchar_t *path)
{
DIR *d;
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
- DWORD fa = GetFileAttributesW(OTTD2FS(path));
+ DWORD fa = GetFileAttributesW(path);
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) {
d = dir_calloc();
if (d != NULL) {
- char search_path[MAX_PATH];
+ wchar_t search_path[MAX_PATH];
/* build search path for FindFirstFile */
- snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path);
- d->hFind = FindFirstFileW(OTTD2FS(search_path), &d->fd);
+ _snwprintf_s(search_path, lengthof(search_path), L"%s\\*", path);
+ d->hFind = FindFirstFileW(search_path, &d->fd);
if (d->hFind != INVALID_HANDLE_VALUE ||
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty