Detects if Mosaic is in a Flatpak or not
If Mosaic is running in a Flatpak, it will use $XDG_DATA_HOME If Mosaic is running outside a Flatpak environment, it will use $HOME/.mosaic
This commit is contained in:
parent
62d9a75478
commit
672bbee31d
|
@ -0,0 +1 @@
|
|||
disable = true
|
|
@ -22,6 +22,7 @@ libhtmlw_static = static_library(
|
|||
'htmlw',
|
||||
sources,
|
||||
dependencies: [openmotif, xmu],
|
||||
include_directories: libhtmlw_inc
|
||||
include_directories: libhtmlw_inc,
|
||||
c_args: '-fcommon'
|
||||
)
|
||||
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int checkDir(char* directory) {
|
||||
DIR *dir = opendir(directory);
|
||||
if (dir) {
|
||||
closedir(dir);
|
||||
free (directory);
|
||||
return 1;
|
||||
} else if (ENOENT == errno) {
|
||||
free (directory);
|
||||
return 0;
|
||||
} else {
|
||||
free (directory);
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
int checkDir(char* directory);
|
|
@ -0,0 +1,6 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void createDir(const char* directory) {
|
||||
mkdir(directory, 0777);
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
void createDir(const char* directory);
|
|
@ -0,0 +1,34 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "isFlatpak.h"
|
||||
#include "checkDir.h"
|
||||
#include "createDir.h"
|
||||
|
||||
char* flatpakCheck() {
|
||||
char *checkFileName;
|
||||
char *homeDirectory = getenv ("HOME");
|
||||
char *mosaicDirectory;
|
||||
|
||||
if (isFlatpak()) {
|
||||
char *xdgdatahome = getenv ("XDG_DATA_HOME");
|
||||
return xdgdatahome;
|
||||
}
|
||||
|
||||
checkFileName = (char *)malloc((
|
||||
strlen (getenv ("HOME") + strlen (".mosaic"))
|
||||
));
|
||||
|
||||
sprintf (checkFileName, "%s/%s", homeDirectory, ".mosaic");
|
||||
|
||||
mosaicDirectory = (char *)malloc((
|
||||
strlen (homeDirectory + strlen("/") + strlen(".mosaic"))
|
||||
));
|
||||
|
||||
sprintf(mosaicDirectory, "%s/%s", homeDirectory, ".mosaic");
|
||||
|
||||
if (!checkDir(checkFileName))
|
||||
createDir(mosaicDirectory);
|
||||
|
||||
return mosaicDirectory;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
char* flatpakCheck();
|
|
@ -0,0 +1,11 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int isFlatpak() {
|
||||
FILE *file;
|
||||
if ((file = fopen("/.flatpak-info", "r"))) {
|
||||
fclose(file);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
int isFlatpak();
|
|
@ -0,0 +1,14 @@
|
|||
sources = [
|
||||
'checkDir.c',
|
||||
'createDir.c',
|
||||
'isFlatpak.c',
|
||||
'flatpakCheck.c'
|
||||
]
|
||||
|
||||
libutils_inc = include_directories('.')
|
||||
|
||||
libutils_static = static_library(
|
||||
'utils',
|
||||
sources,
|
||||
include_directories: libutils_inc
|
||||
)
|
|
@ -44,6 +44,7 @@ libwww2_static = static_library(
|
|||
'www2',
|
||||
sources,
|
||||
dependencies: compactstring,
|
||||
include_directories: libwww2_inc
|
||||
include_directories: libwww2_inc,
|
||||
c_args: '-fcommon'
|
||||
)
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@ compactstring = declare_dependency(link_with: libcompactstring_static, include_d
|
|||
subdir('libwww2')
|
||||
subdir('libXmx')
|
||||
subdir('libhtmlw')
|
||||
subdir('libutils')
|
||||
|
||||
nut = declare_dependency(link_with: libnut_static, include_directories: include_dir)
|
||||
www2 = declare_dependency(link_with: libwww2_static, include_directories: include_dir)
|
||||
Xmx = declare_dependency(link_with: libXmx_static, include_directories: include_dir)
|
||||
htmlw = declare_dependency(link_with: libhtmlw_static, include_directories: include_dir)
|
||||
utils = declare_dependency(link_with: libutils_static, include_directories: include_dir)
|
||||
|
||||
subdir('src')
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include "cciServer.h"
|
||||
#include "list.h"
|
||||
#include "memStuffForPipSqueeks.h"
|
||||
#include <libutils/flatpakCheck.h>
|
||||
|
||||
#include "libwww2/HTFormat.h"
|
||||
|
||||
|
@ -455,7 +456,7 @@ int retVal;
|
|||
retVal = MCCIServerInitialize(portNumber);
|
||||
if (retVal) {
|
||||
/* Write port number to .mosaiccciport */
|
||||
char *home = getenv ("XDG_DATA_HOME"), *fnam;
|
||||
char *home = flatpakCheck(), *fnam;
|
||||
FILE *fp;
|
||||
|
||||
if (!home)
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "libhtmlw/HTML.h"
|
||||
#include <time.h>
|
||||
#include "../libnut/system.h"
|
||||
#include <libutils/flatpakCheck.h>
|
||||
|
||||
/*for memset*/
|
||||
#include <memory.h>
|
||||
|
@ -506,7 +507,7 @@ mo_status mo_wipe_global_history (mo_window *win)
|
|||
static char *cached_global_hist_fname = NULL;
|
||||
mo_status mo_setup_global_history (void)
|
||||
{
|
||||
char *home = getenv ("XDG_DATA_HOME");
|
||||
char *home = flatpakCheck();
|
||||
char *default_filename = get_pref_string(eGLOBAL_HISTORY_FILE);
|
||||
char *filename;
|
||||
FILE *fp;
|
||||
|
|
|
@ -63,6 +63,7 @@
|
|||
#include "pixmaps.h"
|
||||
#include "libnut/system.h"
|
||||
#include "libwww2/HTAABrow.h"
|
||||
#include <libutils/flatpakCheck.h>
|
||||
|
||||
struct Proxy *noproxy_list = NULL, *proxy_list = NULL, *ReadProxies();
|
||||
|
||||
|
@ -4516,7 +4517,7 @@ splash_goto:
|
|||
|
||||
if (get_pref_string(ePERSONAL_EXTENSION_MAP))
|
||||
{
|
||||
char *home = getenv ("XDG_DATA_HOME");
|
||||
char *home = flatpakCheck();
|
||||
|
||||
if (!home)
|
||||
home = "/tmp";
|
||||
|
@ -4535,7 +4536,7 @@ splash_goto:
|
|||
global_type_map = get_pref_string(eGLOBAL_TYPE_MAP);
|
||||
if (get_pref_string(ePERSONAL_TYPE_MAP))
|
||||
{
|
||||
char *home = getenv ("XDG_DATA_HOME");
|
||||
char *home = flatpakCheck();
|
||||
|
||||
if (!home)
|
||||
home = "/tmp";
|
||||
|
@ -4673,7 +4674,7 @@ splash_goto:
|
|||
|
||||
/* Write pid into "~/.mosaicpid". */
|
||||
{
|
||||
char *home = getenv ("XDG_DATA_HOME"), *fnam;
|
||||
char *home = flatpakCheck(), *fnam;
|
||||
FILE *fp;
|
||||
|
||||
if (!home)
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
#include <Xm/TextF.h>
|
||||
#include <Xm/ToggleBG.h>
|
||||
#include <sys/types.h>
|
||||
#include <libutils/flatpakCheck.h>
|
||||
|
||||
#include "bitmaps/hotlist.xbm"
|
||||
#include "../libnut/system.h"
|
||||
|
@ -1295,7 +1296,7 @@ mo_status mo_dump_hotlist (mo_hotlist *list)
|
|||
*/
|
||||
mo_status mo_setup_default_hotlist (void)
|
||||
{
|
||||
char *home = getenv ("XDG_DATA_HOME");
|
||||
char *home = flatpakCheck();
|
||||
char *default_filename = get_pref_string(eDEFAULT_HOTLIST_FILE);
|
||||
char *hot_filename = get_pref_string(eDEFAULT_HOT_FILE);
|
||||
char *filename;
|
||||
|
|
|
@ -51,6 +51,7 @@ exe = executable('Mosaic', sources, dependencies: [
|
|||
Xmx,
|
||||
htmlw,
|
||||
nut,
|
||||
utils,
|
||||
openmotif,
|
||||
libpng,
|
||||
libjpeg
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "libhtmlw/HTML.h"
|
||||
#include <libutils/flatpakCheck.h>
|
||||
|
||||
/*for memset*/
|
||||
#include <memory.h>
|
||||
|
@ -450,7 +451,7 @@ mo_status mo_setup_pan_list (void)
|
|||
|
||||
mo_init_pan ();
|
||||
|
||||
home = getenv ("XDG_DATA_HOME");
|
||||
home = flatpakCheck();
|
||||
|
||||
/* This shouldn't happen. */
|
||||
if (!home)
|
||||
|
|
Reference in New Issue