-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.c
94 lines (79 loc) · 2.51 KB
/
config.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*=====================================================================
save/load config
======================================================================*/
#include <windows.h>
#include "CGE7.h"
char INIFilePath[MAX_PATH];
extern int showgrid;
extern int expansion;
extern int zoomratio;
extern int showbit3;
extern int showdispc00;
extern int mark_is_tp;
extern int showstatusbar;
extern int gridtype;
extern int RecentFileIndex[9];
extern char RecentFiles[9][MAX_PATH];
struct {
char *name;
int *var;
int defvar;
char *str;
} ConfigList[] = {
{ "ShowGrid", &showgrid, 1, NULL },
{ "Zoom", &expansion, 1, NULL },
{ "ZoomRatio", &zoomratio, 1, NULL },
{ "MarkBit3", &showbit3, 0, NULL },
{ "MarkDispc0", &showdispc00, 0, NULL },
{ "MarkIsTransparent",&mark_is_tp, 0, NULL },
{ "ShowStatusBar",&showstatusbar, 0, NULL },
{ "GridType", &gridtype, 1, NULL },
{ NULL, NULL, 0, NULL }
};
/*----------------------------------------------------------------------
CGEdit format
----------------------------------------------------------------------*/
void load_config() {
int i;
char buf[256];
GetCurrentDirectory(MAX_PATH , INIFilePath);
wsprintf(INIFilePath, "%s\\%s", INIFilePath, "CGE7.ini");
for (i=0; ConfigList[i].name != NULL; i++) {
if (ConfigList[i].var != NULL) {
*(ConfigList[i].var) = GetPrivateProfileInt("Config", ConfigList[i].name, ConfigList[i].defvar, INIFilePath);
} else if (ConfigList[i].str != NULL) {
GetPrivateProfileString("Config", ConfigList[i].name, "", ConfigList[i].str, MAX_PATH, INIFilePath);
}
}
for (i=0; i<9; i++) {
wsprintf(buf, "RecentFile%d", i+1);
GetPrivateProfileString("RecentFiles", buf, "", &RecentFiles[i][0], MAX_PATH, INIFilePath);
RecentFileIndex[i] = (RecentFiles[i][0] == 0) ? -1 : i;
}
}
void save_config() {
int i, j;
char buf[4096 + MAX_PATH * 10];
for (i=0, j=0; ConfigList[i].name != NULL; i++) {
if (ConfigList[i].var != NULL) {
j += wsprintf(&buf[j], "%s=%d", ConfigList[i].name, *(ConfigList[i].var));
j++;
} else if (ConfigList[i].str != NULL) {
j += wsprintf(&buf[j], "%s=%s", ConfigList[i].name, ConfigList[i].str);
j++;
}
}
buf[j] = 0;
WritePrivateProfileSection("Config", buf, INIFilePath);
for (i=0, j=0; i<9; i++) {
if (RecentFileIndex[i] >= 0) {
j += wsprintf(&buf[j], "RecentFile%d=%s", i+1, &RecentFiles[RecentFileIndex[i]][0]);
j++;
} else {
j += wsprintf(&buf[j], "RecentFile%d=", i+1);
j++;
}
}
buf[j] = 0;
WritePrivateProfileSection("RecentFiles", buf, INIFilePath);
}