|
@@ -34,7 +34,51 @@
|
|
|
char *
|
|
|
SDL_GetBasePath(void)
|
|
|
{
|
|
|
- return SDL_strdup("G:\\");
|
|
|
+ /* NOTE: This function is a UTF8 version of the Win32 SDL_GetBasePath()!
|
|
|
+ * The GDK actually _recommends_ the 'A' functions over the 'W' functions :o
|
|
|
+ */
|
|
|
+ DWORD buflen = 128;
|
|
|
+ CHAR *path = NULL;
|
|
|
+ DWORD len = 0;
|
|
|
+ int i;
|
|
|
+
|
|
|
+ while (SDL_TRUE) {
|
|
|
+ void *ptr = SDL_realloc(path, buflen * sizeof(CHAR));
|
|
|
+ if (ptr == NULL) {
|
|
|
+ SDL_free(path);
|
|
|
+ SDL_OutOfMemory();
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ path = (CHAR *)ptr;
|
|
|
+
|
|
|
+ len = GetModuleFileNameA(NULL, path, buflen);
|
|
|
+ /* if it truncated, then len >= buflen - 1 */
|
|
|
+ /* if there was enough room (or failure), len < buflen - 1 */
|
|
|
+ if (len < buflen - 1) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* buffer too small? Try again. */
|
|
|
+ buflen *= 2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (len == 0) {
|
|
|
+ SDL_free(path);
|
|
|
+ WIN_SetError("Couldn't locate our .exe");
|
|
|
+ return NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i = len - 1; i > 0; i--) {
|
|
|
+ if (path[i] == '\\') {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_assert(i > 0); /* Should have been an absolute path. */
|
|
|
+ path[i + 1] = '\0'; /* chop off filename. */
|
|
|
+
|
|
|
+ return path;
|
|
|
}
|
|
|
|
|
|
char *
|