static void setProfile (IniPrivData *data, char *profile) { char *fileName; struct stat fileStat; if (data->iniFile) ccsIniClose (data->iniFile); if (data->iniWatchId) ccsRemoveFileWatch (data->iniWatchId); data->iniFile = NULL; data->iniWatchId = 0; /* first we need to find the file name */ fileName = getIniFileName (profile); if (!fileName) return; /* if the file does not exist, we have to create it */ if (stat (fileName, &fileStat) == -1) { if (errno == ENOENT) { FILE *file; file = fopen (fileName, "w"); if (!file) { free (fileName); return; } fclose (file); } else { free (fileName); return; } } data->iniWatchId = ccsAddFileWatch (fileName, TRUE, processFileEvent, data); /* load the data from the file */ data->iniFile = ccsIniOpen (fileName); free (fileName); }
static Bool ccsReadGlobalConfig (ConfigOption option, char **value) { IniDictionary *iniFile; char *entry = NULL; char *section; Bool ret; FILE *fp; /* check if the global config file exists - if it doesn't, exit to avoid it being created by ccsIniOpen */ fp = fopen (SYSCONFDIR "/compizconfig/config", "r"); if (!fp) return FALSE; fclose (fp); iniFile = ccsIniOpen (SYSCONFDIR "/compizconfig/config"); if (!iniFile) return FALSE; switch (option) { case OptionProfile: entry = "profile"; break; case OptionBackend: entry = "backend"; break; case OptionIntegration: entry = "integration"; break; case OptionAutoSort: entry = "plugin_list_autosort"; break; default: break; } if (!entry) { ccsIniClose (iniFile); return FALSE; } *value = NULL; section = getSectionName(); ret = ccsIniGetString (iniFile, section, entry, value); free (section); ccsIniClose (iniFile); return ret; }
static IniDictionary* getConfigFile (void) { char *fileName; IniDictionary *iniFile; fileName = getConfigFileName(); if (!fileName) return NULL; iniFile = ccsIniOpen (fileName); free (fileName); return iniFile; }
static void processFileEvent (unsigned int watchId, void *closure) { IniPrivData *data = (IniPrivData *) closure; char *fileName; /* our ini file has been modified, reload it */ if (data->iniFile) ccsIniClose (data->iniFile); fileName = getIniFileName (data->lastProfile); if (!fileName) return; data->iniFile = ccsIniOpen (fileName); ccsReadSettings (data->context); free (fileName); }