diff options
Diffstat (limited to 'src/cache.c')
-rw-r--r-- | src/cache.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/cache.c b/src/cache.c index 60a0fa6..599879d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -9,10 +9,11 @@ #include "include/cache.h" #include "include/read_cfg.h" -void save_to_cache(int g_hover, int e_hover, int true_hover, char *cfg_name){ +void save_to_cache(int g_count, int g_hover, int *e_hover, int *e_offset, int true_hover, char *cfg_name){ FILE *fp; struct stat cfg_stat; //for determining last modification time of file char *path = get_cache_path(true); + int i; //ensure get_cache_path() did not return NULL if(path == NULL) return; @@ -30,20 +31,26 @@ void save_to_cache(int g_hover, int e_hover, int true_hover, char *cfg_name){ //write to file fwrite(cfg_name, sizeof(char), BUF_LEN, fp); fwrite(&cfg_stat.st_mtime, sizeof(long int), 1, fp); + fwrite(&g_count, sizeof(int), 1, fp); fwrite(&g_hover, sizeof(int), 1, fp); - fwrite(&e_hover, sizeof(int), 1, fp); + for(i = 0; i < g_count; ++i){ + fwrite(&(e_hover[i]), sizeof(int), 1, fp); + fwrite(&(e_offset[i]), sizeof(int), 1, fp); + } fwrite(&true_hover, sizeof(int), 1, fp); fclose(fp); return; } -void load_cache(int *g_hover, int *e_hover, int *true_hover, char *new_cfg_name){ +void load_cache(int g_count, int *g_hover, int **e_hover, int **e_offset, int *true_hover, char *new_cfg_name){ FILE *fp; char *path = get_cache_path(false); char saved_cfg_name[BUF_LEN]; long int saved_cfg_mtime; struct stat new_cfg_stat; + int saved_g_count; + int i; //ensure get_cache_path() did not return NULL if(path == NULL) return; @@ -61,15 +68,15 @@ void load_cache(int *g_hover, int *e_hover, int *true_hover, char *new_cfg_name) stat(new_cfg_name, &new_cfg_stat); if(!(strcmp(saved_cfg_name, new_cfg_name)) && saved_cfg_mtime >= new_cfg_stat.st_mtime){ - fread(g_hover, sizeof(int), 1, fp); - fread(e_hover, sizeof(int), 1, fp); - fread(true_hover, sizeof(int), 1, fp); - } - - else{ - *g_hover = 0; - *e_hover = 0; - *true_hover = 0; + fread(&saved_g_count, sizeof(int), 1, fp); + if(saved_g_count == g_count){ + fread(g_hover, sizeof(int), 1, fp); + for(i = 0; i < g_count; ++i){ + fread(&(*e_hover)[i], sizeof(int), 1, fp); + fread(&(*e_offset)[i], sizeof(int), 1, fp); + } + fread(true_hover, sizeof(int), 1, fp); + } } fclose(fp); |