Skip to content

Commit 62e2c76

Browse files
xordspar0TheAssassin
authored andcommitted
Enable portable home/config dirs for extract-and-run
1 parent b719a7f commit 62e2c76

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/runtime.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,27 @@ bool build_mount_point(char* mount_dir, const char* const argv0, char const* con
524524
mount_dir[templen+8+namelen+6] = 0; // null terminate destination
525525
}
526526

527+
void set_portable_home_and_config(char *basepath) {
528+
char portable_home_dir[PATH_MAX];
529+
char portable_config_dir[PATH_MAX];
530+
531+
/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
532+
strcpy (portable_home_dir, basepath);
533+
strcat (portable_home_dir, ".home");
534+
if(is_writable_directory(portable_home_dir)){
535+
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
536+
setenv("HOME",portable_home_dir,1);
537+
}
538+
539+
/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
540+
strcpy (portable_config_dir, basepath);
541+
strcat (portable_config_dir, ".config");
542+
if(is_writable_directory(portable_config_dir)){
543+
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
544+
setenv("XDG_CONFIG_HOME",portable_config_dir,1);
545+
}
546+
}
547+
527548
int main(int argc, char *argv[]) {
528549
char appimage_path[PATH_MAX];
529550
char argv0_path[PATH_MAX];
@@ -731,6 +752,8 @@ int main(int argc, char *argv[]) {
731752
setenv("ARGV0", argv0_path, 1);
732753
setenv("APPDIR", prefix, 1);
733754

755+
set_portable_home_and_config(fullpath);
756+
734757
execv(apprun_path, new_argv);
735758

736759
int error = errno;
@@ -912,24 +935,7 @@ int main(int argc, char *argv[]) {
912935
setenv( "ARGV0", argv0_path, 1 );
913936
setenv( "APPDIR", mount_dir, 1 );
914937

915-
char portable_home_dir[PATH_MAX];
916-
char portable_config_dir[PATH_MAX];
917-
918-
/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
919-
strcpy (portable_home_dir, fullpath);
920-
strcat (portable_home_dir, ".home");
921-
if(is_writable_directory(portable_home_dir)){
922-
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
923-
setenv("HOME",portable_home_dir,1);
924-
}
925-
926-
/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
927-
strcpy (portable_config_dir, fullpath);
928-
strcat (portable_config_dir, ".config");
929-
if(is_writable_directory(portable_config_dir)){
930-
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
931-
setenv("XDG_CONFIG_HOME",portable_config_dir,1);
932-
}
938+
set_portable_home_and_config(fullpath);
933939

934940
/* Original working directory */
935941
char cwd[1024];

0 commit comments

Comments
 (0)