src/Makefile.am,FbTk/StringUtil.cc: Search relative to the executable.
On Windows, prepend /DUMMYPREFIX to default paths, and replace it at runtime with the prefix relative to the exe directory.
This commit is contained in:
parent
65cb53b685
commit
ea5f7b56ec
2 changed files with 78 additions and 7 deletions
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include "StringUtil.hh"
|
||||
|
||||
#include "../defaults.hh"
|
||||
|
||||
#ifdef HAVE_CSTDIO
|
||||
#include <cstdio>
|
||||
|
@ -57,6 +58,7 @@
|
|||
#include <memory>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
using std::transform;
|
||||
|
@ -167,8 +169,64 @@ const char *strcasestr(const char *str, const char *ptn) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#include <string>
|
||||
#define WIN32_LEAN_AND_MEAN 1
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
|
||||
static void removeTrailingPathSeparators(std::string & path) {
|
||||
// Remove any trailing path separators
|
||||
size_t beforeLastPathSep = path.find_last_not_of("/\\");
|
||||
if (beforeLastPathSep != path.size() - 1) {
|
||||
path.erase(beforeLastPathSep + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static std::string getFluxboxPrefix() {
|
||||
static std::string ret;
|
||||
static bool init = false;
|
||||
if (!init) {
|
||||
char buffer[1024];
|
||||
HMODULE module = GetModuleHandle(NULL);
|
||||
DWORD size = GetModuleFileName(module, buffer, sizeof(buffer));
|
||||
if (sizeof(buffer) > 0)
|
||||
{
|
||||
buffer[sizeof(buffer) - 1] = 0;
|
||||
}
|
||||
static const char slash = '/';
|
||||
static const char backslash = '\\';
|
||||
char * lastslash = std::find_end(buffer, buffer+size, &slash, &slash + 1);
|
||||
char * lastbackslash = std::find_end(buffer, buffer+size, &backslash, &backslash + 1);
|
||||
ret.assign(buffer);
|
||||
|
||||
// Remove the filename
|
||||
size_t lastPathSep = ret.find_last_of("/\\");
|
||||
if (lastPathSep != std::string::npos) {
|
||||
ret.erase(lastPathSep);
|
||||
}
|
||||
|
||||
removeTrailingPathSeparators(ret);
|
||||
|
||||
// If the last directory is bin, remove that too.
|
||||
lastPathSep = ret.find_last_of("/\\");
|
||||
if (lastPathSep != std::string::npos && ret.substr(lastPathSep + 1) == "bin") {
|
||||
ret.erase(lastPathSep);
|
||||
}
|
||||
|
||||
removeTrailingPathSeparators(ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
|
||||
/**
|
||||
if ~ then expand it to home of user
|
||||
if /DUMMYPREFIX on Windows then expand it to the prefix relative to the
|
||||
executable on Windows.
|
||||
returns expanded filename
|
||||
*/
|
||||
string expandFilename(const string &filename) {
|
||||
|
@ -188,6 +246,13 @@ string expandFilename(const string &filename) {
|
|||
retval = filename; //return unmodified value
|
||||
}
|
||||
|
||||
#if defined(_WIN32) && defined(DUMMYPREFIX)
|
||||
if (retval.find(DUMMYPREFIX) == 0) {
|
||||
static const std::string dummyPrefix = DUMMYPREFIX;
|
||||
retval.replace(0, dummyPrefix.size(), getFluxboxPrefix());
|
||||
}
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
@ -48,13 +48,19 @@ defaults.hh: Makefile
|
|||
echo '// This file is generated from Makefile. Do not edit!'; \
|
||||
echo '#include <string>'; \
|
||||
echo ''; \
|
||||
echo '#define DEFAULTMENU "$(DEFAULT_MENU)"'; \
|
||||
echo '#define DEFAULTSTYLE "$(DEFAULT_STYLE)"'; \
|
||||
echo '#define DEFAULTKEYSFILE "$(DEFAULT_KEYSFILE)"'; \
|
||||
echo '#define DEFAULT_APPSFILE "$(DEFAULT_APPSFILE)"'; \
|
||||
echo '#define DEFAULT_OVERLAY "$(DEFAULT_OVERLAY)"'; \
|
||||
echo '#define DEFAULT_INITFILE "$(DEFAULT_INITFILE)"'; \
|
||||
echo '#define DEFAULT_WINDOWMENU "$(DEFAULT_WINDOWMENU)"'; \
|
||||
echo '#ifdef _WIN32'; \
|
||||
echo '#define DUMMYPREFIX "/DUMMYPREFIX"'; \
|
||||
echo '#define PATHPREFIX DUMMYPREFIX'; \
|
||||
echo '#else'; \
|
||||
echo '#define PATHPREFIX'; \
|
||||
echo '#endif'; \
|
||||
echo '#define DEFAULTMENU PATHPREFIX "$(DEFAULT_MENU)"'; \
|
||||
echo '#define DEFAULTSTYLE PATHPREFIX "$(DEFAULT_STYLE)"'; \
|
||||
echo '#define DEFAULTKEYSFILE PATHPREFIX "$(DEFAULT_KEYSFILE)"'; \
|
||||
echo '#define DEFAULT_APPSFILE PATHPREFIX "$(DEFAULT_APPSFILE)"'; \
|
||||
echo '#define DEFAULT_OVERLAY PATHPREFIX "$(DEFAULT_OVERLAY)"'; \
|
||||
echo '#define DEFAULT_INITFILE PATHPREFIX "$(DEFAULT_INITFILE)"'; \
|
||||
echo '#define DEFAULT_WINDOWMENU PATHPREFIX "$(DEFAULT_WINDOWMENU)"'; \
|
||||
echo '#define PROGRAM_PREFIX "$(PROGRAM_PREFIX:NONE=)"'; \
|
||||
echo '#define PROGRAM_SUFFIX "$(PROGRAM_SUFFIX:NONE=)"'; \
|
||||
echo 'std::string realProgramName(const std::string& name);'; \
|
||||
|
|
Loading…
Reference in a new issue