Skip to content
Permalink
Browse files

Add support for running with a versioned root path in mumble.exe.

This commit bakes the MUMBLE_VERSION string into mumble.exe.

This version string is used to determine where to load mumble_app.dll
from, and what to consider the root directory for other binaries.

In pseudo code, if the path

    ${MUMBLE_EXE_DIRECTORY}\Versions\${MUMBLE_VERSION}

exists, the mumble.exe binary will use that as the root for loading
mumble_app.dll, and all further binaries.

If mumble.exe finds the aforementioned directory, it sets the
MUMBLE_VERSION_ROOT environment variable to signal which directory
to use as the "application root" directory for loading further
binaries.
  • Loading branch information...
mkrautz committed Jun 1, 2015
1 parent 1250b04 commit e6b17b561d9743a27e515058c29f88b72111bc38
Showing with 71 additions and 11 deletions.
  1. +71 −11 src/mumble_exe/mumble_exe.cpp
@@ -45,9 +45,22 @@ static void Alert(LPCWSTR title, LPCWSTR msg) {
MessageBox(NULL, msg, title, MB_OK|MB_ICONERROR);
}

// Get the current Mumble version built into this executable.
// If no version is available, this function returns an empty
// string.
static const std::wstring GetMumbleVersion() {
#ifdef MUMBLE_VERSION
# define MUMTEXT(X) L#X
const std::wstring version(MUMTEXT(MUMBLE_VERSION));
return version;
#else
return std::wstring();
#endif
}

// GetExecutableDirPath returns the directory that
// mumble.exe resides in.
static std::wstring GetExecutableDirPath() {
static const std::wstring GetExecutableDirPath() {
wchar_t path[MAX_PATH];

if (GetModuleFileNameW(NULL, path, MAX_PATH) == 0)
@@ -63,7 +76,7 @@ static std::wstring GetExecutableDirPath() {
// ConfigureEnvironment prepares mumble.exe's environment to
// run mumble_app.dll.
static bool ConfigureEnvironment() {
std::wstring exe_path = GetExecutableDirPath();
const std::wstring exe_path = GetExecutableDirPath();

// Remove the current directory from the DLL search path.
if (!SetDllDirectoryW(L""))
@@ -76,18 +89,39 @@ static bool ConfigureEnvironment() {
return true;
}

// GetVersionedRootPath returns the versioned root path if
// Mumble is configured to work with versioned paths.
// If Mumble is not configured for versioned paths, this
// function returns an empty string.
static const std::wstring GetVersionedRootPath() {
const std::wstring versionedRootPath = GetExecutableDirPath();
if (versionedRootPath.empty()) {
return std::wstring();
}

const std::wstring version = GetMumbleVersion();
if (version.length() > 0) {
return versionedRootPath + L"Versions\\" + version;
}

return std::wstring();
}

// GetAbsoluteMumbleAppDllPath returns the absolute path to
// mumble_app.dll - the DLL containing the Mumble client
// application code.
static std::wstring GetAbsoluteMumbleAppDllPath() {
std::wstring exe_path = GetExecutableDirPath();
if (exe_path.empty())
static const std::wstring GetAbsoluteMumbleAppDllPath(std::wstring suggested_base_dir) {
std::wstring base_dir = suggested_base_dir;

if (base_dir.empty()) {
base_dir = GetExecutableDirPath();
}

if (base_dir.empty()) {
return std::wstring();
}

std::wstring abs_dll_path(exe_path);
abs_dll_path.append(L"\\");
abs_dll_path.append(L"mumble_app.dll");
return abs_dll_path;
return base_dir + L"\\mumble_app.dll";
}

#ifdef DEBUG
@@ -97,7 +131,20 @@ int main(int argc, char **argv) {
return -1;
}

std::wstring abs_dll_path = GetAbsoluteMumbleAppDllPath();
std::wstring versioned_root_path = GetVersionedRootPath();

bool ok = false;
if (!versioned_root_path.empty()) {
if (PathFileExists(versioned_root_path.c_str())) {
_wputenv_s(L"MUMBLE_VERSION_ROOT", versioned_root_path.c_str());
ok = true;
}
}
if (!ok) {
_wputenv_s(L"MUMBLE_VERSION_ROOT", L"");
}

std::wstring abs_dll_path = GetAbsoluteMumbleAppDllPath(ok ? versioned_root_path : std::wstring());
if (abs_dll_path.empty()) {
Alert(L"Mumble Launcher Error -2", L"Unable to find the absolute path of mumble_app.dll.");
return -2;
@@ -127,7 +174,20 @@ int APIENTRY wWinMain(HINSTANCE instance, HINSTANCE prevInstance, wchar_t *cmdAr
return -1;
}

std::wstring abs_dll_path = GetAbsoluteMumbleAppDllPath();
std::wstring versioned_root_path = GetVersionedRootPath();

bool ok = false;
if (!versioned_root_path.empty()) {
if (PathFileExists(versioned_root_path.c_str())) {
_wputenv_s(L"MUMBLE_VERSION_ROOT", versioned_root_path.c_str());
ok = true;
}
}
if (!ok) {
_wputenv_s(L"MUMBLE_VERSION_ROOT", L"");
}

std::wstring abs_dll_path = GetAbsoluteMumbleAppDllPath(ok ? versioned_root_path : std::wstring());
if (abs_dll_path.empty()) {
Alert(L"Mumble Launcher Error -2", L"Unable to find the absolute path of mumble_app.dll.");
return -2;

0 comments on commit e6b17b5

Please sign in to comment.
You can’t perform that action at this time.