UI: Add support for portable mode

Portable mode can be enabled via command line options (--portable or -p)
or by having any of the following files present in the base directory of
a portable install:

portable_mode
obs_portable_mode
portable_mode.txt
obs_portable_mode.txt

Portable mode is omitted when obs is built with a unix program
structure.
This commit is contained in:
jp9000 2015-06-01 15:52:23 -07:00
parent 899557699f
commit ea3496e512
2 changed files with 68 additions and 0 deletions

View file

@ -52,6 +52,8 @@ static log_handler_t def_log_handler;
static string currentLogFile;
static string lastLogFile;
static bool portable_mode = false;
QObject *CreateShortcutFilter()
{
return new OBSEventFilter([](QObject *, QEvent *event)
@ -795,6 +797,53 @@ static void load_debug_privilege(void)
}
#endif
#ifdef __APPLE__
#define BASE_PATH ".."
#else
#define BASE_PATH "../.."
#endif
#define CONFIG_PATH BASE_PATH "/config"
#ifndef OBS_UNIX_STRUCTURE
#define OBS_UNIX_STRUCTURE 0
#endif
int GetConfigPath(char *path, size_t size, const char *name)
{
if (!OBS_UNIX_STRUCTURE && portable_mode) {
if (name && *name) {
return snprintf(path, size, CONFIG_PATH "/%s", name);
} else {
return snprintf(path, size, CONFIG_PATH);
}
} else {
return os_get_config_path(path, size, name);
}
}
char *GetConfigPathPtr(const char *name)
{
if (!OBS_UNIX_STRUCTURE && portable_mode) {
char path[512];
if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
return bstrdup(path);
} else {
return NULL;
}
} else {
return os_get_config_path_ptr(name);
}
}
static inline bool arg_is(const char *arg,
const char *long_form, const char *short_form)
{
return (long_form && strcmp(arg, long_form) == 0) ||
(short_form && strcmp(arg, short_form) == 0);
}
int main(int argc, char *argv[])
{
#ifndef _WIN32
@ -808,6 +857,22 @@ int main(int argc, char *argv[])
base_get_log_handler(&def_log_handler, nullptr);
for (int i = 1; i < argc; i++) {
if (arg_is(argv[i], "--portable", "-p")) {
portable_mode = true;
}
}
#if !OBS_UNIX_STRUCTURE
if (!portable_mode) {
portable_mode =
os_file_exists(BASE_PATH "/portable_mode") ||
os_file_exists(BASE_PATH "/obs_portable_mode") ||
os_file_exists(BASE_PATH "/portable_mode.txt") ||
os_file_exists(BASE_PATH "/obs_portable_mode.txt");
}
#endif
fstream logFile;
int ret = run_program(logFile, argc, argv);

View file

@ -102,6 +102,9 @@ public:
const char *GetRenderModule() const;
};
int GetConfigPath(char *path, size_t size, const char *name);
char *GetConfigPathPtr(const char *name);
inline OBSApp *App() {return static_cast<OBSApp*>(qApp);}
inline config_t *GetGlobalConfig() {return App()->GlobalConfig();}