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;
- gchar **cache_file;
- gchar *t = NULL;
- //segfaults here, most likely because of how I made the arrays
- g_printf("%s\n", filename);
- if (!filename) {
- /*
- 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_get_contents (filename, &cache_file[0], NULL, NULL) && !cache_file[0])
- {
- 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, &cache_file[0], NULL, NULL))
- {
- cache_name[0] = filename;
- g_free (path);
- g_free (filename);
- t = g_strdup(cache_file[0]);
- break;
- }
- cursor++;
- }
- }
- else
- {
- cache_name[0] = filename;
- g_free (filename);
- t = cache_file[0];
- }
- }
- else{
- int i;
- i = 0;
- //search cache
- while(cache_name[i]){
- if(filename == cache_name[i]){
- cached = TRUE;
- t = cache_file[i];
- break;
- }
- }
- //cache file if it isn't in the cache
- if (!cached){
- if (g_file_get_contents (filename, &cache_file[i], NULL, NULL))
- {
- cache_name[i] = filename;
- t = cache_file[i];
- }
- else {
- if (cache_name[0] && cache_file[0])
- {
- g_print("Couldn't find specified file, loading default...");
- t = cache_file[0];
- }
- else
- {
- g_printerr ("Couldn't find a menu file\n");
- exit (1);
- }
- }
- }
- g_free (filename);
- }
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment