From f1c2dde13bf1ca59a466cfed2f2d2076c06b235f Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Thu, 5 Jun 2014 12:06:47 +0100 Subject: extend file table with mkdir all and make fs backing store use it. enable fs backing store for RISC OS. --- riscos/Makefile.defaults | 3 ++ riscos/gui.c | 83 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 63 insertions(+), 23 deletions(-) (limited to 'riscos') diff --git a/riscos/Makefile.defaults b/riscos/Makefile.defaults index 8081e5c1a..f719ee3de 100644 --- a/riscos/Makefile.defaults +++ b/riscos/Makefile.defaults @@ -26,5 +26,8 @@ NETSURF_USE_PLUGINS := NO # Valid options: YES, NO NETSURF_USE_DRAW_EXPORT := YES +# Enable building the source object cache filesystem based backing store. +NETSURF_FS_BACKING_STORE := YES + # Optimisation levels CFLAGS += -O2 diff --git a/riscos/gui.c b/riscos/gui.c index e6602acf8..4c04c72ab 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -53,6 +53,7 @@ #include "desktop/netsurf.h" #include "content/urldb.h" #include "content/hlcache.h" +#include "content/backing_store.h" #include "riscos/gui.h" #include "riscos/wimputils.h" @@ -335,22 +336,6 @@ static nserror set_defaults(struct nsoption_s *defaults) } -/** - * Create directory structure for a path - * - * Given a path of x.y.z directories x and x.y will be created - * - * \param path the directory path to create - */ -static void ro_gui_create_dir(char *path) -{ - char *cur = path; - while ((cur = strchr(cur, '.'))) { - *cur = '\0'; - xosfile_create_dir(path, 0); - *cur++ = '.'; - } -} /** @@ -367,23 +352,23 @@ static void ro_gui_create_dirs(void) die("Failed to find NetSurf Choices save path"); snprintf(buf, sizeof(buf), "%s", path); - ro_gui_create_dir(buf); + netsurf_mkdir_all(buf); /* URL */ snprintf(buf, sizeof(buf), "%s", nsoption_charp(url_save)); - ro_gui_create_dir(buf); + netsurf_mkdir_all(buf); /* Hotlist */ snprintf(buf, sizeof(buf), "%s", nsoption_charp(hotlist_save)); - ro_gui_create_dir(buf); + netsurf_mkdir_all(buf); /* Recent */ snprintf(buf, sizeof(buf), "%s", nsoption_charp(recent_save)); - ro_gui_create_dir(buf); + netsurf_mkdir_all(buf); /* Theme */ snprintf(buf, sizeof(buf), "%s", nsoption_charp(theme_save)); - ro_gui_create_dir(buf); + netsurf_mkdir_all(buf); /* and the final directory part (as theme_save is a directory) */ xosfile_create_dir(buf, 0); } @@ -2337,6 +2322,33 @@ static nserror riscos_basename(const char *path, char **str, size_t *size) } +/** + * Ensure that all directory elements needed to store a filename exist. + * + * Given a path of x.y.z directories x and x.y will be created. + * + * @param fname The filename to ensure the path to exists. + * @return NSERROR_OK on success or error code on failure. + */ +static nserror riscos_mkdir_all(const char *fname) +{ + char *dname; + char *cur; + + dname = strdup(fname); + + cur = dname; + while ((cur = strchr(cur, '.'))) { + *cur = '\0'; + xosfile_create_dir(dname, 0); + *cur++ = '.'; + } + + free(dname); + + return NSERROR_OK; +} + /** * Find screen size in OS units. */ @@ -2382,6 +2394,7 @@ static struct gui_file_table riscos_file_table = { .basename = riscos_basename, .nsurl_to_path = ro_nsurl_to_path, .path_to_nsurl = ro_path_to_nsurl, + .mkdir_all = riscos_mkdir_all, }; static struct gui_fetch_table riscos_fetch_table = { @@ -2403,11 +2416,30 @@ static struct gui_browser_table riscos_browser_table = { }; +static char *get_cachepath(void) +{ + char *cachedir; + char *cachepath = NULL; + nserror ret; + + cachedir = getenv("Cache$Dir"); + if ((cachedir == NULL) || (cachedir[0] == 0)) { + LOG(("cachedir was null")); + return NULL; + } + ret = netsurf_mkpath(&cachepath, NULL, 2, cachedir, "NetSurf"); + if (ret != NSERROR_OK) { + return NULL; + } + return cachepath; +} + /** * Normal entry point from RISC OS. */ int main(int argc, char** argv) { + char *cachepath; char path[40]; int length; os_var_type type; @@ -2423,6 +2455,7 @@ int main(int argc, char** argv) .file = &riscos_file_table, .utf8 = riscos_utf8_table, .search = riscos_search_table, + .llcache = filesystem_llcache_table, }; ret = netsurf_register(&riscos_table); @@ -2473,10 +2506,14 @@ int main(int argc, char** argv) die("Failed to locate Messages resource."); } + /* obtain cache path */ + cachepath = get_cachepath(); + /* common initialisation */ - ret = netsurf_init(path, NULL); + ret = netsurf_init(path, cachepath); + free(cachepath); if (ret != NSERROR_OK) { - die("NetSurf failed to initialise"); + die("NetSurf failed to initialise core"); } artworks_init(); -- cgit v1.2.3