OSDN Git Service

フォーカス処理修正
[nlite/nlite.git] / nlite / nlite_property.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4 namespace nlite{
5
6         //
7         //\83}\83N\83\8d\92è\8b`
8         //
9         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
10 #define NLITE_GET_TYPENAME(n)                   (_tcsstr(CComBSTR(typeid(n).name()),TEXT("::")) + 2)
11 #define NLITE_XMLELLMENT_WRITE(s,p)             s->WriteStartElement(NULL, NLITE_GET_TYPENAME(p), NULL)
12
13 #define NLITE_ATTRIBUTE_WRITE_STR(s,n)  s->WriteElementString(NULL, _tcsstr(TEXT(#n),TEXT("."))  != NULL ? _tcsstr(TEXT(#n),TEXT(".")) + 1 : TEXT(#n), NULL, n)
14
15
16 #define NLITE_ATTRIBUTE_WRITE_INT(s,n)  \
17         {\
18         TCHAR buffer[sizeof(n) * 8];\
19         _stprintf(buffer,TEXT("%d"),static_cast<INT>(n));\
20         s->WriteElementString(NULL, _tcsstr(TEXT(#n),TEXT(".")) + 1, NULL,buffer );\
21 }
22
23 #define NLITE_XML_WRITE_FOR_INT(s,n)\
24         {\
25         TCHAR nbuffer[LENGTH_256];\
26         TCHAR buffer[sizeof(n[0]) * 8];\
27         for(UINT_PTR index = 0;index < ARRAY_LENGTH(n);index++){\
28         _stprintf(nbuffer,TEXT("%s%d"),_tcsstr(TEXT(#n),TEXT(".")) + 1,index);\
29         _stprintf(buffer,TEXT("%d"),n[index]);\
30         s->WriteElementString(NULL, nbuffer, NULL,buffer );\
31         }\
32 }
33
34
35
36         //
37         //\92è\90\94\90é\8c¾
38         /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
39         static const LPCTSTR headerFormat = TEXT("headerholSize%u");
40         static const LPCTSTR headerOrderFormat = TEXT("headerOrderArray%u");
41         static const LPCTSTR bt_none = TEXT("none");
42         static const LPCTSTR bt_ie = TEXT("ie");
43         static const LPCTSTR bt_chrome = TEXT("chrome");
44         static const LPCTSTR bt_firefox = TEXT("firefox");
45         static const LPCTSTR bt_iecm = TEXT("iecm");
46
47
48
49
50         CommentViewProperty::CommentViewProperty():
51         commentFoldingFlag(TRUE),
52                 commentTimeType(StreamingTimeType),
53                 baseStringColor(PALETTERGB(0,0,0)),
54                 backColor(PALETTERGB(255,255,255)),
55                 selectBackColor(PALETTERGB(255,240,240)),                       
56                 selectSellLineColor(PALETTERGB(255,0,0)),                                               
57                 normalSellLineColor( PALETTERGB(0,0,0)),
58                 colLineColor(PALETTERGB(224,224,224)),
59                 linkStringColor(PALETTERGB(30,140,255))
60
61         {
62                 for(INT_PTR orderIndex = 0;orderIndex < ARRAY_LENGTH(headerOrderArray);orderIndex++){
63
64                         new(&headerOrderArray[orderIndex]) INT_PTR(orderIndex);
65
66                 }
67
68                 memset(headerholSize,-1,sizeof(headerholSize));
69         }
70
71
72
73
74         CommentReadProperty::CommentReadProperty():
75         commentReadFlag(FALSE),
76                 ngWordReadFlag(TRUE),
77                 ngUserReadFlag(TRUE),
78                 administratorCommentReadFlag(TRUE),
79                 bspReadFlag(TRUE),
80                 userCommentReadFlag(TRUE),
81                 teropReadFlag(TRUE)
82         {}
83
84
85
86
87         GeneralProperty::GeneralProperty():
88         userCountUpdateFlag(TRUE),
89                 commentLogAutoSaveFlag(FALSE),
90                 defaultBrowserFlag(TRUE),
91                 autoNameRegisterFlag(FALSE),
92                 autoNameUpdateFlag(FALSE),
93                 numberNameFlag(FALSE),
94                 autoColorRegisterFlag(FALSE),
95                 activeCountTimeFlag(TRUE),
96                 browserType(BT_NOSETTING)
97         {}
98
99
100
101         MainFrameProperty::MainFrameProperty():
102         windowFrontFlag(TRUE)
103         {
104
105                 ZeroMemory(&windowSize,sizeof(windowSize));
106
107         }
108
109
110
111
112         Property::Property()
113         {
114                 TCHAR localAppPath[_MAX_PATH];
115                 SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppPath);
116
117                 this->appLocalPath = localAppPath;
118         }
119
120         Property::~Property()
121         {
122
123
124         }
125
126         VOID Property::Initialize(){
127                 this->~Property();
128                 new(this) Property;
129
130         }
131
132         BROWSERTYPE Property::CookieSetting(){
133
134                 CCookieSettingWindow cookieSettingwindow;
135
136                 cookieSettingwindow.SetBrowserType(gp.browserType);
137
138                 cookieSettingwindow.DoModal();
139
140                 this->gp.browserType = cookieSettingwindow.GetBrowserType();
141
142                 return this->gp.browserType;
143
144         }
145
146         VOID Property::ReadProperty(){
147
148                 CreatePropertyFile();
149                 CAtlFile        propertyFile;
150                 ULONGLONG nLen;
151
152                 if(SUCCEEDED(propertyFile.Create(propertyPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(propertyFile.GetSize(nLen)) == FALSE){
153
154                         throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\82ª\8aJ\82¯\82Ü\82¹\82ñ\82Å\82µ\82½\81B\82±\82Ì\83G\83\89\81[\82ª\91±\82­\82æ\82¤\82Å\82 \82ê\82Î\81A\88ê\93x\90Ý\92è\83t\83@\83C\83\8b\82ð\8dí\8f\9c\82µ\82Ä\8dÄ\93x\8e\8e\82µ\82Ä\82Ý\82Ä\82­\82¾\82³\82¢"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
155
156                 }
157
158                 std::vector<char> buf(static_cast<UINT_PTR>(nLen / sizeof(char) + 1));
159                 buf[buf.size() -1 ] = '\0'; 
160                 propertyFile.Read(&buf[0],buf.size());
161                 ReadPropertyXML reader(*this);
162                 reader.Parse(&buf[0],buf.size());
163
164                 return;
165         }
166
167
168         VOID Property::CreatePropertyFile(){
169
170                 propertyPath = appLocalPath;
171
172                 propertyPath += TEXT("\\qwerty_nico");
173
174                 if(PathIsDirectory(propertyPath) == FALSE){
175
176                         if(CreateDirectory(propertyPath,NULL) == 0){
177                                 throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
178                         }
179
180                 }
181
182                 propertyPath += TEXT("\\nlite");
183
184                 if(PathIsDirectory(propertyPath) == FALSE){
185
186                         if(CreateDirectory(propertyPath,NULL) == 0){
187                                 throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
188                         }
189
190                 }
191
192                 propertyPath += TEXT("\\property.xml");
193
194
195                 if(PathFileExists(propertyPath)== FALSE || PathIsDirectory(propertyPath) == TRUE){
196
197                         HANDLE hPropertyxml =   CreateFile(propertyPath,GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
198
199                         if(hPropertyxml == INVALID_HANDLE_VALUE ){
200
201                                 throw Exception(TEXT("\90Ý\92è\83t\83@\83C\83\8b\8dì\90¬\82É\8e¸\94s\82µ\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
202
203                         }
204
205
206                         CloseHandle(hPropertyxml);
207
208                 }
209
210                 return;
211         }
212
213
214         VOID Property::WriteProperty(){
215
216                 CreatePropertyFile();
217                 CComPtr<IXmlWriter> pWriter;
218                 CreateXmlWriter(__uuidof(IXmlWriter), reinterpret_cast<void**>(&pWriter), 0);
219
220                 // XML\83t\83@\83C\83\8b\83p\83X\8dì\90¬
221                 TCHAR xml[MAX_PATH];
222                 _tcscpy(xml,this->propertyPath);
223
224
225
226                 // \83t\83@\83C\83\8b\83X\83g\83\8a\81[\83\80\8dì\90¬
227                 CComPtr<IStream> pStream;
228                 SHCreateStreamOnFile(xml, STGM_CREATE | STGM_WRITE, &pStream);
229
230                 pWriter->SetOutput(pStream);
231
232                 // \83C\83\93\83f\83\93\83g\97L\8cø\89»
233                 pWriter->SetProperty(XmlWriterProperty_Indent, TRUE);
234
235                 // <?xml version="1.0" encoding="UTF-8"?>
236                 pWriter->WriteStartDocument(XmlStandalone_Omit);
237
238                 pWriter->WriteStartElement(NULL,TEXT("nliteconfig"),NULL);
239                 //\83R\83\81\83\93\83g\93Ç\82Ý\8fã\82°\90Ý\92è\8f\91\82«\8d\9e\82Ý
240                 NLITE_XMLELLMENT_WRITE(pWriter,crp);
241                 NLITE_ATTRIBUTE_WRITE_STR(pWriter,crp.outString);
242                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.administratorCommentReadFlag);
243                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.besideLengthFlag);
244                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.bspReadFlag);
245                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.commentReadFlag);
246                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.maxCommentLength);
247                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.newLineReadFlag);
248                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.ngUserReadFlag);
249                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.ngWordReadFlag);
250                 NLITE_ATTRIBUTE_WRITE_STR(pWriter,crp.shortComment);
251                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.teropReadFlag);
252                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.userCommentReadFlag);
253                 pWriter->WriteEndElement();
254                 //commentview\90Ý\92è\92l\8f\91\82«\8d\9e\82Ý
255                 NLITE_XMLELLMENT_WRITE(pWriter,cvp);
256                 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerholSize);
257                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.anonymousIDLinkColor);
258                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.backColor);
259                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.baseStringColor);
260                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.commentFoldingFlag);
261                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.commentTimeType);
262                 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerOrderArray);
263                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.linkStringColor);
264                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.selectBackColor);
265                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.selectSellLineColor);
266                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.colLineColor);
267                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.normalSellLineColor);
268
269
270                 pWriter->WriteEndElement();
271
272
273                 NLITE_XMLELLMENT_WRITE(pWriter,mfp);
274                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowSize.cx);
275                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowSize.cy);
276                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowFrontFlag);
277                 pWriter->WriteEndElement();
278
279                 NLITE_XMLELLMENT_WRITE(pWriter,gp);
280                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.activeCountTimeFlag);
281                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoColorRegisterFlag);
282                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoNameUpdateFlag);
283                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoNameRegisterFlag);
284                 NLITE_ATTRIBUTE_WRITE_STR(pWriter,gp.browserPath);
285                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.browserType);
286                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.commentLogAutoSaveFlag);
287                 NLITE_ATTRIBUTE_WRITE_STR(pWriter,gp.commentPath);
288                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.defaultBrowserFlag);
289                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.numberNameFlag);
290                 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.userCountUpdateFlag);
291                 pWriter->WriteEndElement();
292                 pWriter->WriteEndDocument();
293
294                 pWriter->Flush();
295
296                 return;
297         }
298
299
300         ///
301         ///\83R\83\93\83X\83g\83\89\83N\83^
302         ///
303         ReadPropertyXML::ReadPropertyXML(Property &in_property):nliteProperty(in_property),propertyType(Node::None){
304
305                 return;
306         }
307
308
309
310         //
311         //\90Ý\92è\83t\83@\83C\83\8b\89ð\90Í\8f\88\97\9d
312         //
313
314 #define NLITE_PSZNAME_CMP(t,p) (_tcscmp(NLITE_GET_TYPENAME(t),(LPCTSTR)(p)) == 0)
315         void ReadPropertyXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
316
317                 switch(propertyType){
318
319                 case Node::None:
320
321                         if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName)){
322
323                                 propertyType = Node::CommentReadProperty;
324
325                         } else if(NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)){
326
327                                 propertyType = Node::CommentViewProperty;
328
329                         } else if(NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
330
331                                 propertyType = Node::MainFrameProperty;
332
333                         } else if(NLITE_PSZNAME_CMP(nliteProperty.gp,pszName)){
334
335                                 propertyType = Node::GeneralProperty;
336
337                         }
338
339                         break;
340
341
342                 case Node::CommentReadProperty:
343                 case Node::CommentViewProperty:
344                 case Node::GeneralProperty:
345                 case Node::MainFrameProperty:
346
347                         nodeName = (LPCTSTR)pszName;
348                         break;
349
350                 default:
351
352                         break;
353                 }
354
355                 return;
356         }
357
358
359
360
361         void ReadPropertyXML::OnEndElement (const XML_Char *pszName){
362
363                 if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName) || 
364                         NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)||
365                         NLITE_PSZNAME_CMP(nliteProperty.gp,pszName) || 
366                         NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
367
368                                 propertyType = Node::None;
369
370                 }
371                 nodeName = TEXT("");
372
373                 return;
374         }
375
376 #define NLITE_R_X_P_S(p,p2,v) \
377         if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
378         _tcsncpy(p.p2.v,(LPCTSTR)pszData,nLength);\
379         break;\
380         }
381
382 #define NLITE_R_X_P_I(p,p2,v) \
383         if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
384         p.p2.v = 0;\
385         strToIntN(p.p2.v,pszData,nLength);\
386         break;\
387         }
388
389 #define NLITE_RXP_AI(p,p2,v) {\
390         TCHAR name[LENGTH_256];\
391         for(INT_PTR index = 0;index < ARRAY_LENGTH(p.p2.v);index++){\
392         _stprintf(name,TEXT("%s%d"),TEXT(#v),index);\
393         if(_tcscmp(name,nodeName.c_str()) == 0){\
394         p.p2.v[index] = 0;\
395         strToIntN(p.p2.v[index],pszData,nLength);\
396         goto end;\
397         }\
398         }\
399         }
400
401 #define NLITE_NAME(n) (#n)
402
403         void ReadPropertyXML::OnCharacterData (const XML_Char *pszData, int nLength){
404
405                 if (nodeName.empty() == true)return;
406
407                 switch(propertyType){
408
409
410
411                 case Node::CommentReadProperty:
412
413                         NLITE_R_X_P_S(nliteProperty,crp,shortComment);
414                         NLITE_R_X_P_I(nliteProperty,crp,administratorCommentReadFlag);
415                         NLITE_R_X_P_I(nliteProperty,crp,besideLengthFlag);
416                         NLITE_R_X_P_I(nliteProperty,crp,bspReadFlag);
417                         NLITE_R_X_P_I(nliteProperty,crp,commentReadFlag);
418                         NLITE_R_X_P_I(nliteProperty,crp,maxCommentLength);
419                         NLITE_R_X_P_I(nliteProperty,crp,newLineReadFlag);
420                         NLITE_R_X_P_I(nliteProperty,crp,ngUserReadFlag);
421                         NLITE_R_X_P_I(nliteProperty,crp,ngWordReadFlag);
422                         NLITE_R_X_P_S(nliteProperty,crp,outString);
423                         NLITE_R_X_P_S(nliteProperty,crp,shortComment);
424                         NLITE_R_X_P_I(nliteProperty,crp,teropReadFlag);
425                         NLITE_R_X_P_I(nliteProperty,crp,userCommentReadFlag);
426
427                         break;
428                 case Node::CommentViewProperty:
429                         NLITE_R_X_P_I(nliteProperty,cvp,anonymousIDLinkColor);
430                         NLITE_R_X_P_I(nliteProperty,cvp,backColor);
431                         NLITE_R_X_P_I(nliteProperty,cvp,baseStringColor);
432                         NLITE_R_X_P_I(nliteProperty,cvp,commentFoldingFlag);
433                         NLITE_R_X_P_I(nliteProperty,cvp,commentTimeType);
434                         NLITE_R_X_P_I(nliteProperty,cvp,linkStringColor);
435                         NLITE_RXP_AI(nliteProperty,cvp,headerholSize);
436                         NLITE_RXP_AI(nliteProperty,cvp,headerOrderArray);
437                         NLITE_R_X_P_I(nliteProperty,cvp,selectBackColor);
438                         NLITE_R_X_P_I(nliteProperty,cvp,selectSellLineColor);
439                         NLITE_R_X_P_I(nliteProperty,cvp,normalSellLineColor);
440                         NLITE_R_X_P_I(nliteProperty,cvp,colLineColor);
441                         break;
442                 case Node::GeneralProperty:
443                         NLITE_R_X_P_I(nliteProperty,gp,activeCountTimeFlag);
444                         NLITE_R_X_P_I(nliteProperty,gp,autoColorRegisterFlag);
445                         NLITE_R_X_P_I(nliteProperty,gp,autoNameRegisterFlag);
446                         NLITE_R_X_P_I(nliteProperty,gp,autoNameUpdateFlag);
447                         NLITE_R_X_P_S(nliteProperty,gp,browserPath);
448                         NLITE_R_X_P_I(nliteProperty,gp,browserType);
449                         NLITE_R_X_P_I(nliteProperty,gp,commentLogAutoSaveFlag);
450                         NLITE_R_X_P_S(nliteProperty,gp,commentPath);
451                         NLITE_R_X_P_I(nliteProperty,gp,defaultBrowserFlag);
452                         NLITE_R_X_P_I(nliteProperty,gp,numberNameFlag);
453                         NLITE_R_X_P_I(nliteProperty,gp,userCountUpdateFlag);
454                         break;
455                 case Node::MainFrameProperty:
456                         NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cx);
457                         NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cy);
458                         NLITE_R_X_P_I(nliteProperty,mfp,windowFrontFlag);
459                         break;
460
461
462                 default:
463
464                         break;
465
466
467                 }
468
469 end:
470
471                 return;
472         }
473
474 }