diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 7828d94..41aa0be 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -64,6 +64,7 @@ struct _Pw3270SettingsPage { void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser); gchar * pw3270_build_data_filename(const char *filename); +gchar * pw3270_build_data_path(const char *path); G_END_DECLS diff --git a/src/main/linux/tools.c b/src/main/linux/tools.c index e34b254..ae299ef 100644 --- a/src/main/linux/tools.c +++ b/src/main/linux/tools.c @@ -20,12 +20,24 @@ #include #include + gchar * pw3270_build_data_path(const char *name) { + + gchar * path = g_build_filename(G_STRINGIFY(DATADIR),name,NULL); + + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { + return path; + } + g_free(path); + + g_message("Cant find path for '%s'",path); + return NULL; + + } + gchar * pw3270_build_data_filename(const char *filename) { gchar * path = g_build_filename(G_STRINGIFY(DATADIR),filename,NULL); - printf("\n\n\n%s\n\n\n",path); - if(g_file_test(path,G_FILE_TEST_IS_REGULAR)) { return path; } diff --git a/src/main/windows/tools.c b/src/main/windows/tools.c index 3060603..09105cc 100644 --- a/src/main/windows/tools.c +++ b/src/main/windows/tools.c @@ -20,6 +20,27 @@ #include #include + gchar * pw3270_build_data_path(const char *name) { + + g_autofree gchar * pkgdir = g_win32_get_package_installation_directory_of_module(NULL); + + gchar * path = g_build_filename(pkgdir,name,NULL); + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { + return path; + } + g_free(path); + + path = g_build_filename(pkgdir,"share",G_STRINGIFY(PRODUCT_NAME),name,NULL); + if(g_file_test(path,G_FILE_TEST_IS_DIR)) { + return path; + } + + g_free(path); + g_message("Cant find path for '%s'",path); + return NULL; + + } + gchar * pw3270_build_data_filename(const char *filename) { g_autofree gchar * pkgdir = g_win32_get_package_installation_directory_of_module(NULL); diff --git a/src/objects/application/application.c b/src/objects/application/application.c index eccf58c..4bc21c1 100644 --- a/src/objects/application/application.c +++ b/src/objects/application/application.c @@ -486,25 +486,33 @@ void startup(GApplication *application) { // Load keypad models // { - lib3270_autoptr(char) keypad_path = lib3270_build_data_filename("keypad",NULL); + g_autofree gchar *keypad_path = pw3270_build_data_path("keypad"); - g_autoptr(GError) error = NULL; - g_autoptr(GDir) dir = g_dir_open(keypad_path,0,&error); + if(keypad_path) { - if(dir) { + g_message("Searching for keypads in '%s'",keypad_path); + + g_autoptr(GError) error = NULL; + g_autoptr(GDir) dir = g_dir_open(keypad_path,0,&error); + + if(dir) { + + const gchar *name = g_dir_read_name(dir); + while(!error && name) { + g_autofree gchar * path = g_build_filename(keypad_path,name,NULL); + app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path); + name = g_dir_read_name(dir); + } - const gchar *name = g_dir_read_name(dir); - while(!error && name) { - g_autofree gchar * path = g_build_filename(keypad_path,name,NULL); - app->keypads = pw3270_keypad_model_new_from_xml(app->keypads,path); - name = g_dir_read_name(dir); } - } + if(error) { + g_message("Can't read %s: %s",keypad_path,error->message); + } + - if(error) { - g_message("Can't read %s: %s",keypad_path,error->message); } + } // -- libgit2 0.21.2