source: dev/branches/egtra/ab5.0/abdev/BasicCompiler_Common/NonVolatile.cpp

Last change on this file was 719, checked in by dai, 16 years ago
  • ab_breakpoint.tmpをテンポラリディレクトリに生成するようにした。
  • pgm.tmpをユーザ空間に生成するようにした。
  • GetUserAppDir/GetIdeUserAppDir/GetAbcUserAppDirの各メソッドを用意。用途別に呼び出し側の制御を分けた。
File size: 7.9 KB
Line 
1#include "stdafx.h"
2
3#include "../BasicCompiler_Common/common.h"
4
5
6char *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
44BOOL 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
67BOOL 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}
73BOOL 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}
79BOOL 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}
85BOOL CNonVolatile::GetStringValue(char *name,char *str){
86 if(!GetDataLine(name,str)) return 0;
87 return 1;
88}
89BOOL 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}
95BOOL 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
102void CNonVolatile::load(){
103 extern HANDLE hHeap;
104 int i;
105
106 //開く
107 buffer=ReadBuffer_NonErrMsg( Program::GetAbcUserAppDir() + "\\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}
149void 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
226void CNonVolatile::SetWholeValue(char *name,long i32data){
227 sprintf(buffer+lstrlen(buffer),"%s=%d\r\n",name,i32data);
228}
229void 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}
232void CNonVolatile::SetRGBValue(char *name,COLORREF rgb){
233 sprintf(buffer+lstrlen(buffer),"%s=%x\r\n",name,rgb);
234}
235void CNonVolatile::SetStringValue(char *name,char *str){
236 sprintf(buffer+lstrlen(buffer),"%s=%s\r\n",name,str);
237}
238void 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}
241void CNonVolatile::SetPointValue(char *name,POINT *pos){
242 sprintf(buffer+lstrlen(buffer),"%s=%d,%d\r\n",name,pos->x,pos->y);
243}
244
245void CNonVolatile::save(){
246 int i;
247 char temporary[MAX_PATH];
248
249 // ユーザ情報保存用のディレクトリを作成
250 Jenga::Common::Directory dir( Program::GetAbcUserAppDir(), true );
251
252
253 extern HANDLE hHeap;
254 buffer=(char *)HeapAlloc(hHeap,0,65536);
255 buffer[0]=0;
256
257
258 SetWholeValue("IsShow_DefaultSystem_Var",bShow_DefaultSystem_Var);
259 SetWholeValue("IsShow_Rad_Var",bShow_Rad_Var);
260 SetWholeValue("IsShow_GUID_Var",bShow_GUID_Var);
261
262 SetPointValue("MainDlgPos",&MainDlgPos);
263
264 SetRectValue("VarDlgRect",&VarDlgRect);
265
266 //ウォッチリスト
267 SetWholeValue("WatchNum",WatchNum);
268 for(i=0;i<WatchNum;i++){
269 sprintf(temporary,"Watch%03d",i);
270 SetStringValue(temporary,ppWatchStr[i]);
271 HeapDefaultFree(ppWatchStr[i]);
272 }
273 HeapDefaultFree(ppWatchStr);
274
275
276 //保存
277 WriteBuffer(
278 Program::GetAbcUserAppDir() + "\\compiler.ini",
279 buffer,lstrlen(buffer));
280
281
282 HeapDefaultFree(buffer);
283}
Note: See TracBrowser for help on using the repository browser.