Re: [AD] Windows unicode filename support |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
- To: alleg-developers@xxxxxxxxxx
- Subject: Re: [AD] Windows unicode filename support
- From: Chris <chris.kcat@xxxxxxxxxx>
- Date: Wed, 3 May 2006 13:22:18 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:from:to:subject:date:user-agent:references:in-reply-to:mime-version:content-type:message-id; b=pIAWebsJwhHMQLbQJNHjMzw/hS5NcBvZWWw8VXc8MjUyqPUofimJoShLn+ByPoPkKUAHd52HLBXzIOYl1TjV7AOKQr8zFbdjwa4u0UXhxr8kwBQjLqeRx+ynbo4CHIEQsGL4KPFODrmqzTVSQbL4Mo9NCu/TeRhNi1bOhNbK/2U=
On Wednesday 03 May 2006 12:45, Evert Glebbeek wrote:
> Can't you use Allegro's os_type variable to do that?
Yeah, and here is a patch. Tested in Wine, and it works in WinXP mode.
Index: src/win/wfile.c
===================================================================
--- src/win/wfile.c (revision 5781)
+++ src/win/wfile.c (working copy)
@@ -30,7 +30,11 @@
#endif
+#define IS_OLD_WINDOWS (os_type==OSTYPE_WIN3 || os_type==OSTYPE_WIN95 || \
+ os_type==OSTYPE_WIN98 || os_type==OSTYPE_WINME || \
+ os_type==OSTYPE_UNKNOWN)
+
/* _al_file_isok:
* Helper function to check if it is safe to access a file on a floppy
* drive. This really only applies to the DOS library, so we don't bother
@@ -51,10 +55,18 @@
struct _stat s;
char tmp[1024];
- if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
- *allegro_errno = errno;
- return 0;
+ if (IS_OLD_WINDOWS) {
+ if (_stat(uconvert(filename, U_CURRENT, tmp, U_ASCII, sizeof(tmp)), &s) != 0) {
+ *allegro_errno = errno;
+ return 0;
+ }
}
+ else {
+ if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp, U_UNICODE, sizeof(tmp)), &s) != 0) {
+ *allegro_errno = errno;
+ return 0;
+ }
+ }
return s.st_size;
}
@@ -69,10 +81,18 @@
struct _stat s;
char tmp[1024];
- if (_stat(uconvert_toascii(filename, tmp), &s) != 0) {
- *allegro_errno = errno;
- return 0;
+ if (IS_OLD_WINDOWS) {
+ if (_stat(uconvert(filename, U_CURRENT, tmp, U_ASCII, sizeof(tmp)), &s) != 0) {
+ *allegro_errno = errno;
+ return 0;
+ }
}
+ else {
+ if (_wstat((wchar_t*)uconvert(filename, U_CURRENT, tmp, U_UNICODE, sizeof(tmp)), &s) != 0) {
+ *allegro_errno = errno;
+ return 0;
+ }
+ }
return s.st_mtime;
}
@@ -82,7 +102,10 @@
/* structure for use by the directory scanning routines */
struct FF_DATA
{
- struct _finddata_t data;
+ union {
+ struct _finddata_t a;
+ struct _wfinddata_t w;
+ } data;
long handle;
int attrib;
};
@@ -96,11 +119,22 @@
{
struct FF_DATA *ff_data = (struct FF_DATA *) info->ff_data;
- info->attrib = ff_data->data.attrib;
- info->time = ff_data->data.time_write;
- info->size = ff_data->data.size;
+ if (IS_OLD_WINDOWS) {
+ info->attrib = ff_data->data.a.attrib;
+ info->time = ff_data->data.a.time_write;
+ info->size = ff_data->data.a.size;
- do_uconvert(ff_data->data.name, U_ASCII, info->name, U_CURRENT, sizeof(info->name));
+ do_uconvert(ff_data->data.a.name, U_ASCII, info->name, U_CURRENT,
+ sizeof(info->name));
+ }
+ else {
+ info->attrib = ff_data->data.w.attrib;
+ info->time = ff_data->data.w.time_write;
+ info->size = ff_data->data.w.size;
+
+ do_uconvert((const char*)ff_data->data.w.name, U_UNICODE, info->name,
+ U_CURRENT, sizeof(info->name));
+ }
}
@@ -141,22 +175,47 @@
/* start the search */
errno = *allegro_errno = 0;
- ff_data->handle = _findfirst(uconvert_toascii(pattern, tmp), &ff_data->data);
+ if (IS_OLD_WINDOWS) {
+ ff_data->handle = _findfirst(uconvert(pattern, U_CURRENT, tmp,
+ U_ASCII, sizeof(tmp)),
+ &ff_data->data.a);
- if (ff_data->handle < 0) {
- *allegro_errno = errno;
- _AL_FREE(ff_data);
- info->ff_data = NULL;
- return -1;
+ if (ff_data->handle < 0) {
+ *allegro_errno = errno;
+ _AL_FREE(ff_data);
+ info->ff_data = NULL;
+ return -1;
+ }
+
+ if (ff_data->data.a.attrib & ~ff_data->attrib) {
+ if (al_findnext(info) != 0) {
+ al_findclose(info);
+ return -1;
+ }
+ else
+ return 0;
+ }
}
+ else {
+ ff_data->handle = _wfindfirst((wchar_t*)uconvert(pattern, U_CURRENT, tmp,
+ U_UNICODE, sizeof(tmp)),
+ &ff_data->data.w);
- if (ff_data->data.attrib & ~ff_data->attrib) {
- if (al_findnext(info) != 0) {
- al_findclose(info);
+ if (ff_data->handle < 0) {
+ *allegro_errno = errno;
+ _AL_FREE(ff_data);
+ info->ff_data = NULL;
return -1;
}
- else
- return 0;
+
+ if (ff_data->data.w.attrib & ~ff_data->attrib) {
+ if (al_findnext(info) != 0) {
+ al_findclose(info);
+ return -1;
+ }
+ else
+ return 0;
+ }
}
fill_ffblk(info);
@@ -172,14 +231,23 @@
{
struct FF_DATA *ff_data = (struct FF_DATA *) info->ff_data;
- do {
- if (_findnext(ff_data->handle, &ff_data->data) != 0) {
- *allegro_errno = errno;
- return -1;
- }
+ if (IS_OLD_WINDOWS) {
+ do {
+ if (_findnext(ff_data->handle, &ff_data->data.a) != 0) {
+ *allegro_errno = errno;
+ return -1;
+ }
+ } while (ff_data->data.a.attrib & ~ff_data->attrib);
+ }
+ else {
+ do {
+ if (_wfindnext(ff_data->handle, &ff_data->data.w) != 0) {
+ *allegro_errno = errno;
+ return -1;
+ }
+ } while (ff_data->data.w.attrib & ~ff_data->attrib);
+ }
- } while (ff_data->data.attrib & ~ff_data->attrib);
-
fill_ffblk(info);
return 0;
}
@@ -229,8 +297,16 @@
{
char tmp[1024];
- if (_getdcwd(drive+1, tmp, sizeof(tmp)))
- do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
- else
- usetc(buf, 0);
+ if (IS_OLD_WINDOWS) {
+ if (_getdcwd(drive+1, tmp, sizeof(tmp)))
+ do_uconvert(tmp, U_ASCII, buf, U_CURRENT, size);
+ else
+ usetc(buf, 0);
+ }
+ else {
+ if (_wgetdcwd(drive+1, (wchar_t*)tmp, sizeof(tmp)/sizeof(wchar_t*)))
+ do_uconvert(tmp, U_UNICODE, buf, U_CURRENT, size);
+ else
+ usetc(buf, 0);
+ }
}