3 #include "nlite_include.h"
8 //
\83}
\83N
\83\8d\92è
\8b`
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)
14 #define NLITE_ATTRIBUTE_WRITE_STR(s,n) s->WriteElementString(NULL, _tcsstr(TEXT(#n),TEXT(".")) != NULL ? _tcsstr(TEXT(#n),TEXT(".")) + 1 : TEXT(#n), NULL, n)
17 #define NLITE_ATTRIBUTE_WRITE_INT(s,n) \
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 );\
24 #define NLITE_XML_WRITE_FOR_INT(s,n)\
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 );\
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");
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))
64 for(INT_PTR orderIndex = 0;orderIndex < ARRAY_LENGTH(headerOrderArray);orderIndex++){
66 new(&headerOrderArray[orderIndex]) INT_PTR(orderIndex);
70 memset(headerholSize,-1,sizeof(headerholSize));
76 CommentReadProperty::CommentReadProperty():
77 commentReadFlag(FALSE),
80 administratorCommentReadFlag(TRUE),
82 userCommentReadFlag(TRUE),
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)
104 MainFrameProperty::MainFrameProperty():
105 windowFrontFlag(TRUE)
108 ZeroMemory(&windowSize,sizeof(windowSize));
117 TCHAR localAppPath[_MAX_PATH];
118 SHGetFolderPathW(0,CSIDL_LOCAL_APPDATA,0,SHGFP_TYPE_CURRENT,localAppPath);
120 this->appLocalPath = localAppPath;
123 Property::~Property()
129 VOID Property::Initialize(){
135 BROWSERTYPE Property::CookieSetting(){
137 CCookieSettingWindow cookieSettingwindow;
139 cookieSettingwindow.SetBrowserType(gp.browserType);
141 cookieSettingwindow.DoModal();
143 this->gp.browserType = cookieSettingwindow.GetBrowserType();
148 return this->gp.browserType;
152 VOID Property::ReadProperty(){
154 CreatePropertyFile();
155 CAtlFile propertyFile;
156 CAtlFile ncvUserSettingFile;
157 ULONGLONG propertyFileSize;
158 ULONGLONG ncvUserSettingFileSize;
159 if(SUCCEEDED(propertyFile.Create(propertyPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(propertyFile.GetSize(propertyFileSize)) == FALSE){
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__));
165 std::vector<char> propertyBuf(static_cast<UINT_PTR>(propertyFileSize / sizeof(char) + (1 * sizeof(char))));
168 propertyFile.Read(&propertyBuf[0],propertyBuf.size());
170 LPSTR propertyTagStart = strstr(&propertyBuf[0],"<");
171 if(propertyTagStart != NULL){
172 ReadPropertyXML reader(*this);
173 reader.Parse(propertyTagStart);
177 if(this->gp.ncvUserSettingReadedFlag == FALSE){
179 TCHAR appFolderPath[_MAX_PATH];
180 SHGetFolderPathW(0,CSIDL_APPDATA,0,SHGFP_TYPE_CURRENT,appFolderPath);
181 CString ncvUserSettingPath = appFolderPath;
182 ncvUserSettingPath += TEXT("\\posite-c\\NiconamaCommentViewer\\UserSetting.xml");
183 if(SUCCEEDED(ncvUserSettingFile.Create(ncvUserSettingPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(ncvUserSettingFile.GetSize(ncvUserSettingFileSize)) == FALSE){
185 throw Exception(TEXT("
\83\8a\83X
\83i
\81[
\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__));
187 std::vector<char> ncvUserSettingBuf(static_cast<UINT_PTR>(ncvUserSettingFileSize / sizeof(char) + (1 * sizeof(char))));
188 ncvUserSettingFile.Read(&ncvUserSettingBuf[0],ncvUserSettingBuf.size());
189 LPSTR ncvUserSettingStart = strstr(&ncvUserSettingBuf[0],"<");
190 if(ncvUserSettingStart != NULL){
191 ReadUserSettingXML rusx;
192 rusx.Parse(ncvUserSettingStart);
200 VOID Property::CreatePropertyFile(){
203 iniFile = appLocalPath;
204 iniFile += TEXT("\\qwerty_nico\\nlite.ini");
205 SurelyCreate(iniFile,TRUE);
208 TCHAR propertyBuf[_MAX_PATH];
209 LPCTSTR sectionName = TEXT("property");
210 LPCTSTR keyName = TEXT("dir");
211 ::GetPrivateProfileString(sectionName,keyName,TEXT(""),propertyBuf,ARRAY_LENGTH(propertyBuf),iniFile);
213 if((_tcslen(propertyBuf) == 0) || !((PathFileExists(propertyBuf) && !::PathIsDirectory( propertyBuf )))){
215 propertyFolderPath = appLocalPath;
216 propertyFolderPath += TEXT("\\qwerty_nico");
218 ::WritePrivateProfileString(sectionName,keyName,propertyFolderPath,iniFile);
221 propertyFolderPath = propertyBuf;
224 propertySaveFolderPath = propertyFolderPath;
225 propertySaveFolderPath += TEXT("\\nlite");
226 propertyPath = propertySaveFolderPath;
227 propertyPath += TEXT("\\property.xml");
228 userSettingPath = propertySaveFolderPath;
229 userSettingPath += TEXT("\\user_setting.xml");
230 SurelyCreate(propertySaveFolderPath,FALSE);
231 SurelyCreate(propertyPath,TRUE);
232 SurelyCreate(userSettingPath,TRUE);
238 VOID Property::WriteProperty(){
240 CreatePropertyFile();
241 CComPtr<IXmlWriter> pWriter;
242 CreateXmlWriter(__uuidof(IXmlWriter), reinterpret_cast<void**>(&pWriter), 0);
244 // XML
\83t
\83@
\83C
\83\8b\83p
\83X
\8dì
\90¬
246 _tcscpy(xml,this->propertyPath);
250 //
\83t
\83@
\83C
\83\8b\83X
\83g
\83\8a\81[
\83\80\8dì
\90¬
251 CComPtr<IStream> pStream;
252 SHCreateStreamOnFile(xml, STGM_CREATE | STGM_WRITE, &pStream);
254 pWriter->SetOutput(pStream);
256 //
\83C
\83\93\83f
\83\93\83g
\97L
\8cø
\89»
257 pWriter->SetProperty(XmlWriterProperty_Indent, TRUE);
259 // <?xml version="1.0" encoding="UTF-8"?>
260 pWriter->WriteStartDocument(XmlStandalone_Omit);
262 pWriter->WriteStartElement(NULL,TEXT("nliteconfig"),NULL);
263 //
\83R
\83\81\83\93\83g
\93Ç
\82Ý
\8fã
\82°
\90Ý
\92è
\8f\91\82«
\8d\9e\82Ý
264 NLITE_XMLELLMENT_WRITE(pWriter,crp);
265 NLITE_ATTRIBUTE_WRITE_STR(pWriter,crp.outString);
266 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.administratorCommentReadFlag);
267 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.besideLengthFlag);
268 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.bspReadFlag);
269 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.commentReadFlag);
270 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.maxCommentLength);
271 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.newLineReadFlag);
272 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.ngUserReadFlag);
273 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.ngWordReadFlag);
274 NLITE_ATTRIBUTE_WRITE_STR(pWriter,crp.shortComment);
275 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.teropReadFlag);
276 NLITE_ATTRIBUTE_WRITE_INT(pWriter,crp.userCommentReadFlag);
277 pWriter->WriteEndElement();
278 //commentview
\90Ý
\92è
\92l
\8f\91\82«
\8d\9e\82Ý
279 NLITE_XMLELLMENT_WRITE(pWriter,cvp);
280 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerholSize);
281 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.anonymousIDLinkColor);
282 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.backColor);
283 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.baseStringColor);
284 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.commentFoldingFlag);
285 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.commentTimeType);
286 NLITE_XML_WRITE_FOR_INT(pWriter,cvp.headerOrderArray);
287 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.linkStringColor);
288 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.selectBackColor);
289 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.selectSellLineColor);
290 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.colLineColor);
291 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.normalSellLineColor);
292 NLITE_ATTRIBUTE_WRITE_INT(pWriter,cvp.ownerStringColor);
294 pWriter->WriteEndElement();
297 NLITE_XMLELLMENT_WRITE(pWriter,mfp);
298 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowSize.cx);
299 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowSize.cy);
300 NLITE_ATTRIBUTE_WRITE_INT(pWriter,mfp.windowFrontFlag);
301 pWriter->WriteEndElement();
304 //
\8b¤
\92Ê
\90Ý
\92è
\8f\91\82«
\8d\9e\82Ý
305 NLITE_XMLELLMENT_WRITE(pWriter,gp);
306 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.activeCountTimeFlag);
307 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoColorRegisterFlag);
308 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoNameUpdateFlag);
309 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.autoNameRegisterFlag);
310 NLITE_ATTRIBUTE_WRITE_STR(pWriter,gp.browserPath);
311 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.browserType);
312 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.commentLogAutoSaveFlag);
313 NLITE_ATTRIBUTE_WRITE_STR(pWriter,gp.commentPath);
314 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.defaultBrowserFlag);
315 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.numberNameFlag);
316 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.userCountUpdateFlag);
317 NLITE_ATTRIBUTE_WRITE_INT(pWriter,gp.ncvUserSettingReadedFlag);
319 pWriter->WriteEndElement();
320 pWriter->WriteEndDocument();
329 ///
\83R
\83\93\83X
\83g
\83\89\83N
\83^
331 ReadPropertyXML::ReadPropertyXML(Property &in_property):nliteProperty(in_property),propertyType(Node::None){
339 //
\90Ý
\92è
\83t
\83@
\83C
\83\8b\89ð
\90Í
\8f\88\97\9d
342 #define NLITE_PSZNAME_CMP(t,p) (_tcscmp(NLITE_GET_TYPENAME(t),(LPCTSTR)(p)) == 0)
343 void ReadPropertyXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
345 switch(propertyType){
349 if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName)){
351 propertyType = Node::CommentReadProperty;
353 } else if(NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)){
355 propertyType = Node::CommentViewProperty;
357 } else if(NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
359 propertyType = Node::MainFrameProperty;
361 } else if(NLITE_PSZNAME_CMP(nliteProperty.gp,pszName)){
363 propertyType = Node::GeneralProperty;
370 case Node::CommentReadProperty:
371 case Node::CommentViewProperty:
372 case Node::GeneralProperty:
373 case Node::MainFrameProperty:
375 nodeName = (LPCTSTR)pszName;
389 void ReadPropertyXML::OnEndElement (const XML_Char *pszName){
391 if(NLITE_PSZNAME_CMP(nliteProperty.crp,pszName) ||
392 NLITE_PSZNAME_CMP(nliteProperty.cvp,pszName)||
393 NLITE_PSZNAME_CMP(nliteProperty.gp,pszName) ||
394 NLITE_PSZNAME_CMP(nliteProperty.mfp,pszName)){
396 propertyType = Node::None;
404 #define NLITE_R_X_P_S(p,p2,v) \
405 if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
406 _tcsncpy(p.p2.v,(LPCTSTR)pszData,nLength);\
410 #define NLITE_R_X_P_I(p,p2,v) \
411 if(_tcscmp(TEXT(#v),nodeName.c_str()) == 0){\
413 strToIntN(p.p2.v,pszData,nLength);\
417 #define NLITE_RXP_AI(p,p2,v) {\
418 TCHAR name[LENGTH_256];\
419 for(INT_PTR index = 0;index < ARRAY_LENGTH(p.p2.v);index++){\
420 _stprintf(name,TEXT("%s%d"),TEXT(#v),index);\
421 if(_tcscmp(name,nodeName.c_str()) == 0){\
423 strToIntN(p.p2.v[index],pszData,nLength);\
429 #define NLITE_NAME(n) (#n)
431 void ReadPropertyXML::OnCharacterData (const XML_Char *pszData, int nLength){
433 if (nodeName.empty() == true)return;
435 switch(propertyType){
439 case Node::CommentReadProperty:
441 NLITE_R_X_P_S(nliteProperty,crp,shortComment);
442 NLITE_R_X_P_I(nliteProperty,crp,administratorCommentReadFlag);
443 NLITE_R_X_P_I(nliteProperty,crp,besideLengthFlag);
444 NLITE_R_X_P_I(nliteProperty,crp,bspReadFlag);
445 NLITE_R_X_P_I(nliteProperty,crp,commentReadFlag);
446 NLITE_R_X_P_I(nliteProperty,crp,maxCommentLength);
447 NLITE_R_X_P_I(nliteProperty,crp,newLineReadFlag);
448 NLITE_R_X_P_I(nliteProperty,crp,ngUserReadFlag);
449 NLITE_R_X_P_I(nliteProperty,crp,ngWordReadFlag);
450 NLITE_R_X_P_S(nliteProperty,crp,outString);
451 NLITE_R_X_P_S(nliteProperty,crp,shortComment);
452 NLITE_R_X_P_I(nliteProperty,crp,teropReadFlag);
453 NLITE_R_X_P_I(nliteProperty,crp,userCommentReadFlag);
456 case Node::CommentViewProperty:
457 NLITE_R_X_P_I(nliteProperty,cvp,anonymousIDLinkColor);
458 NLITE_R_X_P_I(nliteProperty,cvp,backColor);
459 NLITE_R_X_P_I(nliteProperty,cvp,baseStringColor);
460 NLITE_R_X_P_I(nliteProperty,cvp,commentFoldingFlag);
461 NLITE_R_X_P_I(nliteProperty,cvp,commentTimeType);
462 NLITE_R_X_P_I(nliteProperty,cvp,linkStringColor);
463 NLITE_RXP_AI(nliteProperty,cvp,headerholSize);
464 NLITE_RXP_AI(nliteProperty,cvp,headerOrderArray);
465 NLITE_R_X_P_I(nliteProperty,cvp,selectBackColor);
466 NLITE_R_X_P_I(nliteProperty,cvp,selectSellLineColor);
467 NLITE_R_X_P_I(nliteProperty,cvp,normalSellLineColor);
468 NLITE_R_X_P_I(nliteProperty,cvp,colLineColor);
469 NLITE_R_X_P_I(nliteProperty,cvp,ownerStringColor);
472 case Node::GeneralProperty:
473 NLITE_R_X_P_I(nliteProperty,gp,activeCountTimeFlag);
474 NLITE_R_X_P_I(nliteProperty,gp,autoColorRegisterFlag);
475 NLITE_R_X_P_I(nliteProperty,gp,autoNameRegisterFlag);
476 NLITE_R_X_P_I(nliteProperty,gp,autoNameUpdateFlag);
477 NLITE_R_X_P_S(nliteProperty,gp,browserPath);
478 NLITE_R_X_P_I(nliteProperty,gp,browserType);
479 NLITE_R_X_P_I(nliteProperty,gp,commentLogAutoSaveFlag);
480 NLITE_R_X_P_S(nliteProperty,gp,commentPath);
481 NLITE_R_X_P_I(nliteProperty,gp,defaultBrowserFlag);
482 NLITE_R_X_P_I(nliteProperty,gp,numberNameFlag);
483 NLITE_R_X_P_I(nliteProperty,gp,userCountUpdateFlag);
484 NLITE_R_X_P_I(nliteProperty,gp,ncvUserSettingReadedFlag);
486 case Node::MainFrameProperty:
487 NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cx);
488 NLITE_R_X_P_I(nliteProperty,mfp,windowSize.cy);
489 NLITE_R_X_P_I(nliteProperty,mfp,windowFrontFlag);
507 #define NLITE_READ_USER_STRING(at,l,t) if(_tcscmp(at[0],TEXT(#t)) == 0)l.t = at[1]
508 #define NLITE_READ_USER_INT(at,l,t) if(_tcscmp(at[0],TEXT(#t))==0)l.t = _tcstol((const wchar_t*)at[1],NULL,10)
510 void ReadUserSettingXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
512 if(_tcscmp(pszName,TEXT("user")) == 0){
514 this->userNodeFlag = TRUE;
517 for(;papszAttrs[0] != NULL;papszAttrs += 2){
519 NLITE_READ_USER_STRING(papszAttrs,listenerBuff,name);
520 NLITE_READ_USER_STRING(papszAttrs,listenerBuff,community);
521 NLITE_READ_USER_INT(papszAttrs,listenerBuff,bgcolor);
522 NLITE_READ_USER_INT(papszAttrs,listenerBuff,time);
531 void ReadUserSettingXML::OnEndElement (const XML_Char *pszName){
533 if(_tcscmp(pszName,TEXT("user")) == 0){
535 listenerList.Register(listenerBuff,TRUE);
536 this->userNodeFlag = FALSE;
537 this->listenerBuff.~ListenerData();
538 new(&listenerBuff) ListenerData();
545 void ReadUserSettingXML::OnCharacterData (const XML_Char *pszData, int nLength){
547 if(this->userNodeFlag == TRUE){
550 listenerBuff.user_id.Append(pszData,nLength);