GF_EXPORT GF_Config *gf_cfg_init(const char *file, Bool *new_cfg) { GF_Config *cfg; char szPath[GF_MAX_PATH]; if (new_cfg) *new_cfg = GF_FALSE; if (file) { cfg = gf_cfg_new(NULL, file); /*force creation of a new config*/ if (!cfg) { FILE *fcfg = gf_fopen(file, "wt"); if (fcfg) { gf_fclose(fcfg); cfg = gf_cfg_new(NULL, file); if (new_cfg) *new_cfg = GF_TRUE; } } if (cfg) { check_modules_dir(cfg); return cfg; } } if (!get_default_install_path(szPath, GF_PATH_CFG)) { fprintf(stderr, "Fatal error: Cannot create a configuration file in application or user home directory - no write access\n"); return NULL; } cfg = gf_cfg_new(szPath, CFG_FILE_NAME); if (!cfg) { fprintf(stderr, "GPAC config file %s not found in %s - creating new file\n", CFG_FILE_NAME, szPath); cfg = create_default_config(szPath); } if (!cfg) { fprintf(stderr, "\nCannot create config file %s in %s directory\n", CFG_FILE_NAME, szPath); return NULL; } #ifndef GPAC_IPHONE fprintf(stderr, "Using config file in %s directory\n", szPath); #endif check_modules_dir(cfg); if (!gf_cfg_get_key(cfg, "General", "StorageDirectory")) { get_default_install_path(szPath, GF_PATH_CFG); strcat(szPath, "/Storage"); if (!gf_dir_exists(szPath)) gf_mkdir(szPath); gf_cfg_set_key(cfg, "General", "StorageDirectory", szPath); } if (new_cfg) *new_cfg = GF_TRUE; return cfg; }
static void gf_ios_refresh_cache_directory( GF_Config *cfg, char *file_path) { char *cache_dir; char buf[GF_MAX_PATH], *res, *sep; res = realpath(file_path, buf); if (!res) return; sep = strstr(res, ".gpac"); assert(sep); sep[0] = 0; gf_cfg_set_key(cfg, "General", "LastWorkingDir", res); gf_cfg_set_key(cfg, "General", "iOSDocumentsDir", res); sep = strstr(res, "Documents"); assert(sep); sep[0]=0; strcat(res, "tmp/"); cache_dir = res; if (!gf_dir_exists(cache_dir)) gf_mkdir(cache_dir); gf_cfg_set_key(cfg, "General", "CacheDirectory", cache_dir); }
static Bool get_default_install_path(char *file_path, u32 path_type) { char app_path[GF_MAX_PATH]; char *sep; u32 size = GF_MAX_PATH; /*on OSX, Linux & co, user home is where we store the cfg file*/ if (path_type==GF_PATH_CFG) { char *user_home = getenv("HOME"); #ifdef GPAC_IPHONE char buf[PATH_MAX]; char *res; #endif if (!user_home) return 0; #ifdef GPAC_IPHONE res = realpath(user_home, buf); if (res) { strcpy(file_path, buf); strcat(file_path, "/Documents"); } else #endif strcpy(file_path, user_home); if (file_path[strlen(file_path)-1] == '/') file_path[strlen(file_path)-1] = 0; //cleanup of old install in .gpacrc if (check_file_exists(".gpacrc", file_path, file_path)) { strcpy(app_path, file_path); strcat(app_path, "/.gpacrc"); gf_delete_file(app_path); } strcat(file_path, "/.gpac"); if (!gf_dir_exists(file_path)) { gf_mkdir(file_path); } return 1; } if (path_type==GF_PATH_APP) { #if (defined(__DARWIN__) || defined(__APPLE__) ) if (_NSGetExecutablePath(app_path, &size) ==0) { realpath(app_path, file_path); char *sep = strrchr(file_path, '/'); if (sep) sep[0] = 0; return 1; } #elif defined(GPAC_CONFIG_LINUX) size = readlink("/proc/self/exe", file_path, GF_MAX_PATH); if (size>0) { char *sep = strrchr(file_path, '/'); if (sep) sep[0] = 0; return 1; } #endif return 0; } /*locate the app*/ if (!get_default_install_path(app_path, GF_PATH_APP)) return 0; /*installed or symlink on system, user user home directory*/ if (!strnicmp(app_path, "/usr/", 5) || !strnicmp(app_path, "/opt/", 5)) { if (path_type==GF_PATH_GUI) { /*look in possible install dirs ...*/ if (check_file_exists("gui.bt", "/usr/share/gpac/gui", file_path)) return 1; if (check_file_exists("gui.bt", "/usr/local/share/gpac/gui", file_path)) return 1; if (check_file_exists("gui.bt", "/opt/share/gpac/gui", file_path)) return 1; if (check_file_exists("gui.bt", "/opt/local/share/gpac/gui", file_path)) return 1; } else if (path_type==GF_PATH_MODULES) { /*look in possible install dirs ...*/ if (check_file_exists(TEST_MODULE, "/usr/lib/gpac", file_path)) return 1; if (check_file_exists(TEST_MODULE, "/usr/local/lib/gpac", file_path)) return 1; if (check_file_exists(TEST_MODULE, "/opt/lib/gpac", file_path)) return 1; if (check_file_exists(TEST_MODULE, "/opt/local/lib/gpac", file_path)) return 1; if (check_file_exists(TEST_MODULE, "/usr/lib/x86_64-linux-gnu/gpac", file_path)) return 1; if (check_file_exists(TEST_MODULE, "/usr/lib/i386-linux-gnu/gpac", file_path)) return 1; } } if (path_type==GF_PATH_GUI) { if (get_default_install_path(app_path, GF_PATH_CFG)) { /*GUI not found, look in ~/.gpac/gui/ */ strcat(app_path, "/.gpac/gui"); if (check_file_exists("gui.bt", app_path, file_path)) return 1; } /*GUI not found, look in gpac distribution if any */ if (get_default_install_path(app_path, GF_PATH_APP)) { char *sep = strstr(app_path, "/bin/gcc"); if (!sep) sep = strstr(app_path, "/bin/osx"); if (sep) { sep[0] = 0; strcat(app_path, "/gui"); if (check_file_exists("gui.bt", app_path, file_path)) return 1; } } /*GUI not found, look in .app for OSX case*/ } if (path_type==GF_PATH_MODULES) { /*look in gpac compilation tree (modules are output in the same folder as apps) */ if (get_default_install_path(app_path, GF_PATH_APP)) { if (check_file_exists(TEST_MODULE, app_path, file_path)) return 1; /*on OSX check modules subdirectory */ strcat(app_path, "/modules"); if (check_file_exists(TEST_MODULE, app_path, file_path)) return 1; } /*modules not found, look in ~/.gpac/modules/ */ if (get_default_install_path(app_path, GF_PATH_CFG)) { strcpy(app_path, file_path); strcat(app_path, "/.gpac/modules"); if (check_file_exists(TEST_MODULE, app_path, file_path)) return 1; } /*modules not found, failure*/ return 0; } /*OSX way vs iPhone*/ sep = strstr(app_path, ".app/"); if (sep) sep[4] = 0; /*we are looking for .app install path, or GUI */ if (path_type==GF_PATH_GUI) { #ifndef GPAC_IPHONE strcat(app_path, "/Contents/MacOS/gui"); if (check_file_exists("gui.bt", app_path, file_path)) return 1; #else /*iOS: for now, everything is set flat within the package*/ /*iOS app is distributed with embedded GUI*/ get_default_install_path(app_path, GF_PATH_APP); strcat(app_path, "/gui"); if (check_file_exists("gui.bt", app_path, file_path)) return 1; #endif } else { // (path_type==GF_PATH_MODULES) strcat(app_path, "/Contents/MacOS/modules"); if (check_file_exists(TEST_MODULE, app_path, file_path)) return 1; } /*not found ...*/ return 0; }
static void ft_rescan_fonts(GF_FontReader *dr) { u32 i, count; GF_Config *cfg = gf_modules_get_config((GF_BaseInterface *)dr); FTBuilder *ftpriv = (FTBuilder *)dr->udta; GF_LOG(GF_LOG_INFO, GF_LOG_PARSER, ("[FreeType] Rescaning %d font directories\n", gf_list_count(ftpriv->font_dirs) )); count = gf_cfg_get_key_count(cfg, "FontEngine"); for (i=0; i<count; i++) { const char *key = gf_cfg_get_key_name(cfg, "FontEngine", i); if (!strcmp(key, "FontReader")) continue; if (!strcmp(key, "FontDirectory")) continue; if (!strcmp(key, "RescanFonts")) continue; /*any other persistent options should go here*/ gf_cfg_set_key(cfg, "FontEngine", key, NULL); count--; i--; } gf_modules_set_option((GF_BaseInterface *)dr, "FontEngine", "RescanFonts", "no"); if (ftpriv->font_fixed) gf_free(ftpriv->font_fixed); ftpriv->font_fixed = NULL; if (ftpriv->font_sans) gf_free(ftpriv->font_sans); ftpriv->font_sans = NULL; if (ftpriv->font_serif) gf_free(ftpriv->font_serif); ftpriv->font_serif = NULL; if (ftpriv->font_default) gf_free(ftpriv->font_default); ftpriv->font_default = NULL; count = gf_list_count(ftpriv->font_dirs); for (i=0; i<count; i++) { char *font_dir = gf_list_get(ftpriv->font_dirs, i); if (gf_dir_exists(font_dir)) { gf_enum_directory(font_dir, 0, ft_enum_fonts, dr, "ttf;ttc"); gf_enum_directory(font_dir, 1, ft_enum_fonts_dir, dr, NULL); } } if (ftpriv->font_fixed) gf_free(ftpriv->font_fixed); ftpriv->font_fixed = NULL; if (ftpriv->font_sans) gf_free(ftpriv->font_sans); ftpriv->font_sans = NULL; if (ftpriv->font_serif) gf_free(ftpriv->font_serif); ftpriv->font_serif = NULL; /* let's check we have fonts that match our default Bol/Italic/BoldItalic conventions*/ count = gf_cfg_get_key_count(cfg, "FontEngine"); for (i=0; i<count; i++) { const char *opt; char fkey[GF_MAX_PATH]; const char *key = gf_cfg_get_key_name(cfg, "FontEngine", i); opt = gf_cfg_get_key(cfg, "FontEngine", key); if (!strchr(opt, '/') && !strchr(opt, '\\')) continue; if (!strcmp(key, "FontDirectory")) continue; if (strstr(key, "Bold")) continue; if (strstr(key, "Italic")) continue; strcpy(fkey, key); strcat(fkey, " Italic"); opt = gf_cfg_get_key(cfg, "FontEngine", fkey); if (!opt) continue; strcpy(fkey, key); strcat(fkey, " Bold"); opt = gf_cfg_get_key(cfg, "FontEngine", fkey); if (!opt) continue; strcpy(fkey, key); strcat(fkey, " Bold Italic"); opt = gf_cfg_get_key(cfg, "FontEngine", fkey); if (!opt) continue; strcpy(fkey, key); strlwr(fkey); /*this font is suited for our case*/ if (isBestFontFor(BEST_FIXED_FONTS, ftpriv->font_fixed, key) || (!ftpriv->font_fixed && (strstr(fkey, "fixed") || strstr(fkey, "mono")) ) ) { if (ftpriv->font_fixed) gf_free(ftpriv->font_fixed); ftpriv->font_fixed = gf_strdup(key); } if (isBestFontFor(BEST_SANS_FONTS, ftpriv->font_sans, key) || (!ftpriv->font_sans && strstr(fkey, "sans")) ) { if (ftpriv->font_sans) gf_free(ftpriv->font_sans); ftpriv->font_sans = gf_strdup(key); } if (isBestFontFor(BEST_SERIF_FONTS, ftpriv->font_serif, key) || (!ftpriv->font_serif && strstr(fkey, "serif")) ) { if (ftpriv->font_serif) gf_free(ftpriv->font_serif); ftpriv->font_serif = gf_strdup(key); } } if (!ftpriv->font_serif) ftpriv->font_serif = gf_strdup(ftpriv->font_default ? ftpriv->font_default : ""); if (!ftpriv->font_sans) ftpriv->font_sans = gf_strdup(ftpriv->font_default ? ftpriv->font_default : ""); if (!ftpriv->font_fixed) ftpriv->font_fixed = gf_strdup(ftpriv->font_default ? ftpriv->font_default : ""); gf_modules_set_option((GF_BaseInterface *)dr, "FontEngine", "FontFixed", ftpriv->font_fixed); gf_modules_set_option((GF_BaseInterface *)dr, "FontEngine", "FontSerif", ftpriv->font_serif); gf_modules_set_option((GF_BaseInterface *)dr, "FontEngine", "FontSans", ftpriv->font_sans); GF_LOG(GF_LOG_INFO, GF_LOG_PARSER, ("[FreeType] Font directories scanned\n")); }