diff -r 5914de4a823f -r 0e1a57225c62 pre-inst/pre-inst.c --- a/pre-inst/pre-inst.c Fri Mar 08 13:50:07 2019 +0000 +++ b/pre-inst/pre-inst.c Mon Jul 13 13:19:03 2020 +0100 @@ -90,10 +90,11 @@ unsigned pre_install_thread(void *data) { int retval; - char *path=data; + gchar *path=data; gchar *s,*uri; char *install[]={"plover-gtkui",NULL}; GError *error=NULL; + plover__uri_handler_init(); prefix=plover_pre_install_prefix(); s=g_strconcat(prefix,"/var/log/pre-install",NULL); plover_log_open(s); @@ -105,7 +106,7 @@ free(uri); if (verify_and_fix(prefix)) { - free(path); + g_free(path); g_free(prefix); return -1; } @@ -117,7 +118,7 @@ fprintf(stderr,"%s\n",error->message); g_error_free(error); } - free(path); + g_free(path); #ifdef WIN32 PostQuitMessage(retval); PostThreadMessage(main_thread_id,WM_QUIT,retval,0); @@ -455,6 +456,38 @@ } #endif /* WIN32 */ +gchar *pre_install_default_path(const char *argv0) +{ + size_t length; + void *contents; + gchar *path; + gchar *s,*uri; + struct razor_error *tmp_error=NULL; + /* + * The default path is the executable itself if it's an archive + * or otherwise the directory in which the executable is stored. + */ + path=plover_get_program(argv0); + uri=razor_path_to_uri(path); + s=g_strconcat(uri,"/repodata/comps.xml",NULL); + free(uri); + contents=razor_uri_get_contents(s,&length,FALSE,&tmp_error); + g_free(s); + if (contents) + razor_uri_free_contents(contents,length); + else + { + if (razor_error_matches(tmp_error,RAZOR_GENERAL_ERROR, + RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE)) + { + g_free(path); + path=plover_get_program_directory(argv0); + } + razor_error_free(tmp_error); + } + return path; +} + int main(int argc,char **argv) { gboolean success,uninstall=FALSE,enable_post=FALSE; @@ -512,7 +545,7 @@ else { if (!path) - path=plover_get_program_directory(argv[0]); + path=pre_install_default_path(argv[0]); #ifdef WIN32 success=win32_pre_install_gui(path)==EXIT_SUCCESS; #else