OSDN Git Service

readme変更
[nlite/nlite.git] / nlite / nlite_chatData.cpp
index 36112f7..51ac8af 100644 (file)
@@ -1,8 +1,7 @@
 #include "stdafx.h"
 #include "nlite_include.h"
-
+using namespace std::tr1;
 namespace nlite{
-CListenerList nlite::listenerList;
 
 
 
@@ -19,7 +18,7 @@ struct ListenerPre{
        bool operator()(CListenerList::reference listenerData){
 
                
-               return (user.user_id == listenerData.user_id) && (user.community == listenerData.community);
+               return (user.user_id == listenerData.user_id)/* && (user.community == listenerData.community)*/;
        }
 
 };
@@ -35,15 +34,30 @@ user_id(TEXT("")),
 name(TEXT("")),
 community(TEXT("")),
 bgcolor(INIT_COLOR),
-//originBkFlag(FALSE),
-time(0)
+time(0),
+onlyCommunityFlag(FALSE),
+nameColor(INIT_COLOR)
 {}
 
+VOID ListenerData::SetNameColor(COLORREF nameColor_in){
+       nameColor = nameColor_in;
+
+       return;
+}
+
 VOID ListenerData::SetBkColor(COLORREF bkColor_in){
        bgcolor = bkColor_in;
+
        return;
 }
 
+VOID ListenerData::SetUserName(LPCTSTR name){
+
+       this->name = name;
+
+
+}
+
 
 CChatData::ViewData::ViewData():
                        sellLineColor(INIT_COLOR),
@@ -76,8 +90,19 @@ VOID CChatData::SetChat(NicoLiveChat &chat_in,ListenerData &listener){
 
 
        
-       this->listenerData = &listenerList.Register(listener);
-
+       this->listenerData = &listenerList.Register(listener,FALSE);
+       tstring target(chat_in.chatBuf);
+       
+       match_results<tstring::iterator> results;
+       if(regex_match(target.begin(),target.end(),results,nliteregex::NAMESERTCHREGEX) == TRUE){
+               
+               const tstring &name = results.str(results.size() - 1).c_str();
+               
+               if(nliteProperty.gp.numberNameFlag == TRUE || _tcstol(name.c_str(),NULL,10) == 0){
+                       this->listenerData->SetUserName(name.c_str());
+               }
+               
+       }
        
        this->vpos = _ttol(chat_in.vpos);
        this->thread = _ttol(chat_in.thread);
@@ -289,7 +314,7 @@ VOID CListenerList::BkColorCollect(CListenerColorCollector &target){
        std::for_each(m_listenerList.begin(), end,target);
 }
 
-CListenerList::reference CListenerList::Register(ListenerData &listener){
+CListenerList::reference CListenerList::Register(ListenerData &listener,BOOL bUpdate){
 
        ListenerPre listenerPre(listener);
 
@@ -298,20 +323,154 @@ CListenerList::reference CListenerList::Register(ListenerData &listener){
 
        iterator rslt = std::find_if(begin,end,listenerPre);
 
-       
+
 
        if(rslt == end){
 
                
+               
                m_listenerList.push_back(listener);
-
                return m_listenerList.back();
 
+       } else if(bUpdate == TRUE){
+
+               *rslt = listener;
+
+               
        }
        
        return *rslt;
 
 }
 
+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("\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__));
+       }
+       std::vector<char> userSettingBuf(static_cast<UINT_PTR>(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;
+}
+#define NLITE_ATTRIBUTE_WRITE_STR(s,n) s->WriteAttributeString(NULL, _tcsstr(TEXT(#n),TEXT("."))  != NULL ? _tcsstr(TEXT(#n),TEXT(".")) + 1 : TEXT(#n), NULL, n)
+
+#define NLITE_ATTRIBUTE_WRITE_INT(s,n) \
+       {\
+       TCHAR buffer[sizeof(n) * 8];\
+       _stprintf(buffer,TEXT("%d"),static_cast<INT>(n));\
+       s->WriteAttributeString(NULL, _tcsstr(TEXT(#n),TEXT(".")) + 1, NULL,buffer );\
+}
+BOOL CListenerList::WriteProperty(LPCTSTR fileName){
+       BOOL rslt = FALSE;
+
+
+       CComPtr<IXmlWriter> pWriter;
+       CreateXmlWriter(__uuidof(IXmlWriter), reinterpret_cast<void**>(&pWriter), 0);
+       // \83t\83@\83C\83\8b\83X\83g\83\8a\81[\83\80\8dì\90¬
+       CComPtr<IStream> pStream;
+       SHCreateStreamOnFile(fileName, STGM_CREATE | STGM_WRITE, &pStream);
+
+       pWriter->SetOutput(pStream);
+
+       // \83C\83\93\83f\83\93\83g\97L\8cø\89»
+       pWriter->SetProperty(XmlWriterProperty_Indent, TRUE);
+
+       // <?xml version="1.0" encoding="UTF-8"?>
+       pWriter->WriteStartDocument(XmlStandalone_Omit);
+
+       pWriter->WriteStartElement(NULL,TEXT("listenerData"),NULL);
+
+
+       auto begin = m_listenerList.begin();
+       auto end = m_listenerList.end();
+
+       for(;begin != end;++begin){
+               if(begin->name.Length() > 0 || begin->nameColor != ListenerData::INIT_COLOR || begin->bgcolor != ListenerData::INIT_COLOR){
+                       pWriter->WriteStartElement(NULL,TEXT("user"),NULL);
+                       if(begin->name.Length() > 0) NLITE_ATTRIBUTE_WRITE_STR(pWriter,(*begin).name);
+                       if(begin->community.Length()> 0) NLITE_ATTRIBUTE_WRITE_STR(pWriter,(*begin).community);
+                       NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).time);
+                       if(begin->bgcolor != ListenerData::INIT_COLOR)NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).bgcolor);
+                       if(begin->nameColor != ListenerData::INIT_COLOR)NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).nameColor);
+                       pWriter->WriteString(begin->user_id);
+                       pWriter->WriteEndElement();
+               }
+       }
+       pWriter->WriteEndDocument();
+       rslt = TRUE;
+       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,nameColor);
+                               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){
+
+                       
+                       if(_tcstol(listenerBuff.user_id,NULL,10) != 0 || ((difftime(time(NULL),604800)) <listenerBuff.time)){
+                               listenerBuff.user_id.Append(pszData,nLength);
+                       }
+
+
+
+               }
+
+               
+
+               return;
+       }
 
 }
\ No newline at end of file