From: unknown Date: Fri, 10 Feb 2012 03:47:29 +0000 (+0900) Subject: NCVのリスナー情報同期処理 X-Git-Tag: v0.002~2^2~8 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=31e2d889329170fedc336c95048b1c1b42afc8ba;p=nlite%2Fnlite.git NCVのリスナー情報同期処理 --- diff --git a/nlite.suo b/nlite.suo index 912e188..a4ef26b 100644 Binary files a/nlite.suo and b/nlite.suo differ diff --git a/nlite/nlite.cpp b/nlite/nlite.cpp index 99421dd..8872a48 100644 --- a/nlite/nlite.cpp +++ b/nlite/nlite.cpp @@ -9,7 +9,7 @@ CAppModule _Module; -static TCHAR localAppDataPath[_MAX_PATH]; + static WSAData wsaData; //winsockdata static HINTERNET hInternet = NULL; @@ -159,6 +159,10 @@ static BOOL InitializeNlite(){ SystemParametersInfo (SPI_SETLISTBOXSMOOTHSCROLLING,FALSE,FALSE,0); + + SHGetFolderPathW(0,CSIDL_APPDATA,0,SHGFP_TYPE_CURRENT,appFolderPath); + ncvAppSettingPath = appFolderPath; + ncvAppSettingPath += TEXT("\\posite-c\\NiconamaCommentViewer\\AppSetting.xml"); }catch (AppInitException e){ return rslt; diff --git a/nlite/nlite.vcxproj b/nlite/nlite.vcxproj index d868d3c..16cf7e5 100644 --- a/nlite/nlite.vcxproj +++ b/nlite/nlite.vcxproj @@ -106,7 +106,6 @@ - diff --git a/nlite/nlite.vcxproj.filters b/nlite/nlite.vcxproj.filters index fabd5c6..e0c83f6 100644 --- a/nlite/nlite.vcxproj.filters +++ b/nlite/nlite.vcxproj.filters @@ -24,7 +24,6 @@ リソース ファイル - リソース ファイル diff --git a/nlite/nlite_chatData.cpp b/nlite/nlite_chatData.cpp index 0177243..2d59a08 100644 --- a/nlite/nlite_chatData.cpp +++ b/nlite/nlite_chatData.cpp @@ -2,7 +2,6 @@ #include "nlite_include.h" namespace nlite{ -CListenerList nlite::listenerList; @@ -317,5 +316,84 @@ CListenerList::reference CListenerList::Register(ListenerData &listener,BOOL bUp } +BOOL CListenerList::ReadProperty(LPCTSTR fileName){ + BOOL rslt = FALSE; + CAtlFile userSettingFile; + ULONGLONG userSettingFileSize; + + + if(SUCCEEDED(userSettingFile.Create(fileName,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(userSettingFile.GetSize(userSettingFileSize)) == FALSE){ + + throw Exception(TEXT("ƒŠƒXƒi[Ý’èƒtƒ@ƒCƒ‹‚ªŠJ‚¯‚Ü‚¹‚ñ‚Å‚µ‚½B‚±‚̃Gƒ‰[‚ª‘±‚­‚悤‚Å‚ ‚ê‚΁Aˆê“xÝ’èƒtƒ@ƒCƒ‹‚ðíœ‚µ‚čēxŽŽ‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__)); + } + std::vector userSettingBuf(static_cast(userSettingFileSize / sizeof(char) + (1 * sizeof(char)))); + userSettingFile.Read(&userSettingBuf[0],userSettingBuf.size()); + LPSTR userSettingStart = strstr(&userSettingBuf[0],"<"); + if(userSettingStart != NULL){ + ReadUserSettingXML rusx(nlite::listenerList); + rusx.Parse(userSettingStart); + } + + + return rslt; +} + + +ReadUserSettingXML::ReadUserSettingXML(CListenerList &in_listenerList):m_listenerList(in_listenerList),userNodeFlag(FALSE){} + +#define NLITE_READ_USER_STRING(at,l,t) if(_tcscmp(at[0],TEXT(#t)) == 0)l.t = at[1] +#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) + + void ReadUserSettingXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){ + + if(_tcscmp(pszName,TEXT("user")) == 0){ + + this->userNodeFlag = TRUE; + + + for(;papszAttrs[0] != NULL;papszAttrs += 2){ + + NLITE_READ_USER_STRING(papszAttrs,listenerBuff,name); + NLITE_READ_USER_STRING(papszAttrs,listenerBuff,community); + NLITE_READ_USER_INT(papszAttrs,listenerBuff,bgcolor); + NLITE_READ_USER_INT(papszAttrs,listenerBuff,time); + + } + + } + + return; + } + + void ReadUserSettingXML::OnEndElement (const XML_Char *pszName){ + + if(_tcscmp(pszName,TEXT("user")) == 0){ + + listenerList.Register(listenerBuff,TRUE); + this->userNodeFlag = FALSE; + this->listenerBuff.~ListenerData(); + new(&listenerBuff) ListenerData(); + + } + + return; + } + + void ReadUserSettingXML::OnCharacterData (const XML_Char *pszData, int nLength){ + + if(this->userNodeFlag == TRUE){ + + + listenerBuff.user_id.Append(pszData,nLength); + + + + + } + + + + return; + } } \ No newline at end of file diff --git a/nlite/nlite_chatData.h b/nlite/nlite_chatData.h index 0690b24..cc9efa1 100644 --- a/nlite/nlite_chatData.h +++ b/nlite/nlite_chatData.h @@ -104,6 +104,15 @@ namespace nlite{ reference Register(ListenerData &listener,BOOL bUpdate); + /// + ///ƒŠƒXƒi[ƒf[ƒ^“ǂݍž‚Ý + /// + BOOL ReadProperty(LPCTSTR fileName); + + /// + /// + /// + /// ///”wŒiF‚ðŽûW‚·‚é @@ -158,6 +167,8 @@ namespace nlite{ }; + + /// ///ƒRƒƒ“ƒgƒŠƒXƒgƒNƒ‰ƒX /// @@ -293,5 +304,30 @@ namespace nlite{ }; + + /// + ///ƒ†[ƒUÝ’èƒtƒ@ƒCƒ‹“ÇŽæƒNƒ‰ƒX + /// + class ReadUserSettingXML:public CXmlParser{ + + private: + ListenerData listenerBuff; + CListenerList &m_listenerList; + BOOL userNodeFlag; + + + + + + public: + + ReadUserSettingXML(CListenerList &in_listenerList); + + void OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs); + + void OnEndElement (const XML_Char *pszName); + + void OnCharacterData (const XML_Char *pszData, int nLength); + }; } \ No newline at end of file diff --git a/nlite/nlite_common.cpp b/nlite/nlite_common.cpp index 84710f7..055ca1f 100644 --- a/nlite/nlite_common.cpp +++ b/nlite/nlite_common.cpp @@ -21,7 +21,10 @@ namespace nliteregex{ const tstring NUTHINGSTRING(TEXT("")); } Property nliteProperty; - +CListenerList nlite::listenerList; +TCHAR appFolderPath[_MAX_PATH]; +CString ncvAppSettingPath; +TCHAR localAppDataPath[_MAX_PATH]; VOID nlite::UnexpectedErrorMessageShow(LPCTSTR headMessage,LPCTSTR summary,UINT line,LPCTSTR fileName,LPCTSTR function){ tstring errMessage; @@ -122,6 +125,90 @@ err: goto end; } + +/// +///NCVƒ†[ƒUî•ñƒtƒ@ƒCƒ‹ƒpƒXŽæ“¾XMLƒp[ƒT +/// +class CReadNCVListenerInfoFile:public CXmlParser{ + +private: + + BOOL settingDirFlag; + CString &path; + + + + +public: + + CReadNCVListenerInfoFile(CString &in_path):settingDirFlag(FALSE),path(in_path){} + + void OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){ + + if(_tcscmp(pszName,TEXT("SettingDir")) == 0){ + + settingDirFlag = TRUE; + + } + + } + + void OnEndElement (const XML_Char *pszName){ + + if(_tcscmp(pszName,TEXT("SettingDir")) == 0){ + + settingDirFlag = FALSE; + + } + + } + + void OnCharacterData (const XML_Char *pszData, int nLength){ + + if(settingDirFlag == TRUE){ + + path.Append(pszData,nLength); + + } + + } +}; + + CString GetNCVListenerInfoFilePath(){ + + + CString rslt; + + + if((PathFileExists(ncvAppSettingPath) && (!::PathIsDirectory( ncvAppSettingPath )))){ + + + CAtlFile ncvAppSettingFile; + ULONGLONG ncvAppSettingFileSize = 0; + if(SUCCEEDED(ncvAppSettingFile.Create(ncvAppSettingPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || + SUCCEEDED(ncvAppSettingFile.GetSize(ncvAppSettingFileSize)) == FALSE){ + + throw Exception(TEXT("NCV‚̐ݒèƒtƒ@ƒCƒ‹‚ª“ǂݍž‚ß‚Ü‚¹‚ñ‚Å‚µ‚½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__)); + + } + std::vector fileBuf(static_cast(ncvAppSettingFileSize) / sizeof(char) + (1 * sizeof(char))); + ncvAppSettingFile.Read(&fileBuf[0],fileBuf.size()); + LPSTR startPtr = strstr(&fileBuf[0],"<"); + if(startPtr != NULL){ + CReadNCVListenerInfoFile parser(rslt); + parser.Parse(startPtr); + rslt += TEXT("UserSetting.xml"); + + } + + } + + + + + return rslt; + } + const CApplicationInfo * appInfo = NULL; } \ No newline at end of file diff --git a/nlite/nlite_common.h b/nlite/nlite_common.h index c667a51..8089571 100644 --- a/nlite/nlite_common.h +++ b/nlite/nlite_common.h @@ -5,6 +5,9 @@ namespace nlite{ //ƒOƒ[ƒoƒ‹•Ï” extern const CApplicationInfo * appInfo; extern CListenerList listenerList; + extern TCHAR localAppDataPath[]; + extern TCHAR appFolderPath[]; + extern CString ncvAppSettingPath; //ƒOƒ[ƒoƒ‹ŠÖ” extern VOID UnexpectedErrorMessageShow(LPCTSTR headMessage,LPCTSTR summary,UINT line,LPCTSTR fileName,LPCTSTR function); @@ -17,6 +20,13 @@ namespace nlite{ /// extern BOOL SurelyCreate(LPCTSTR dir,BOOL bFile); + + /// + ///ncv‚̃ŠƒXƒi[î•ñƒtƒ@ƒCƒ‹ƒpƒX‚ðŽæ“¾ + /// + extern CString GetNCVListenerInfoFilePath(); + + namespace nliteregex{ typedef std::tr1::basic_regex tregex; namespace text{ diff --git a/nlite/nlite_mainframe.cpp b/nlite/nlite_mainframe.cpp index ff13f7b..90e9079 100644 --- a/nlite/nlite_mainframe.cpp +++ b/nlite/nlite_mainframe.cpp @@ -182,20 +182,41 @@ LRESULT CNliteMainFrame::OnCreate(LPCREATESTRUCT lpcs){ VOID CNliteMainFrame::Initialize(LPCTSTR localAppDataPath){ - nliteProperty.ReadProperty(); + try{ + nliteProperty.ReadProperty(); - commentView.SetProperty(nliteProperty.cvp,nliteProperty.gp); + + if((nliteProperty.gp.ncvUserSettingReadedFlag == FALSE) && + ((PathFileExists(ncvAppSettingPath) && (!::PathIsDirectory( ncvAppSettingPath ))))){ + + if((::MessageBox(NULL,TEXT("NCV‚̃ŠƒXƒi[î•ñ‚Æ“¯Šú‚µ‚Ü‚·‚©H"),TEXT("ƒŠƒXƒi[î•ñ“ǂݍž‚Ý"),MB_OK | MB_OKCANCEL) == IDOK)){ + listenerList.ReadProperty(GetNCVListenerInfoFilePath()); + } + nliteProperty.gp.ncvUserSettingReadedFlag = TRUE; + - if(nliteProperty.gp.browserType == BT_NOSETTING){ - nliteProperty.CookieSetting(); - while(nliteProperty.gp.browserType == BT_NOSETTING){ - ::MessageBox(NULL,TEXT("ƒuƒ‰ƒEƒUƒ^ƒCƒv‚ðŽw’肵‚Ä‚­‚¾‚³‚¢B‚±‚êˆÈŠO‚̃uƒ‰ƒEƒU‚ÍŒ»ÝŽg—p‚·‚邱‚Æ‚Í‚Å‚«‚Ü‚¹‚ñ"),TEXT("ƒuƒ‰ƒEƒUƒ^ƒCƒvŽw’èƒGƒ‰["),MB_OK); + + + } + + listenerList.ReadProperty(nliteProperty.userSettingPath); + + commentView.SetProperty(nliteProperty.cvp,nliteProperty.gp); + if(nliteProperty.gp.browserType == BT_NOSETTING){ nliteProperty.CookieSetting(); + while(nliteProperty.gp.browserType == BT_NOSETTING){ + ::MessageBox(NULL,TEXT("ƒuƒ‰ƒEƒUƒ^ƒCƒv‚ðŽw’肵‚Ä‚­‚¾‚³‚¢B‚±‚êˆÈŠO‚̃uƒ‰ƒEƒU‚ÍŒ»ÝŽg—p‚·‚邱‚Æ‚Í‚Å‚«‚Ü‚¹‚ñ"),TEXT("ƒuƒ‰ƒEƒUƒ^ƒCƒvŽw’èƒGƒ‰["),MB_OK); + nliteProperty.CookieSetting(); + } } - } - nicoVideoAuth.SetBrowserType(nliteProperty.gp.browserType); - nicoLiveStream.SetResFrom(200); + nicoVideoAuth.SetBrowserType(nliteProperty.gp.browserType); + nicoLiveStream.SetResFrom(200); + }catch(Exception &e){ + + ::MessageBox(NULL,e.what(),TEXT("Ý’èƒtƒ@ƒCƒ‹“ǂݍž‚݃Gƒ‰["),MB_OK | MB_ICONERROR); + + } return; diff --git a/nlite/nlite_property.cpp b/nlite/nlite_property.cpp index 9edb220..c3a1fc6 100644 --- a/nlite/nlite_property.cpp +++ b/nlite/nlite_property.cpp @@ -153,9 +153,9 @@ namespace nlite{ CreatePropertyFile(); CAtlFile propertyFile; - CAtlFile ncvUserSettingFile; + ULONGLONG propertyFileSize; - ULONGLONG ncvUserSettingFileSize; + if(SUCCEEDED(propertyFile.Create(propertyPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(propertyFile.GetSize(propertyFileSize)) == FALSE){ throw Exception(TEXT("Ý’èƒtƒ@ƒCƒ‹‚ªŠJ‚¯‚Ü‚¹‚ñ‚Å‚µ‚½B‚±‚̃Gƒ‰[‚ª‘±‚­‚悤‚Å‚ ‚ê‚΁Aˆê“xÝ’èƒtƒ@ƒCƒ‹‚ðíœ‚µ‚čēxŽŽ‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__)); @@ -174,24 +174,7 @@ namespace nlite{ } - if(this->gp.ncvUserSettingReadedFlag == FALSE){ - - TCHAR appFolderPath[_MAX_PATH]; - SHGetFolderPathW(0,CSIDL_APPDATA,0,SHGFP_TYPE_CURRENT,appFolderPath); - CString ncvUserSettingPath = appFolderPath; - ncvUserSettingPath += TEXT("\\posite-c\\NiconamaCommentViewer\\UserSetting.xml"); - if(SUCCEEDED(ncvUserSettingFile.Create(ncvUserSettingPath,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || SUCCEEDED(ncvUserSettingFile.GetSize(ncvUserSettingFileSize)) == FALSE){ - - throw Exception(TEXT("ƒŠƒXƒi[Ý’èƒtƒ@ƒCƒ‹‚ªŠJ‚¯‚Ü‚¹‚ñ‚Å‚µ‚½B‚±‚̃Gƒ‰[‚ª‘±‚­‚悤‚Å‚ ‚ê‚΁Aˆê“xÝ’èƒtƒ@ƒCƒ‹‚ðíœ‚µ‚čēxŽŽ‚µ‚Ä‚Ý‚Ä‚­‚¾‚³‚¢"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__)); - } - std::vector ncvUserSettingBuf(static_cast(ncvUserSettingFileSize / sizeof(char) + (1 * sizeof(char)))); - ncvUserSettingFile.Read(&ncvUserSettingBuf[0],ncvUserSettingBuf.size()); - LPSTR ncvUserSettingStart = strstr(&ncvUserSettingBuf[0],"<"); - if(ncvUserSettingStart != NULL){ - ReadUserSettingXML rusx; - rusx.Parse(ncvUserSettingStart); - } - } + return; } @@ -213,7 +196,7 @@ namespace nlite{ if((_tcslen(propertyBuf) == 0) || !((PathFileExists(propertyBuf) && !::PathIsDirectory( propertyBuf )))){ propertyFolderPath = appLocalPath; - propertyFolderPath += TEXT("\\qwerty_nico"); + propertyFolderPath += TEXT("\\qwerty_nico\\"); ::WritePrivateProfileString(sectionName,keyName,propertyFolderPath,iniFile); @@ -222,11 +205,11 @@ namespace nlite{ } propertySaveFolderPath = propertyFolderPath; - propertySaveFolderPath += TEXT("\\nlite"); + propertySaveFolderPath += TEXT("nlite\\"); propertyPath = propertySaveFolderPath; - propertyPath += TEXT("\\property.xml"); + propertyPath += TEXT("property.xml"); userSettingPath = propertySaveFolderPath; - userSettingPath += TEXT("\\user_setting.xml"); + userSettingPath += TEXT("listenerData.xml"); SurelyCreate(propertySaveFolderPath,FALSE); SurelyCreate(propertyPath,TRUE); SurelyCreate(userSettingPath,TRUE); @@ -504,59 +487,6 @@ end: -#define NLITE_READ_USER_STRING(at,l,t) if(_tcscmp(at[0],TEXT(#t)) == 0)l.t = at[1] -#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) - - void ReadUserSettingXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){ - - if(_tcscmp(pszName,TEXT("user")) == 0){ - - this->userNodeFlag = TRUE; - - - for(;papszAttrs[0] != NULL;papszAttrs += 2){ - - NLITE_READ_USER_STRING(papszAttrs,listenerBuff,name); - NLITE_READ_USER_STRING(papszAttrs,listenerBuff,community); - NLITE_READ_USER_INT(papszAttrs,listenerBuff,bgcolor); - NLITE_READ_USER_INT(papszAttrs,listenerBuff,time); - - } - - } - - return; - } - - void ReadUserSettingXML::OnEndElement (const XML_Char *pszName){ - if(_tcscmp(pszName,TEXT("user")) == 0){ - - listenerList.Register(listenerBuff,TRUE); - this->userNodeFlag = FALSE; - this->listenerBuff.~ListenerData(); - new(&listenerBuff) ListenerData(); - - } - - return; - } - - void ReadUserSettingXML::OnCharacterData (const XML_Char *pszData, int nLength){ - - if(this->userNodeFlag == TRUE){ - - - listenerBuff.user_id.Append(pszData,nLength); - - - - - } - - - - return; - } } \ No newline at end of file diff --git a/nlite/nlite_property.h b/nlite/nlite_property.h index 4bc12ee..ff09d9e 100644 --- a/nlite/nlite_property.h +++ b/nlite/nlite_property.h @@ -198,26 +198,7 @@ namespace nlite{ }; - /// - ///ƒ†[ƒUÝ’èƒtƒ@ƒCƒ‹“ÇŽæƒNƒ‰ƒX - /// - class ReadUserSettingXML:public CXmlParser{ - - private: - ListenerData listenerBuff; - BOOL userNodeFlag; - - - - - - public: - void OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs); - - void OnEndElement (const XML_Char *pszName); - - void OnCharacterData (const XML_Char *pszData, int nLength); - }; + } \ No newline at end of file diff --git a/todo.txt b/todo.txt index 079b0d9..f58ccf9 100644 --- a/todo.txt +++ b/todo.txt @@ -27,16 +27,16 @@ nlite EƒRƒƒ“ƒgŒŸõ‹@”\ŽÀ‘• EOpenJTalk‚É‚æ‚éƒRƒƒ“ƒg“ǂݏグ‹@”\ŽÀ‘• E–_“Ç‚Ý‚¿‚á‚ñ‚É‚æ‚éƒRƒƒ“ƒg“ǂݏグ‹@”\ŽÀ‘• -Eƒo[ƒWƒ‡ƒ“0.0.0.4ŒöŠJ +Eƒo[ƒWƒ‡ƒ“0.0.1.0ŒöŠJ +E•]‰¿”ÅŒöŠJ EƒRƒƒ“ƒg“ǂݏグŠwK‹@”\ŽÀ‘• Eƒc[ƒ‹ƒo[ŽÀ‘• -Eƒo[ƒWƒ‡ƒ“0.0.0.5ŒöŠJ +Eƒo[ƒWƒ‡ƒ“0.0.1.1ŒöŠJ EcomƒXƒNƒŠƒvƒgƒGƒ“ƒWƒ“‚ðŽg‚Á‚ăvƒ‰ƒOƒCƒ“‹@”\ŽÀ‘• EƒvƒƒpƒeƒBÝ’èƒEƒBƒ“ƒhƒE‚̍쐬 -Eƒo[ƒWƒ‡ƒ“0.0.0.6ŒöŠJ -Eˆê”ÊŒöŠJH +Eƒo[ƒWƒ‡ƒ“0.0.1.2ŒöŠJ