int LoadConfig(PcsxConfig *Conf) { struct stat buf; FILE *f; int size; char *data; /* TODO local var called cfgfile */ // Ryan says: use dotdir, dotdir is GOOD // No giant homedir names strncpy(cfgfile, getenv("HOME"), 200); strcat(cfgfile, PCSXR_DOT_DIR); // proceed to load the cfg file // append its name strcat(cfgfile, cfgfile_basename); // file is now ~/.pcsxr/pcsxr.cfg (or whatever cfgfile_basename is) if (stat(cfgfile, &buf) == -1) { // the config file doesn't exist! /* TODO Error checking? */ printf("Configuration file %s couldn't be found\n", cfgfile); return -1; } size = buf.st_size; /* TODO Error checking for the next two lines, and at least log failures */ f = fopen(cfgfile, "r"); if (f == NULL) return -1; data = (char *)malloc(size + 1); if (data == NULL) return -1; fread(data, 1, buf.st_size, f); fclose(f); data[size] = '\0'; GetValue(data, "Bios", Config.Bios); GetValue(data, "Gpu", Config.Gpu); GetValue(data, "Spu", Config.Spu); GetValue(data, "Cdr", Config.Cdr); #ifdef ENABLE_SIO1API GetValue(data, "Sio1", Config.Sio1); #endif GetValue(data, "Pad1", Config.Pad1); GetValue(data, "Pad2", Config.Pad2); GetValue(data, "Net", Config.Net); GetValue(data, "Mcd1", Config.Mcd1); GetValue(data, "Mcd2", Config.Mcd2); GetValue(data, "BiosDir", Config.BiosDir); GetValue(data, "PluginsDir", Config.PluginsDir); GetValue(data, "IsoImgDir", Config.IsoImgDir); Config.Xa = GetValueb(data, "Xa"); Config.SioIrq = GetValueb(data, "SioIrq"); Config.Mdec = GetValueb(data, "Mdec"); Config.PsxAuto = GetValueb(data, "PsxAuto"); Config.Cdda = GetValuel(data, "Cdda"); Config.SlowBoot= GetValueb(data, "SlowBoot"); Config.Debug = GetValueb(data, "Dbg"); Config.PsxOut = (Config.PsxOut || GetValueb(data, "PsxOut")); Config.SpuIrq = GetValueb(data, "SpuIrq"); Config.RCntFix = GetValueb(data, "RCntFix"); Config.VSyncWA = GetValueb(data, "VSyncWA"); Config.NoMemcard = GetValueb(data, "NoMemcard"); Config.Widescreen = GetValueb(data, "Widescreen"); Config.Cpu = GetValuel(data, "Cpu"); Config.PsxType = GetValuel(data, "PsxType"); Config.RewindCount = GetValuel(data, "RewindCount"); Config.RewindInterval = GetValuel(data, "RewindInterval"); free(data); return 0; }
int LoadConfig(PcsxConfig *Conf) { struct stat buf; FILE *f; int size; char *data,*tmp; if (stat(cfgfile, &buf) == -1) { char file[256]; strcpy(file, getenv("HOME")); strcat(file, "/"); strcat(file, cfgfile); strcpy(cfgfile, file); if (stat(cfgfile, &buf) == -1) { return -1; } } size = buf.st_size; f = fopen(cfgfile,"r"); if (f == NULL) return -1; data = (char*)malloc(size); if (data == NULL) return -1; fread(data, 1, size, f); fclose(f); GetValue("Bios", Config.Bios); GetValue("Gpu", Config.Gpu); GetValue("Spu", Config.Spu); GetValue("Cdr", Config.Cdr); GetValue("Pad1", Config.Pad1); GetValue("Pad2", Config.Pad2); GetValue("Net", Config.Net); GetValue("Mcd1", Config.Mcd1); GetValue("Mcd2", Config.Mcd2); GetValue("PluginsDir", Config.PluginsDir); GetValue("BiosDir", Config.BiosDir); GetValuel("Xa", Config.Xa); GetValuel("Sio", Config.Sio); GetValuel("Mdec", Config.Mdec); GetValuel("PsxAuto", Config.PsxAuto); GetValuel("PsxType", Config.PsxType); GetValuel("Cdda", Config.Cdda); GetValuel("Cpu", Config.Cpu); GetValuel("PsxOut", Config.PsxOut); GetValuel("SpuIrq", Config.SpuIrq); GetValuel("RCntFix", Config.RCntFix); GetValuel("VSyncWA", Config.VSyncWA); Config.Lang[0] = 0; GetValue("Lang", Config.Lang); free(data); #ifdef ENABLE_NLS if (Config.Lang[0]) { extern int _nl_msg_cat_cntr; setenv("LANGUAGE", Config.Lang, 1); ++_nl_msg_cat_cntr; } #endif return 0; }