Windows: moved user settings dir to the "Personal" user special folder (aka "My documents", but portable and locale aware)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@1428 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 61c37c42c4504c807e1b07cb0a20b6d5651b578e Former-commit-id: f2649712fc41b5c77112f0e5aad2cf0c45881c01
This commit is contained in:
parent
81bcaf215f
commit
be0b6e3a05
1 changed files with 79 additions and 59 deletions
|
@ -19,6 +19,7 @@
|
|||
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#include <GL/glut.h>
|
||||
|
@ -34,21 +35,21 @@ init_args(int argc, char **argv)
|
|||
int i;
|
||||
i = 1;
|
||||
while (i < argc) {
|
||||
if ((strncmp(argv[i], "-s", 2) == 0) || (strncmp(argv[i], "/s", 2) == 0)) {
|
||||
if (!strncmp(argv[i], "-s", 2) || !strncmp(argv[i], "/s", 2)) {
|
||||
i++;
|
||||
SetSingleTextureMode ();
|
||||
} else
|
||||
i++; // Ignore bad args
|
||||
}
|
||||
|
||||
static const int BUFSIZE = 1024;
|
||||
static const int BUFSIZE = MAX_PATH;
|
||||
char buf[BUFSIZE];
|
||||
strncpy(buf, argv[0], BUFSIZE);
|
||||
buf[BUFSIZE-1] = '\0'; // Guarantee zero termination for next operation.
|
||||
char *end = strrchr(buf, '\\');
|
||||
|
||||
// Did we find the last '\' and do we get a complete path?
|
||||
if (end != NULL && buf[1] == ':') {
|
||||
if (end && buf[1] == ':') {
|
||||
end++;
|
||||
*(end) = '\0';
|
||||
// replace '\' with '/'
|
||||
|
@ -60,7 +61,7 @@ init_args(int argc, char **argv)
|
|||
SetDataDir(buf);
|
||||
SetLibDir("");
|
||||
} else {
|
||||
if (_fullpath(buf, argv[0], BUFSIZE) != NULL &&
|
||||
if (_fullpath(buf, argv[0], BUFSIZE) &&
|
||||
(strcmp(argv[0], "wtorcs") == 0 ||
|
||||
strcmp(argv[0], "wtorcs.exe") == 0)
|
||||
)
|
||||
|
@ -82,12 +83,31 @@ init_args(int argc, char **argv)
|
|||
}
|
||||
|
||||
// Set LocalDir to the user settings dir for Torcs-NG
|
||||
snprintf(buf, BUFSIZE, "%s/.torcs-ng/", getenv("USERPROFILE"));
|
||||
for (i = 0; i < BUFSIZE && buf[i] != '\0'; i++) {
|
||||
// (in My documents, to give access to the user for advanced settings).
|
||||
//snprintf(buf, BUFSIZE, "%s", getenv("USERPROFILE"));
|
||||
//#if (WINVER < 0x0600)
|
||||
// if (SHGetSpecialFolderPath(0, buf, CSIDL_PERSONAL, 0))
|
||||
//#else
|
||||
// How can we do that under Vista / 7 as CSIDL_PERSONAL is a virtual folder
|
||||
// and SHGetSpecialFolderPath is told to fail in this case ?
|
||||
//#endif
|
||||
LPITEMIDLIST pidl;
|
||||
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_PERSONAL, &pidl))
|
||||
&& SHGetPathFromIDList(pidl, buf))
|
||||
{
|
||||
for (i = 0; i < BUFSIZE && buf[i]; i++)
|
||||
if (buf[i] == '\\')
|
||||
buf[i] = '/';
|
||||
}
|
||||
if (buf[0] && buf[strlen(buf)-1] != '/')
|
||||
strcat(buf, "/");
|
||||
strcat(buf, ".torcs-ng/");
|
||||
SetLocalDir(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Could not get user's My documents folder path\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue