OSDN Git Service

suoの保存
[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
239                 // \83C\83\93\83f\83\93\83g\97L\8cø\89»
240                 pWriter->SetProperty(XmlWriterProperty_Indent, TRUE);
241
242                 // <?xml version="1.0" encoding="UTF-8"?>
243                 pWriter->WriteStartDocument(XmlStandalone_Omit);
244
245                 pWriter->WriteStartElement(NULL,TEXT("nliteconfig"),NULL);
246                 //\83R\83\81\83\93\83g\93Ç\82Ý\8fã\82°\90Ý\92è\8f\91\82«\8d\9e\82Ý
247                 NLITE_XMLELLMENT_WRITE(pWriter,crp);
248                 NLITE_ELLEMENT_WRITE_STR(pWriter,crp.outString);
249                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.administratorCommentReadFlag);
250                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.besideLengthFlag);
251                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.bspReadFlag);
252                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.commentReadFlag);
253                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.maxCommentLength);
254                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.newLineReadFlag);
255                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.ngUserReadFlag);
256                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.ngWordReadFlag);
257                 NLITE_ELLEMENT_WRITE_STR(pWriter,crp.shortComment);
258                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.teropReadFlag);
259                 NLITE_ELLEMENT_WRITE_INT(pWriter,crp.userCommentReadFlag);
260                 pWriter->WriteEndElement();
261                 //commentview\90Ý\92è\92l\8f\91\82«\8d\9e\82Ý
262                 NLITE_XMLELLMENT_WRITE(pWriter,cvp);
263                 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerholSize);
264                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.anonymousIDLinkColor);
265                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.backColor);
266                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.baseStringColor);
267                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.commentFoldingFlag);
268                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.commentTimeType);
269                 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerOrderArray);
270                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.linkStringColor);
271                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.selectBackColor);
272                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.selectSellLineColor);
273                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.colLineColor);
274                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.normalSellLineColor);
275                 NLITE_ELLEMENT_WRITE_INT(pWriter,cvp.ownerStringColor);
276                 
277                 pWriter->WriteEndElement();
278
279
280                 NLITE_XMLELLMENT_WRITE(pWriter,mfp);
281                 NLITE_ELLEMENT_WRITE_INT(pWriter,mfp.windowSize.cx);
282                 NLITE_ELLEMENT_WRITE_INT(pWriter,mfp.windowSize.cy);
283                 NLITE_ELLEMENT_WRITE_INT(pWriter,mfp.windowFrontFlag);
284                 pWriter->WriteEndElement();
285
286
287                 //\8b¤\92Ê\90Ý\92è\8f\91\82«\8d\9e\82Ý
288                 NLITE_XMLELLMENT_WRITE(pWriter,gp);
289                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.activeCountTimeFlag);
290                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.autoColorRegisterFlag);
291                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.autoNameUpdateFlag);
292                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.autoNameRegisterFlag);
293                 NLITE_ELLEMENT_WRITE_STR(pWriter,gp.browserPath);
294                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.browserType);
295                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.commentLogAutoSaveFlag);
296                 NLITE_ELLEMENT_WRITE_STR(pWriter,gp.commentPath);
297                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.defaultBrowserFlag);
298                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.numberNameFlag);
299                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.userCountUpdateFlag);
300                 NLITE_ELLEMENT_WRITE_INT(pWriter,gp.ncvUserSettingReadedFlag);
301                 
302                 pWriter->WriteEndElement();
303                 pWriter->WriteEndDocument();
304
305                 pWriter->Flush();
306
307                 return;
308         }
309
310
311         ///
312         ///\83R\83\93\83X\83g\83\89\83N\83^
313         ///
314         ReadPropertyXML::ReadPropertyXML(Property &in_property):nliteProperty(in_property),propertyType(Node::None){
315
316                 return;
317         }
318
319
320
321         //
322         //\90Ý\92è\83t\83@\83C\83\8b\89ð\90Í\8f\88\97\9d
323         //
324
325 #define NLITE_PSZNAME_CMP(t,p) (_tcscmp(NLITE_GET_TYPENAME(t),(LPCTSTR)(p)) == 0)
326         void ReadPropertyXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
327
328                 switch(propertyType){
329
330                 case Node::None:
331
332                         if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName)){
333
334                                 propertyType = Node::CommentReadProperty;
335
336                         } else if(NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)){
337
338                                 propertyType = Node::CommentViewProperty;
339
340                         } else if(NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
341
342                                 propertyType = Node::MainFrameProperty;
343
344                         } else if(NLITE_PSZNAME_CMP(nliteProperty.gp,pszName)){
345
346                                 propertyType = Node::GeneralProperty;
347
348                         }
349
350                         break;
351
352
353                 case Node::CommentReadProperty:
354                 case Node::CommentViewProperty:
355                 case Node::GeneralProperty:
356                 case Node::MainFrameProperty:
357
358                         nodeName = (LPCTSTR)pszName;
359                         break;
360
361                 default:
362
363                         break;
364                 }
365
366                 return;
367         }
368
369
370
371
372         void ReadPropertyXML::OnEndElement (const XML_Char *pszName){
373
374                 if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName) || 
375                         NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)||
376                         NLITE_PSZNAME_CMP(nliteProperty.gp,pszName) || 
377                         NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
378
379                                 propertyType = Node::None;
380
381                 }
382                 nodeName = TEXT("");
383
384                 return;
385         }
386
387 #define NLITE_R_X_P_S(p,p2,v) \
388         if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
389         _tcsncpy(p.p2.v,(LPCTSTR)pszData,nLength);\
390         break;\
391         }
392
393 #define NLITE_R_X_P_I(p,p2,v) \
394         if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
395         p.p2.v = 0;\
396         strToIntN(p.p2.v,pszData,nLength);\
397         break;\
398         }
399
400 #define NLITE_RXP_AI(p,p2,v) {\
401         TCHAR name[LENGTH_256];\
402         for(INT_PTR index = 0;index < ARRAY_LENGTH(p.p2.v);index++){\
403         _stprintf(name,TEXT("%s%d"),TEXT(#v),index);\
404         if(_tcscmp(name,nodeName.c_str()) == 0){\
405         p.p2.v[index] = 0;\
406         strToIntN(p.p2.v[index],pszData,nLength);\
407         goto end;\
408         }\
409         }\
410         }
411
412 #define NLITE_NAME(n) (#n)
413
414         void ReadPropertyXML::OnCharacterData (const XML_Char *pszData, int nLength){
415
416                 if (nodeName.empty() == true)return;
417
418                 switch(propertyType){
419
420
421
422                 case Node::CommentReadProperty:
423
424                         NLITE_R_X_P_S(nliteProperty,crp,shortComment);
425                         NLITE_R_X_P_I(nliteProperty,crp,administratorCommentReadFlag);
426                         NLITE_R_X_P_I(nliteProperty,crp,besideLengthFlag);
427                         NLITE_R_X_P_I(nliteProperty,crp,bspReadFlag);
428                         NLITE_R_X_P_I(nliteProperty,crp,commentReadFlag);
429                         NLITE_R_X_P_I(nliteProperty,crp,maxCommentLength);
430                         NLITE_R_X_P_I(nliteProperty,crp,newLineReadFlag);
431                         NLITE_R_X_P_I(nliteProperty,crp,ngUserReadFlag);
432                         NLITE_R_X_P_I(nliteProperty,crp,ngWordReadFlag);
433                         NLITE_R_X_P_S(nliteProperty,crp,outString);
434                         NLITE_R_X_P_S(nliteProperty,crp,shortComment);
435                         NLITE_R_X_P_I(nliteProperty,crp,teropReadFlag);
436                         NLITE_R_X_P_I(nliteProperty,crp,userCommentReadFlag);
437
438                         break;
439                 case Node::CommentViewProperty:
440                         NLITE_R_X_P_I(nliteProperty,cvp,anonymousIDLinkColor);
441                         NLITE_R_X_P_I(nliteProperty,cvp,backColor);
442                         NLITE_R_X_P_I(nliteProperty,cvp,baseStringColor);
443                         NLITE_R_X_P_I(nliteProperty,cvp,commentFoldingFlag);
444                         NLITE_R_X_P_I(nliteProperty,cvp,commentTimeType);
445                         NLITE_R_X_P_I(nliteProperty,cvp,linkStringColor);
446                         NLITE_RXP_AI(nliteProperty,cvp,headerholSize);
447                         NLITE_RXP_AI(nliteProperty,cvp,headerOrderArray);
448                         NLITE_R_X_P_I(nliteProperty,cvp,selectBackColor);
449                         NLITE_R_X_P_I(nliteProperty,cvp,selectSellLineColor);
450                         NLITE_R_X_P_I(nliteProperty,cvp,normalSellLineColor);
451                         NLITE_R_X_P_I(nliteProperty,cvp,colLineColor);
452                         NLITE_R_X_P_I(nliteProperty,cvp,ownerStringColor);
453                         
454                         break;
455                 case Node::GeneralProperty:
456                         NLITE_R_X_P_I(nliteProperty,gp,activeCountTimeFlag);
457                         NLITE_R_X_P_I(nliteProperty,gp,autoColorRegisterFlag);
458                         NLITE_R_X_P_I(nliteProperty,gp,autoNameRegisterFlag);
459                         NLITE_R_X_P_I(nliteProperty,gp,autoNameUpdateFlag);
460                         NLITE_R_X_P_S(nliteProperty,gp,browserPath);
461                         NLITE_R_X_P_I(nliteProperty,gp,browserType);
462                         NLITE_R_X_P_I(nliteProperty,gp,commentLogAutoSaveFlag);
463                         NLITE_R_X_P_S(nliteProperty,gp,commentPath);
464                         NLITE_R_X_P_I(nliteProperty,gp,defaultBrowserFlag);
465                         NLITE_R_X_P_I(nliteProperty,gp,numberNameFlag);
466                         NLITE_R_X_P_I(nliteProperty,gp,userCountUpdateFlag);
467                         NLITE_R_X_P_I(nliteProperty,gp,ncvUserSettingReadedFlag);
468                         break;
469                 case Node::MainFrameProperty:
470                         NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cx);
471                         NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cy);
472                         NLITE_R_X_P_I(nliteProperty,mfp,windowFrontFlag);
473                         break;
474
475
476                 default:
477
478                         break;
479
480
481                 }
482
483 end:
484
485                 return;
486         }
487
488
489
490
491
492 }