mirror of
https://github.com/gnif/LookingGlass.git
synced 2024-11-25 14:57:20 +00:00
[host] search the applications local directory for the config
This commit is contained in:
parent
fcbdf7ba4f
commit
67dec216d2
@ -27,3 +27,4 @@ void app_quit();
|
|||||||
|
|
||||||
// these must be implemented for each OS
|
// these must be implemented for each OS
|
||||||
const char * os_getExecutable();
|
const char * os_getExecutable();
|
||||||
|
const char * os_getDataPath();
|
||||||
|
@ -30,6 +30,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
struct app
|
struct app
|
||||||
{
|
{
|
||||||
const char * executable;
|
const char * executable;
|
||||||
|
char * dataPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct app app = { 0 };
|
struct app app = { 0 };
|
||||||
@ -37,7 +38,13 @@ struct app app = { 0 };
|
|||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
app.executable = argv[0];
|
app.executable = argv[0];
|
||||||
|
|
||||||
|
struct passwd * pw = getpwuid(getuid());
|
||||||
|
alloc_sprintf(&app.dataPath, "%s/", pw->pw_dir);
|
||||||
|
|
||||||
int result = app_main(argc, argv);
|
int result = app_main(argc, argv);
|
||||||
|
|
||||||
|
free(app.dataPath);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,3 +64,8 @@ const char * os_getExecutable()
|
|||||||
{
|
{
|
||||||
return app.executable;
|
return app.executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * os_getDataPath()
|
||||||
|
{
|
||||||
|
return app.dataPath;
|
||||||
|
}
|
||||||
|
@ -303,6 +303,24 @@ const char * os_getExecutable()
|
|||||||
return app.executable;
|
return app.executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char * os_getDataPath()
|
||||||
|
{
|
||||||
|
static char path[MAX_PATH] = { 0 };
|
||||||
|
if (!path[0])
|
||||||
|
{
|
||||||
|
if (!GetModuleFileName(NULL, path, MAX_PATH))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
char *p = strrchr(path, '\\');
|
||||||
|
if (!p)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
++p;
|
||||||
|
*p = '\0';
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
HWND os_getMessageWnd()
|
HWND os_getMessageWnd()
|
||||||
{
|
{
|
||||||
return app.messageWnd;
|
return app.messageWnd;
|
||||||
|
@ -38,6 +38,8 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define CONFIG_FILE "looking-glass-host.ini"
|
||||||
|
|
||||||
#define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F)
|
#define ALIGN_DN(x) ((uintptr_t)(x) & ~0x7F)
|
||||||
#define ALIGN_UP(x) ALIGN_DN(x + 0x7F)
|
#define ALIGN_UP(x) ALIGN_DN(x + 0x7F)
|
||||||
|
|
||||||
@ -400,7 +402,22 @@ int app_main(int argc, char * argv[])
|
|||||||
CaptureInterfaces[i]->initOptions();
|
CaptureInterfaces[i]->initOptions();
|
||||||
|
|
||||||
// try load values from a config file
|
// try load values from a config file
|
||||||
option_load("looking-glass-host.ini");
|
const char * dataPath = os_getDataPath();
|
||||||
|
if (!dataPath)
|
||||||
|
{
|
||||||
|
option_free();
|
||||||
|
DEBUG_ERROR("Failed to get the application's data path");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t len = strlen(dataPath) + sizeof(CONFIG_FILE) + 1;
|
||||||
|
char configFile[len];
|
||||||
|
snprintf(configFile, sizeof(configFile), "%s%s", dataPath, CONFIG_FILE);
|
||||||
|
DEBUG_INFO("Looking for configuration file at: %s", configFile);
|
||||||
|
if (option_load(configFile))
|
||||||
|
DEBUG_INFO("Configuration file loaded");
|
||||||
|
else
|
||||||
|
DEBUG_INFO("Configuration file not found or invalid");
|
||||||
|
|
||||||
// parse the command line arguments
|
// parse the command line arguments
|
||||||
if (!option_parse(argc, argv))
|
if (!option_parse(argc, argv))
|
||||||
|
Loading…
Reference in New Issue
Block a user