OSDN Git Service

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