mirror of https://github.com/OpenTTD/OpenTTD
(svn r8872) [0.5] -Backport from trunk (r8784, r8821, r8823, r8824):
- Unable to load TTDP (on *NIX) games (r8784) - Unable to browse directories on *nix if the filesystem is not in UTF-8 charset and special characters are used (r8821, r8823, r8824)release/0.5
parent
36134a7285
commit
9e3f020ae8
10
fios.c
10
fios.c
|
@ -20,7 +20,6 @@
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#else
|
#else
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <dirent.h>
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
/* Variables to display file lists */
|
/* Variables to display file lists */
|
||||||
|
@ -201,6 +200,7 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
FiosItem *fios;
|
FiosItem *fios;
|
||||||
int sort_start;
|
int sort_start;
|
||||||
|
char d_name[sizeof(fios->name)];
|
||||||
|
|
||||||
/* A parent directory link exists if we are not in the root directory */
|
/* A parent directory link exists if we are not in the root directory */
|
||||||
if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
|
if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
|
||||||
|
@ -212,9 +212,9 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show subdirectories */
|
/* 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) {
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
const char *d_name = FS2OTTD(dirent->d_name);
|
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
|
||||||
|
|
||||||
/* found file must be directory, but not '.' or '..' */
|
/* found file must be directory, but not '.' or '..' */
|
||||||
if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
|
if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
|
||||||
|
@ -242,13 +242,13 @@ static FiosItem *FiosGetFileList(int mode, fios_getlist_callback_proc *callback_
|
||||||
sort_start = _fios_count;
|
sort_start = _fios_count;
|
||||||
|
|
||||||
/* Show files */
|
/* Show files */
|
||||||
dir = opendir(_fios_path);
|
dir = ttd_opendir(_fios_path);
|
||||||
if (dir != NULL) {
|
if (dir != NULL) {
|
||||||
while ((dirent = readdir(dir)) != NULL) {
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
char fios_title[64];
|
char fios_title[64];
|
||||||
char *t;
|
char *t;
|
||||||
char *d_name = (char*)FS2OTTD(dirent->d_name);
|
|
||||||
byte type;
|
byte type;
|
||||||
|
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
|
||||||
|
|
||||||
if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue;
|
if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG)) continue;
|
||||||
|
|
||||||
|
|
19
fios.h
19
fios.h
|
@ -77,10 +77,25 @@ struct DIR {
|
||||||
bool at_first_entry;
|
bool at_first_entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
DIR *opendir(const char *path);
|
DIR *opendir(const wchar_t *path);
|
||||||
struct dirent *readdir(DIR *d);
|
struct dirent *readdir(DIR *d);
|
||||||
int closedir(DIR *d);
|
int closedir(DIR *d);
|
||||||
|
#else
|
||||||
|
/* Use system-supplied opendir/readdir/closedir functions */
|
||||||
|
# include <sys/types.h>
|
||||||
|
# include <dirent.h>
|
||||||
#endif /* defined(WIN32) */
|
#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 */
|
#endif /* FIOS_H */
|
||||||
|
|
|
@ -15,14 +15,10 @@
|
||||||
|
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "fios.h"
|
#include "fios.h"
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#else
|
|
||||||
# include <unistd.h>
|
|
||||||
# include <dirent.h>
|
|
||||||
#endif /* WIN32 */
|
#endif /* WIN32 */
|
||||||
|
|
||||||
|
|
||||||
|
@ -266,7 +262,7 @@ static uint ScanPath(const char *path)
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
GRFConfig *c;
|
GRFConfig *c;
|
||||||
|
|
||||||
if ((dir = opendir(path)) == NULL) return 0;
|
if ((dir = ttd_opendir(path)) == NULL) return 0;
|
||||||
|
|
||||||
while ((dirent = readdir(dir)) != NULL) {
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
const char *d_name = FS2OTTD(dirent->d_name);
|
const char *d_name = FS2OTTD(dirent->d_name);
|
||||||
|
|
|
@ -23,13 +23,8 @@
|
||||||
#include "date.h"
|
#include "date.h"
|
||||||
#include "industry.h"
|
#include "industry.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
/* for opendir/readdir/closedir */
|
/* for opendir/readdir/closedir */
|
||||||
# include "fios.h"
|
# include "fios.h"
|
||||||
#else
|
|
||||||
# include <sys/types.h>
|
|
||||||
# include <dirent.h>
|
|
||||||
#endif /* WIN32 */
|
|
||||||
|
|
||||||
char _userstring[128];
|
char _userstring[128];
|
||||||
|
|
||||||
|
@ -1225,7 +1220,7 @@ static int GetLanguageList(char **languages, int max)
|
||||||
struct dirent *dirent;
|
struct dirent *dirent;
|
||||||
int num = 0;
|
int num = 0;
|
||||||
|
|
||||||
dir = opendir(_paths.lang_dir);
|
dir = ttd_opendir(_paths.lang_dir);
|
||||||
if (dir != NULL) {
|
if (dir != NULL) {
|
||||||
while ((dirent = readdir(dir)) != NULL) {
|
while ((dirent = readdir(dir)) != NULL) {
|
||||||
const char *d_name = FS2OTTD(dirent->d_name);
|
const char *d_name = FS2OTTD(dirent->d_name);
|
||||||
|
|
11
win32.c
11
win32.c
|
@ -652,19 +652,20 @@ static inline void dir_free(DIR *d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DIR *opendir(const char *path)
|
DIR *opendir(const wchar_t *path)
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
UINT sem = SetErrorMode(SEM_FAILCRITICALERRORS); // disable 'no-disk' message box
|
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)) {
|
if ((fa != INVALID_FILE_ATTRIBUTES) && (fa & FILE_ATTRIBUTE_DIRECTORY)) {
|
||||||
d = dir_calloc();
|
d = dir_calloc();
|
||||||
if (d != NULL) {
|
if (d != NULL) {
|
||||||
char search_path[MAX_PATH];
|
wchar_t search_path[MAX_PATH];
|
||||||
/* build search path for FindFirstFile */
|
/* build search path for FindFirstFile */
|
||||||
snprintf(search_path, lengthof(search_path), "%s" PATHSEP "*", path);
|
_snwprintf(search_path, lengthof(search_path), L"%s\\*", path);
|
||||||
d->hFind = FindFirstFileW(OTTD2FS(search_path), &d->fd);
|
*lastof(search_path) = '\0';
|
||||||
|
d->hFind = FindFirstFileW(search_path, &d->fd);
|
||||||
|
|
||||||
if (d->hFind != INVALID_HANDLE_VALUE ||
|
if (d->hFind != INVALID_HANDLE_VALUE ||
|
||||||
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty
|
GetLastError() == ERROR_NO_MORE_FILES) { // the directory is empty
|
||||||
|
|
Loading…
Reference in New Issue