2 #include "nlite_include.h"
3 using namespace std::tr1;
9 //
\83\8a\83X
\83i
\81[
\8c\9f\8dõ
\83I
\83u
\83W
\83F
\83N
\83g
14 ListenerPre(CListenerData &in_user):
18 bool operator()(CListenerList::reference listenerData){
21 return (user.GetUserID() == listenerData.GetUserID())/* && (user.community == listenerData.community)*/;
28 //
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
29 /////////////////////////////////////////////////////////////////////////////////////////////////
32 CListenerData::CListenerData():
38 onlyCommunityFlag(FALSE),
42 VOID CListenerData::SetNameColor(COLORREF nameColor_in){
44 nameColor = nameColor_in;
49 VOID CListenerData::SetBkColor(COLORREF bkColor_in){
55 VOID CListenerData::SetUserName(LPCTSTR name){
62 COLORREF CListenerData::GetBackColor()const {
68 COLORREF CListenerData::GetNameColor()const{
70 return this->nameColor;
74 const CNLiteString &CListenerData::GetUserID()const{
82 const CNLiteString &CListenerData::GetName()const{
88 CChatData::ViewData::ViewData():
89 sellLineColor(INIT_COLOR),
90 stringColor(INIT_COLOR),
91 backColor(INIT_COLOR),
96 VOID CChatData::SetChat(NicoLiveChat &chat_in,CListenerData &listener){
99 this->anonymity = _ttol(chat_in.anonymity);
100 this->premium = _ttol(chat_in.premium);
101 this->chatBuf = chat_in.chatBuf;
102 this->no = _ttol(chat_in.no);
104 if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){
105 this->locale = cuntry::jp;
107 this->locale = cuntry::unknown;
109 this->mail.reserve(chat_in.mailCount);
110 for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){
112 this->mail.push_back(chat_in.mail[index]);
115 this->name = chat_in.name;
119 this->listenerData = &listenerList.Register(listener,FALSE);
120 tstring target(chat_in.chatBuf);
122 match_results<tstring::iterator> results;
123 if(regex_match(target.begin(),target.end(),results,nliteregex::NAMESERTCHREGEX) == TRUE){
125 const tstring &name = results.str(results.size() - 1).c_str();
127 if(nliteProperty.GetGeneralProperty().IsNumberName() == TRUE || _tcstol(name.c_str(),NULL,10) == 0){
128 this->listenerData->SetUserName(name.c_str());
133 this->vpos = _ttol(chat_in.vpos);
134 this->thread = _ttol(chat_in.thread);
135 this->date = _ttol(chat_in.date);
143 VOID CChatData::SetHeight(UINT_PTR height){
145 this->viewData.height = height;
149 CListenerData &CChatData::GetListnerData() {
152 return *this->listenerData;
155 const CNLiteString &CChatData::GetChatBuff()const{
157 return this->chatBuf;
160 BOOL CChatData::IsSelect()const{
162 return this->viewData.selectFlag;
165 COLORREF CChatData::GetBackColor()const{
167 return this->viewData.backColor;
170 UINT_PTR CChatData::GetPremium()const{
172 return this->premium;
176 time_t CChatData::GetDate()const{
182 UINT_PTR CChatData::GetNo()const{
187 COLORREF CChatData::GetStringColor()const{
189 return this->viewData.stringColor;
193 COLORREF CChatData::GetSellLineColor()const{
195 return this->viewData.sellLineColor;
198 UINT_PTR CChatData::GetHeight()const{
200 return this->viewData.height;
205 //
\83R
\83\81\83\93\83g
\83\8a\83X
\83g
\83N
\83\89\83X
206 //////////////////////////////////////////////////////////////////////////
208 //
\91I
\91ð
\8ds
\8eæ
\93¾
\97p
\83t
\83@
\83\93\83N
\83V
\83\87\83i
\83\8b
209 struct GetCurSelFunc_t{
217 BOOL operator() (const CChatData &target){
219 return target.IsSelect();
224 //
\91}
\93ü
\88Ê
\92u
\8c\9f\8dõ
\83t
\83@
\83\93\83N
\83V
\83\87\83i
\83\8b
225 struct SeartchSetPos_t{
228 SeartchSetPos_t(time_t in_time):time(in_time){}
230 bool operator()(const CChatData &target){
232 return time > target.GetDate();
236 CCommentList::CCommentList(){}
238 CCommentList::~CCommentList(){}
240 CCommentList::iterator CCommentList::GetCurSel(){
241 auto end = this->end();
242 auto ite = this->begin();
244 for(;ite != end && ite->viewData.selectFlag == FALSE;++ite);
250 INT_PTR CCommentList::GetCurSelNo(){
252 auto end = this->end();
253 auto ite = this->begin();
255 for(;ite != end && ite->viewData.selectFlag == FALSE;++ite,++no);
257 return ite != end ? no : -1;
262 CCommentList::iterator CCommentList::OnChatReceve(NicoLiveChat_P chatData_in,LPCTSTR communityID, UINT_PTR commnetCountSum,CCommentListWindow &listWindow){
265 CListenerData listenerData;
266 listenerData.user_id = chatData_in->user_id;
267 listenerData.time = time(NULL);
268 listenerData.community = communityID;
269 chatData.SetChat(*chatData_in,listenerData);
271 if(empty() == TRUE || back().date <= chatData.date){
272 chatList.push_back(chatData);
273 rslt = (--chatList.end());
274 if(nlite::nliteProperty.GetCommentReadProperty().IsCommentRead() == TRUE){
276 g_speaker.SynthesisAsync((const speaker::TChar_P)(LPCTSTR)rslt->chatBuf);
280 rslt = chatList.insert(std::find_if(chatList.begin(),chatList.end(),SeartchSetPos_t(chatData.date)),chatData);
283 if(shortcut ==chatList.end())shortcut = chatList.begin();
288 CCommentList::iterator CCommentList::GetCurSelItem(){
289 auto rslt = std::find_if(chatList.begin(),chatList.end(),GetCurSelFunc_t());
295 VOID CCommentList::SetCurSel(CCommentList::iterator cursel){
297 auto end = this->end();
298 if(cursel == end)goto end;
300 auto curselItem = this->GetCurSelItem();
302 if(curselItem != end){
303 curselItem->viewData.selectFlag = FALSE;
307 cursel->viewData.selectFlag = TRUE;
315 CCommentList::reference CCommentList::GetChatAt(UINT_PTR no){
317 iterator data = chatList.begin();
318 std::advance(data,no);
323 UINT_PTR CCommentList::Size(){
325 return chatList.size();
328 BOOL CCommentList::empty(){
330 return chatList.empty();
335 CCommentList::iterator CCommentList::begin(){
337 return chatList.begin();
340 CCommentList::iterator CCommentList::end(){
342 return chatList.end();
346 CCommentList::reverse_iterator CCommentList::rbegein(){
349 return chatList.rbegin();
355 CCommentList::reverse_iterator CCommentList::rend(){
357 return chatList.rend();
360 VOID CCommentList::OnDestroy(){
366 VOID CCommentList::OnConnect(){
368 shortcut = chatList.begin();
371 CCommentList::reference CCommentList::back(){
373 return chatList.back();
377 ///
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\83C
\83e
\83\8c\81[
\83^
\82ð
\8eæ
\93¾
379 CCommentList::iterator CCommentList::GetShortCut(){
385 ///
\83V
\83\87\81[
\83g
\83J
\83b
\83g
\82ð
\90Ý
\92è
387 BOOL CCommentList::SetShortCut(UINT_PTR no){
390 if(static_cast<INT_PTR>(chatList.size()) <= no)return FALSE;
392 shortcut = chatList.begin();
393 std::advance(shortcut,no);
401 VOID CListenerList::BkColorCollect(CListenerColorCollector &target){
403 iterator end = m_listenerList.end();
404 std::for_each(m_listenerList.begin(), end,target);
407 CListenerList::reference CListenerList::Register(CListenerData &listener,BOOL bUpdate){
409 //
\8aÖ
\90\94\83I
\83u
\83W
\83F
\83N
\83g
\90¶
\90¬
410 ListenerPre listenerPre(listener);
413 iterator begin = m_listenerList.begin();
414 iterator end = m_listenerList.end();
416 //
\93o
\98^
\97\
\92è
\82Ì
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
\82ª
\82·
\82Å
\82É
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\82©
\8c\9f\8dõ
417 iterator rslt = std::find_if(begin,end,listenerPre);
420 //
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
\82ª
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82È
\82¢
\8fê
\8d\87
423 //
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
\82ð
\93o
\98^
424 m_listenerList.push_back(listener);
425 return m_listenerList.back();
429 //
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
\82ª
\93o
\98^
\82³
\82ê
\82Ä
\82¢
\82é
\8fê
\8d\87\82Å
\81A
\8dX
\90V
\83t
\83\89\83O
\82ªtrue
\82Ì
\8fê
\8d\87
430 } else if(bUpdate == TRUE){
432 //
\83\8a\83X
\83i
\81[
\83f
\81[
\83^
\82ð
\8dX
\90V
442 BOOL CListenerList::ReadProperty(LPCTSTR fileName){
444 CAtlFile userSettingFile;
445 ULONGLONG userSettingFileSize;
446 std::vector<char> userSettingBuf;
448 if(SUCCEEDED(userSettingFile.Create(fileName,GENERIC_READ,FILE_SHARE_READ,OPEN_ALWAYS)) == FALSE || userSettingFile.m_h == NULL || SUCCEEDED(userSettingFile.GetSize(userSettingFileSize)) == FALSE){
450 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__));
453 userSettingBuf.resize(static_cast<UINT_PTR>(userSettingFileSize / sizeof(char) + (1 * sizeof(char))));
454 userSettingFile.Read(&userSettingBuf[0],userSettingBuf.size());
455 LPSTR userSettingStart = strstr(&userSettingBuf[0],"<");
456 if(userSettingStart != NULL){
457 CReadUserSettingXML rusx(nlite::listenerList);
458 rusx.Parse(userSettingStart);
464 #define NLITE_ATTRIBUTE_WRITE_STR(s,n) s->WriteAttributeString(NULL, _tcsstr(TEXT(#n),TEXT(".")) != NULL ? _tcsstr(TEXT(#n),TEXT(".")) + 1 : TEXT(#n), NULL, n)
466 #define NLITE_ATTRIBUTE_WRITE_INT(s,n) \
468 TCHAR buffer[sizeof(n) * 8];\
469 _stprintf(buffer,TEXT("%d"),static_cast<INT>(n));\
470 s->WriteAttributeString(NULL, _tcsstr(TEXT(#n),TEXT(".")) + 1, NULL,buffer );\
472 BOOL CListenerList::WriteProperty(LPCTSTR fileName){
476 CComPtr<IXmlWriter> pWriter;
477 CreateXmlWriter(__uuidof(IXmlWriter), reinterpret_cast<void**>(&pWriter), 0);
478 CComPtr<IStream> pStream;
479 SHCreateStreamOnFile(fileName, STGM_CREATE | STGM_WRITE, &pStream);
481 pWriter->SetOutput(pStream);
483 //
\83C
\83\93\83f
\83\93\83g
\97L
\8cø
\89»
484 pWriter->SetProperty(XmlWriterProperty_Indent, TRUE);
486 // <?xml version="1.0" encoding="UTF-8"?>
487 pWriter->WriteStartDocument(XmlStandalone_Omit);
489 pWriter->WriteStartElement(NULL,TEXT("listenerData"),NULL);
492 auto begin = m_listenerList.begin();
493 auto end = m_listenerList.end();
495 //
\83\8a\83X
\83i
\81[
\83\8a\83X
\83g
\82©
\82ç
\95Û
\91¶
\91Î
\8fÛ
\82Ì
\83f
\81[
\83^
\82Ì
\82Ýxml
\8c`
\8e®
\82Å
\95Û
\91¶
496 for(;begin != end;++begin){
497 if(begin->name.Length() > 0 || begin->nameColor != CListenerData::INIT_COLOR || begin->bgcolor != CListenerData::INIT_COLOR){
498 pWriter->WriteStartElement(NULL,TEXT("user"),NULL);
499 if(begin->name.Length() > 0) NLITE_ATTRIBUTE_WRITE_STR(pWriter,(*begin).name);
500 if(begin->community.Length()> 0) NLITE_ATTRIBUTE_WRITE_STR(pWriter,(*begin).community);
501 NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).time);
502 if(begin->bgcolor != CListenerData::INIT_COLOR)NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).bgcolor);
503 if(begin->nameColor != CListenerData::INIT_COLOR)NLITE_ATTRIBUTE_WRITE_INT(pWriter,(*begin).nameColor);
504 pWriter->WriteString(begin->user_id);
505 pWriter->WriteEndElement();
508 pWriter->WriteEndDocument();
514 CReadUserSettingXML::CReadUserSettingXML(CListenerList &in_listenerList):m_listenerList(in_listenerList),userNodeFlag(FALSE){}
516 #define NLITE_READ_USER_STRING(at,l,t) if(_tcscmp(at[0],TEXT(#t)) == 0)l.t = at[1]
517 #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)
519 void CReadUserSettingXML::OnStartElement (const XML_Char *pszName, const XML_Char **papszAttrs){
521 if(_tcscmp(pszName,TEXT("user")) == 0){
523 this->userNodeFlag = TRUE;
526 for(;papszAttrs[0] != NULL;papszAttrs += 2){
528 NLITE_READ_USER_STRING(papszAttrs,listenerBuff,name);
529 NLITE_READ_USER_STRING(papszAttrs,listenerBuff,community);
530 NLITE_READ_USER_INT(papszAttrs,listenerBuff,bgcolor);
531 NLITE_READ_USER_INT(papszAttrs,listenerBuff,nameColor);
532 NLITE_READ_USER_INT(papszAttrs,listenerBuff,time);
541 void CReadUserSettingXML::OnEndElement (const XML_Char *pszName){
543 if(_tcscmp(pszName,TEXT("user")) == 0){
545 listenerList.Register(listenerBuff,TRUE);
546 this->userNodeFlag = FALSE;
547 this->listenerBuff.~CListenerData();
548 new(&listenerBuff) CListenerData();
555 void CReadUserSettingXML::OnCharacterData (const XML_Char *pszData, int nLength){
557 if(this->userNodeFlag == TRUE){
560 if(_tcstol(listenerBuff.user_id,NULL,10) != 0 || ((difftime(time(NULL),604800)) <listenerBuff.time)){
561 listenerBuff.user_id.Append(pszData,nLength);