-
Notifications
You must be signed in to change notification settings - Fork 2
/
registry.cpp
99 lines (92 loc) · 3.76 KB
/
registry.cpp
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
95
96
97
98
99
/************************************************************************
* registry.cpp *
* - functions for saving and loading Borgs settings in the registry *
************************************************************************/
#include <windows.h>
#include "dasm.h"
char reg_borg[]="Software\\Borg";
/************************************************************************
* save_reg_entries *
* - Saves Borgs settings to the registry :) *
* - these are just colours, fonts, version, directory and window status *
************************************************************************/
void save_reg_entries(void)
{ HKEY regkey;
DWORD disposition;
DWORD rver,dsize;
COLORREF cl;
char cdir[MAX_PATH];
if(RegCreateKeyEx(HKEY_CURRENT_USER,reg_borg,0,"",REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
NULL,®key,&disposition)!=ERROR_SUCCESS)
return;
// now write values out.......
dsize=sizeof(rver);
rver=BORG_VER;
RegSetValueEx(regkey,"Version",0,REG_DWORD,(LPBYTE)&rver,dsize);
GetCurrentDirectory(MAX_PATH,cdir);
dsize=strlen(cdir)+1;
RegSetValueEx(regkey,"Curdir",0,REG_SZ,(LPBYTE)cdir,dsize);
dsize=sizeof(options.winmax);
RegSetValueEx(regkey,"Winmax",0,REG_DWORD,(LPBYTE)&options.winmax,dsize);
dsize=sizeof(COLORREF);
cl=options.bgcolor;
RegSetValueEx(regkey,"BackgroundColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.highcolor;
RegSetValueEx(regkey,"HighlightColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.textcolor;
RegSetValueEx(regkey,"TextColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.font;
RegSetValueEx(regkey,"Font",0,REG_DWORD,(LPBYTE)&cl,dsize);
RegCloseKey(regkey);
}
/************************************************************************
* load_reg_entries *
* - Loads Borgs saved settings from the registry :) *
* - these are just colours, fonts, version, directory and window status *
* - settings are then restored *
************************************************************************/
void load_reg_entries(void)
{ HKEY regkey;
DWORD disposition;
DWORD rver,dsize;
COLORREF cl;
char cdir[MAX_PATH];
if(RegCreateKeyEx(HKEY_CURRENT_USER,reg_borg,0,"",REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
NULL,®key,&disposition)!=ERROR_SUCCESS)
return;
if(disposition==REG_CREATED_NEW_KEY)
{ RegCloseKey(regkey);
return;
}
dsize=sizeof(rver);
rver=0;
RegQueryValueEx(regkey,"Version",NULL,NULL,(LPBYTE)&rver,&dsize);
// now read values in.......
cdir[0]=0;
dsize=MAX_PATH;
RegQueryValueEx(regkey,"Curdir",NULL,NULL,(LPBYTE)cdir,&dsize);
if(cdir[0])
SetCurrentDirectory(cdir);
dsize=sizeof(options.winmax);
RegQueryValueEx(regkey,"Winmax",NULL,NULL,(LPBYTE)&options.winmax,&dsize);
if(options.winmax)
{ PostMessage(mainwindow,WM_MAXITOUT,0,0);
}
dsize=sizeof(cl);
if(RegQueryValueEx(regkey,"BackgroundColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.bgcolor=cl;
if(RegQueryValueEx(regkey,"HighlightColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.highcolor=cl;
if(RegQueryValueEx(regkey,"TextColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.textcolor=cl;
if(RegQueryValueEx(regkey,"Font",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
{ options.font=(fontselection)cl;
}
RegCloseKey(regkey);
if(rver!=BORG_VER)
{ RegCloseKey(regkey);
RegDeleteKey(HKEY_CURRENT_USER,reg_borg);
save_reg_entries();
return;
}
}