early-access version 2847
This commit is contained in:
+11
-13
@@ -31,7 +31,6 @@
|
||||
|
||||
#define INCL_DOSFILEMGR
|
||||
#define INCL_DOSPROCESS
|
||||
#define INCL_DOSMODULEMGR
|
||||
#define INCL_DOSERRORS
|
||||
#include <os2.h>
|
||||
|
||||
@@ -43,31 +42,30 @@ SDL_GetBasePath(void)
|
||||
PPIB pib;
|
||||
ULONG ulRC = DosGetInfoBlocks(&tib, &pib);
|
||||
PCHAR pcEnd;
|
||||
ULONG cbResult;
|
||||
CHAR acBuf[CCHMAXPATH];
|
||||
|
||||
if (ulRC != NO_ERROR) {
|
||||
SDL_SetError("Can't get process information block (E%lu)", ulRC);
|
||||
debug_os2("DosGetInfoBlocks() failed, rc = %u", ulRC);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ulRC = DosQueryModuleName(pib->pib_hmte, sizeof(acBuf), acBuf);
|
||||
if (ulRC != NO_ERROR) {
|
||||
SDL_SetError("Can't query the module name (E%lu)", ulRC);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pcEnd = SDL_strrchr(acBuf, '\\');
|
||||
pcEnd = SDL_strrchr(pib->pib_pchcmd, '\\');
|
||||
if (pcEnd != NULL)
|
||||
pcEnd[1] = '\0';
|
||||
pcEnd++;
|
||||
else {
|
||||
if (acBuf[1] == ':') /* e.g. "C:FOO" */
|
||||
acBuf[2] = '\0';
|
||||
if (pib->pib_pchcmd[1] == ':')
|
||||
pcEnd = &pib->pib_pchcmd[2];
|
||||
else {
|
||||
SDL_SetError("No path in module name");
|
||||
SDL_SetError("No path in pib->pib_pchcmd");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
cbResult = pcEnd - pib->pib_pchcmd;
|
||||
SDL_memcpy(acBuf, pib->pib_pchcmd, cbResult);
|
||||
acBuf[cbResult] = '\0';
|
||||
|
||||
return OS2_SysToUTF8(acBuf);
|
||||
}
|
||||
|
||||
|
||||
+29
-29
@@ -34,44 +34,44 @@
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char cwd[FILENAME_MAX];
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char cwd[FILENAME_MAX];
|
||||
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 2;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
SDL_snprintf(retval, len, "%s/", cwd);
|
||||
|
||||
getcwd(cwd, sizeof(cwd));
|
||||
len = SDL_strlen(cwd) + 2;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
SDL_snprintf(retval, len, "%s/", cwd);
|
||||
|
||||
return retval;
|
||||
return retval;
|
||||
}
|
||||
|
||||
char *
|
||||
SDL_GetPrefPath(const char *org, const char *app)
|
||||
{
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if(!org) {
|
||||
org = "";
|
||||
}
|
||||
char *retval = NULL;
|
||||
size_t len;
|
||||
char *base = SDL_GetBasePath();
|
||||
if (!app) {
|
||||
SDL_InvalidParamError("app");
|
||||
return NULL;
|
||||
}
|
||||
if(!org) {
|
||||
org = "";
|
||||
}
|
||||
|
||||
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
len = SDL_strlen(base) + SDL_strlen(org) + SDL_strlen(app) + 4;
|
||||
retval = (char *) SDL_malloc(len);
|
||||
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s/", base, app);
|
||||
}
|
||||
free(base);
|
||||
if (*org) {
|
||||
SDL_snprintf(retval, len, "%s%s/%s/", base, org, app);
|
||||
} else {
|
||||
SDL_snprintf(retval, len, "%s%s/", base, app);
|
||||
}
|
||||
free(base);
|
||||
|
||||
mkdir(retval, 0755);
|
||||
return retval;
|
||||
mkdir(retval, 0755);
|
||||
return retval;
|
||||
}
|
||||
|
||||
#endif /* SDL_FILESYSTEM_PSP */
|
||||
|
||||
+19
-1
@@ -35,23 +35,39 @@
|
||||
char *
|
||||
SDL_GetBasePath(void)
|
||||
{
|
||||
typedef DWORD (WINAPI *GetModuleFileNameExW_t)(HANDLE, HMODULE, LPWSTR, DWORD);
|
||||
GetModuleFileNameExW_t pGetModuleFileNameExW;
|
||||
DWORD buflen = 128;
|
||||
WCHAR *path = NULL;
|
||||
HANDLE psapi = LoadLibrary(TEXT("psapi.dll"));
|
||||
char *retval = NULL;
|
||||
DWORD len = 0;
|
||||
int i;
|
||||
|
||||
if (!psapi) {
|
||||
WIN_SetError("Couldn't load psapi.dll");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pGetModuleFileNameExW = (GetModuleFileNameExW_t)GetProcAddress(psapi, "GetModuleFileNameExW");
|
||||
if (!pGetModuleFileNameExW) {
|
||||
WIN_SetError("Couldn't find GetModuleFileNameExW");
|
||||
FreeLibrary(psapi);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (SDL_TRUE) {
|
||||
void *ptr = SDL_realloc(path, buflen * sizeof (WCHAR));
|
||||
if (!ptr) {
|
||||
SDL_free(path);
|
||||
FreeLibrary(psapi);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
path = (WCHAR *) ptr;
|
||||
|
||||
len = GetModuleFileNameW(NULL, path, buflen);
|
||||
len = pGetModuleFileNameExW(GetCurrentProcess(), NULL, path, buflen);
|
||||
/* if it truncated, then len >= buflen - 1 */
|
||||
/* if there was enough room (or failure), len < buflen - 1 */
|
||||
if (len < buflen - 1) {
|
||||
@@ -62,6 +78,8 @@ SDL_GetBasePath(void)
|
||||
buflen *= 2;
|
||||
}
|
||||
|
||||
FreeLibrary(psapi);
|
||||
|
||||
if (len == 0) {
|
||||
SDL_free(path);
|
||||
WIN_SetError("Couldn't locate our .exe");
|
||||
|
||||
Reference in New Issue
Block a user