Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- gchar *deskmenu_check_file_cache (gchar *filename){
- gboolean cached = FALSE;
- gchar *cache_name[1000];
- gchar *cache_file[1000];
- gchar *t = NULL;
- gchar *f;
- if (strlen(filename) == 0) {
- /*
- set 0,0 & 0,1 to be the default config
- check to see given argument for filename
- set default filename to be [configdir]/compiz/deskmenu/menu.xml
- create it if don't exist
- */
- filename = g_build_path (G_DIR_SEPARATOR_S,
- g_get_user_config_dir (),
- "compiz",
- "deskmenu",
- "menu.xml",
- NULL);
- if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
- {
- const gchar* const *cursor = g_get_system_config_dirs ();
- gchar *path = NULL;
- while (*cursor)
- {
- g_free (path);
- path = g_strdup (*cursor);
- filename = g_build_path (G_DIR_SEPARATOR_S,
- path,
- "compiz",
- "deskmenu",
- "menu.xml",
- NULL);
- if (g_file_get_contents (filename, &f, NULL, NULL))
- {
- cache_name[0] = filename;
- g_free (path);
- break;
- }
- cursor++;
- }
- }
- else
- {
- if (filename != cache_name[0]) //somehow this comparison always works, even though it shouldn't
- {
- g_file_get_contents (filename, &f, NULL, NULL);
- g_print("Cacheing default file...\n");
- }
- g_print("Retrieving cached default file...\n");
- cache_name[0] = filename;
- }
- cache_file[0] = f; //doesn't write back to the slot in array
- g_print(cache_name[0]);
- g_free (filename);
- t = g_strdup(cache_file[0]);
- }
- else {
- int i;
- i = 0;
- //search cache
- while(cache_name[i]){
- if (filename == cache_name[i]) //this comparison doesn't work
- {
- cached = TRUE;
- t = g_strdup(cache_file[i]);
- g_print("Found cached file!\n");
- break;
- }
- i++;
- }
- //cache file if it isn't in the cache
- if (!cached) {
- if (g_file_get_contents (filename, &f, NULL, NULL))
- {
- g_print("Cacheing new file...\n");
- cache_name[i+1] = filename; //doesn't write back to the slot in array
- cache_file[i+1] = f; //doesn't write back to the slot in array
- t = g_strdup(cache_file[i+1]);
- }
- else {
- if (cache_name[0] && cache_file[0]) //do if both exist, again, doesn't work
- {
- g_print("Couldn't find specified file, loading default...\n");
- t = g_strdup(cache_file[0]);
- }
- else
- {
- g_printerr ("Couldn't find a menu file\n");
- exit (1);
- }
- }
- }
- g_print(filename);
- g_free (filename);
- }
- return t;
- }
Add Comment
Please, Sign In to add comment