Skip to content

Commit

Permalink
More of Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
kozec committed Dec 25, 2019
1 parent a271dc0 commit e9274e5
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 20 deletions.
39 changes: 39 additions & 0 deletions src/config/config_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,45 @@ config_value_t* config_get_value(struct _Config* c, const char* path, ConfigValu
return NULL;
}

ConfigValueType config_get_type(Config* _c, const char* path) {
struct _Config* c = container_of(_c, struct _Config, config);
config_value_t* value;
// First, try to return cached value
if (hashmap_get(c->values, path, (void*)&value) == MAP_OK)
return value->type;

// 2nd, try to use type from default
const struct config_item* def = config_get_default(c, path);
if (def != NULL)
return def->type;

// 3rd, try to read value from registry
value = NULL;
HKEY parent = config_get_parent(c, path, false);

if (parent != NULL) {
DWORD reg_type;
DWORD size;
LSTATUS r;
const char* last = last_element(path);
r = RegGetValueA(parent, NULL, last, RRF_RT_REG_QWORD, &reg_type, NULL, &size);
if (r != ERROR_SUCCESS)
return 0;
switch (reg_type) {
case RRF_RT_REG_SZ:
return CVT_STRING;
case RRF_RT_REG_MULTI_SZ:
return CVT_STR_ARRAY;
case RRF_RT_REG_QWORD:
return CVT_INT;
default:
return 0;
}
}

return 0;
}

static inline config_value_t* config_get_or_create(struct _Config* c, const char* path, ConfigValueType type) {
config_get_parent(c, path, true);
config_value_t* value = config_get_value(c, path, type);
Expand Down
9 changes: 7 additions & 2 deletions src/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
":/usr/lib/python2.7/site-packages"

#ifdef _WIN32
#ifdef FORCE_CONSOLE
int main(int argc, char** argv) {
INFO("Starting SC Controller GUI (forced console) v%s...", DAEMON_VERSION);
#else // FORCE_CONSOLE
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
#endif // FORCE_CONSOLE
_putenv("PYTHONIOENCODING=UTF-8");
char* new_path = NULL;
if (getenv("PATH") == NULL)
Expand All @@ -32,13 +37,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
ASSERT(new_path != NULL);
_putenv(new_path);
free(new_path);
#else
#else // _WIN32
int main(int argc, char** argv) {
INFO("Starting SC Controller GUI v%s...", DAEMON_VERSION);
// Just btw, GUI version and DAEMON_VERSION should match. GUI will
// try to get rid of old daemon automatically
traceback_set_argv0(argv[0]);
#endif
#endif // _WIN32

DEBUG("Initializing python...");
StrBuilder* sys_path = strbuilder_new();
Expand Down
41 changes: 23 additions & 18 deletions src/gui/meson.build
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
platform_dependent_deps = []
platform_dependent_src = []
platform_dependent_link_args = []
deps = [ dependency('python-2.7') ]
link = [ utils_lib, tools_lib ]
sources = [ 'gui.c' ]
link_args = []

if host_machine.system() == 'linux'
platform_dependent_deps = []
platform_dependent_src = []
# pass
elif host_machine.system() == 'openbsd' or host_machine.system() == 'netbsd'
platform_dependent_deps = []
platform_dependent_src = []
# pass
elif host_machine.system() == 'windows'
platform_dependent_deps = []
platform_dependent_link_args += [ '-mwindows' ]
platform_dependent_src = [
link_args += [ '-mwindows' ]
sources += [
import('windows').compile_resources('sc-controller.rc')
]
else
Expand All @@ -21,17 +19,24 @@ endif

sc_controller = executable('sc-controller',
include_directories: include,
link_with: [ utils_lib, tools_lib ],
link_args: platform_dependent_link_args,
dependencies: platform_dependent_deps + [
dependency('python-2.7')
],
build_rpath: '/usr/X11R6/lib',
sources: platform_dependent_src + [
'gui.c',
],
link_args: link_args,
dependencies: deps,
sources: sources,
link_with: link,
)

if host_machine.system() == 'windows'
# Windows-only 'stay attached to console' executable
sc_controller_console = executable('sc-controller-console',
include_directories: include,
build_rpath: '/usr/X11R6/lib',
c_args: [ '-DFORCE_CONSOLE' ],
dependencies: deps,
sources: sources,
link_with: link,
)
endif

run_target('sc-controller', command: ['sh', '../../meson-run.sh', 'src/gui/sc-controller'],
dependencies: [sc_controller])
Expand Down

0 comments on commit e9274e5

Please sign in to comment.