int CDynamicString::CompareIgnoreCase(LPCTSTR pszString) const { if (IsEmpty()) { if (IsStringEmpty(pszString)) return 0; return -1; } if (IsStringEmpty(pszString)) return 1; return ::lstrcmpi(m_pszString,pszString); }
bool CTSProcessor::LoadModule(LPCWSTR pszName) { if (m_pFilterModule == nullptr) { SetError(E_NOTIMPL, TEXT("モジュールは利用できません。")); return false; } if (IsModuleLoaded()) { if (IsStringEmpty(pszName)) { if (m_ModuleName.empty()) return true; } else { if (IsEqualFileName(m_ModuleName.c_str(), pszName)) return true; } } UnloadModule(); if (FAILED(m_pFilterModule->LoadModule(pszName))) return false; StringUtility::Assign(m_ModuleName, pszName); ClearError(); return true; }
bool CTSProcessor::OpenFilter(int Device, LPCWSTR pszName) { if (m_pFilter != nullptr) { if (m_CurDevice == Device) { if (IsStringEmpty(pszName)) { if (m_CurFilter.empty()) return true; } else { if (StringUtility::CompareNoCase(m_CurFilter, pszName) == 0) return true; } } } if (m_pFilterModule == nullptr) { SetError(E_NOTIMPL, TEXT("フィルターは利用できません。")); return false; } CloseFilter(); Interface::IFilter *pFilter = nullptr; if (FAILED(m_pFilterModule->OpenFilter(Device, pszName, &pFilter))) return false; m_pFilter = pFilter; m_CurDevice = Device; StringUtility::Assign(m_CurFilter, pszName); ClearError(); return true; }
bool CStreamPool::Create(LPCWSTR pszName,DWORD BufferLength) { if (IsStringEmpty(pszName) || BufferLength==0) return false; bool fExists; if (!m_SharedMemory.Create(pszName,sizeof(StreamInfo)+BufferLength*TS_PACKET_SIZE, PAGE_READWRITE,&fExists)) return false; if (fExists) { m_SharedMemory.Close(); return false; } m_pBuffer=static_cast<BYTE*>(m_SharedMemory.Map()); if (m_pBuffer==nullptr) { m_SharedMemory.Close(); return false; } OutLog(LOG_VERBOSE,L"ストリームプールのメモリをマップしました。(Address %p)",m_pBuffer); StreamInfo *pInfo=reinterpret_cast<StreamInfo*>(m_pBuffer); ::ZeroMemory(pInfo,sizeof(StreamInfo)); pInfo->BufferLength=BufferLength; return true; }
bool CSharedMemory::Open(LPCWSTR pszName,DWORD DesiredAccess,bool fInheritHandle) { if (IsStringEmpty(pszName)) return false; if (m_hFileMapping!=nullptr) return false; String MutexName; GetMutexName(pszName,&MutexName); if (!m_Mutex.Open(MutexName.c_str())) { OutLog(LOG_ERROR,L"共有メモリのMutex(%s)を開けません。",MutexName.c_str()); return false; } OutLog(LOG_VERBOSE,L"共有メモリのMutex(%s)を開きました。",MutexName.c_str()); CBasicSecurityAttributes SecurityAttributes; SecurityAttributes.Initialize(); m_hFileMapping=::OpenFileMapping(DesiredAccess,fInheritHandle,pszName); if (m_hFileMapping==nullptr) { OutSystemErrorLog(::GetLastError(), L"ファイルマッピングオブジェクト(%s)を開けません。", pszName); m_Mutex.Close(); return false; } OutLog(LOG_VERBOSE,L"ファイルマッピングオブジェクト(%s)を開きました。(%p)", pszName,m_hFileMapping); return true; }
bool CCommandLineParser::HasOption(LPCWSTR pszKey) const { if (IsStringEmpty(pszKey)) return false; return m_OptionMap.find(pszKey)!=m_OptionMap.end(); }
bool TIniFile::ValueExists(const wxString &Section, const wxString &Ident) { if (IsStringEmpty(ReadString(Section, Ident, wxT("")))) return false; else return true; }
int CDriverManager::FindByFileName(LPCTSTR pszFileName) const { if (IsStringEmpty(pszFileName)) return -1; for (size_t i=0;i<m_DriverList.size();i++) { if (IsEqualFileName(m_DriverList[i]->GetFileName(),pszFileName)) return (int)i; } return -1; }
int CompareNoCase(const String &String1,LPCWSTR pszString2,String::size_type Length) { if (IsStringEmpty(pszString2)) { if (String1.empty()) return 0; return 1; } return ::StrCmpNIW(String1.c_str(),pszString2,(int)Length); }
int CompareNoCase(const String &String1,LPCWSTR pszString2) { if (IsStringEmpty(pszString2)) { if (String1.empty()) return 0; return 1; } return ::lstrcmpiW(String1.c_str(),pszString2); }
bool Replace(String &Str,LPCWSTR pszFrom,LPCWSTR pszTo) { if (IsStringEmpty(pszFrom)) return false; const String::size_type FromLength=::lstrlenW(pszFrom); const String::size_type ToLength=IsStringEmpty(pszTo) ? 0 : ::lstrlenW(pszTo); String::size_type Next=0,Pos; while ((Pos=Str.find(pszFrom,Next))!=String::npos) { if (ToLength==0) { Str.erase(Pos,FromLength); Next=Pos; } else { Str.replace(Pos,FromLength,pszTo); Next=Pos+ToLength; } } return true; }
bool Trim(String &Str,LPCWSTR pszSpaces) { if (IsStringEmpty(pszSpaces)) return false; const String::size_type First=Str.find_first_not_of(pszSpaces); if (First==String::npos) return false; Str=Str.substr(First,Str.find_last_not_of(pszSpaces)-First+1); return true; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,String *pValue) const { if (IsStringEmpty(pszKey) || pValue==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i==m_OptionMap.end() || i->second+1>=m_ArgCount) return false; *pValue=m_ppszArgList[i->second+1]; return true; }
int CPanelOptions::RegisterPanelItem(LPCTSTR pszID,LPCTSTR pszTitle) { if (IsStringEmpty(pszID) || IsStringEmpty(pszTitle)) return -1; PanelItemInfo Item; Item.ID=pszID; Item.Title=pszTitle; Item.fVisible=true; if (GetItemIDFromIDText(Item.ID)>=0) return -1; // ID重複 m_AvailItemList.push_back(Item); auto it=std::find_if(m_ItemList.begin(),m_ItemList.end(), [&](const PanelItemInfo &Info) -> bool { return CompareID(Info.ID,Item.ID); }); if (it==m_ItemList.end()) m_ItemList.push_back(Item); return (int)m_AvailItemList.size()-1; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,FILETIME *pTime) const { if (IsStringEmpty(pszKey) || pTime==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i==m_OptionMap.end() || i->second+1>=m_ArgCount) return false; if (!ParseTime(m_ppszArgList[i->second+1],pTime)) return false; return true; }
bool CCommandLineParser::GetOptionDuration(LPCWSTR pszKey,int *pDuration) const { if (IsStringEmpty(pszKey) || pDuration==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i==m_OptionMap.end() || i->second+1>=m_ArgCount) return false; if (!ParseDuration(m_ppszArgList[i->second+1],pDuration)) return false; return true; }
bool CCommandLineParser::GetOptions(LPCWSTR pszKey,std::vector<String> *pValues) const { if (IsStringEmpty(pszKey) || pValues==nullptr) return false; pValues->clear(); auto p=m_OptionMap.equal_range(pszKey); for (auto i=p.first;i!=p.second;i++) { if (i->second+1<m_ArgCount) pValues->push_back(String(m_ppszArgList[i->second+1])); } return true; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,int *pValue) const { if (IsStringEmpty(pszKey) || pValue==nullptr) return false; LONGLONG Value; if (!GetOption(pszKey,&Value)) return false; if (Value<INT_MIN || Value>INT_MAX) return false; *pValue=(int)Value; return true; }
bool CSharedMemory::Create(LPCWSTR pszName,size_t Size,DWORD Protect,bool *pfExists) { if (IsStringEmpty(pszName) || Size==0) return false; if (m_hFileMapping!=nullptr) return false; String MutexName; GetMutexName(pszName,&MutexName); if (!m_Mutex.Create(MutexName.c_str(),false)) { OutLog(LOG_ERROR,L"共有メモリのMutex(%s)を作成できません。",MutexName.c_str()); return false; } OutLog(LOG_VERBOSE,L"共有メモリのMutex(%s)を作成しました。",MutexName.c_str()); CBasicSecurityAttributes SecurityAttributes; SecurityAttributes.Initialize(); m_hFileMapping=::CreateFileMapping( INVALID_HANDLE_VALUE, &SecurityAttributes, Protect, #ifdef _WIN64 (DWORD)(Size>>32),(DWORD)(Size&0xFFFFFFFFULL), #else 0,Size, #endif pszName); if (m_hFileMapping==nullptr) { OutSystemErrorLog(::GetLastError(), L"ファイルマッピングオブジェクト(%s)を作成できません。", pszName); m_Mutex.Close(); return false; } OutLog(LOG_VERBOSE,L"ファイルマッピングオブジェクト(%s)を作成しました。(%Iu bytes)", pszName,Size); if (pfExists!=nullptr) *pfExists=::GetLastError()==ERROR_ALREADY_EXISTS; return true; }
bool CDriverManager::GetTunerSpec(LPCTSTR pszTunerName,TunerSpec *pSpec) const { if (IsStringEmpty(pszTunerName) || pSpec==nullptr) return false; LPCTSTR pszName=::PathFindFileName(pszTunerName); if (pszName[0]==_T('\0')) return false; for (auto it=m_TunerSpecList.begin();it!=m_TunerSpecList.end();++it) { if (::PathMatchSpec(pszName,it->TunerMask.c_str())) { *pSpec=it->Spec; return true; } } return false; }
bool StringIsDigit(LPCTSTR pszString) { if (IsStringEmpty(pszString)) return false; LPCTSTR p=pszString; if (*p==_T('-') || *p==_T('+')) p++; if (*p<_T('0') || *p>_T('9')) return false; p++; while (*p!=_T('\0')) { if (*p<_T('0') || *p>_T('9')) return false; p++; } return true; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,BoolSettingValue *pValue) const { if (IsStringEmpty(pszKey) || pValue==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i!=m_OptionMap.end()) { *pValue=BOOL_TRUE; } else { String Key(pszKey); Key+=L"-"; i=m_OptionMap.find(Key.c_str()); if (i!=m_OptionMap.end()) *pValue=BOOL_FALSE; else *pValue=BOOL_DEFAULT; } return true; }
bool Split(const String &Src,LPCWSTR pszDelimiter,std::vector<String> *pList) { if (pList==nullptr) return false; pList->clear(); if (IsStringEmpty(pszDelimiter)) return false; const int DelimiterLength=::lstrlenW(pszDelimiter); String::const_iterator SrcBegin=Src.begin(); String::size_type Pos,Next=0; while ((Pos=Src.find(pszDelimiter,Next))!=String::npos) { pList->push_back(String(SrcBegin+Next,SrcBegin+Pos)); Next=Pos+DelimiterLength; } pList->push_back(String(SrcBegin+Next,Src.end())); return true; }
bool CTuningSpaceInfo::SetName(LPCTSTR pszName) { // チューニング空間の種類を判定する // BonDriverから取得できないので苦肉の策 m_Space=SPACE_UNKNOWN; if (!IsStringEmpty(pszName)) { m_Name=pszName; if (::StrStr(pszName,TEXT("地"))!=NULL || ::StrStrI(pszName,TEXT("VHF"))!=NULL || ::StrStrI(pszName,TEXT("UHF"))!=NULL || ::StrStrI(pszName,TEXT("CATV"))!=NULL) { m_Space=SPACE_TERRESTRIAL; } else if (::StrStrI(pszName,TEXT("BS"))!=NULL) { m_Space=SPACE_BS; } else if (::StrStrI(pszName,TEXT("CS"))!=NULL) { m_Space=SPACE_110CS; } } else { m_Name.clear(); } return true; }
bool CEpgDataLoader::LoadAsync(LPCTSTR pszFolder,CEventHandler *pEventHandler) { if (IsStringEmpty(pszFolder)) return false; if (m_hThread!=NULL) { if (::WaitForSingleObject(m_hThread,0)==WAIT_TIMEOUT) return false; ::CloseHandle(m_hThread); m_hThread=NULL; } m_Folder.Set(pszFolder); m_pEventHandler=pEventHandler; if (m_hAbortEvent==NULL) m_hAbortEvent=::CreateEvent(NULL,FALSE,FALSE,NULL); else ::ResetEvent(m_hAbortEvent); m_hThread=(HANDLE)::_beginthreadex(NULL,0,LoadThread,this,0,NULL); if (m_hThread==NULL) return false; return true; }
bool CCommandLineParser::GetOption(LPCWSTR pszKey,LONGLONG *pValue) const { if (IsStringEmpty(pszKey) || pValue==nullptr) return false; auto i=m_OptionMap.find(pszKey); if (i==m_OptionMap.end() || i->second+1>=m_ArgCount) return false; wchar_t *pEnd; __int64 Value=::_wcstoi64(m_ppszArgList[i->second+1],&pEnd,0); // TODO: オーバフロー、アンダーフローのチェック switch (*pEnd) { case L'K': Value*=1024; break; case L'k': Value*=1000; break; case L'M': Value*=1024*1024; break; case L'G': Value*=1024*1024*1024; break; case L'T': Value*=0x10000000000LL; break; } *pValue=Value; return true; }
bool COSDManager::ShowOSD(LPCTSTR pszText,unsigned int Flags) { if (IsStringEmpty(pszText)) return false; CAppMain &App=GetAppClass(); CCoreEngine &CoreEngine=*App.GetCoreEngine(); HWND hwnd; RECT rc; bool fForcePseudoOSD=false; if (!m_pEventHandler->GetOSDWindow(&hwnd,&rc,&fForcePseudoOSD)) return false; if ((Flags & SHOW_PSEUDO)!=0) fForcePseudoOSD=true; DWORD FadeTime; if ((Flags & SHOW_NO_FADE)!=0) FadeTime=0; else FadeTime=m_pOptions->GetFadeTime(); if (!m_pOptions->GetPseudoOSD() && !fForcePseudoOSD && CoreEngine.m_DtvEngine.m_MediaViewer.IsDrawTextSupported()) { RECT rcSrc; if (CoreEngine.m_DtvEngine.m_MediaViewer.GetSourceRect(&rcSrc)) { LOGFONT lf; HFONT hfont; ::GetObject(::GetStockObject(DEFAULT_GUI_FONT),sizeof(LOGFONT),&lf); lf.lfHeight=(rcSrc.right-rcSrc.left)/20; lf.lfWidth=0; lf.lfQuality=NONANTIALIASED_QUALITY; hfont=::CreateFontIndirect(&lf); int Rate,Factor; if (!App.GetUICore()->GetZoomRate(&Rate,&Factor)) { if ((rc.right-rc.left)/(rcSrc.right-rcSrc.left)< (rc.bottom-rc.top)/(rcSrc.bottom-rcSrc.top)) { Rate=rc.right-rc.left; Factor=rcSrc.right-rcSrc.left; } else { Rate=rc.bottom-rc.top; Factor=rcSrc.bottom-rcSrc.top; } } if (Rate!=0) { rcSrc.left+=8*Factor/Rate; rcSrc.top+=(rc.top+8)*Factor/Rate; } else { rcSrc.left+=16; rcSrc.top+=48; } if (CoreEngine.m_DtvEngine.m_MediaViewer.DrawText(pszText, rcSrc.left,rcSrc.top,hfont, m_pOptions->GetTextColor(),m_pOptions->GetOpacity())) { if (FadeTime>0) m_pEventHandler->SetOSDHideTimer(FadeTime); } ::DeleteObject(hfont); } } else { int TextHeight; SIZE sz; TextHeight=max((rc.right-rc.left)/24,12); m_OSD.Create(hwnd,m_pOptions->GetLayeredWindow()); m_OSD.SetTextHeight(TextHeight); m_OSD.SetText(pszText); m_OSD.CalcTextSize(&sz); m_OSD.SetPosition(rc.left+8,rc.top+8,sz.cx,sz.cy); m_OSD.SetTextColor(m_pOptions->GetTextColor()); m_OSD.SetOpacity(m_pOptions->GetOpacity()); m_OSD.Show(FadeTime,false); } return true; }
void CEventInfoPopup::SetEventInfo(const CEventInfoData *pEventInfo) { if (m_EventInfo==*pEventInfo) return; m_EventInfo=*pEventInfo; TCHAR szText[4096]; CStaticStringFormatter Formatter(szText,lengthof(szText)); if (!IsStringEmpty(m_EventInfo.GetEventText())) { Formatter.Append(m_EventInfo.GetEventText()); Formatter.RemoveTrailingWhitespace(); } if (!IsStringEmpty(m_EventInfo.GetEventExtText())) { if (!Formatter.IsEmpty()) Formatter.Append(TEXT("\r\n\r\n")); Formatter.Append(m_EventInfo.GetEventExtText()); Formatter.RemoveTrailingWhitespace(); } Formatter.Append(TEXT("\r\n")); LPCTSTR pszVideo=EpgUtil::GetVideoComponentTypeText(m_EventInfo.m_VideoInfo.ComponentType); if (pszVideo!=NULL) { Formatter.AppendFormat(TEXT("\r\n■ 映像: %s"),pszVideo); } if (!m_EventInfo.m_AudioList.empty()) { const CEventInfoData::AudioInfo *pMainAudioInfo=m_EventInfo.GetMainAudioInfo(); TCHAR szBuff[64]; Formatter.Append(TEXT("\r\n■ 音声: ")); if (m_EventInfo.m_AudioList.size()==1) { FormatAudioInfo(pMainAudioInfo,szBuff,lengthof(szBuff)); Formatter.Append(szBuff); } else { Formatter.Append(TEXT("主: ")); FormatAudioInfo(pMainAudioInfo,szBuff,lengthof(szBuff)); Formatter.Append(szBuff); for (size_t i=0;i<m_EventInfo.m_AudioList.size();i++) { const CEventInfoData::AudioInfo *pAudioInfo=&m_EventInfo.m_AudioList[i]; if (pAudioInfo!=pMainAudioInfo) { Formatter.Append(TEXT(" / 副: ")); FormatAudioInfo(pAudioInfo,szBuff,lengthof(szBuff)); Formatter.Append(szBuff); } } } } for (int i=0;i<m_EventInfo.m_ContentNibble.NibbleCount;i++) { if (m_EventInfo.m_ContentNibble.NibbleList[i].ContentNibbleLevel1!=0xE) { CEpgGenre EpgGenre; LPCTSTR pszGenre=EpgGenre.GetText(m_EventInfo.m_ContentNibble.NibbleList[i].ContentNibbleLevel1,-1); if (pszGenre!=NULL) { Formatter.AppendFormat(TEXT("\r\n■ ジャンル: %s"),pszGenre); pszGenre=EpgGenre.GetText( m_EventInfo.m_ContentNibble.NibbleList[i].ContentNibbleLevel1, m_EventInfo.m_ContentNibble.NibbleList[i].ContentNibbleLevel2); if (pszGenre!=NULL) Formatter.AppendFormat(TEXT(" - %s"),pszGenre); } break; } } if (m_fDetailInfo) { Formatter.AppendFormat(TEXT("\r\n■ イベントID: 0x%04X"),m_EventInfo.m_EventID); if (m_EventInfo.m_fCommonEvent) Formatter.AppendFormat(TEXT(" (イベント共有 サービスID 0x%04X / イベントID 0x%04X)"), m_EventInfo.m_CommonEventInfo.ServiceID, m_EventInfo.m_CommonEventInfo.EventID); } LOGFONT lf; CHARFORMAT cf; HDC hdc=::GetDC(m_hwndEdit); m_Font.GetLogFont(&lf); CRichEditUtil::LogFontToCharFormat(hdc,&lf,&cf); cf.dwMask|=CFM_COLOR; cf.crTextColor=m_TextColor; ::ReleaseDC(m_hwndEdit,hdc); ::SendMessage(m_hwndEdit,WM_SETREDRAW,FALSE,0); ::SetWindowText(m_hwndEdit,NULL); CRichEditUtil::AppendText(m_hwndEdit, SkipLeadingWhitespace(Formatter.GetString()),&cf); CRichEditUtil::DetectURL(m_hwndEdit,&cf); POINT pt={0,0}; ::SendMessage(m_hwndEdit,EM_SETSCROLLPOS,0,reinterpret_cast<LPARAM>(&pt)); ::SendMessage(m_hwndEdit,WM_SETREDRAW,TRUE,0); ::InvalidateRect(m_hwndEdit,NULL,TRUE); CalcTitleHeight(); RECT rc; GetClientRect(&rc); ::MoveWindow(m_hwndEdit,0,m_TitleHeight,rc.right,max(rc.bottom-m_TitleHeight,0),TRUE); Invalidate(); }
bool CDynamicString::IsEmpty() const { return IsStringEmpty(m_pszString); }
bool CTSProcessor::GetModuleInfo(LPCWSTR pszModule, ModuleInfo *pInfo) const { if (pInfo == nullptr) return false; pInfo->DeviceList.clear(); Interface::IFilterModule *pModule = nullptr; if (IsModuleLoaded()) { if (IsStringEmpty(pszModule)) { if (m_ModuleName.empty()) pModule = m_pFilterModule; } else { if (IsEqualFileName(m_ModuleName.c_str(), pszModule)) pModule = m_pFilterModule; } } if (pModule == nullptr) { if (m_pFilterManager == nullptr) return false; if (FAILED(m_pFilterManager->CreateModule(&pModule))) return false; if (FAILED(pModule->LoadModule(pszModule))) { pModule->Release(); return false; } } HRESULT hr; int DeviceCount; hr = pModule->GetDeviceCount(&DeviceCount); if (SUCCEEDED(hr)) { for (int i = 0; i < DeviceCount; i++) { Interface::IFilterDevice *pDevice; hr = pModule->GetDevice(i, &pDevice); if (SUCCEEDED(hr)) { Interface::FilterDeviceInfo DeviceInfo; hr = pDevice->GetDeviceInfo(&DeviceInfo); if (SUCCEEDED(hr)) { ModuleDeviceInfo Info; Info.DeviceID = DeviceInfo.DeviceID; Info.Flags = DeviceInfo.Flags; Info.Name = DeviceInfo.Name; Info.Text = DeviceInfo.Text; ::SysFreeString(DeviceInfo.Name); ::SysFreeString(DeviceInfo.Text); int FilterCount; hr = pDevice->GetFilterCount(&FilterCount); if (SUCCEEDED(hr)) { for (int j = 0; j < FilterCount; j++) { BSTR Name; hr = pDevice->GetFilterName(j, &Name); if (FAILED(hr)) break; Info.FilterList.push_back(String(Name)); ::SysFreeString(Name); } } pInfo->DeviceList.push_back(Info); } pDevice->Release(); } if (FAILED(hr)) { pInfo->DeviceList.clear(); break; } } } if (pModule != m_pFilterModule) { pModule->UnloadModule(); pModule->Release(); } return SUCCEEDED(hr); }