1 | #include "stdafx.h"
|
---|
2 |
|
---|
3 | #include "../BasicCompiler_Common/common.h"
|
---|
4 |
|
---|
5 |
|
---|
6 | char *ReadBuffer_NonErrMsg( const std::string &path ){
|
---|
7 | extern HANDLE hHeap;
|
---|
8 | int i;
|
---|
9 | DWORD dw;
|
---|
10 | char *buffer;
|
---|
11 | HANDLE hFile;
|
---|
12 |
|
---|
13 | hFile=CreateFile(path.c_str(),GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
|
---|
14 | if(hFile==INVALID_HANDLE_VALUE) return 0;
|
---|
15 | i=GetFileSize(hFile,0);
|
---|
16 | buffer=(char *)HeapAlloc(hHeap,0,i+1);
|
---|
17 | ReadFile(hFile,buffer,i,&dw,0);
|
---|
18 | buffer[dw]=0;
|
---|
19 | CloseHandle(hFile);
|
---|
20 | return buffer;
|
---|
21 | }
|
---|
22 | _int8 WriteBuffer( const std::string &path, char *buffer,int length){
|
---|
23 | extern HWND hOwnerEditor;
|
---|
24 | HANDLE hFile;
|
---|
25 | DWORD dw;
|
---|
26 | hFile=CreateFile(path.c_str(),GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
|
---|
27 | if(hFile==INVALID_HANDLE_VALUE){
|
---|
28 | char temporary[MAX_PATH];
|
---|
29 |
|
---|
30 | sprintf(temporary,"\"%s\" ファイルへの書き込みに失敗しました。",path);
|
---|
31 | MessageBox(hOwnerEditor,temporary,"エラー",MB_OK|MB_ICONEXCLAMATION);
|
---|
32 | return 0;
|
---|
33 | }
|
---|
34 | if(length) WriteFile(hFile,buffer,length,&dw,NULL);
|
---|
35 | CloseHandle(hFile);
|
---|
36 | return 1;
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | ///////////////////////////
|
---|
41 | // 不揮発性のデータ管理
|
---|
42 | ///////////////////////////
|
---|
43 |
|
---|
44 | BOOL CNonVolatile::GetDataLine(char *name,char *parms){
|
---|
45 | int i,i2,length;
|
---|
46 | length=lstrlen(name);
|
---|
47 | for(i=0;;i++){
|
---|
48 | if(buffer[i]=='\0') break;
|
---|
49 | if(i==0||buffer[i]=='\r'&&buffer[i+1]=='\n'){
|
---|
50 | if(buffer[i]=='\r'&&buffer[i+1]=='\n') i+=2;
|
---|
51 | if(memcmp(buffer+i,name,length)==0&&buffer[i+length]=='='){
|
---|
52 | i+=length+1;
|
---|
53 | for(i2=0;;i++,i2++){
|
---|
54 | if(buffer[i]=='\r'&&buffer[i+1]=='\n'||buffer[i]=='\0'){
|
---|
55 | parms[i2]=0;
|
---|
56 | break;
|
---|
57 | }
|
---|
58 | parms[i2]=buffer[i];
|
---|
59 | }
|
---|
60 | return 1;
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|
64 | return 0;
|
---|
65 | }
|
---|
66 |
|
---|
67 | BOOL CNonVolatile::GetWholeValue(char *name,int *pi32data){
|
---|
68 | char temporary[8192];
|
---|
69 | if(!GetDataLine(name,temporary)) return 0;
|
---|
70 | *pi32data=atoi(temporary);
|
---|
71 | return 1;
|
---|
72 | }
|
---|
73 | BOOL CNonVolatile::Get3WholeValue(char *name,int *pd1,int *pd2,int *pd3){
|
---|
74 | char temporary[8192];
|
---|
75 | if(!GetDataLine(name,temporary)) return 0;
|
---|
76 | sscanf(temporary,"%d,%d,%d",pd1,pd2,pd3);
|
---|
77 | return 1;
|
---|
78 | }
|
---|
79 | BOOL CNonVolatile::GetRGBValue(char *name,COLORREF *prgb){
|
---|
80 | char temporary[8192];
|
---|
81 | if(!GetDataLine(name,temporary)) return 0;
|
---|
82 | sscanf(temporary,"%x",prgb);
|
---|
83 | return 1;
|
---|
84 | }
|
---|
85 | BOOL CNonVolatile::GetStringValue(char *name,char *str){
|
---|
86 | if(!GetDataLine(name,str)) return 0;
|
---|
87 | return 1;
|
---|
88 | }
|
---|
89 | BOOL CNonVolatile::GetRectValue(char *name,RECT *prc){
|
---|
90 | char temporary[8192];
|
---|
91 | if(!GetDataLine(name,temporary)) return 0;
|
---|
92 | sscanf(temporary,"%d,%d,%d,%d",&prc->left,&prc->top,&prc->right,&prc->bottom);
|
---|
93 | return 1;
|
---|
94 | }
|
---|
95 | BOOL CNonVolatile::GetPointValue(char *name,POINT *pos){
|
---|
96 | char temporary[8192];
|
---|
97 | if(!GetDataLine(name,temporary)) return 0;
|
---|
98 | sscanf(temporary,"%d,%d",&pos->x,&pos->y);
|
---|
99 | return 1;
|
---|
100 | }
|
---|
101 |
|
---|
102 | void CNonVolatile::load(){
|
---|
103 | extern HANDLE hHeap;
|
---|
104 | int i;
|
---|
105 |
|
---|
106 | //開く
|
---|
107 | buffer=ReadBuffer_NonErrMsg( Jenga::Common::Environment::GetAppDir() + "\\UserSetting\\compiler.ini" );
|
---|
108 | if(!buffer){
|
---|
109 | //レジストリを読み込む
|
---|
110 | OldLoad();
|
---|
111 | return;
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | if(!GetWholeValue("IsShow_DefaultSystem_Var",&bShow_DefaultSystem_Var)) bShow_DefaultSystem_Var=0;
|
---|
116 | if(!GetWholeValue("IsShow_Rad_Var",&bShow_Rad_Var)) bShow_Rad_Var=0;
|
---|
117 | if(!GetWholeValue("IsShow_GUID_Var",&bShow_GUID_Var)) bShow_Rad_Var=0;
|
---|
118 |
|
---|
119 | extern int ScreenX,ScreenY;
|
---|
120 | if(!GetPointValue("MainDlgPos",&MainDlgPos)){
|
---|
121 | MainDlgPos.x=ScreenX/2-100;
|
---|
122 | MainDlgPos.y=ScreenX/2-250;
|
---|
123 | }
|
---|
124 |
|
---|
125 | if(!GetRectValue("VarDlgRect",&VarDlgRect)){
|
---|
126 | VarDlgRect.left=ScreenX/2-390/2;
|
---|
127 | VarDlgRect.top=ScreenY/2-270/2;
|
---|
128 | VarDlgRect.right=ScreenX/2+390/2;
|
---|
129 | VarDlgRect.bottom=ScreenY/2+270/2;
|
---|
130 | }
|
---|
131 |
|
---|
132 | //ウォッチリスト
|
---|
133 | if(!GetWholeValue("WatchNum",&WatchNum)) WatchNum=0;
|
---|
134 |
|
---|
135 | ppWatchStr=(char **)HeapAlloc(hHeap,0,WatchNum*sizeof(char *)+1);
|
---|
136 | for(i=0;i<WatchNum;i++){
|
---|
137 | char temporary[VN_SIZE];
|
---|
138 | sprintf(temporary,"Watch%03d",i);
|
---|
139 |
|
---|
140 | char temp2[VN_SIZE];
|
---|
141 | GetStringValue(temporary,temp2);
|
---|
142 | ppWatchStr[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temp2)+1);
|
---|
143 | lstrcpy(ppWatchStr[i],temp2);
|
---|
144 | }
|
---|
145 |
|
---|
146 |
|
---|
147 | HeapDefaultFree(buffer);
|
---|
148 | }
|
---|
149 | void CNonVolatile::OldLoad(){
|
---|
150 | extern HANDLE hHeap;
|
---|
151 | extern int ScreenX,ScreenY;
|
---|
152 |
|
---|
153 | int i;
|
---|
154 | HKEY hKey;
|
---|
155 | ULONG ulSize;
|
---|
156 | char temporary[MAX_PATH],temp2[VN_SIZE];
|
---|
157 |
|
---|
158 | if(RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\Discoversoft\\BasicCompiler",0,KEY_ALL_ACCESS,&hKey)!=ERROR_SUCCESS){
|
---|
159 | bShow_DefaultSystem_Var=0;
|
---|
160 | bShow_Rad_Var=0;
|
---|
161 | bShow_GUID_Var=0;
|
---|
162 |
|
---|
163 | MainDlgPos.x=ScreenX/2-100;
|
---|
164 | MainDlgPos.y=ScreenX/2-250;
|
---|
165 |
|
---|
166 | VarDlgRect.left=ScreenX/2-390/2;
|
---|
167 | VarDlgRect.top=ScreenY/2-270/2;
|
---|
168 | VarDlgRect.right=ScreenX/2+390/2;
|
---|
169 | VarDlgRect.bottom=ScreenY/2+270/2;
|
---|
170 |
|
---|
171 | WatchNum=0;
|
---|
172 | ppWatchStr=(char **)HeapAlloc(hHeap,0,1);
|
---|
173 | }
|
---|
174 | else{
|
---|
175 | ulSize=sizeof(DWORD);
|
---|
176 | if(RegQueryValueEx(hKey,"bShow_DefaultSystem_Var",NULL,NULL,(BYTE *)&bShow_DefaultSystem_Var,&ulSize)!=ERROR_SUCCESS)
|
---|
177 | bShow_DefaultSystem_Var=0;
|
---|
178 |
|
---|
179 | ulSize=sizeof(DWORD);
|
---|
180 | if(RegQueryValueEx(hKey,"bShow_Rad_Var",NULL,NULL,(BYTE *)&bShow_Rad_Var,&ulSize)!=ERROR_SUCCESS)
|
---|
181 | bShow_Rad_Var=0;
|
---|
182 |
|
---|
183 | ulSize=sizeof(DWORD);
|
---|
184 | if(RegQueryValueEx(hKey,"bShow_GUID_Var",NULL,NULL,(BYTE *)&bShow_GUID_Var,&ulSize)!=ERROR_SUCCESS)
|
---|
185 | bShow_GUID_Var=0;
|
---|
186 |
|
---|
187 | ulSize=1024;
|
---|
188 | if(RegQueryValueEx(hKey,"MainDlgPos",NULL,NULL,(unsigned char *)temporary,&ulSize)!=ERROR_SUCCESS){
|
---|
189 | MainDlgPos.x=ScreenX/2-100;
|
---|
190 | MainDlgPos.y=ScreenX/2-250;
|
---|
191 | }
|
---|
192 | else sscanf(temporary,"%d %d",
|
---|
193 | &MainDlgPos.x,
|
---|
194 | &MainDlgPos.y);
|
---|
195 |
|
---|
196 | ulSize=1024;
|
---|
197 | if(RegQueryValueEx(hKey,"VarDlgRect",NULL,NULL,(unsigned char *)temporary,&ulSize)!=ERROR_SUCCESS){
|
---|
198 | VarDlgRect.left=ScreenX/2-390/2;
|
---|
199 | VarDlgRect.top=ScreenY/2-270/2;
|
---|
200 | VarDlgRect.right=ScreenX/2+390/2;
|
---|
201 | VarDlgRect.bottom=ScreenY/2+270/2;
|
---|
202 | }
|
---|
203 | else sscanf(temporary,"%d %d %d %d",
|
---|
204 | &VarDlgRect.left,
|
---|
205 | &VarDlgRect.top,
|
---|
206 | &VarDlgRect.right,
|
---|
207 | &VarDlgRect.bottom);
|
---|
208 |
|
---|
209 | ulSize=sizeof(DWORD);
|
---|
210 | if(RegQueryValueEx(hKey,"WatchNum",NULL,NULL,(BYTE *)&WatchNum,&ulSize)!=ERROR_SUCCESS)
|
---|
211 | WatchNum=0;
|
---|
212 | ppWatchStr=(char **)HeapAlloc(hHeap,0,WatchNum*sizeof(char *)+1);
|
---|
213 | for(i=0;i<WatchNum;i++){
|
---|
214 | sprintf(temporary,"WathNum%03d",i);
|
---|
215 | ulSize=VN_SIZE;
|
---|
216 | if(RegQueryValueEx(hKey,temporary,NULL,NULL,(unsigned char *)temp2,&ulSize)!=ERROR_SUCCESS){
|
---|
217 | WatchNum=i;
|
---|
218 | break;
|
---|
219 | }
|
---|
220 | ppWatchStr[i]=(char *)HeapAlloc(hHeap,0,lstrlen(temp2)+1);
|
---|
221 | lstrcpy(ppWatchStr[i],temp2);
|
---|
222 | }
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | void CNonVolatile::SetWholeValue(char *name,long i32data){
|
---|
227 | sprintf(buffer+lstrlen(buffer),"%s=%d\r\n",name,i32data);
|
---|
228 | }
|
---|
229 | void CNonVolatile::Set3WholeValue(char *name,long d1,long d2,long d3){
|
---|
230 | sprintf(buffer+lstrlen(buffer),"%s=%d,%d,%d\r\n",name,d1,d2,d3);
|
---|
231 | }
|
---|
232 | void CNonVolatile::SetRGBValue(char *name,COLORREF rgb){
|
---|
233 | sprintf(buffer+lstrlen(buffer),"%s=%x\r\n",name,rgb);
|
---|
234 | }
|
---|
235 | void CNonVolatile::SetStringValue(char *name,char *str){
|
---|
236 | sprintf(buffer+lstrlen(buffer),"%s=%s\r\n",name,str);
|
---|
237 | }
|
---|
238 | void CNonVolatile::SetRectValue(char *name,RECT *prc){
|
---|
239 | sprintf(buffer+lstrlen(buffer),"%s=%d,%d,%d,%d\r\n",name,prc->left,prc->top,prc->right,prc->bottom);
|
---|
240 | }
|
---|
241 | void CNonVolatile::SetPointValue(char *name,POINT *pos){
|
---|
242 | sprintf(buffer+lstrlen(buffer),"%s=%d,%d\r\n",name,pos->x,pos->y);
|
---|
243 | }
|
---|
244 |
|
---|
245 | void CNonVolatile::save(){
|
---|
246 | int i;
|
---|
247 | char temporary[MAX_PATH];
|
---|
248 |
|
---|
249 | const std::string userSettingDirPath = Jenga::Common::Environment::GetAppDir() + "\\UserSetting";
|
---|
250 |
|
---|
251 | HANDLE hFind;
|
---|
252 | WIN32_FIND_DATA wfd;
|
---|
253 | hFind=FindFirstFile( userSettingDirPath.c_str() ,&wfd);
|
---|
254 | if(hFind==INVALID_HANDLE_VALUE){
|
---|
255 | //UserSettingディレクトリを作成
|
---|
256 | if(!CreateDirectory( userSettingDirPath.c_str() ,NULL)){
|
---|
257 | extern HWND hOwnerEditor;
|
---|
258 | MessageBox(hOwnerEditor,"UserSettingディレクトリの作成に失敗","ActiveBasic",MB_OK|MB_ICONEXCLAMATION);
|
---|
259 | return;
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | extern HANDLE hHeap;
|
---|
264 | buffer=(char *)HeapAlloc(hHeap,0,65536);
|
---|
265 | buffer[0]=0;
|
---|
266 |
|
---|
267 |
|
---|
268 | SetWholeValue("IsShow_DefaultSystem_Var",bShow_DefaultSystem_Var);
|
---|
269 | SetWholeValue("IsShow_Rad_Var",bShow_Rad_Var);
|
---|
270 | SetWholeValue("IsShow_GUID_Var",bShow_GUID_Var);
|
---|
271 |
|
---|
272 | SetPointValue("MainDlgPos",&MainDlgPos);
|
---|
273 |
|
---|
274 | SetRectValue("VarDlgRect",&VarDlgRect);
|
---|
275 |
|
---|
276 | //ウォッチリスト
|
---|
277 | SetWholeValue("WatchNum",WatchNum);
|
---|
278 | for(i=0;i<WatchNum;i++){
|
---|
279 | sprintf(temporary,"Watch%03d",i);
|
---|
280 | SetStringValue(temporary,ppWatchStr[i]);
|
---|
281 | HeapDefaultFree(ppWatchStr[i]);
|
---|
282 | }
|
---|
283 | HeapDefaultFree(ppWatchStr);
|
---|
284 |
|
---|
285 |
|
---|
286 | //保存
|
---|
287 | WriteBuffer(
|
---|
288 | userSettingDirPath + "\\compiler.ini",
|
---|
289 | buffer,lstrlen(buffer));
|
---|
290 |
|
---|
291 |
|
---|
292 | HeapDefaultFree(buffer);
|
---|
293 | }
|
---|