author | Ryan C. Gordon <icculus@icculus.org> |
Wed, 21 Mar 2012 23:52:44 -0400 | |
changeset 1245 | 1709a0f75ee3 |
parent 1244 | 528c98081b16 |
child 1246 | 4fa9fe3e0b52 |
permissions | -rw-r--r-- |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
1 |
/* |
810 | 2 |
* Windows support routines for PhysicsFS. |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
3 |
* |
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
4 |
* Please see the file LICENSE.txt in the source's root directory. |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
5 |
* |
198 | 6 |
* This file written by Ryan C. Gordon, and made sane by Gregory S. Read. |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
7 |
*/ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
8 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
9 |
#define __PHYSICSFS_INTERNAL__ |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
10 |
#include "physfs_platforms.h" |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
11 |
|
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
12 |
#ifdef PHYSFS_PLATFORM_WINDOWS |
327
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
313
diff
changeset
|
13 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
14 |
/* Forcibly disable UNICODE macro, since we manage this ourselves. */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
15 |
#ifdef UNICODE |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
16 |
#undef UNICODE |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
17 |
#endif |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
18 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
19 |
#define WIN32_LEAN_AND_MEAN 1 |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
20 |
#include <windows.h> |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
21 |
#include <userenv.h> |
1244
528c98081b16
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1242
diff
changeset
|
22 |
#include <shlobj.h> |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
23 |
#include <dbt.h> |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
24 |
#include <errno.h> |
76
d6405544e896
__PHYSFS_platformGetUserDir() checks some win32 standard environment variables,
Ryan C. Gordon <icculus@icculus.org>
parents:
71
diff
changeset
|
25 |
#include <ctype.h> |
262
2d332d53c263
-Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents:
240
diff
changeset
|
26 |
#include <time.h> |
210
f5507414f7b7
-Added optional DISABLE_NT_SUPPORT to not compile NT specific code
Gregory S. Read <zeph@clutteredmind.org>
parents:
198
diff
changeset
|
27 |
|
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
28 |
#include "physfs_internal.h" |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
29 |
|
908
662ca06432ef
Mingw32 fix for 64-bit literals.
Ryan C. Gordon <icculus@icculus.org>
parents:
906
diff
changeset
|
30 |
#define LOWORDER_UINT64(pos) ((PHYSFS_uint32) (pos & 0xFFFFFFFF)) |
662ca06432ef
Mingw32 fix for 64-bit literals.
Ryan C. Gordon <icculus@icculus.org>
parents:
906
diff
changeset
|
31 |
#define HIGHORDER_UINT64(pos) ((PHYSFS_uint32) ((pos >> 32) & 0xFFFFFFFF)) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
32 |
|
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
33 |
/* |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
34 |
* Users without the platform SDK don't have this defined. The original docs |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
35 |
* for SetFilePointer() just said to compare with 0xFFFFFFFF, so this should |
784 | 36 |
* work as desired. |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
37 |
*/ |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
38 |
#define PHYSFS_INVALID_SET_FILE_POINTER 0xFFFFFFFF |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
39 |
|
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
40 |
/* just in case... */ |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
41 |
#define PHYSFS_INVALID_FILE_ATTRIBUTES 0xFFFFFFFF |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
42 |
|
875
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
43 |
/* Not defined before the Vista SDK. */ |
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
44 |
#define PHYSFS_IO_REPARSE_TAG_SYMLINK 0xA000000C |
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
45 |
|
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
46 |
|
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
47 |
#define UTF8_TO_UNICODE_STACK_MACRO(w_assignto, str) { \ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
48 |
if (str == NULL) \ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
49 |
w_assignto = NULL; \ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
50 |
else { \ |
915
1445c55cdbe6
Fixed allocation size when converting from UTF-8 to UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents:
910
diff
changeset
|
51 |
const PHYSFS_uint64 len = (PHYSFS_uint64) ((strlen(str) + 1) * 2); \ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
52 |
w_assignto = (WCHAR *) __PHYSFS_smallAlloc(len); \ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
53 |
if (w_assignto != NULL) \ |
1237
6d8b32355a28
Use UTF-16 on Windows, not UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents:
1226
diff
changeset
|
54 |
PHYSFS_utf8ToUtf16(str, (PHYSFS_uint16 *) w_assignto, len); \ |
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
55 |
} \ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
56 |
} \ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
57 |
|
1237
6d8b32355a28
Use UTF-16 on Windows, not UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents:
1226
diff
changeset
|
58 |
/* Note this counts WCHARs, not codepoints! */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
59 |
static PHYSFS_uint64 wStrLen(const WCHAR *wstr) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
60 |
{ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
61 |
PHYSFS_uint64 len = 0; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
62 |
while (*(wstr++)) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
63 |
len++; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
64 |
return len; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
65 |
} /* wStrLen */ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
66 |
|
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
67 |
static char *unicodeToUtf8Heap(const WCHAR *w_str) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
68 |
{ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
69 |
char *retval = NULL; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
70 |
if (w_str != NULL) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
71 |
{ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
72 |
void *ptr = NULL; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
73 |
const PHYSFS_uint64 len = (wStrLen(w_str) * 4) + 1; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
74 |
retval = allocator.Malloc(len); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
75 |
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1237
6d8b32355a28
Use UTF-16 on Windows, not UCS-2.
Ryan C. Gordon <icculus@icculus.org>
parents:
1226
diff
changeset
|
76 |
PHYSFS_utf8FromUtf16((const PHYSFS_uint16 *) w_str, retval, len); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
77 |
ptr = allocator.Realloc(retval, strlen(retval) + 1); /* shrink. */ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
78 |
if (ptr != NULL) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
79 |
retval = (char *) ptr; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
80 |
} /* if */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
81 |
return retval; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
82 |
} /* unicodeToUtf8Heap */ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
83 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
84 |
/* !!! FIXME: do we really need readonly? If not, do we need this struct? */ |
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
85 |
typedef struct |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
86 |
{ |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
87 |
HANDLE handle; |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
88 |
int readonly; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
89 |
} WinApiFile; |
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
90 |
|
864
ce0fcbbba8a3
Man, I knew I would need getOSInfo() as soon as I deleted it!
Ryan C. Gordon <icculus@icculus.org>
parents:
862
diff
changeset
|
91 |
|
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
92 |
/* !!! FIXME: we cache userDir in physfs.c during PHYSFS_init(), too. */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
93 |
static char *userDir = NULL; |
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
94 |
static HANDLE libUserEnv = NULL; |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
95 |
static HANDLE detectCDThreadHandle = NULL; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
96 |
static HWND detectCDHwnd = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
97 |
static volatile int initialDiscDetectionComplete = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
98 |
static volatile DWORD drivesWithMediaBitmap = 0; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
99 |
|
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
100 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
101 |
static PHYSFS_ErrorCode errcodeFromWinApiError(const DWORD err) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
102 |
{ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
103 |
/* |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
104 |
* win32 error codes are sort of a tricky thing; Microsoft intentionally |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
105 |
* doesn't list which ones a given API might trigger, there are several |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
106 |
* with overlapping and unclear meanings...and there's 16 thousand of |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
107 |
* them in Windows 7. It looks like the ones we care about are in the |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
108 |
* first 500, but I can't say this list is perfect; we might miss |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
109 |
* important values or misinterpret others. |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
110 |
* |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
111 |
* Don't treat this list as anything other than a work in progress. |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
112 |
*/ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
113 |
switch (err) |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
114 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
115 |
case ERROR_SUCCESS: return PHYSFS_ERR_OK; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
116 |
case ERROR_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
117 |
case ERROR_NETWORK_ACCESS_DENIED: return PHYSFS_ERR_PERMISSION; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
118 |
case ERROR_NOT_READY: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
119 |
case ERROR_CRC: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
120 |
case ERROR_SEEK: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
121 |
case ERROR_SECTOR_NOT_FOUND: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
122 |
case ERROR_NOT_DOS_DISK: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
123 |
case ERROR_WRITE_FAULT: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
124 |
case ERROR_READ_FAULT: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
125 |
case ERROR_DEV_NOT_EXIST: return PHYSFS_ERR_IO; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
126 |
/* !!! FIXME: ?? case ELOOP: return PHYSFS_ERR_SYMLINK_LOOP; */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
127 |
case ERROR_BUFFER_OVERFLOW: return PHYSFS_ERR_BAD_FILENAME; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
128 |
case ERROR_INVALID_NAME: return PHYSFS_ERR_BAD_FILENAME; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
129 |
case ERROR_BAD_PATHNAME: return PHYSFS_ERR_BAD_FILENAME; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
130 |
case ERROR_DIRECTORY: return PHYSFS_ERR_BAD_FILENAME; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
131 |
case ERROR_FILE_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
132 |
case ERROR_PATH_NOT_FOUND: return PHYSFS_ERR_NO_SUCH_PATH; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
133 |
case ERROR_DELETE_PENDING: return PHYSFS_ERR_NO_SUCH_PATH; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
134 |
case ERROR_INVALID_DRIVE: return PHYSFS_ERR_NO_SUCH_PATH; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
135 |
case ERROR_HANDLE_DISK_FULL: return PHYSFS_ERR_NO_SPACE; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
136 |
case ERROR_DISK_FULL: return PHYSFS_ERR_NO_SPACE; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
137 |
/* !!! FIXME: ?? case ENOTDIR: return PHYSFS_ERR_NO_SUCH_PATH; */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
138 |
/* !!! FIXME: ?? case EISDIR: return PHYSFS_ERR_NOT_A_FILE; */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
139 |
case ERROR_WRITE_PROTECT: return PHYSFS_ERR_READ_ONLY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
140 |
case ERROR_LOCK_VIOLATION: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
141 |
case ERROR_SHARING_VIOLATION: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
142 |
case ERROR_CURRENT_DIRECTORY: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
143 |
case ERROR_DRIVE_LOCKED: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
144 |
case ERROR_PATH_BUSY: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
145 |
case ERROR_BUSY: return PHYSFS_ERR_BUSY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
146 |
case ERROR_NOT_ENOUGH_MEMORY: return PHYSFS_ERR_OUT_OF_MEMORY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
147 |
case ERROR_OUTOFMEMORY: return PHYSFS_ERR_OUT_OF_MEMORY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
148 |
case ERROR_DIR_NOT_EMPTY: return PHYSFS_ERR_DIR_NOT_EMPTY; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
149 |
default: return PHYSFS_ERR_OS_ERROR; |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
150 |
} /* switch */ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
151 |
} /* errcodeFromWinApiError */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
152 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
153 |
static inline PHYSFS_ErrorCode errcodeFromWinApi(void) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
154 |
{ |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
155 |
return errcodeFromWinApiError(GetLastError()); |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
156 |
} /* errcodeFromWinApi */ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
157 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
158 |
|
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
159 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
160 |
/* |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
161 |
* On success, module-scope variable (userDir) will have a pointer to |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
162 |
* a malloc()'d string of the user's profile dir, and a non-zero value is |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
163 |
* returned. If we can't determine the profile dir, (userDir) will |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
164 |
* be NULL, and zero is returned. |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
165 |
*/ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
166 |
static int determineUserDir(void) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
167 |
{ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
168 |
typedef BOOL (WINAPI *fnGetUserProfDirW)(HANDLE, LPWSTR, LPDWORD); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
169 |
fnGetUserProfDirW pGetDir = NULL; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
170 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
171 |
HANDLE accessToken = NULL; /* Security handle to process */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
172 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
173 |
if (userDir != NULL) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
174 |
return 1; /* already good to go. */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
175 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
176 |
pGetDir = (fnGetUserProfDirW) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
177 |
GetProcAddress(libUserEnv, "GetUserProfileDirectoryW"); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
178 |
BAIL_IF_MACRO(pGetDir == NULL, errcodeFromWinApi(), 0); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
179 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
180 |
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &accessToken)) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
181 |
BAIL_MACRO(errcodeFromWinApi(), 0); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
182 |
else |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
183 |
{ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
184 |
DWORD psize = 0; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
185 |
WCHAR dummy = 0; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
186 |
LPWSTR wstr = NULL; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
187 |
BOOL rc = 0; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
188 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
189 |
/* |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
190 |
* Should fail. Will write the size of the profile path in |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
191 |
* psize. Also note that the second parameter can't be |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
192 |
* NULL or the function fails. |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
193 |
*/ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
194 |
rc = pGetDir(accessToken, &dummy, &psize); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
195 |
assert(!rc); /* !!! FIXME: handle this gracefully. */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
196 |
(void) rc; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
197 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
198 |
/* Allocate memory for the profile directory */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
199 |
wstr = (LPWSTR) __PHYSFS_smallAlloc(psize * sizeof (WCHAR)); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
200 |
if (wstr != NULL) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
201 |
{ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
202 |
if (pGetDir(accessToken, wstr, &psize)) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
203 |
userDir = unicodeToUtf8Heap(wstr); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
204 |
__PHYSFS_smallFree(wstr); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
205 |
} /* if */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
206 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
207 |
CloseHandle(accessToken); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
208 |
} /* if */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
209 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
210 |
return 1; /* We made it: hit the showers. */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
211 |
} /* determineUserDir */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
212 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
213 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
214 |
typedef BOOL (WINAPI *fnSTEM)(DWORD, LPDWORD b); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
215 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
216 |
static DWORD pollDiscDrives(void) |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
217 |
{ |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
218 |
/* Try to use SetThreadErrorMode(), which showed up in Windows 7. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
219 |
HANDLE lib = LoadLibraryA("kernel32.dll"); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
220 |
fnSTEM stem = NULL; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
221 |
char drive[4] = { 'x', ':', '\\', '\0' }; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
222 |
DWORD oldErrorMode = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
223 |
DWORD drives = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
224 |
DWORD i; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
225 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
226 |
if (lib) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
227 |
stem = (fnSTEM) GetProcAddress(lib, "SetThreadErrorMode"); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
228 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
229 |
if (stem) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
230 |
stem(SEM_FAILCRITICALERRORS, &oldErrorMode); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
231 |
else |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
232 |
oldErrorMode = SetErrorMode(SEM_FAILCRITICALERRORS); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
233 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
234 |
/* Do detection. This may block if a disc is spinning up. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
235 |
for (i = 'A'; i <= 'Z'; i++) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
236 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
237 |
DWORD tmp = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
238 |
drive[0] = (char) i; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
239 |
if (GetDriveTypeA(drive) != DRIVE_CDROM) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
240 |
continue; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
241 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
242 |
/* If this function succeeds, there's media in the drive */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
243 |
if (GetVolumeInformationA(drive, NULL, 0, NULL, NULL, &tmp, NULL, 0)) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
244 |
drives |= (1 << (i - 'A')); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
245 |
} /* for */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
246 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
247 |
if (stem) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
248 |
stem(oldErrorMode, NULL); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
249 |
else |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
250 |
SetErrorMode(oldErrorMode); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
251 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
252 |
if (lib) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
253 |
FreeLibrary(lib); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
254 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
255 |
return drives; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
256 |
} /* pollDiscDrives */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
257 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
258 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
259 |
static LRESULT CALLBACK detectCDWndProc(HWND hwnd, UINT msg, |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
260 |
WPARAM wp, LPARAM lparam) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
261 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
262 |
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR) lparam; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
263 |
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME) lparam; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
264 |
const int removed = (wp == DBT_DEVICEREMOVECOMPLETE); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
265 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
266 |
if (msg == WM_DESTROY) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
267 |
return 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
268 |
else if ((msg != WM_DEVICECHANGE) || |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
269 |
((wp != DBT_DEVICEARRIVAL) && (wp != DBT_DEVICEREMOVECOMPLETE)) || |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
270 |
(lpdb->dbch_devicetype != DBT_DEVTYP_VOLUME) || |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
271 |
((lpdbv->dbcv_flags & DBTF_MEDIA) == 0)) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
272 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
273 |
return DefWindowProcW(hwnd, msg, wp, lparam); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
274 |
} /* else if */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
275 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
276 |
if (removed) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
277 |
drivesWithMediaBitmap &= ~lpdbv->dbcv_unitmask; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
278 |
else |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
279 |
drivesWithMediaBitmap |= lpdbv->dbcv_unitmask; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
280 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
281 |
return TRUE; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
282 |
} /* detectCDWndProc */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
283 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
284 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
285 |
static DWORD WINAPI detectCDThread(LPVOID lpParameter) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
286 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
287 |
const char *classname = "PhysicsFSDetectCDCatcher"; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
288 |
const char *winname = "PhysicsFSDetectCDMsgWindow"; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
289 |
HINSTANCE hInstance = GetModuleHandleW(NULL); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
290 |
ATOM class_atom = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
291 |
WNDCLASSEXA wce; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
292 |
MSG msg; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
293 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
294 |
memset(&wce, '\0', sizeof (wce)); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
295 |
wce.cbSize = sizeof (wce); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
296 |
wce.lpfnWndProc = detectCDWndProc; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
297 |
wce.lpszClassName = classname; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
298 |
wce.hInstance = hInstance; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
299 |
class_atom = RegisterClassExA(&wce); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
300 |
if (class_atom == 0) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
301 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
302 |
initialDiscDetectionComplete = 1; /* let main thread go on. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
303 |
return 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
304 |
} /* if */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
305 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
306 |
detectCDHwnd = CreateWindowExA(0, classname, winname, WS_OVERLAPPEDWINDOW, |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
307 |
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
308 |
CW_USEDEFAULT, HWND_DESKTOP, NULL, hInstance, NULL); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
309 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
310 |
if (detectCDHwnd == NULL) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
311 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
312 |
initialDiscDetectionComplete = 1; /* let main thread go on. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
313 |
UnregisterClassA(classname, hInstance); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
314 |
return 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
315 |
} /* if */ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
316 |
|
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
317 |
/* We'll get events when discs come and go from now on. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
318 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
319 |
/* Do initial detection, possibly blocking awhile... */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
320 |
drivesWithMediaBitmap = pollDiscDrives(); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
321 |
initialDiscDetectionComplete = 1; /* let main thread go on. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
322 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
323 |
do |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
324 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
325 |
const BOOL rc = GetMessageW(&msg, detectCDHwnd, 0, 0); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
326 |
if ((rc == 0) || (rc == -1)) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
327 |
break; /* don't care if WM_QUIT or error break this loop. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
328 |
TranslateMessage(&msg); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
329 |
DispatchMessageW(&msg); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
330 |
} while (1); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
331 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
332 |
/* we've been asked to quit. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
333 |
DestroyWindow(detectCDHwnd); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
334 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
335 |
do |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
336 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
337 |
const BOOL rc = GetMessage(&msg, detectCDHwnd, 0, 0); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
338 |
if ((rc == 0) || (rc == -1)) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
339 |
break; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
340 |
TranslateMessage(&msg); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
341 |
DispatchMessageW(&msg); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
342 |
} while (1); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
343 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
344 |
UnregisterClassA(classname, hInstance); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
345 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
346 |
return 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
347 |
} /* detectCDThread */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
348 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
349 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
350 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
351 |
{ |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
352 |
char drive_str[4] = { 'x', ':', '\\', '\0' }; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
353 |
DWORD drives = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
354 |
DWORD i; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
355 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
356 |
/* |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
357 |
* If you poll a drive while a user is inserting a disc, the OS will |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
358 |
* block this thread until the drive has spun up. So we swallow the risk |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
359 |
* once for initial detection, and spin a thread that will get device |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
360 |
* events thereafter, for apps that use this interface to poll for |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
361 |
* disc insertion. |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
362 |
*/ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
363 |
if (!detectCDThreadHandle) |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
364 |
{ |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
365 |
initialDiscDetectionComplete = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
366 |
detectCDThreadHandle = CreateThread(NULL,0,detectCDThread,NULL,0,NULL); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
367 |
if (detectCDThreadHandle == NULL) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
368 |
return; /* oh well. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
369 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
370 |
while (!initialDiscDetectionComplete) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
371 |
Sleep(50); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
372 |
} /* if */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
373 |
|
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
374 |
drives = drivesWithMediaBitmap; /* whatever the thread has seen, we take. */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
375 |
for (i = 'A'; i <= 'Z'; i++) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
376 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
377 |
if (drives & (1 << (i - 'A'))) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
378 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
379 |
drive_str[0] = (char) i; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
380 |
cb(data, drive_str); |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
381 |
} /* if */ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
382 |
} /* for */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
383 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
384 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
385 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
386 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
387 |
{ |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
388 |
DWORD buflen = 64; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
389 |
LPWSTR modpath = NULL; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
390 |
char *retval = NULL; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
391 |
|
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
392 |
while (1) |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
393 |
{ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
394 |
DWORD rc; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
395 |
void *ptr; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
396 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
397 |
if ( (ptr = allocator.Realloc(modpath, buflen*sizeof(WCHAR))) == NULL ) |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
398 |
{ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
399 |
allocator.Free(modpath); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
400 |
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
401 |
} /* if */ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
402 |
modpath = (LPWSTR) ptr; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
403 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
404 |
rc = GetModuleFileNameW(NULL, modpath, buflen); |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
405 |
if (rc == 0) |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
406 |
{ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
407 |
allocator.Free(modpath); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
408 |
BAIL_MACRO(errcodeFromWinApi(), NULL); |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
409 |
} /* if */ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
410 |
|
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
411 |
if (rc < buflen) |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
412 |
{ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
413 |
buflen = rc; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
414 |
break; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
415 |
} /* if */ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
416 |
|
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
417 |
buflen *= 2; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
418 |
} /* while */ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
419 |
|
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
420 |
if (buflen > 0) /* just in case... */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
421 |
{ |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
422 |
WCHAR *ptr = (modpath + buflen) - 1; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
423 |
while (ptr != modpath) |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
424 |
{ |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
425 |
if (*ptr == '\\') |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
426 |
break; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
427 |
ptr--; |
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
428 |
} /* while */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
429 |
|
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
430 |
if ((ptr == modpath) && (*ptr != '\\')) |
1244
528c98081b16
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1242
diff
changeset
|
431 |
__PHYSFS_setError(PHYSFS_ERR_OTHER_ERROR); /* oh well. */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
432 |
else |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
433 |
{ |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
434 |
*(ptr + 1) = '\0'; /* chop off filename. */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
435 |
retval = unicodeToUtf8Heap(modpath); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
436 |
} /* else */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
437 |
} /* else */ |
859
7702965ac1f4
Reworked getExePath() to remove some FIXMEs and respect Unicode.
Ryan C. Gordon <icculus@icculus.org>
parents:
858
diff
changeset
|
438 |
allocator.Free(modpath); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
439 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
440 |
return retval; /* w00t. */ |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
441 |
} /* __PHYSFS_platformCalcBaseDir */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
442 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
443 |
|
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
444 |
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app) |
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
445 |
{ |
1245
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
446 |
/* |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
447 |
* Vista and later has a new API for this, but SHGetFolderPath works there, |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
448 |
* and apparently just wraps the new API. This is the new way to do it: |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
449 |
* |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
450 |
* SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE, |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
451 |
* NULL, &wszPath); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
452 |
*/ |
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
453 |
|
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
454 |
WCHAR path[MAX_PATH]; |
1245
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
455 |
char *utf8 = NULL; |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
456 |
size_t len = 0; |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
457 |
char *retval = NULL; |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
458 |
|
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
459 |
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, |
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
460 |
NULL, 0, path))) |
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
461 |
BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL); |
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
462 |
|
1245
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
463 |
utf8 = unicodeToUtf8Heap(path); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
464 |
BAIL_IF_MACRO(!utf8, ERRPASS, NULL); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
465 |
len = strlen(utf8) + strlen(org) + strlen(app) + 3; |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
466 |
retval = allocator.Malloc(len); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
467 |
if (!retval) |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
468 |
{ |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
469 |
allocator.Free(utf8); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
470 |
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
471 |
} /* if */ |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
472 |
|
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
473 |
sprintf(retval, "%s\\%s\\%s", utf8, org, app); |
1709a0f75ee3
Fixed some brainfarts in the Windows version of PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1244
diff
changeset
|
474 |
return retval; |
1242
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
475 |
} /* __PHYSFS_platformCalcPrefDir */ |
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
476 |
|
1e6db80d2393
Added PHYSFS_getPrefDir().
Ryan C. Gordon <icculus@icculus.org>
parents:
1240
diff
changeset
|
477 |
|
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
478 |
char *__PHYSFS_platformGetUserName(void) |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
479 |
{ |
71 | 480 |
DWORD bufsize = 0; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
481 |
char *retval = NULL; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
482 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
483 |
if (GetUserNameW(NULL, &bufsize) == 0) /* This SHOULD fail. */ |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
484 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
485 |
LPWSTR wbuf = (LPWSTR) __PHYSFS_smallAlloc(bufsize * sizeof (WCHAR)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
486 |
BAIL_IF_MACRO(!wbuf, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
487 |
if (GetUserNameW(wbuf, &bufsize) == 0) /* ?! */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
488 |
__PHYSFS_setError(errcodeFromWinApi()); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
489 |
else |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
490 |
retval = unicodeToUtf8Heap(wbuf); |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
491 |
__PHYSFS_smallFree(wbuf); |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
492 |
} /* if */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
493 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
494 |
return retval; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
495 |
} /* __PHYSFS_platformGetUserName */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
496 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
497 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
498 |
char *__PHYSFS_platformGetUserDir(void) |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
499 |
{ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
500 |
char *retval = (char *) allocator.Malloc(strlen(userDir) + 1); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
501 |
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
502 |
strcpy(retval, userDir); /* calculated at init time. */ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
503 |
return retval; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
504 |
} /* __PHYSFS_platformGetUserDir */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
505 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
506 |
|
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
507 |
void *__PHYSFS_platformGetThreadID(void) |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
508 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
509 |
return ( (void *) ((size_t) GetCurrentThreadId()) ); |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
510 |
} /* __PHYSFS_platformGetThreadID */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
511 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
512 |
|
875
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
513 |
static int isSymlinkAttrs(const DWORD attr, const DWORD tag) |
874
ad804f24633f
Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents:
864
diff
changeset
|
514 |
{ |
875
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
515 |
return ( (attr & FILE_ATTRIBUTE_REPARSE_POINT) && |
6a5f06dbd423
Patched to compile, and work with pre-Vista versions of the Platform SDK.
Ryan C. Gordon <icculus@icculus.org>
parents:
874
diff
changeset
|
516 |
(tag == PHYSFS_IO_REPARSE_TAG_SYMLINK) ); |
874
ad804f24633f
Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents:
864
diff
changeset
|
517 |
} /* isSymlinkAttrs */ |
ad804f24633f
Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents:
864
diff
changeset
|
518 |
|
ad804f24633f
Symlink support for Windows Vista. Untested code.
Ryan C. Gordon <icculus@icculus.org>
parents:
864
diff
changeset
|
519 |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
520 |
void __PHYSFS_platformEnumerateFiles(const char *dirname, |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
521 |
int omitSymLinks, |
754
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
748
diff
changeset
|
522 |
PHYSFS_EnumFilesCallback callback, |
e7cd7411eadf
API BREAKAGE: Changed PHYSFS_enumerateFilesCallback() to pass the originally
Ryan C. Gordon <icculus@icculus.org>
parents:
748
diff
changeset
|
523 |
const char *origdir, |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
524 |
void *callbackdata) |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
525 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
526 |
HANDLE dir = INVALID_HANDLE_VALUE; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
527 |
WIN32_FIND_DATAW entw; |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
528 |
size_t len = strlen(dirname); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
529 |
char *searchPath = NULL; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
530 |
WCHAR *wSearchPath = NULL; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
531 |
|
268
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
532 |
/* Allocate a new string for path, maybe '\\', "*", and NULL terminator */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
533 |
searchPath = (char *) __PHYSFS_smallAlloc(len + 3); |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
534 |
if (searchPath == NULL) |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
535 |
return; |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
536 |
|
262
2d332d53c263
-Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents:
240
diff
changeset
|
537 |
/* Copy current dirname */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
538 |
strcpy(searchPath, dirname); |
268
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
539 |
|
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
540 |
/* if there's no '\\' at the end of the path, stick one in there. */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
541 |
if (searchPath[len - 1] != '\\') |
268
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
542 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
543 |
searchPath[len++] = '\\'; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
544 |
searchPath[len] = '\0'; |
268
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
545 |
} /* if */ |
0f47386615f0
Enumerate files code: cleaned up memory leak, Doesn't throw away file entry
Ryan C. Gordon <icculus@icculus.org>
parents:
262
diff
changeset
|
546 |
|
262
2d332d53c263
-Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents:
240
diff
changeset
|
547 |
/* Append the "*" to the end of the string */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
548 |
strcat(searchPath, "*"); |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
549 |
|
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
550 |
UTF8_TO_UNICODE_STACK_MACRO(wSearchPath, searchPath); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
551 |
if (!wSearchPath) |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
552 |
return; /* oh well. */ |
262
2d332d53c263
-Fixed file enumerator function (needed a wildcard '*' specification)
Gregory S. Read <zeph@clutteredmind.org>
parents:
240
diff
changeset
|
553 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
554 |
dir = FindFirstFileW(wSearchPath, &entw); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
555 |
|
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
556 |
__PHYSFS_smallFree(wSearchPath); |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
557 |
__PHYSFS_smallFree(searchPath); |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
558 |
if (dir == INVALID_HANDLE_VALUE) |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
651
diff
changeset
|
559 |
return; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
560 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
561 |
do |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
562 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
563 |
const DWORD attr = entw.dwFileAttributes; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
564 |
const DWORD tag = entw.dwReserved0; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
565 |
const WCHAR *fn = entw.cFileName; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
566 |
char *utf8; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
567 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
568 |
if ((fn[0] == '.') && (fn[1] == '\0')) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
569 |
continue; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
570 |
if ((fn[0] == '.') && (fn[1] == '.') && (fn[2] == '\0')) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
571 |
continue; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
572 |
if ((omitSymLinks) && (isSymlinkAttrs(attr, tag))) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
573 |
continue; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
574 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
575 |
utf8 = unicodeToUtf8Heap(fn); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
576 |
if (utf8 != NULL) |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
577 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
578 |
callback(callbackdata, origdir, utf8); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
579 |
allocator.Free(utf8); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
580 |
} /* if */ |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
581 |
} while (FindNextFileW(dir, &entw) != 0); |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
582 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
583 |
FindClose(dir); |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
584 |
} /* __PHYSFS_platformEnumerateFiles */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
585 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
586 |
|
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
587 |
int __PHYSFS_platformMkDir(const char *path) |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
588 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
589 |
WCHAR *wpath; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
590 |
DWORD rc; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
591 |
UTF8_TO_UNICODE_STACK_MACRO(wpath, path); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
592 |
rc = CreateDirectoryW(wpath, NULL); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
593 |
__PHYSFS_smallFree(wpath); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
594 |
BAIL_IF_MACRO(rc == 0, errcodeFromWinApi(), 0); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
595 |
return 1; |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
596 |
} /* __PHYSFS_platformMkDir */ |
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
597 |
|
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
598 |
|
131
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
599 |
int __PHYSFS_platformInit(void) |
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
600 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
601 |
libUserEnv = LoadLibraryA("userenv.dll"); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
602 |
BAIL_IF_MACRO(libUserEnv == NULL, errcodeFromWinApi(), 0); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
603 |
|
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
604 |
/* !!! FIXME: why do we precalculate this? */ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
605 |
BAIL_IF_MACRO(!determineUserDir(), ERRPASS, 0); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
606 |
return 1; /* It's all good */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
607 |
} /* __PHYSFS_platformInit */ |
131
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
608 |
|
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
609 |
|
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
610 |
int __PHYSFS_platformDeinit(void) |
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
611 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
612 |
if (detectCDThreadHandle) |
1217
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
613 |
{ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
614 |
if (detectCDHwnd) |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
615 |
PostMessageW(detectCDHwnd, WM_QUIT, 0, 0); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
616 |
CloseHandle(detectCDThreadHandle); |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
617 |
detectCDThreadHandle = NULL; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
618 |
initialDiscDetectionComplete = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
619 |
drivesWithMediaBitmap = 0; |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
620 |
} /* if */ |
e38ffad216e8
Move Windows CD-ROM detection to another thread that uses device notifications.
Ryan C. Gordon <icculus@icculus.org>
parents:
1213
diff
changeset
|
621 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
622 |
if (libUserEnv) |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
623 |
FreeLibrary(libUserEnv); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
624 |
libUserEnv = NULL; |
858
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
625 |
allocator.Free(userDir); |
969e69b2822f
Improved dynamic loader and initial Unicode work in windows.c ...
Ryan C. Gordon <icculus@icculus.org>
parents:
856
diff
changeset
|
626 |
userDir = NULL; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
627 |
return 1; /* It's all good */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
628 |
} /* __PHYSFS_platformDeinit */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
629 |
|
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
630 |
|
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
631 |
static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly) |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
632 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
633 |
HANDLE fileh; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
634 |
WinApiFile *retval; |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
635 |
WCHAR *wfname; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
636 |
|
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
637 |
UTF8_TO_UNICODE_STACK_MACRO(wfname, fname); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
638 |
BAIL_IF_MACRO(!wfname, PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
639 |
fileh = CreateFileW(wfname, mode, FILE_SHARE_READ | FILE_SHARE_WRITE, |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
640 |
NULL, creation, FILE_ATTRIBUTE_NORMAL, NULL); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
641 |
__PHYSFS_smallFree(wfname); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
642 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
643 |
BAIL_IF_MACRO(fileh == INVALID_HANDLE_VALUE,errcodeFromWinApi(), NULL); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
644 |
|
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
645 |
retval = (WinApiFile *) allocator.Malloc(sizeof (WinApiFile)); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
646 |
if (!retval) |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
647 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
648 |
CloseHandle(fileh); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
649 |
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL); |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
650 |
} /* if */ |
131
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
651 |
|
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
652 |
retval->readonly = rdonly; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
653 |
retval->handle = fileh; |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
654 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
655 |
} /* doOpen */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
656 |
|
131
69b093825303
-Added init and deinit routines per physfs_internal.h changes.
Gregory S. Read <zeph@clutteredmind.org>
parents:
127
diff
changeset
|
657 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
658 |
void *__PHYSFS_platformOpenRead(const char *filename) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
659 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
660 |
return doOpen(filename, GENERIC_READ, OPEN_EXISTING, 1); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
661 |
} /* __PHYSFS_platformOpenRead */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
662 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
663 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
664 |
void *__PHYSFS_platformOpenWrite(const char *filename) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
665 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
666 |
return doOpen(filename, GENERIC_WRITE, CREATE_ALWAYS, 0); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
667 |
} /* __PHYSFS_platformOpenWrite */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
668 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
669 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
670 |
void *__PHYSFS_platformOpenAppend(const char *filename) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
671 |
{ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
672 |
void *retval = doOpen(filename, GENERIC_WRITE, OPEN_ALWAYS, 0); |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
673 |
if (retval != NULL) |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
674 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
675 |
HANDLE h = ((WinApiFile *) retval)->handle; |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
676 |
DWORD rc = SetFilePointer(h, 0, NULL, FILE_END); |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
677 |
if (rc == PHYSFS_INVALID_SET_FILE_POINTER) |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
678 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
679 |
const PHYSFS_ErrorCode err = errcodeFromWinApi(); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
680 |
CloseHandle(h); |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
681 |
allocator.Free(retval); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
682 |
BAIL_MACRO(err, NULL); |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
683 |
} /* if */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
684 |
} /* if */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
685 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
686 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
687 |
} /* __PHYSFS_platformOpenAppend */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
688 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
689 |
|
1135
3b71a0c08665
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
690 |
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */ |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
691 |
PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buf, PHYSFS_uint64 len) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
692 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
693 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
694 |
DWORD CountOfBytesRead = 0; |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
695 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
696 |
if (!__PHYSFS_ui64FitsAddressSpace(len)) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
697 |
BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
698 |
else if(!ReadFile(Handle, buf, (DWORD) len, &CountOfBytesRead, NULL)) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
699 |
BAIL_MACRO(errcodeFromWinApi(), -1); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
700 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
701 |
return (PHYSFS_sint64) CountOfBytesRead; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
702 |
} /* __PHYSFS_platformRead */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
703 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
704 |
|
1135
3b71a0c08665
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
705 |
/* !!! FIXME: this function fails if len > 0xFFFFFFFF. */ |
310
f8bca4a93fd5
Patched to compile on Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
275
diff
changeset
|
706 |
PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, |
1135
3b71a0c08665
Patched to compile on Windows.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
707 |
PHYSFS_uint64 len) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
708 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
709 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
710 |
DWORD CountOfBytesWritten = 0; |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
711 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
712 |
if (!__PHYSFS_ui64FitsAddressSpace(len)) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
713 |
BAIL_MACRO(PHYSFS_ERR_INVALID_ARGUMENT, -1); |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
714 |
else if(!WriteFile(Handle, buffer, (DWORD) len, &CountOfBytesWritten, NULL)) |
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
715 |
BAIL_MACRO(errcodeFromWinApi(), -1); |
1098
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
716 |
|
4e86cec1143f
Moved all the file i/o from stdio-style to POSIX-style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1067
diff
changeset
|
717 |
return (PHYSFS_sint64) CountOfBytesWritten; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
718 |
} /* __PHYSFS_platformWrite */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
719 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
720 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
721 |
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
722 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
723 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
930
45ad625f03bc
Fixed compiler warnings in win32 API calls (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
926
diff
changeset
|
724 |
LONG HighOrderPos; |
45ad625f03bc
Fixed compiler warnings in win32 API calls (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
926
diff
changeset
|
725 |
PLONG pHighOrderPos; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
726 |
DWORD rc; |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
727 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
728 |
/* Get the high order 32-bits of the position */ |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
729 |
HighOrderPos = HIGHORDER_UINT64(pos); |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
730 |
|
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
731 |
/* |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
732 |
* MSDN: "If you do not need the high-order 32 bits, this |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
733 |
* pointer must be set to NULL." |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
734 |
*/ |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
735 |
pHighOrderPos = (HighOrderPos) ? &HighOrderPos : NULL; |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
736 |
|
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
737 |
/* |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
738 |
* !!! FIXME: MSDN: "Windows Me/98/95: If the pointer |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
739 |
* !!! FIXME: lpDistanceToMoveHigh is not NULL, then it must |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
740 |
* !!! FIXME: point to either 0, INVALID_SET_FILE_POINTER, or |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
741 |
* !!! FIXME: the sign extension of the value of lDistanceToMove. |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
742 |
* !!! FIXME: Any other value will be rejected." |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
743 |
*/ |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
744 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
745 |
/* Move pointer "pos" count from start of file */ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
615
diff
changeset
|
746 |
rc = SetFilePointer(Handle, LOWORDER_UINT64(pos), |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
747 |
pHighOrderPos, FILE_BEGIN); |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
748 |
|
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
749 |
if ( (rc == PHYSFS_INVALID_SET_FILE_POINTER) && |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
750 |
(GetLastError() != NO_ERROR) ) |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
751 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
752 |
BAIL_MACRO(errcodeFromWinApi(), 0); |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
753 |
} /* if */ |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
754 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
755 |
return 1; /* No error occured */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
756 |
} /* __PHYSFS_platformSeek */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
757 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
758 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
759 |
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
760 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
761 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
930
45ad625f03bc
Fixed compiler warnings in win32 API calls (thanks, Dennis!).
Ryan C. Gordon <icculus@icculus.org>
parents:
926
diff
changeset
|
762 |
LONG HighPos = 0; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
763 |
DWORD LowPos; |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
764 |
PHYSFS_sint64 retval; |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
765 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
766 |
/* Get current position */ |
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
615
diff
changeset
|
767 |
LowPos = SetFilePointer(Handle, 0, &HighPos, FILE_CURRENT); |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
768 |
if ( (LowPos == PHYSFS_INVALID_SET_FILE_POINTER) && |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
769 |
(GetLastError() != NO_ERROR) ) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
770 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
771 |
BAIL_MACRO(errcodeFromWinApi(), -1); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
772 |
} /* if */ |
211
e9a1d8b11e85
-Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents:
210
diff
changeset
|
773 |
else |
e9a1d8b11e85
-Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents:
210
diff
changeset
|
774 |
{ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
775 |
/* Combine the high/low order to create the 64-bit position value */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
776 |
retval = (((PHYSFS_uint64) HighPos) << 32) | LowPos; |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
777 |
assert(retval >= 0); |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
778 |
} /* else */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
779 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
780 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
781 |
} /* __PHYSFS_platformTell */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
782 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
783 |
|
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
784 |
PHYSFS_sint64 __PHYSFS_platformFileLength(void *opaque) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
785 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
786 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
787 |
DWORD SizeHigh; |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
788 |
DWORD SizeLow; |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
789 |
PHYSFS_sint64 retval; |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
790 |
|
651
cbe4ea4c7e8e
Changed vars named "FileHandle" to "Handle" to not cause confusion with
Ryan C. Gordon <icculus@icculus.org>
parents:
615
diff
changeset
|
791 |
SizeLow = GetFileSize(Handle, &SizeHigh); |
606
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
792 |
if ( (SizeLow == PHYSFS_INVALID_SET_FILE_POINTER) && |
70cf47819dd2
Fixed Win32 seeking on > 2gig files, other Cygwin issues.
Ryan C. Gordon <icculus@icculus.org>
parents:
596
diff
changeset
|
793 |
(GetLastError() != NO_ERROR) ) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
794 |
{ |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
795 |
BAIL_MACRO(errcodeFromWinApi(), -1); |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
796 |
} /* if */ |
211
e9a1d8b11e85
-Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents:
210
diff
changeset
|
797 |
else |
e9a1d8b11e85
-Fixed a lot of the file functions error handling. Many were handling
Gregory S. Read <zeph@clutteredmind.org>
parents:
210
diff
changeset
|
798 |
{ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
799 |
/* Combine the high/low order to create the 64-bit position value */ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
800 |
retval = (((PHYSFS_uint64) SizeHigh) << 32) | SizeLow; |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
801 |
assert(retval >= 0); |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
802 |
} /* else */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
803 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
804 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
805 |
} /* __PHYSFS_platformFileLength */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
806 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
807 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
808 |
int __PHYSFS_platformFlush(void *opaque) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
809 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
810 |
WinApiFile *fh = ((WinApiFile *) opaque); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
811 |
if (!fh->readonly) |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
812 |
BAIL_IF_MACRO(!FlushFileBuffers(fh->handle), errcodeFromWinApi(), 0); |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
813 |
|
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
814 |
return 1; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
815 |
} /* __PHYSFS_platformFlush */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
816 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
817 |
|
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
818 |
void __PHYSFS_platformClose(void *opaque) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
819 |
{ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
820 |
HANDLE Handle = ((WinApiFile *) opaque)->handle; |
1118
2e09fc635fdd
Abstracted file i/o into PHYSFS_Io interface.
Ryan C. Gordon <icculus@icculus.org>
parents:
1115
diff
changeset
|
821 |
(void) CloseHandle(Handle); /* ignore errors. You should have flushed! */ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
822 |
allocator.Free(opaque); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
823 |
} /* __PHYSFS_platformClose */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
824 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
825 |
|
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
826 |
static int doPlatformDelete(LPWSTR wpath) |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
827 |
{ |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
828 |
const int isdir = (GetFileAttributesW(wpath) & FILE_ATTRIBUTE_DIRECTORY); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
829 |
const BOOL rc = (isdir) ? RemoveDirectoryW(wpath) : DeleteFileW(wpath); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
830 |
BAIL_IF_MACRO(!rc, errcodeFromWinApi(), 0); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
831 |
return 1; /* if you made it here, it worked. */ |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
832 |
} /* doPlatformDelete */ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
833 |
|
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
834 |
|
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
835 |
int __PHYSFS_platformDelete(const char *path) |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
836 |
{ |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
837 |
int retval = 0; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
838 |
LPWSTR wpath = NULL; |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
839 |
UTF8_TO_UNICODE_STACK_MACRO(wpath, path); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
840 |
BAIL_IF_MACRO(!wpath, PHYSFS_ERR_OUT_OF_MEMORY, 0); |
861
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
841 |
retval = doPlatformDelete(wpath); |
9b405bf6a95d
Tons of Unicode work in windows.c ... should now use UCS-2 on NT/XP/Vista/etc
Ryan C. Gordon <icculus@icculus.org>
parents:
859
diff
changeset
|
842 |
__PHYSFS_smallFree(wpath); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
843 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
844 |
} /* __PHYSFS_platformDelete */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
845 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
846 |
|
853
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
847 |
/* |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
848 |
* !!! FIXME: why aren't we using Critical Sections instead of Mutexes? |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
849 |
* !!! FIXME: mutexes on Windows are for cross-process sync. CritSects are |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
850 |
* !!! FIXME: mutexes for threads in a single process and are faster. |
8df352657911
Added some FIXME comments.
Ryan C. Gordon <icculus@icculus.org>
parents:
852
diff
changeset
|
851 |
*/ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
852 |
void *__PHYSFS_platformCreateMutex(void) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
853 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
854 |
return ((void *) CreateMutex(NULL, FALSE, NULL)); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
855 |
} /* __PHYSFS_platformCreateMutex */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
856 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
857 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
858 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
859 |
{ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
860 |
CloseHandle((HANDLE) mutex); |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
861 |
} /* __PHYSFS_platformDestroyMutex */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
862 |
|
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
863 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
864 |
int __PHYSFS_platformGrabMutex(void *mutex) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
865 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
866 |
return (WaitForSingleObject((HANDLE) mutex, INFINITE) != WAIT_FAILED); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
867 |
} /* __PHYSFS_platformGrabMutex */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
868 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
869 |
|
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
870 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
871 |
{ |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
872 |
ReleaseMutex((HANDLE) mutex); |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
873 |
} /* __PHYSFS_platformReleaseMutex */ |
159
a893392b1628
-Implemented PHYSFS file routines
Gregory S. Read <zeph@clutteredmind.org>
parents:
131
diff
changeset
|
874 |
|
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
875 |
|
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
876 |
static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft) |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
877 |
{ |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
878 |
SYSTEMTIME st_utc; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
879 |
SYSTEMTIME st_localtz; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
880 |
TIME_ZONE_INFORMATION tzi; |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
881 |
DWORD tzid; |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
882 |
PHYSFS_sint64 retval; |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
883 |
struct tm tm; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
884 |
BOOL rc; |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
885 |
|
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
886 |
BAIL_IF_MACRO(!FileTimeToSystemTime(ft, &st_utc), errcodeFromWinApi(), -1); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
887 |
tzid = GetTimeZoneInformation(&tzi); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
888 |
BAIL_IF_MACRO(tzid == TIME_ZONE_ID_INVALID, errcodeFromWinApi(), -1); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
889 |
rc = SystemTimeToTzSpecificLocalTime(&tzi, &st_utc, &st_localtz); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
890 |
BAIL_IF_MACRO(!rc, errcodeFromWinApi(), -1); |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
891 |
|
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
892 |
/* Convert to a format that mktime() can grok... */ |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
893 |
tm.tm_sec = st_localtz.wSecond; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
894 |
tm.tm_min = st_localtz.wMinute; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
895 |
tm.tm_hour = st_localtz.wHour; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
896 |
tm.tm_mday = st_localtz.wDay; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
897 |
tm.tm_mon = st_localtz.wMonth - 1; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
898 |
tm.tm_year = st_localtz.wYear - 1900; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
899 |
tm.tm_wday = -1 /*st_localtz.wDayOfWeek*/; |
275
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
900 |
tm.tm_yday = -1; |
42f0e962abbb
Lots of cleanups, fixes, and corrections. Should now work on all win32
Ryan C. Gordon <icculus@icculus.org>
parents:
268
diff
changeset
|
901 |
tm.tm_isdst = -1; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
902 |
|
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
903 |
/* Convert to a format PhysicsFS can grok... */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
904 |
retval = (PHYSFS_sint64) mktime(&tm); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
905 |
BAIL_IF_MACRO(retval == -1, PHYSFS_ERR_OS_ERROR, -1); |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
906 |
return retval; |
312
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
907 |
} /* FileTimeToPhysfsTime */ |
4996c48861db
_LOTS_ of cleanups, rewrites, fixes, and improvements. Builds on Cygwin again,
Ryan C. Gordon <icculus@icculus.org>
parents:
310
diff
changeset
|
908 |
|
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
909 |
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat) |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
910 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
911 |
WIN32_FILE_ATTRIBUTE_DATA winstat; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
912 |
WCHAR *wstr = NULL; |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
913 |
DWORD err = 0; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
914 |
BOOL rc = 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
915 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
916 |
UTF8_TO_UNICODE_STACK_MACRO(wstr, filename); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
917 |
BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0); |
1198
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
918 |
rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat); |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
919 |
err = (!rc) ? GetLastError() : 0; |
4cdb856021dd
Removed the non-Unicode fallbacks from platform_windows.c, other cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents:
1180
diff
changeset
|
920 |
*exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND)); |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
921 |
__PHYSFS_smallFree(wstr); |
1240
22d4d1bd4e21
Reworked the error reporting API. Now we use error codes instead of strings.
Ryan C. Gordon <icculus@icculus.org>
parents:
1237
diff
changeset
|
922 |
BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0); |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
923 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
924 |
stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
925 |
stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
926 |
stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
927 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
928 |
if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
929 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
930 |
stat->filetype = PHYSFS_FILETYPE_DIRECTORY; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
931 |
stat->filesize = 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
932 |
} /* if */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
933 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
934 |
else if(winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE)) |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
935 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
936 |
/* !!! FIXME: what are reparse points? */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
937 |
stat->filetype = PHYSFS_FILETYPE_OTHER; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
938 |
/* !!! FIXME: don't rely on this */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
939 |
stat->filesize = 0; |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
940 |
} /* else if */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
941 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
942 |
/* !!! FIXME: check for symlinks on Vista. */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
943 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
944 |
else |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
945 |
{ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
946 |
stat->filetype = PHYSFS_FILETYPE_REGULAR; |
1055
8974a4a352fd
Patched to compile (thanks, Christoph!).
Ryan C. Gordon <icculus@icculus.org>
parents:
1054
diff
changeset
|
947 |
stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
948 |
} /* else */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
949 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
950 |
stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0); |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
951 |
|
1106
94c3669d0311
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
Ryan C. Gordon <icculus@icculus.org>
parents:
1104
diff
changeset
|
952 |
return 1; |
1054
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
953 |
} /* __PHYSFS_platformStat */ |
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
954 |
|
57f4af811ffb
THIS is Christoph's PHYSFS_stat() work.
Ryan C. Gordon <icculus@icculus.org>
parents:
1053
diff
changeset
|
955 |
|
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
956 |
/* !!! FIXME: Don't use C runtime for allocators? */ |
845
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
957 |
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
958 |
{ |
1016
957c97389257
Cleaned up returns that look like function calls for my updated coding style.
Ryan C. Gordon <icculus@icculus.org>
parents:
1012
diff
changeset
|
959 |
return 0; /* just use malloc() and friends. */ |
845
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
960 |
} /* __PHYSFS_platformSetDefaultAllocator */ |
691
71d9affe0d8a
All memory management now goes through allocation hooks instead of directly to
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
961 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
962 |
#endif /* PHYSFS_PLATFORM_WINDOWS */ |
327
76e207c6b4a7
Build system corrections for BeOS and Cygwin.
Ryan C. Gordon <icculus@icculus.org>
parents:
313
diff
changeset
|
963 |
|
791
43051d05bcc3
Renamed win32.c to windows.c (since it would be used for Win64, too.)
Ryan C. Gordon <icculus@icculus.org>
parents:
784
diff
changeset
|
964 |
/* end of windows.c ... */ |
68
c9a10b5d5f4f
Initial add; NOT complete.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset
|
965 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
810
diff
changeset
|
966 |