Skip to content

Commit

Permalink
Enable portable home/config dirs for extract-and-run
Browse files Browse the repository at this point in the history
  • Loading branch information
xordspar0 authored and TheAssassin committed Mar 8, 2023
1 parent b719a7f commit 62e2c76
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions src/runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,27 @@ bool build_mount_point(char* mount_dir, const char* const argv0, char const* con
mount_dir[templen+8+namelen+6] = 0; // null terminate destination
}

void set_portable_home_and_config(char *basepath) {
char portable_home_dir[PATH_MAX];
char portable_config_dir[PATH_MAX];

/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
strcpy (portable_home_dir, basepath);
strcat (portable_home_dir, ".home");
if(is_writable_directory(portable_home_dir)){
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
setenv("HOME",portable_home_dir,1);
}

/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
strcpy (portable_config_dir, basepath);
strcat (portable_config_dir, ".config");
if(is_writable_directory(portable_config_dir)){
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
setenv("XDG_CONFIG_HOME",portable_config_dir,1);
}
}

int main(int argc, char *argv[]) {
char appimage_path[PATH_MAX];
char argv0_path[PATH_MAX];
Expand Down Expand Up @@ -731,6 +752,8 @@ int main(int argc, char *argv[]) {
setenv("ARGV0", argv0_path, 1);
setenv("APPDIR", prefix, 1);

set_portable_home_and_config(fullpath);

execv(apprun_path, new_argv);

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

char portable_home_dir[PATH_MAX];
char portable_config_dir[PATH_MAX];

/* If there is a directory with the same name as the AppImage plus ".home", then export $HOME */
strcpy (portable_home_dir, fullpath);
strcat (portable_home_dir, ".home");
if(is_writable_directory(portable_home_dir)){
fprintf(stderr, "Setting $HOME to %s\n", portable_home_dir);
setenv("HOME",portable_home_dir,1);
}

/* If there is a directory with the same name as the AppImage plus ".config", then export $XDG_CONFIG_HOME */
strcpy (portable_config_dir, fullpath);
strcat (portable_config_dir, ".config");
if(is_writable_directory(portable_config_dir)){
fprintf(stderr, "Setting $XDG_CONFIG_HOME to %s\n", portable_config_dir);
setenv("XDG_CONFIG_HOME",portable_config_dir,1);
}
set_portable_home_and_config(fullpath);

/* Original working directory */
char cwd[1024];
Expand Down

0 comments on commit 62e2c76

Please sign in to comment.