fixed remnant of set-root-dir problem; now finally works correcly when started from batch file. no extra path/chdir necessary.
This was SVN commit r276.
This commit is contained in:
parent
9aacf9b4bf
commit
bb3db6daf8
@ -126,6 +126,20 @@ int file_rel_chdir(const char* argv0, const char* rel_path)
|
|||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Win32-specific: if started via batch file, argv0 might not end
|
||||||
|
// with ".exe". access and realpath require the filename with extension,
|
||||||
|
// so append it if not there. we don't get the full path either in that
|
||||||
|
// case, but realpath takes care of it.
|
||||||
|
#ifdef _WIN32
|
||||||
|
char fixed_argv0[PATH_MAX];
|
||||||
|
if(!strchr(argv0, '.'))
|
||||||
|
{
|
||||||
|
strncpy(fixed_argv0, argv0, PATH_MAX-5);
|
||||||
|
strcat(fixed_argv0, ".exe");
|
||||||
|
argv0 = fixed_argv0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// get full path to executable
|
// get full path to executable
|
||||||
if(access(argv0, X_OK) < 0)
|
if(access(argv0, X_OK) < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -157,6 +171,7 @@ fail:
|
|||||||
if(msg)
|
if(msg)
|
||||||
{
|
{
|
||||||
debug_out("file_rel_chdir: %s\n", msg);
|
debug_out("file_rel_chdir: %s\n", msg);
|
||||||
|
printf("%s\n", msg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,16 +380,23 @@ void ParseArgs(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern "C" char* _getcwd(char*, int);
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
const int ERR_MSG_SIZE = 1000;
|
const int ERR_MSG_SIZE = 1000;
|
||||||
wchar_t err_msg[ERR_MSG_SIZE];
|
wchar_t err_msg[ERR_MSG_SIZE];
|
||||||
|
|
||||||
// display_startup_error(argv[0]);
|
char cwd[100];
|
||||||
|
_getcwd(cwd, 100);
|
||||||
|
char xbuf[1000];
|
||||||
|
sprintf(xbuf, "%s\t%s\n", cwd, argv[0]);
|
||||||
|
//display_startup_error(xbuf);
|
||||||
|
|
||||||
|
|
||||||
|
freopen("stdout2.txt", "w", stdout);
|
||||||
|
setvbuf(stdout, 0, _IONBF, 0);
|
||||||
|
|
||||||
// set current directory to "$game_dir/data".
|
// set current directory to "$game_dir/data".
|
||||||
// this is necessary because it is otherwise unknown,
|
// this is necessary because it is otherwise unknown,
|
||||||
// especially if run from a shortcut, batch file, or symlink.
|
// especially if run from a shortcut, batch file, or symlink.
|
||||||
|
Loading…
Reference in New Issue
Block a user