fix: windows: config file couldn't be written
now cfg and log file will be in the same directory than the exe (portable mode)
This commit is contained in:
51
closure.c
51
closure.c
@@ -28,6 +28,33 @@
|
|||||||
#define Verbose(format, ...)
|
#define Verbose(format, ...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef SYS_MINGW
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
/* safety margin in case we're getting UTF path names */
|
||||||
|
#define WIN_MAX_PATH (4*MAX_PATH)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the place of our executable
|
||||||
|
* (Windows only)
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char* get_exe_path()
|
||||||
|
{ char path[WIN_MAX_PATH];
|
||||||
|
int n = GetModuleFileNameA(NULL, path, WIN_MAX_PATH);
|
||||||
|
|
||||||
|
if(n>0 && n<WIN_MAX_PATH-1)
|
||||||
|
{ char *backslash = strrchr(path, '\\');
|
||||||
|
|
||||||
|
if(backslash) *backslash=0;
|
||||||
|
return g_strdup(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_strdup(".");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/***
|
/***
|
||||||
*** Locate the binary and documentation directory
|
*** Locate the binary and documentation directory
|
||||||
***/
|
***/
|
||||||
@@ -36,9 +63,9 @@ static void get_base_dirs()
|
|||||||
{
|
{
|
||||||
/*** Unless completely disabled through a configure option, the
|
/*** Unless completely disabled through a configure option, the
|
||||||
source directory is supposed to hold the most recent files,
|
source directory is supposed to hold the most recent files,
|
||||||
so try this first. */
|
so try this first (never under Windows). */
|
||||||
|
|
||||||
#ifdef WITH_EMBEDDED_SRC_PATH_YES
|
#if defined(WITH_EMBEDDED_SRC_PATH_YES) && !defined(SYS_MINGW)
|
||||||
if(DirStat(SRCDIR))
|
if(DirStat(SRCDIR))
|
||||||
{ Closure->binDir = g_strdup(SRCDIR);
|
{ Closure->binDir = g_strdup(SRCDIR);
|
||||||
Closure->docDir = g_strdup_printf("%s/documentation",SRCDIR);
|
Closure->docDir = g_strdup_printf("%s/documentation",SRCDIR);
|
||||||
@@ -50,26 +77,40 @@ static void get_base_dirs()
|
|||||||
/*** Otherwise try the installation directory.
|
/*** Otherwise try the installation directory.
|
||||||
On Unices this is a hardcoded directory. */
|
On Unices this is a hardcoded directory. */
|
||||||
|
|
||||||
#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_KFREEBSD) || \
|
#ifndef SYS_MINGW
|
||||||
defined(SYS_NETBSD) || defined(SYS_HURD) || defined(SYS_UNKNOWN)
|
|
||||||
if(DirStat(BINDIR))
|
if(DirStat(BINDIR))
|
||||||
Closure->binDir = g_strdup(BINDIR);
|
Closure->binDir = g_strdup(BINDIR);
|
||||||
|
|
||||||
if(DirStat(DOCDIR))
|
if(DirStat(DOCDIR))
|
||||||
Closure->docDir = g_strdup(DOCDIR);
|
Closure->docDir = g_strdup(DOCDIR);
|
||||||
Verbose("Using hardcoded BINDIR = %s, DOCDIR = %s\n", BINDIR, DOCDIR);
|
Verbose("Using hardcoded BINDIR = %s, DOCDIR = %s\n", BINDIR, DOCDIR);
|
||||||
|
#else
|
||||||
|
Closure->binDir = get_exe_path();
|
||||||
|
/* We'll just put the 2 PDF in the same dir, portable mode */
|
||||||
|
Closure->docDir = g_strdup(Closure->binDir);
|
||||||
|
Verbose("Using path from get_exe_path() = %s\n", Closure->binDir);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*** The location of the dotfile depends on the operating system.
|
/*** The location of the dotfile depends on the operating system.
|
||||||
Under Unix the users home directory is used. */
|
Under Unix the users home directory is used. */
|
||||||
|
|
||||||
#ifdef WITH_EMBEDDED_SRC_PATH_YES
|
#if defined(WITH_EMBEDDED_SRC_PATH_YES) && !defined(SYS_MINGW)
|
||||||
find_dotfile:
|
find_dotfile:
|
||||||
#endif /* WITH_EMBEDDED_SRC_PATH_YES */
|
#endif /* WITH_EMBEDDED_SRC_PATH_YES */
|
||||||
|
|
||||||
|
#ifndef SYS_MINGW
|
||||||
Closure->homeDir = g_strdup(g_getenv("HOME"));
|
Closure->homeDir = g_strdup(g_getenv("HOME"));
|
||||||
|
#else
|
||||||
|
Closure->homeDir = g_strdup(Closure->binDir); /* portable mode */
|
||||||
|
#endif
|
||||||
if(!Closure->dotFile) /* may have been set by the --resource-file option */
|
if(!Closure->dotFile) /* may have been set by the --resource-file option */
|
||||||
|
#ifndef SYS_MINGW
|
||||||
Closure->dotFile = g_strdup_printf("%s/.dvdisaster", Closure->homeDir);
|
Closure->dotFile = g_strdup_printf("%s/.dvdisaster", Closure->homeDir);
|
||||||
|
#else
|
||||||
|
/* Windows doesn't really love dotfiles */
|
||||||
|
Closure->dotFile = g_strdup_printf("%s/dvdisaster.cfg", Closure->homeDir);
|
||||||
|
#endif
|
||||||
|
|
||||||
Verbose("\nUsing file locations:\n"
|
Verbose("\nUsing file locations:\n"
|
||||||
"- Homedir: %s\n"
|
"- Homedir: %s\n"
|
||||||
|
|||||||
@@ -29,7 +29,11 @@
|
|||||||
|
|
||||||
void DefaultLogFile()
|
void DefaultLogFile()
|
||||||
{
|
{
|
||||||
|
#ifndef SYS_MINGW
|
||||||
Closure->logFile = g_strdup_printf("%s/.dvdisaster.log", g_getenv("HOME"));
|
Closure->logFile = g_strdup_printf("%s/.dvdisaster.log", g_getenv("HOME"));
|
||||||
|
#else
|
||||||
|
Closure->logFile = g_strdup_printf("%s/dvdisaster.log", Closure->homeDir); /* portable mode */
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user