minimal working gtk-less build
[pcsx_rearmed.git] / plugins / dfcdrom / cfg.c
CommitLineData
ef79bbde
P
1/*
2 * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
3 * All Rights Reserved.
4 *
5 * Based on: Cdrom for Psemu Pro like Emulators
6 * By: linuzappz <linuzappz@hotmail.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses>.
20 */
21
22#include "cdr.h"
23
24char CdromDev[256];
25long ReadMode;
26long UseSubQ;
27long CacheSize;
28long CdrSpeed;
29long SpinDown;
30
31void LoadConf() {
32 FILE *f;
33
34#if defined (__sun)
35 char buf[256], *devname, *nick;
36
37 CdromDev[0] = '\0';
38 f = popen("eject -l", "r");
39
40 if (f != NULL) {
41 while (!feof(f)) {
42 fgets(buf, 256, f);
43
44 devname = strtok(buf, " ");
45 nick = strtok(NULL, " ");
46
47 if (devname == NULL || nick == NULL) continue;
48
49 if (strstr(nick, "cdrom") != NULL) {
50 strcpy(CdromDev, devname);
51 break;
52 }
53 }
54
55 pclose(f);
56 }
57#else
58 strcpy(CdromDev, DEV_DEF);
59#endif
60
61 ReadMode = THREADED;
62 UseSubQ = 0;
63 CacheSize = 64;
64 CdrSpeed = 0;
65 SpinDown = SPINDOWN_VENDOR_SPECIFIC;
66
67 f = fopen("dfcdrom.cfg", "r");
68 if (f == NULL) return;
69
70 fscanf(f, "CdromDev = %s\n", CdromDev);
71 fscanf(f, "ReadMode = %ld\n", &ReadMode);
72 fscanf(f, "UseSubQ = %ld\n", &UseSubQ);
73 fscanf(f, "CacheSize = %ld\n", &CacheSize);
74 fscanf(f, "CdrSpeed = %ld\n", &CdrSpeed);
75 fscanf(f, "SpinDown = %ld\n", &SpinDown);
76 fclose(f);
77
78 if (ReadMode >= READ_MODES) ReadMode = THREADED;
79 if (CacheSize <= 0) CacheSize = 32;
80 if (CacheSize > 2048) CacheSize = 2048;
81 if (SpinDown <= 0) SpinDown = SPINDOWN_VENDOR_SPECIFIC;
82 if (SpinDown > SPINDOWN_32MIN) SpinDown = SPINDOWN_32MIN;
83}
84
85void SaveConf() {
86 FILE *f;
87
88 f = fopen("dfcdrom.cfg", "w");
89 if (f == NULL)
90 return;
91
92 fprintf(f, "CdromDev = %s\n", CdromDev);
93 fprintf(f, "ReadMode = %ld\n", ReadMode);
94 fprintf(f, "UseSubQ = %ld\n", UseSubQ);
95 fprintf(f, "CacheSize = %ld\n", CacheSize);
96 fprintf(f, "CdrSpeed = %ld\n", CdrSpeed);
97 fprintf(f, "SpinDown = %ld\n", SpinDown);
98 fclose(f);
99}