From 6aacf694a9156aa99b80e398587fcf5cb24d985f Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Fri, 22 Nov 2024 17:36:26 +0100 Subject: [PATCH] copy default styles css files to use datadir if needed --- src/x50ng/module.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/x50ng/module.c b/src/x50ng/module.c index 68bc62d..a17947d 100644 --- a/src/x50ng/module.c +++ b/src/x50ng/module.c @@ -6,12 +6,42 @@ #include #include +#include +#include + #include "list.h" #include "x49gp.h" #include "options.h" +#ifdef X49GP_DATADIR +# define GLOBAL_DATADIR X49GP_DATADIR +#else +# define GLOBAL_DATADIR x49gp->progpath +#endif #define STATE_FILE_NAME "state" +static int copy_file_from_global_datadir_to_user_datadir( const char* filename ) +{ + GError* gerror = NULL; + if ( !g_file_test( g_build_filename( opt.datadir, filename, NULL ), G_FILE_TEST_EXISTS ) ) { + if ( opt.verbose ) + fprintf( stderr, "Copying %s to %s\n", g_build_filename( GLOBAL_DATADIR, filename, NULL ), + g_build_filename( opt.datadir, filename, NULL ) ); + + if ( !g_file_test( g_build_filename( GLOBAL_DATADIR, filename, NULL ), G_FILE_TEST_EXISTS ) ) + return EXIT_FAILURE; + + if ( !g_file_copy( g_file_new_build_filename( GLOBAL_DATADIR, filename, NULL ), + g_file_new_build_filename( opt.datadir, filename, NULL ), G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &gerror ) ) { + fprintf( stderr, "Unable to copy style: %s\n", gerror->message ); + g_error_free( gerror ); + return -errno; + } + } + + return EXIT_SUCCESS; +} + int x49gp_modules_init( x49gp_t* x49gp ) { x49gp_module_t* module; @@ -104,6 +134,9 @@ int x49gp_modules_load( x49gp_t* x49gp ) return error; } + copy_file_from_global_datadir_to_user_datadir( "style-50g.css" ); + copy_file_from_global_datadir_to_user_datadir( "style-49gp.css" ); + x49gp->state = g_key_file_new(); if ( NULL == x49gp->state ) { fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ );