Skip to content

Commit

Permalink
fix: re-introduce Windows-specific code in closure.c
Browse files Browse the repository at this point in the history
  • Loading branch information
speed47 committed Oct 9, 2021
1 parent 3d3a65d commit 06b367e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
38 changes: 35 additions & 3 deletions src/closure.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@
/* 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

#ifdef WITH_GUI_YES
Expand Down Expand Up @@ -378,7 +396,7 @@ static void get_base_dirs()
source directory is supposed to hold the most recent files,
so try this first. */

#ifdef WITH_EMBEDDED_SRC_PATH_YES
#if defined(WITH_EMBEDDED_SRC_PATH_YES) && !defined(SYS_MINGW)
if(DirStat(SRCDIR))
{ Closure->binDir = g_strdup(SRCDIR);
Closure->docDir = g_strdup_printf("%s/documentation",SRCDIR);
Expand All @@ -390,25 +408,39 @@ static void get_base_dirs()
/*** Otherwise try the installation directory.
On Unices this is a hardcoded directory. */

#if defined(SYS_LINUX) || defined(SYS_FREEBSD) || defined(SYS_NETBSD) || defined(SYS_UNKNOWN)
#ifndef SYS_MINGW
if(DirStat(BINDIR))
Closure->binDir = g_strdup(BINDIR);

if(DirStat(DOCDIR))
Closure->docDir = g_strdup(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

/*** The location of the dotfile depends on the operating system.
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:
#endif /* WITH_EMBEDDED_SRC_PATH_YES */

#ifndef SYS_MINGW
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 */
#ifndef SYS_MINGW
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"
"- Homedir: %s\n"
Expand Down
12 changes: 0 additions & 12 deletions src/help-dialogs.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,6 @@ char *find_file(char *file, size_t *size, char *lang)
g_free(path);
}

{ if(lang)
path = g_strdup_printf("%s.%s", file, lang_suffix);
else path = g_strdup_printf("%s", file);

if(LargeStat(path, &stat_size))
{ *size = stat_size;
return path;
}

g_free(path);
}

return NULL;
}

Expand Down

0 comments on commit 06b367e

Please sign in to comment.