bool DeleteFiles(const TString& directory, const TString& extension) { WIN32_FIND_DATA findData; bool result = true; TString searchPath = CreatePath(directory, TString(TEXT("*")) + extension); HANDLE hFind = FindFirstFile(searchPath.c_str(), &findData); if(hFind != INVALID_HANDLE_VALUE) { do { TString name = findData.cFileName; if(name != TEXT(".") && name != TEXT("..")) { TString pathForDel = CreatePath(directory, name); if(!DeleteFile(pathForDel.c_str())) { result = false; break; } } } while(FindNextFile(hFind, &findData)); FindClose(hFind); } return result; }
CEnumPropertyDescription::CEnumPropertyDescription(CSerializer* pSerializer) : super(eRPT_Enum) , m_pPropertyData(NULL) { int iValue = 0; if (pSerializer != NULL) { TString enumTypeStr; (*pSerializer) >> iValue; (*pSerializer) >> enumTypeStr; std::vector<TString> vecNames; CStringHelper::GetInstance()->SplitString(enumTypeStr.c_str(), _T("::"), vecNames); //HACK: Force ignore namespace. enumTypeStr = vecNames[vecNames.size() - 1]; std::map<TString, SEnumPropertyData*>::iterator iter = m_enumPropertyDataMap.m_data.find(enumTypeStr); if (iter == m_enumPropertyDataMap.m_data.end()) { const std::vector<SEnumData*>* pEnumValue = NULL; bool bFind = CEnumStrGenerator::GetInstance()->GetEnumValueData(enumTypeStr.c_str(), pEnumValue); BEATS_ASSERT(bFind, _T("Can't find the enum str for type : %s"), enumTypeStr.c_str()); if (bFind) { m_pPropertyData = new SEnumPropertyData(pEnumValue); m_enumPropertyDataMap.m_data[enumTypeStr] = m_pPropertyData; } } else { m_pPropertyData = iter->second; } }
// // Same error message for all binary operations don't work. // void TParseContext::binaryOpError(int line, const char* op, TString left, TString right) { error(line, " wrong operand types ", op, "no operation '%s' exists that takes a left-hand operand of type '%s' and " "a right operand of type '%s' (or there is no acceptable conversion)", op, left.c_str(), right.c_str()); }
void ReadServerErrCodeFile(std::map<uint32_t, std::map<ELanguageType, TString> >& languageServerErrCodeMap) { TString filePath = CResourceManager::GetInstance()->GetResourcePath(eRT_Language); filePath.append(_T("\\")).append("networkError.xml"); if (CFilePathTool::GetInstance()->Exists(filePath.c_str())) { rapidxml::file<> fdoc(filePath.c_str()); rapidxml::xml_document<> errCodeXML; try { errCodeXML.parse<rapidxml::parse_default>(fdoc.data()); } catch (rapidxml::parse_error err) { BEATS_ASSERT(false, _T("Load config file %s faled!/n%s/n"), "errno.xml", err.what()); } rapidxml::xml_node<>* pRootElement = errCodeXML.first_node("config"); if (pRootElement) { for (auto element = pRootElement->first_node(); element; element = element->next_sibling()) { std::map<ELanguageType, TString> curMap; curMap[eLT_Chinese] = element->first_attribute("lang_zhCN")->value(); curMap[eLT_English] = element->first_attribute("lang_enUS")->value(); languageServerErrCodeMap[_tstoi(element->first_attribute("code")->value())] = curMap; } } } }
void CSVString( const TStringVector &sv, TString &string, char adelimiter ) { TString word; int i; int n = sv.size(); int totallength = 0; // int pos = 0; char *pos; if( sv.size()==0 ) { string = "\"\""; return; } for( unsigned int i=0; i<n; i++ ) { word = CSVString( sv[i], adelimiter ); totallength += word.Length(); } if( n>0 ) totallength += n-1; string.SetLength( totallength ); pos = string.c_str(); for( unsigned int i=0; i<n; i++ ) { word = CSVString( sv[i], adelimiter ); strcpy( pos, word.c_str() ); pos += word.Length(); if( i<(n-1) ) { *pos = adelimiter; pos++; } } }
bool CEnumStrGenerator::LoadCacheFile(const TCHAR* pszCacheFileName) { bool bRet = false; TString fullPathStr = CFilePathTool::GetInstance()->ParentPath(CUtilityManager::GetInstance()->GetModuleFileName().c_str()); fullPathStr.append(_T("/")).append(pszCacheFileName); if (CFilePathTool::GetInstance()->Exists(fullPathStr.c_str())) { CSerializer serializer(fullPathStr.c_str()); uint32_t enumTypeCount = 0; serializer >> enumTypeCount; for(uint32_t i = 0; i < enumTypeCount; ++i) { TString enumTypeStr; serializer >> enumTypeStr; std::map<TString, SEnumScanData*>::iterator iter = m_enumStrPool.find(enumTypeStr); if (iter == m_enumStrPool.end()) { SEnumScanData* pEnumScanData = new SEnumScanData; serializer >> pEnumScanData->m_enumFilePath; uint32_t dataStrCount = 0; serializer >> dataStrCount; for (uint32_t j = 0; j < dataStrCount; ++j) { SEnumData* pEnumData = new SEnumData(); serializer >> pEnumData->m_str; serializer >> pEnumData->m_value; pEnumScanData->m_enumValue.push_back(pEnumData); } m_enumStrPool[enumTypeStr] = pEnumScanData; } else {
bool CEnumStrGenerator::ScanEnum( const TFileData& fileData, const TString& fullDirectoryPath ) { #if (BEATS_PLATFORM == BEATS_PLATFORM_WIN32) if ((fileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) == 0) { if ((fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { const TCHAR* pReader = &fileData.cFileName[_tcslen(fileData.cFileName) - 4]; if (memcmp(pReader, _T(".cpp"), 4 * sizeof(TCHAR)) == 0 || memcmp(pReader + 2, _T(".h"), 2 * sizeof(TCHAR)) == 0) { TString fileFullPath = fullDirectoryPath; fileFullPath.append(_T("/")).append(fileData.cFileName); ScanEnumInFile(fileFullPath.c_str()); } } else { if (_tcsicmp(fileData.cFileName, _T(".")) != 0 && _tcsicmp(fileData.cFileName, _T("..")) != 0 ) { TString fileFullPath = fullDirectoryPath; fileFullPath.append(_T("/")).append(fileData.cFileName); ScanEnumInDirectory(fileFullPath.c_str()); } } } #endif return true; }
/* ******************************************************************************** ************************ FileSystem::GetFileBaseName *************************** ******************************************************************************** */ TString FileSystem::GetFileBaseName (const TString& pathName) { #if qPlatform_Windows TString useFName = pathName; { TChar fNameBuf[4 * MAX_PATH ]; DWORD r = GetLongPathName (pathName.c_str (), fNameBuf, NEltsOf (fNameBuf) - 1); if (r != 0) { useFName = fNameBuf; } } TChar fname[_MAX_FNAME]; TChar drive[_MAX_DRIVE]; TChar dir[_MAX_DIR]; TChar ext[_MAX_EXT]; memset (drive, 0, sizeof (drive)); memset (dir, 0, sizeof (dir)); memset (fname, 0, sizeof (fname)); memset (ext, 0, sizeof (ext)); ::_tsplitpath_s (useFName.c_str (), drive, dir, fname, ext); return fname; #else AssertNotImplemented (); #endif }
inline void operator()(TVarEntryInfo& ent) { ent.newLocation = -1; ent.newComponent = -1; ent.newBinding = -1; ent.newSet = -1; ent.newIndex = -1; const bool isValid = resolver.validateBinding(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); if (isValid) { ent.newBinding = resolver.resolveBinding(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); ent.newSet = resolver.resolveSet(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); if (ent.newBinding != -1) { if (ent.newBinding >= int(TQualifier::layoutBindingEnd)) { TString err = "mapped binding out of range: " + ent.symbol->getName(); infoSink.info.message(EPrefixInternalError, err.c_str()); error = true; } } if (ent.newSet != -1) { if (ent.newSet >= int(TQualifier::layoutSetEnd)) { TString err = "mapped set out of range: " + ent.symbol->getName(); infoSink.info.message(EPrefixInternalError, err.c_str()); error = true; } } } else { TString errorMsg = "Invalid binding: " + ent.symbol->getName(); infoSink.info.message(EPrefixInternalError, errorMsg.c_str()); error = true; } }
bool CSymbolEngine::LoadModuleSymbols( HANDLE hFile, const TString& ImageName, DWORD64 ModBase, DWORD ModSize ) { // Check preconditions if( m_hProcess == NULL ) { _ASSERTE( !_T("Symbol engine is not yet initialized.") ); m_LastError = ERROR_INVALID_FUNCTION; return false; } // In Unicode build, ImageName parameter should be translated to ANSI #ifdef _UNICODE char* pImageName = 0; if( !ImageName.empty() ) { size_t BufSize = 2 * ImageName.length(); pImageName = (char*)_alloca( BufSize + 2 ); size_t res = wcstombs( pImageName, ImageName.c_str(), BufSize ); pImageName[BufSize] = 0; if( res == -1 ) { _ASSERTE( !_T("Module name has bad format.") ); m_LastError = ERROR_INVALID_PARAMETER; return false; } } #else const char* pImageName = ImageName.empty() ? 0 : ImageName.c_str(); #endif //_UNICODE // Load symbols for the module #pragma TODO("replace SymLoadModule64 with SymLoadModuleEx ") DWORD64 rv = SymLoadModule64( m_hProcess, hFile, pImageName, NULL, ModBase, ModSize ); if( rv == 0 ) { m_LastError = GetLastError(); _ASSERTE( !_T("SymLoadModule64() failed.") ); return false; } // Complete return true; }
void CEnumStrGenerator::RescanEnum(const TString& strEnumType) { auto iter = m_enumStrPool.find(strEnumType); if (iter != m_enumStrPool.end()) { TString strFilePath = iter->second->m_enumFilePath; BEATS_SAFE_DELETE(iter->second); m_enumStrPool.erase(iter); ScanEnumInFile(strFilePath.c_str(), strEnumType.c_str()); } }
TString TOutputGLSLBase::hashName(const TString& name) { if (mHashFunction == NULL || name.empty()) return name; NameMap::const_iterator it = mNameMap.find(name.c_str()); if (it != mNameMap.end()) return it->second.c_str(); TString hashedName = TIntermTraverser::hash(name, mHashFunction); mNameMap[name.c_str()] = hashedName.c_str(); return hashedName; }
TString MapLongVariableNames::mapGlobalLongName(const TString& name) { ASSERT(mGlobalMap); const char* mappedName = mGlobalMap->Find(name.c_str()); if (mappedName != NULL) return mappedName; size_t id = mGlobalMap->Size(); TString rt = mapLongName(id, name, true); mGlobalMap->Insert(name.c_str(), rt.c_str()); return rt; }
/* ******************************************************************************** ********************* FileSystem::AssureLongFileName *************************** ******************************************************************************** */ TString FileSystem::AssureLongFileName (const TString& fileName) { #if qPlatform_Windows DWORD r = ::GetLongPathName (fileName.c_str (), nullptr, 0); if (r != 0) { Memory::SmallStackBuffer<TChar> buf (r); r = ::GetLongPathName (fileName.c_str (), buf, r); if (r != 0) { return TString (buf); } } #endif return fileName; }
void TInfoSinkBase::append(const TString& t) { if (outputStream & EString) { checkMem(t.size()); sink.append(t.c_str()); } #ifdef _WIN32 if (outputStream & EDebugger) OutputDebugString(t.c_str()); #endif if (outputStream & EStdOut) fprintf(stdout, "%s", t.c_str()); }
bool CShader::Load() { TString strExtension = CFilePathTool::GetInstance()->Extension(GetFilePath().c_str()); bool bIsVS = strExtension.compare(_T(".vs")) == 0; m_shaderType = bIsVS ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; if (m_commonHeader.GetWritePos() == 0) { #if (BEYONDENGINE_PLATFORM == PLATFORM_ANDROID) const char* pszPlatformDef = "#define PLATFORM_ANDROID\r\n"; #elif (BEYONDENGINE_PLATFORM == PLATFORM_IOS) const char* pszPlatformDef = "#define PLATFORM_IOS\r\n"; #else const char* pszPlatformDef = "#define PLATFORM_WIN32\r\n"; #endif m_commonHeader.Serialize((const void *)pszPlatformDef, strlen(pszPlatformDef)); TString strPath = CResourceManager::GetInstance()->GetFullPath(_T("commonheader.txt"), eRT_Shader); m_commonHeader.Serialize(strPath.c_str()); } BEATS_ASSERT(m_pData == NULL); m_pData = new CSerializer(m_commonHeader); BEATS_ASSERT(CFilePathTool::GetInstance()->Exists(m_strPath.m_value.c_str()), "Can't find shader file %s", m_strPath.m_value.c_str()) m_pData->Serialize(m_strPath.m_value.c_str()); super::Load(); return true; }
void TOutputGLSLBase::writeBuiltInFunctionTriplet( Visit visit, const char *preStr, bool useEmulatedFunction) { TString preString = useEmulatedFunction ? BuiltInFunctionEmulator::GetEmulatedFunctionName(preStr) : preStr; writeTriplet(visit, preString.c_str(), ", ", ")"); }
// // Enforce non-initializer type/qualifier rules. // // Returns true if there was an error. // bool TParseContext::nonInitConstErrorCheck(int line, TString& identifier, TPublicType& type, bool array) { if (type.qualifier == EvqConst) { // Make the qualifier make sense. type.qualifier = EvqTemporary; if (array) { error(line, "arrays may not be declared constant since they cannot be initialized", identifier.c_str()); } else if (type.isStructureContainingArrays()) { error(line, "structures containing arrays may not be declared constant since they cannot be initialized", identifier.c_str()); } else { error(line, "variables with qualifier 'const' must be initialized", identifier.c_str()); } return true; } return false; }
STDMETHODIMP COLED::get_Text(BSTR *pText) { HRESULT hr = NOERROR; if( NULL==pText ) hr = Exception(BVR_SOURCE_LED,E_POINTER); else { try { TString s; if( NULL!=m_pWnd ) { ((LEDWnd*)m_pWnd)->GetText(s); *pText = ::SysAllocString(s.c_str()); } // of if else GetPropertySet().Get(_T("text"),pText); } catch(const BVR20983Exception& e) { LOGGER_ERROR<<e<<endl; hr = e.GetErrorCode(); } catch(...) { hr = Exception(BVR_SOURCE_LED,E_FAIL); } } // of else return hr; } // of COLED::get_Text()
TString GetNewNameForFileDigit(const TPath &oldPath, const TString &nameWithoutDigit, __int64 & counter, size_t & leadingZeros, const TPath &pathForRename) { TString pathWithDigit; const int BUFFER_SIZE = 65; char buffer[BUFFER_SIZE]; TString leadingZeroString; counter++; if (leadingZeros > 0) { if (LengthOfLong(counter) > LengthOfLong(counter - 1)) //если цифра удленилась leadingZeros--; for (size_t i = 0; i < leadingZeros; i++) leadingZeroString.push_back('0'); } if (_i64toa_s(counter, buffer, BUFFER_SIZE, 10) == 0) { pathWithDigit = CreatePath(oldPath.GetDirectory(), nameWithoutDigit + leadingZeroString + TString(buffer) + oldPath.GetExtension()); if(TPath::EqualByNameWithExtension(pathWithDigit, pathForRename)) return pathForRename.Original(); if (IsFileExists(pathWithDigit.c_str())) //если такой файл уже есть, то не увеличиваем номер, а добавляем _2 return GetNewNameForFileAdd(oldPath); } else return GetNewNameForFileAdd(oldPath); return pathWithDigit; }
//----------------------------------------------------------------------- // a d d I t e m //----------------------------------------------------------------------- u32 TTextOverlay::addItem(const TString& text,TTextAlignment a, TColor color, TColor bgColor) { s32 offset = 0; int idx; IGUIEnvironment* mgr = getApplication()->getGUIManager(); IGUIFont* font=m_panel->getOverrideFont(); if(!font) font = mgr->getSkin()->getFont(); TRecti apos = m_panel->getAbsolutePosition(); idx = (int)m_textItems.size(); TStrStream name; name << m_name.c_str() << "-item" << idx+1; TStringW wstr = text.c_str(); s32 cheight = font->getDimension(L"Ay").Height; cheight += font->getKerningHeight(); TRecti tdim(0,0,apos.getWidth(),cheight); TTextElement* textArea = mgr->addStaticText(wstr.c_str(),tdim,false,false,m_panel); textArea->move(position2di(0,cheight*idx)); textArea->setOverrideFont(font); textArea->setOverrideColor(color); textArea->setBackgroundColor(bgColor); offset = idx * (cheight); s32 theight = ((idx+1) * cheight) + (m_margins.Height * 2); EGUI_ALIGNMENT oa=EGUIA_UPPERLEFT; switch(a) { case taLeft: oa = EGUIA_UPPERLEFT; break; case taCenter: oa = EGUIA_CENTER; break; case taRight: oa = EGUIA_LOWERRIGHT; break; }; textArea->setTextAlignment(oa,EGUIA_UPPERLEFT); m_panel->addChild(textArea); m_textItems.push_back(textArea); if(apos.getHeight() < theight) { m_panel->setMinSize(TDimensionu(0,theight)); } return m_textItems.size()-1; }
void IOFile::OpenForOutput(TString tstrPath, bool isTruncate) { #ifdef __WINDOWS__ m_upFile.reset(::CreateFile( tstrPath.c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, isTruncate ? CREATE_ALWAYS : OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)); if (INVALID_HANDLE_VALUE == m_upFile.get()) { throw FileException("Cannot open file."); } #else // TODO: fcntl() or flock()? m_upFile.reset(fopen(ConvertTStringToString( tstrPath).c_str(), isTruncate ? "wb+" : "wb")); if (!m_upFile) { throw FileException("Cannot open file."); } #endif m_tstrPath = tstrPath; }
bool TString::operator==( const TString& str ) const { if( Length()!=str.Length() ) return false; return strcmp( c_str(), str.c_str() ) == 0; }
void CEditLanguageDialog::InitLanguageMap() { TString tmpPath = _T("Language.bin"); TString FilePath = CResourcePathManager::GetInstance()->GetFullPathForFilename("Language.bin"); if (tmpPath == FilePath) { return; } int count = 0; CSerializer tmp(FilePath.c_str()); tmp >> count; for (int i = 0; i < count; i++) { TString tmpstrEnum; tmp >> tmpstrEnum; TString tmpstrChinese; tmp >> tmpstrChinese; TString tmpstrEnglish; tmp >> tmpstrEnglish; std::vector<TString> mLanguageVector; mLanguageVector.push_back(tmpstrChinese); mLanguageVector.push_back(tmpstrEnglish); m_languageMap.insert(std::map<TString, std::vector<TString>>::value_type(tmpstrEnum,mLanguageVector)); } }
void GetVariableTraverser::traverse(const TType &type, const TString &name, std::vector<VarT> *output) { const TStructure *structure = type.getStruct(); VarT variable; variable.name = name.c_str(); variable.arraySize = static_cast<unsigned int>(type.getArraySize()); if (!structure) { variable.type = GLVariableType(type); variable.precision = GLVariablePrecision(type); } else { // Note: this enum value is not exposed outside ANGLE variable.type = GL_STRUCT_ANGLEX; variable.structName = structure->name().c_str(); const TFieldList &fields = structure->fields(); for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) { TField *field = fields[fieldIndex]; traverse(*field->type(), field->name(), &variable.fields); } } visitVariable(&variable); ASSERT(output); output->push_back(variable); }
inline void operator()(TVarEntryInfo& ent) { ent.newLocation = -1; ent.newComponent = -1; ent.newBinding = -1; ent.newSet = -1; ent.newIndex = -1; const bool isValid = resolver.validateInOut(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); if (isValid) { ent.newLocation = resolver.resolveInOutLocation(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); ent.newComponent = resolver.resolveInOutComponent(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); ent.newIndex = resolver.resolveInOutIndex(stage, ent.symbol->getName().c_str(), ent.symbol->getType(), ent.live); } else { TString errorMsg = "Invalid shader In/Out variable semantic: "; errorMsg += ent.symbol->getType().getQualifier().semanticName; infoSink.info.message(EPrefixInternalError, errorMsg.c_str()); error = true; } }
bool TWinUtility::StartupApp(const TString& appName) { TCHAR szCommandLine[MAX_PATH]; _tcscpy_s(szCommandLine, appName.c_str()); PROCESS_INFORMATION processInfo; STARTUPINFO startupInfo; memset(&startupInfo, 0, sizeof(STARTUPINFO)); startupInfo.cb = sizeof(STARTUPINFO); startupInfo.dwFlags = STARTF_USESHOWWINDOW; startupInfo.wShowWindow = SW_SHOWDEFAULT; BOOL success = CreateProcess( NULL, szCommandLine, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInfo); if(success) { CloseHandle(processInfo.hThread); CloseHandle(processInfo.hProcess); } return TRUE == success; }
static TString FindOutputFile() { TString candidate; if (!out_argument.empty()) { candidate = StripQuotes(out_argument); } else if (!first_object_name.empty()) { candidate = first_object_name; if (!StripSuffix(candidate, TEXT(".obj"))) StripSuffix(candidate, TEXT(".o")); } else { return TString(); } if (PathFileExists(candidate.c_str())) return candidate; // FIXME: we should figure out from the linker's command line // whether the output file is an .exe or .dll TString exe_file = candidate + TEXT(".exe"); if (PathFileExists(exe_file.c_str())) return exe_file; TString dll_file = candidate + TEXT(".dll"); if (PathFileExists(dll_file.c_str())) return dll_file; return TString(); }
bool TString::operator!=( const TString& str ) const { if( Length()!=str.Length() ) return true; return strcmp( c_str(), str.c_str() ) != 0; }
/** * Write data to file. * <br>write strings * * @param szData write strings data * @param ... vargs * * @return AT_OK : write success */ int ATFile::write(const TString &szData, ...) { if (ATStringUtl::isEmpty(szData)) { return AT_ERR_ARGUMENTS; } if (!isOpen()) { return AT_ERR_IOEXCEPTION; } /* variable args */ va_list vaList; TCHAR szBuff[_MAX_PATH] = {0}; const TCHAR *pSrc = szData.c_str(); va_start(vaList, pSrc); #ifdef PLATFORM_WINDOWS _vstprintf_s(szBuff, _MAX_PATH, pSrc, vaList); #else vsprintf(szBuff, pSrc, vaList); #endif va_end(vaList); /* Lock file */ if (ml_oLock.lock() != AT_OK) { return AT_ERR_IOEXCEPTION; } _ftprintf_s(ml_pFile, _T("%s"), szBuff); ml_oLock.unlock(); return AT_OK; }