static void CheckUpdates(void *) { TCHAR tszBuff[2048] = { 0 }, tszFileInfo[30] = { 0 }, tszTmpIni[MAX_PATH] = { 0 }; char szKey[64] = { 0 }; vector<FILEINFO> UpdateFiles; if (!Exists(tszRoot)) CreateDirectory(tszRoot, NULL); Files.clear(); Reminder = db_get_b(NULL, MODNAME, "Reminder", DEFAULT_REMINDER); FileCount = db_get_dw(NULL, MODNAME, "FileCount", DEFAULT_FILECOUNT); // Load files info ptrT tszDownloadURL(db_get_tsa(NULL, MODNAME, "File_VersionURL")); if (!tszDownloadURL) { // URL is not set Title = TranslateT("Pack Updater"); Text = TranslateT("URL for checking updates not found."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; show_popup(0, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) MessageBox(NULL, Text, Title, MB_ICONSTOP); hCheckThread = NULL; return; } // Download version info pFileUrl = (FILEURL *)mir_alloc(sizeof(*pFileUrl)); mir_tstrncpy(pFileUrl->tszDownloadURL, tszDownloadURL, _countof(pFileUrl->tszDownloadURL)); mir_sntprintf(tszBuff, _countof(tszBuff), _T("%s\\tmp.ini"), tszRoot); mir_tstrncpy(pFileUrl->tszDiskPath, tszBuff, _countof(pFileUrl->tszDiskPath)); mir_tstrncpy(tszTmpIni, tszBuff, _countof(tszTmpIni)); Title = TranslateT("Pack Updater"); Text = TranslateT("Downloading version info..."); DlgDownloadProc(); mir_free(pFileUrl); if (!DlgDld) { hCheckThread = NULL; return; } for (CurrentFile = 0; CurrentFile < FileCount; CurrentFile++) { FILEINFO FileInfo = { _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), _T(""), { _T(""), _T("") } }; mir_snprintf(szKey, _countof(szKey), "File_%d_CurrentVersion", CurrentFile + 1); ptrT tszCurVer(db_get_tsa(NULL, MODNAME, szKey)); if (tszCurVer) mir_tstrncpy(FileInfo.tszCurVer, tszCurVer, _countof(FileInfo.tszCurVer)); else mir_tstrncpy(FileInfo.tszCurVer, _T(""), _countof(FileInfo.tszCurVer)); mir_snprintf(szKey, _countof(szKey), "File_%d_LastVersion", CurrentFile + 1); ptrT tszLastVer(db_get_tsa(NULL, MODNAME, szKey)); if (tszLastVer) mir_tstrncpy(FileInfo.tszLastVer, tszLastVer, _countof(FileInfo.tszLastVer)); else mir_tstrncpy(FileInfo.tszLastVer, _T(""), _countof(FileInfo.tszLastVer)); Files.push_back(FileInfo); // Read version info mir_sntprintf(tszFileInfo, _countof(tszFileInfo), _T("FileInfo_%d"), CurrentFile + 1); GetPrivateProfileString(tszFileInfo, _T("FileVersion"), _T(""), Files[CurrentFile].tszNewVer, _countof(Files[CurrentFile].tszNewVer), tszTmpIni); GetPrivateProfileString(tszFileInfo, _T("Message"), _T(""), Files[CurrentFile].tszMessage, _countof(Files[CurrentFile].tszMessage), tszTmpIni); GetPrivateProfileString(tszFileInfo, _T("DownloadURL"), _T(""), Files[CurrentFile].File.tszDownloadURL, _countof(Files[CurrentFile].File.tszDownloadURL), tszTmpIni); GetPrivateProfileString(tszFileInfo, _T("AdvFolder"), _T(""), Files[CurrentFile].tszAdvFolder, _countof(Files[CurrentFile].tszAdvFolder), tszTmpIni); GetPrivateProfileString(tszFileInfo, _T("Descr"), _T(""), Files[CurrentFile].tszDescr, _countof(Files[CurrentFile].tszDescr), tszTmpIni); GetPrivateProfileString(tszFileInfo, _T("DiskFileName"), _T(""), tszBuff, MAX_PATH, tszTmpIni); if (_tcsstr(tszBuff, _T("\\"))) { //check update name Title = TranslateT("Pack Updater"); Text = TranslateT("Name of Update's file is not supported."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups1", DEFAULT_POPUP_ENABLED)) { Number = 1; show_popup(0, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups1M", DEFAULT_MESSAGE_ENABLED)) MessageBox(NULL, Text, Title, MB_ICONINFORMATION); continue; } // end check update name mir_tstrncpy(Files[CurrentFile].File.tszDiskPath, tszBuff, _countof(Files[CurrentFile].File.tszDiskPath)); GetPrivateProfileString(tszFileInfo, _T("InfoURL"), _T(""), Files[CurrentFile].tszInfoURL, _countof(Files[CurrentFile].tszInfoURL), tszTmpIni); Files[CurrentFile].FileType = GetPrivateProfileInt(tszFileInfo, _T("FileType"), 0, tszTmpIni); Files[CurrentFile].Force = GetPrivateProfileInt(tszFileInfo, _T("Force"), 0, tszTmpIni); Files[CurrentFile].FileNum = CurrentFile + 1; if (Files[CurrentFile].FileType == 2) { if (mir_tstrcmp(Files[CurrentFile].tszAdvFolder, _T("")) == 0) mir_sntprintf(tszBuff, _countof(tszBuff), _T("Plugins\\%s"), Files[CurrentFile].File.tszDiskPath); else mir_sntprintf(tszBuff, _countof(tszBuff), _T("Plugins\\%s\\%s"), Files[CurrentFile].tszAdvFolder, Files[CurrentFile].File.tszDiskPath); TCHAR pluginFolderName[MAX_PATH]; PathToAbsoluteT(tszBuff, pluginFolderName); if (!Files[CurrentFile].Force && (IsPluginDisabled(Files[CurrentFile].File.tszDiskPath) || !Exists(pluginFolderName))) //check if plugin disabled or not exists continue; } // Compare versions if (getVer(Files[CurrentFile].tszCurVer) < getVer(Files[CurrentFile].tszNewVer)) { // Yeah, we've got new version. VARST tszSysRoot(_T("%SystemRoot%")); VARST tszProgFiles(_T("%ProgramFiles%")); if (Files[CurrentFile].FileType != 1 && !IsUserAnAdmin() && (_tcsstr(tszRoot, tszSysRoot) || _tcsstr(tszRoot, tszProgFiles))) { MessageBox(NULL, TranslateT("Update is not possible!\nYou have no Administrator's rights.\nPlease run Miranda NG with Administrator's rights."), Title, MB_ICONINFORMATION); DeleteFile(tszTmpIni); hCheckThread = NULL; return; } // user have not admin's rights //добавить проверку на существование файла TCHAR tszFilePathDest[MAX_PATH] = { 0 }; switch (Files[CurrentFile].FileType) { case 0: case 1: break; case 2: { VARST tszUtilRootPlug(_T("%miranda_path%\\Plugins")); if (mir_tstrcmp(Files[CurrentFile].tszAdvFolder, _T("")) == 0) mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s"), tszUtilRootPlug, Files[CurrentFile].File.tszDiskPath); else mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s\\%s"), tszUtilRootPlug, Files[CurrentFile].tszAdvFolder, Files[CurrentFile].File.tszDiskPath); } break; case 3: { VARST tszUtilRootIco(_T("%miranda_path%\\Icons")); if (mir_tstrcmp(Files[CurrentFile].tszAdvFolder, _T("")) == 0) mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s"), tszUtilRootIco, Files[CurrentFile].File.tszDiskPath); else mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s\\%s"), tszUtilRootIco, Files[CurrentFile].tszAdvFolder, Files[CurrentFile].File.tszDiskPath); } break; case 4: case 5: { VARST tszUtilRoot = Utils_ReplaceVarsT(_T("%miranda_path%")); if (mir_tstrcmp(Files[CurrentFile].tszAdvFolder, _T("")) == 0) mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s"), tszUtilRoot, Files[CurrentFile].File.tszDiskPath); else mir_sntprintf(tszFilePathDest, _countof(tszFilePathDest), _T("%s\\%s\\%s"), tszUtilRoot, Files[CurrentFile].tszAdvFolder, Files[CurrentFile].File.tszDiskPath); } break; }//end* switch (Files[CurrentFile].FileType) if (Files[CurrentFile].Force || Exists(tszFilePathDest)) UpdateFiles.push_back(Files[CurrentFile]); // Save last version mir_tstrncpy(Files[CurrentFile].tszLastVer, Files[CurrentFile].tszNewVer, _countof(Files[CurrentFile].tszLastVer)); mir_snprintf(szKey, _countof(szKey), "File_%d_LastVersion", CurrentFile + 1); db_set_ts(NULL, MODNAME, szKey, Files[CurrentFile].tszLastVer); } // end compare versions } //end checking all files in for () // Show dialog INT upd_ret = 0; if (UpdateFiles.size() > 0) upd_ret = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_UPDATE), GetDesktopWindow(), DlgUpdate, (LPARAM)&UpdateFiles); DeleteFile(tszTmpIni); if (upd_ret == IDCANCEL) { hCheckThread = NULL; return; } if (!UpdatesCount && !Silent) { Title = TranslateT("Pack Updater"); Text = TranslateT("No updates found."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; show_popup(0, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) MessageBox(NULL, Text, Title, MB_ICONINFORMATION); } if (!FileCount) { Title = TranslateT("Pack Updater"); Text = TranslateT("No files for update."); if (ServiceExists(MS_POPUP_ADDPOPUPT) && db_get_b(NULL, "Popup", "ModuleIsEnabled", 1) && db_get_b(NULL, MODNAME, "Popups2", DEFAULT_POPUP_ENABLED)) { Number = 2; show_popup(0, Title, Text, Number, 0); } else if (db_get_b(NULL, MODNAME, "Popups2M", DEFAULT_MESSAGE_ENABLED)) MessageBox(NULL, Text, Title, MB_ICONINFORMATION); } hCheckThread = NULL; }
CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) { int ret; if (pszFile == NULL) return; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); bool fCreate = strchr(pszMode, 'c'); unsigned int nFlags = DB_THREAD; if (fCreate) nFlags |= DB_CREATE; CRITICAL_BLOCK(cs_db) { if (!dbLock) { if (fShutdown) return; string strDataDir = GetDataDir(); string strLogDir = strDataDir + "/database"; filesystem::create_directory(strLogDir.c_str()); string strErrorFile = strDataDir + "/db.log"; printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str()); // if strErrorFile exists and is locked, exception: another Bitcoin must // be using this DataDir: if (boost::filesystem::exists(strErrorFile)) { dbLock = new boost::interprocess::file_lock(strErrorFile.c_str()); bool locked = dbLock->try_lock(); if (!locked) throw runtime_error(_("Cannot lock db.log, is bitcoin already running?\n")); } dbenv.set_lg_dir(strLogDir.c_str()); dbenv.set_lg_max(10000000); dbenv.set_lk_max_locks(10000); dbenv.set_lk_max_objects(10000); dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug dbenv.set_flags(DB_AUTO_COMMIT, 1); ret = dbenv.open(strDataDir.c_str(), DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD | DB_PRIVATE | DB_RECOVER, S_IRUSR | S_IWUSR); if (ret > 0) throw runtime_error(strprintf("CDB() : error %d opening database environment\n", ret)); if (!dbLock) { dbLock = new boost::interprocess::file_lock(strErrorFile.c_str()); dbLock->lock(); } } strFile = pszFile; ++mapFileUseCount[strFile]; pdb = mapDb[strFile]; if (pdb == NULL) { pdb = new Db(&dbenv, 0); ret = pdb->open(NULL, // Txn pointer pszFile, // Filename "main", // Logical db name DB_BTREE, // Database type nFlags, // Flags 0); if (ret > 0) { delete pdb; pdb = NULL; CRITICAL_BLOCK(cs_db) --mapFileUseCount[strFile]; strFile = ""; throw runtime_error(strprintf("CDB() : can't open database file %s, error %d\n", pszFile, ret)); } if (fCreate && !Exists(string("version"))) { bool fTmp = fReadOnly; fReadOnly = false; WriteVersion(VERSION); fReadOnly = fTmp; } mapDb[strFile] = pdb; } } }
//##################################################################### // Function Exists //##################################################################### template<class TV> bool RIGID_GEOMETRY_COLLECTION<TV>:: Is_Active(const int particle) const { return Exists(particle) && particles.rigid_geometry(particle)->particle_index>0; }
Buyout BuyoutManager::Get(const Item &item) const { if (!Exists(item)) throw std::runtime_error("Asked to get inexistant buyout."); return buyouts_.at(item.hash()); }
bool plKey::isLoaded() const { if (!Exists()) return true; return fKeyData->getObj() != NULL; }
ALERROR CObjectImage::OnCreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc) // CreateFromXML // // Creates the object from and XML element { ALERROR error; // Load on use m_bLoadOnUse = pDesc->GetAttributeBool(LOAD_ON_USE_ATTRIB); // Get the file paths m_sResourceDb = Ctx.sResDb; if (Ctx.sFolder.IsBlank()) { m_sBitmap = pDesc->GetAttribute(BITMAP_ATTRIB); m_sBitmask = pDesc->GetAttribute(BITMASK_ATTRIB); } else { CString sFilespec; if (pDesc->FindAttribute(BITMAP_ATTRIB, &sFilespec)) m_sBitmap = pathAddComponent(Ctx.sFolder, sFilespec); if (pDesc->FindAttribute(BITMASK_ATTRIB, &sFilespec)) m_sBitmask = pathAddComponent(Ctx.sFolder, sFilespec); } // Transparent color CString sTransColor; if (m_bTransColor = pDesc->FindAttribute(BACK_COLOR_ATTRIB, &sTransColor)) m_wTransColor = LoadRGBColor(sTransColor); // Sprite m_bSprite = pDesc->GetAttributeBool(SPRITE_ATTRIB); // Pre-multiply transparency m_bPreMult = !pDesc->GetAttributeBool(NO_PM_ATTRIB); // Initialize m_bMarked = false; m_bLocked = false; m_pBitmap = NULL; // If we're loading on use, make sure the image exists. For other // images we don't bother checking because we will load them // soon enough. if (m_bLoadOnUse) if (error = Exists(Ctx)) return error; // Done return NOERROR; }
// Note: UNIX-only (for now.) // bool OTString::TokenizeIntoKeyValuePairs(std::map<std::string, std::string> & mapOutput) const { #if !(defined(_WIN32) || defined(TARGET_OS_IPHONE) || defined(ANDROID)) // fabcy-pansy parser that allows for multiple level of quotes nesting and escaped quotes if (!Exists()) return true; // -------------- wordexp_t exp_result; exp_result.we_wordc = 0; exp_result.we_wordv = NULL; exp_result.we_offs = 0; if (wordexp(Get(), &exp_result, 0)) // non-zero == failure. { OTLog::vError("OTString::TokenizeIntoKeyValuePairs: Error calling wordexp() " "(to expand user-defined script args.)\nData: %s\n", Get()); // wordfree(&exp_result); return false; } // ---------------------------- if ((exp_result.we_wordc > 0) && (NULL != exp_result.we_wordv)) { // wordexp tokenizes by space (as well as expands, which is why I'm using it.) // Therefore we need to iterate through the tokens, and create a single string // with spaces between the tokens. // for (uint32_t i = 0; (i < (exp_result.we_wordc - 1)) && (exp_result.we_wordv[i] != NULL) && (exp_result.we_wordv[i+1] != NULL); // odd man out. Only PAIRS of strings are processed! i += 2) { const std::string str_key = exp_result.we_wordv[i]; const std::string str_val = exp_result.we_wordv[i+1]; OTLog::vOutput(2, "%s:Parsed: %s = %s\n", __FUNCTION__, str_key.c_str(), str_val.c_str()); mapOutput.insert(std::pair<std::string, std::string>(str_key, str_val)); } wordfree(&exp_result); } // -------------- return true; #else // simple parser that allows for one level of quotes nesting but no escaped quotes if (!Exists()) return true; const char * txt = Get(); std::string buf = txt; for (int32_t i = 0; txt[i] != 0;) { while (txt[i] == ' ') i++; int32_t k = i; int32_t k2 = i; if (txt[i] == '\'' || txt[i] == '"') { // quoted string char quote = txt[i++]; k = i; while (txt[i] != quote && txt[i] != 0) i++; if (txt[i] != quote) { OTLog::vError("%s: Unmatched quotes in: %s\n", __FUNCTION__, txt); return false; } k2 = i; i++; } else { while (txt[i] != ' ' && txt[i] != 0) i++; k2 = i; } const std::string key = buf.substr(k, k2 - k); while (txt[i] == ' ') i++; int32_t v = i; int32_t v2 = i; if (txt[i] == '\'' || txt[i] == '"') { // quoted string char quote = txt[i++]; v = i; while (txt[i] != quote && txt[i] != 0) i++; if (txt[i] != quote) { OTLog::vError("%s: Unmatched quotes in: %s\n", __FUNCTION__, txt); return false; } v2 = i; i++; } else { while (txt[i] != ' ' && txt[i] != 0) i++; v2 = i; } const std::string value = buf.substr(v, v2 - v); if (key.length() != 0 && value.length() != 0) { OTLog::vOutput(2, "%s:Parsed: %s = %s\n", __FUNCTION__, key.c_str(), value.c_str()); mapOutput.insert(std::pair<std::string, std::string>(key, value)); } } return true; #endif }
bool BuyoutManager::IsItemManuallySet(const Item &item) const { return Exists(item) ? buyouts_.value(ItemHash(item)).set_by == "" : false; }
bool CSettings::Open(CString strPath, bool bCreate, bool bSave, bool bClient) { // Flag we are not allowed to save the file by default m_bSave = false; // Load the default settings LoadDefaults(bClient); // Does the settings file not exist? bool bExists = true; if(!SharedUtility::Exists(strPath.Get())) { if(!bCreate) { CLogFile::Printf("ERROR: Settings file %s does not exist.", strPath.Get()); return false; } else { CLogFile::Printf("WARNING: Settings file %s does not exist, it will now be created.", strPath.Get()); // Attempt to open the file for write FILE * fFile = fopen(strPath.Get(), "w"); // Ensure the file was opened if(!fFile) { CLogFile::Printf("WARNING: Failed to create settings file %s, no settings will be loaded or saved.", strPath.Get()); // Flag the settings file as does not exist bExists = false; } else { // Write the default contents to the file fprintf(fFile, "<settings />"); // Close the file fclose(fFile); } } } // Load the settings file if(bExists) { // Attempt to load the XML file if(m_XMLDocument.LoadFile(strPath.Get())) { // Flag ourselves as open m_bOpen = true; // Loop through all XML nodes for(TiXmlNode * pNode = m_XMLDocument.RootElement()->FirstChildElement(); pNode; pNode = pNode->NextSibling()) { // Is this not an element node? if(pNode->Type() != TiXmlNode::ELEMENT) continue; // Get the setting and value CString strSetting = pNode->Value(); CString strValue = pNode->ToElement()->GetText(); // Does the setting not exist? if(!Exists(strSetting)) CLogFile::Printf("WARNING: Log file setting %s does not exist.", strSetting.Get()); else SetEx(strSetting, strValue); } // Flag if we are allowed to save the file m_bSave = bSave; // Save the XML file Save(); } else { if(bCreate) { CLogFile::Printf("ERROR: Failed to open settings file %s.", strPath.Get()); return false; } else CLogFile::Printf("WARNING: Failed to open settings file %s, no settings will be loaded or saved.", strPath.Get()); } } return true; }
CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL) { int ret; if (pszFile == NULL) return; fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w')); bool fCreate = strchr(pszMode, 'c'); unsigned int nFlags = DB_THREAD; if (fCreate) nFlags |= DB_CREATE; CRITICAL_BLOCK(cs_db) { if (!fDbEnvInit) { if (fShutdown) return; string strDataDir = GetDataDir(); string strLogDir = strDataDir + "/database"; filesystem::create_directory(strLogDir.c_str()); string strErrorFile = strDataDir + "/db.log"; printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str()); dbenv.set_lg_dir(strLogDir.c_str()); dbenv.set_lg_max(10000000); #if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) dbenv.set_lk_max_locks(10000); dbenv.set_lk_max_objects(10000); #endif dbenv.set_errfile(fopen(strErrorFile.c_str(), "a")); /// debug dbenv.set_flags(DB_AUTO_COMMIT, 1); ret = dbenv.open(strDataDir.c_str(), DB_CREATE | #if !(TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR) DB_INIT_LOCK | #endif DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | DB_THREAD | DB_RECOVER, S_IRUSR | S_IWUSR); if (ret > 0) throw runtime_error(strprintf("CDB() : error %d opening database environment", ret)); fDbEnvInit = true; } strFile = pszFile; ++mapFileUseCount[strFile]; pdb = mapDb[strFile]; if (pdb == NULL) { pdb = new Db(&dbenv, 0); ret = pdb->open(NULL, // Txn pointer pszFile, // Filename "main", // Logical db name DB_BTREE, // Database type nFlags, // Flags 0); if (ret > 0) { delete pdb; pdb = NULL; CRITICAL_BLOCK(cs_db) --mapFileUseCount[strFile]; strFile = ""; throw runtime_error(strprintf("CDB() : can't open database file %s, error %d", pszFile, ret)); } if (fCreate && !Exists(string("version"))) { bool fTmp = fReadOnly; fReadOnly = false; WriteVersion(VERSION); fReadOnly = fTmp; } mapDb[strFile] = pdb; } } }
Buyout BuyoutManager::Get(const Item &item) const { Q_ASSERT(Exists(item)); return buyouts_.value(ItemHash(item)); }
void RAUX::MTLFile :: Load ( uint32_t * Status ) { if ( ! Exists () ) { * Status = kStatus_Failure_NonExistantFile; return; } uint32_t SubStatus; FileInstance.Open ( & SubStatus ); if ( SubStatus != TextFile :: kStatus_Success ) { * Status = kStatus_Failure_Load; return; } std :: string ReadBlock; FileInstance.LoadToString ( & SubStatus, ReadBlock, 0, READBLOCK_SIZE ); if ( SubStatus != TextFile :: kStatus_Success ) { * Status = kStatus_Failure_Load; return; } if ( ReadBlock.size () == 0 ) { * Status = kStatus_Failure_InvalidFile; return; } std :: string Line; uint64_t Index = 0; bool EndOfReadBlock = false; while ( ! EndOfReadBlock ) { if ( Index >= ReadBlock.size () ) break; char Charachter = ReadBlock.at ( Index ); while ( Charachter != '\n' ) { Line.push_back ( Charachter ); Index ++; if ( Index >= ReadBlock.size () ) { EndOfReadBlock = true; break; } else Charachter = ReadBlock.at ( Index ); } if ( ! ProcessTextLine ( Line ) ) { * Status = kStatus_Failure_InvalidFile; return; } Line = ""; Index ++; } }
ZtringList Dir::GetAllFileNames(const Ztring &Dir_Name_, dirlist_t Options) { ZtringList ToReturn; Ztring Dir_Name=Dir_Name_; #ifdef ZENLIB_USEWX int Flags=wxDIR_FILES | wxDIR_DIRS; //Search for files wxArrayString Liste; wxFileName FullPath; FullPath=Dir_Name.c_str(); //-File if (FullPath.FileExists()) { FullPath.Normalize(); Liste.Add(FullPath.GetFullPath()); } //-Directory else if (FullPath.DirExists()) { FullPath.Normalize(); wxDir::GetAllFiles(FullPath.GetFullPath(), &Liste, Ztring(), Flags); } //-WildCards else { wxString FileName=FullPath.GetFullName(); FullPath.SetFullName(Ztring()); //Supress filename FullPath.Normalize(); if (FullPath.DirExists()) wxDir::GetAllFiles(FullPath.GetPath(), &Liste, FileName, Flags); } //Compatible array ToReturn.reserve(Liste.GetCount()); for (size_t Pos=0; Pos<Liste.GetCount(); Pos++) ToReturn.push_back(Liste[Pos].c_str()); #else //ZENLIB_USEWX #ifdef WINDOWS //Is a dir? if (Exists(Dir_Name)) Dir_Name+=__T("\\*"); //Path Ztring Path=FileName::Path_Get(Dir_Name); if (Path.empty()) { #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) { DWORD Path_Size=GetFullPathNameA(Dir_Name.To_Local().c_str(), 0, NULL, NULL); char* PathTemp=new char[Path_Size+1]; if (GetFullPathNameA(Dir_Name.To_Local().c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; } else #endif //ZENLIB_NO_WIN9X_SUPPORT { DWORD Path_Size=GetFullPathName(Dir_Name.c_str(), 0, NULL, NULL); Char* PathTemp=new Char[Path_Size+1]; if (GetFullPathNameW(Dir_Name.c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; } #else DWORD Path_Size=GetFullPathName(Dir_Name.c_str(), 0, NULL, NULL); Char* PathTemp=new Char[Path_Size+1]; if (GetFullPathName(Dir_Name.c_str(), Path_Size+1, PathTemp, NULL)) Path=FileName::Path_Get(PathTemp); delete [] PathTemp; //PathTemp=NULL; #endif //UNICODE } #ifdef UNICODE WIN32_FIND_DATAW FindFileDataW; HANDLE hFind; #ifndef ZENLIB_NO_WIN9X_SUPPORT WIN32_FIND_DATAA FindFileDataA; if (IsWin9X_Fast()) hFind=FindFirstFileA(Dir_Name.To_Local().c_str(), &FindFileDataA); else #endif //ZENLIB_NO_WIN9X_SUPPORT hFind=FindFirstFileW(Dir_Name.c_str(), &FindFileDataW); #else WIN32_FIND_DATA FindFileData; HANDLE hFind=FindFirstFile(Dir_Name.c_str(), &FindFileData); #endif //UNICODE if (hFind==INVALID_HANDLE_VALUE) return ZtringList(); BOOL ReturnValue; do { #ifdef UNICODE Ztring File_Name; #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) File_Name=FindFileDataA.cFileName; else #endif //ZENLIB_NO_WIN9X_SUPPORT File_Name=FindFileDataW.cFileName; #else Ztring File_Name(FindFileData.cFileName); #endif //UNICODE if (File_Name!=__T(".") && File_Name!=__T("..")) //Avoid . an .. { Ztring File_Name_Complete=Path+__T("\\")+File_Name; if (Exists(File_Name_Complete)) { if (Options&Parse_SubDirs) ToReturn+=GetAllFileNames(File_Name_Complete, Options); //A SubDir } else if ((Options&Include_Hidden) || (!File_Name.empty() && File_Name[0]!=__T('.'))) ToReturn.push_back(File_Name_Complete); //A file } #ifdef UNICODE #ifndef ZENLIB_NO_WIN9X_SUPPORT if (IsWin9X_Fast()) ReturnValue=FindNextFileA(hFind, &FindFileDataA); else #endif //ZENLIB_NO_WIN9X_SUPPORT ReturnValue=FindNextFileW(hFind, &FindFileDataW); #else ReturnValue=FindNextFile(hFind, &FindFileData); #endif //UNICODE } while (ReturnValue); FindClose(hFind); #else //WINDOWS //A file? if (File::Exists(Dir_Name)) { ToReturn.push_back(Dir_Name); //TODO return ToReturn; } //A dir? if (!Dir::Exists(Dir_Name)) return ToReturn; //Does not exist //open #ifdef UNICODE DIR* Dir=opendir(Dir_Name.To_Local().c_str()); #else DIR* Dir=opendir(Dir_Name.c_str()); #endif //UNICODE if (Dir) { //This is a dir //Normalizing dir (the / at the end) size_t Dir_Pos=Dir_Name.rfind(FileName_PathSeparator); if (Dir_Pos==std::string::npos) Dir_Name+=FileName_PathSeparator; else if (Dir_Pos+Ztring(FileName_PathSeparator).size()!=Dir_Name.size()) Dir_Name+=FileName_PathSeparator; struct dirent *DirEnt; while((DirEnt=readdir(Dir))!=NULL) { //A file Ztring File_Name(DirEnt->d_name); if (File_Name!=__T(".") && File_Name!=__T("..")) //Avoid . an .. { Ztring File_Name_Complete=Dir_Name+File_Name; if (Exists(File_Name_Complete)) { if (Options&Parse_SubDirs) ToReturn+=GetAllFileNames(File_Name_Complete, Options); //A SubDir } else if ((Options&Include_Hidden) || (!File_Name.empty() && File_Name[0]!=__T('.'))) ToReturn.push_back(File_Name_Complete); //A file } } //Close it closedir(Dir); } else { glob_t globbuf; if (glob(Dir_Name.To_Local().c_str(), GLOB_NOSORT, NULL, &globbuf)==0) { for (int Pos=0; Pos<globbuf.gl_pathc; Pos++) ToReturn.push_back(Ztring().From_Local(globbuf.gl_pathv[Pos])); } } #endif #endif //ZENLIB_USEWX return ToReturn; }
/* Generate grid ---------------------------------------------------------------------------------*/ void TableSkin::ThinkGrid( PointList& points, RectList& rects, const Pos &p ) { Tiler tiler( points, rects, p); tiler.SetClipRect( GetClipRect() ); // TOP/LEFT DIVIDERS // BOTTOM/RIGHT DIVIDERS // DIVIDERS int i, n = _x_dividers.Size(); int j, m = _y_dividers.Size(); if ( Exists(BODY+VDIV) ) for( i=1; i<n-1; ++i ) { int begin = (_x_dividers[i-1] + _x_dividers[i])/2; int end = (_x_dividers[i] + _x_dividers[i+1])/2; int shift = _x_dividers[i] - (end+begin-1)/2; Rect top_bound = Rect( begin, _rLU.GetY1(), end-begin, _rLU.GetH() ); Rect mid_bound = Rect( begin, _rLU.GetY2(), end-begin, _rLD.GetY1()-_rLU.GetY2()); Rect btm_bound = Rect( begin, _rLD.GetY1(), end-begin, _rLD.GetH() ); tiler.Orient(VERTICAL); if ( Exists(HEAD+VDIV) ) { IGraphics &g = ImageDicer::GetImage(HEAD+VDIV); tiler.RectCut( g.GetRect(), top_bound, Tiler::HALIGNCENTER|Tiler::VALIGNTOP, shift ); } IGraphics &g = ImageDicer::GetImage(BODY+VDIV); tiler.RectFill1D( g.GetRect(), mid_bound, Tiler::HALIGNCENTER, shift ); if ( Exists(TAIL+VDIV) ) { IGraphics &g = ImageDicer::GetImage(TAIL+VDIV); tiler.RectCut( g.GetRect(), btm_bound, Tiler::HALIGNCENTER|Tiler::VALIGNBOTTOM, shift ); } } if ( Exists(BODY+HDIV) ) for( j=1; j<m-1; ++j ) { int begin = (_y_dividers[j-1] + _y_dividers[j])/2; int end = (_y_dividers[j] + _y_dividers[j+1])/2; int shift = _y_dividers[j] - (end+begin-1)/2; Rect top_bound = Rect( _rLU.GetX1(), begin, _rLU.GetW(), end-begin ); Rect mid_bound = Rect( _rLU.GetX2(), begin, _rRU.GetX1()-_rLU.GetX2(), end-begin); Rect btm_bound = Rect( _rRU.GetX1(), begin, _rRU.GetW(), end-begin ); tiler.Orient(HORIZONTAL); if ( Exists(HEAD+HDIV) ) { IGraphics &g = ImageDicer::GetImage(HEAD+HDIV); tiler.RectCut( g.GetRect(), top_bound, Tiler::VALIGNCENTER|Tiler::HALIGNLEFT, shift ); } IGraphics &g = ImageDicer::GetImage(BODY+HDIV); tiler.RectFill1D( g.GetRect(), mid_bound, Tiler::VALIGNCENTER, shift ); if ( Exists(TAIL+HDIV) ) { IGraphics &g = ImageDicer::GetImage(TAIL+HDIV); tiler.RectCut( g.GetRect(), btm_bound, Tiler::VALIGNCENTER|Tiler::HALIGNRIGHT, shift ); } } if ( Exists(CROSSING) ) { for( i=1; i<n-1; ++i) for( j=1; j<m-1; ++j) { int xb = (_x_dividers[i-1] + _x_dividers[i])/2; int yb = (_y_dividers[j-1] + _y_dividers[j])/2; int xe = (_x_dividers[i+1] + _x_dividers[i])/2; int ye = (_y_dividers[j+1] + _y_dividers[j])/2; int xs = _x_dividers[i] - (xe+xb-1)/2; int ys = _y_dividers[j] - (ye+yb-1)/2; Rect r = Rect( xb, yb, xe-xb, ye-yb ); IGraphics &g = ImageDicer::GetImage(CROSSING); tiler.Orient(VERTICAL); tiler.RectCut( g.GetRect(), r, Tiler::VALIGNCENTER|Tiler::HALIGNCENTER, xs, ys); } } }
bool nglZipPath::CanRead() const { return mpZipFS->CanRead() && Exists(); }
bool slConfig::HasSection( const wxString& strName) const { return Exists( strName ) || ( m_global_config && m_global_config->Exists( strName ) ); }
bool NandTitle::ExistsFromIndex(u32 i) { if (i >= titleIds.size()) return false; return Exists(titleIds.at(i)); }
// check cache for already downloaded url // result TRUE : srcFilePath contains local file, info file info // if checkTime, cache creation time must be >= checkTime // gbool GUrlCache::GetUrl(const char *url,time_t checkTime, CString &srcFilePath,GFileInfo &info) { CString relFilePath,absFilePath; BOOL expiredCheck = TRUE; if ((!readCacheEnabled) && (!readMediaCacheEnabled)) // Laurent - Jan.2000 return FALSE; if (!UrlToFilePath(url,relFilePath)) { return FALSE; } if (!Combine(writeCacheDir,relFilePath,absFilePath)) { return FALSE; } gbool exists= Exists(absFilePath,&info); // hints to not cache if (strstr(url,"/no_cache/")) { return FALSE; } if (strstr(url,"/cgi-bin/")) { return FALSE; } if (!exists) { // check readonly cache for (int i=0; i<readCacheDirs.GetSize(); i++) { CString dir = readCacheDirs.GetAt(i); if (Combine(dir,relFilePath,absFilePath) && (Exists(absFilePath,&info))) { srcFilePath = absFilePath; if (checkTime >0 && info.getLastModifiedTime() <checkTime) // refresg return FALSE; // no expired check if in RO-Cache ! return TRUE; } } return FALSE; } bytesReadFromCache += info.sizeLow; #ifdef _DEBUG time_t t= checkTime; TRACE("URL %s cache checkTime %s \n",url,ctime(&t)); t = info.creationTime; TRACE("cache creationTime %s \n",ctime(&t)); t = info.lastWriteTime; TRACE("cache lastWriteTime %s \n",ctime(&t)); #endif if (checkTime >0 && /*info.creationTime*/ info.getLastModifiedTime() <checkTime) return FALSE; /* // day check alreay in checktime if (expiredCheck && Expired(absFilePath,info)) { return FALSE; } */ srcFilePath = absFilePath; return TRUE; }
void Enemy::Update( Character players[2], int soundTimer, int soundTimer2, float gameTimer, SAMPLE* sndAttack, SAMPLE* sndDamage, int MaxText, TextEffect txteffect[] ) { if ( deadTimer > 0 ) { deadTimer -= 0.1; if ( deadTimer <= 0 ) { Reset(); } } if ( exists ) { collisionRegion.X( position.x + 5 ); collisionRegion.Y( position.y + 5 ); collisionRegion.W( 24 ); collisionRegion.H( 24 ); if ( atkCounter > 0 ) { atkCounter -= 0.5; } else { atkCounter = -1; action = WALKING; } for ( int p = 0; p < 2; p++ ) { if ( Exists() == true && players[p].Exists() && IsCollision( &players[p] ) ) { if ( players[p].Is() == ATTACKING ) { if ( soundTimer <= 0 ) { play_sample( sndAttack, 255, 128, 1000, false ); soundTimer = 5.0; ChangeHP( players[p].StrengthFloat() ); if ( hp <= 0 ) { players[p].Exp( Exp() ); } bool foundText = false; //Setup fancy text crap for ( int j=0; j<MaxText; j++ ) { if ( foundText == false ) { if ( txteffect[j].inUse == false ) { txteffect[j].Setup( players[p].StrengthString().c_str(), X()+3, Y(), 255, 100, 75 ); foundText = true; } } } } }//attacking //enemy attack if ( soundTimer2 <= 0 && gameTimer > 20 ) { play_sample( sndDamage, 255, 128, 1000, false ); soundTimer2 = 10.0; players[p].AddHP( -0.1 ); bool foundText = false; //Setup fancy text crap for ( int j=0; j<MaxText; j++ ) { if ( foundText == false ) { if ( txteffect[j].inUse == false ) { txteffect[j].Setup( "-2", players[p].X()+3, players[p].Y(), 255, 0, 0 ); foundText = true; } } } }//not attacking }//if ( enemy[i].Exists() == true && IsCollision( &player, &enemy[i] ) ) } if ( hp <= 0 ) { exists = false; SetDeadTimer(); } } }
// save downloaded url to cache gbool GUrlCache::SaveUrl(const char *url,const CString &srcFilePath,time_t creationTime,CString &cacheFileName) { CString relFilePath,absFilePath; GFileInfo info; CString selectedCacheDirectory; selectedCacheDirectory = writeCacheDir; int urlStrip= 0; if (writeMediaCacheEnabled && writeMediaCacheDirValid) { // Check if file to cache is from recognized Media Library mirror site. // If so, cache it in Media Library directory instead of regular cache directory if (strprefix(url,mirror1)) { selectedCacheDirectory = writeMediaCacheDir; urlStrip=strlen(mirror1); } else if (strprefix(url,mirror2)) { selectedCacheDirectory = writeMediaCacheDir; urlStrip=strlen(mirror2); } else if (strprefix(url,mirror3)) { selectedCacheDirectory = writeMediaCacheDir; urlStrip=strlen(mirror3); } else if (strprefix(url,mirror4)) { selectedCacheDirectory = writeMediaCacheDir; urlStrip=strlen(mirror4); } } if ((urlStrip == 0) && (!writeCacheEnabled) ) return FALSE; if (!UrlToFilePath(url+urlStrip,relFilePath)) { return FALSE; } if (!CombineCreateDirectory(selectedCacheDirectory,relFilePath,absFilePath)) { return FALSE; } // end Laurent - Jan.2000 cacheFileName = absFilePath; if (!CopyFile(srcFilePath,absFilePath,FALSE,creationTime)) { DWORD lastErr = GetLastError(); if ( (lastErr ==ERROR_NOT_ENOUGH_MEMORY || lastErr == ERROR_OUTOFMEMORY ) && (!cleanerBusy) ) { TRACE("GurlCache::Was out of disk space try cleaning \n"); CheckCache(); // try to make space if (!CopyFile(srcFilePath,absFilePath,FALSE,creationTime)) // retry return FALSE; } else return FALSE; } if (creationTime>0) // store the URL lastModified date for once per session comparison SetUrlModified(url,creationTime); if (Exists(absFilePath,&info)) { bytesWrittenToCache += info.sizeLow; return TRUE; } else return FALSE; }
bool Exists( const std::string &path ) { return Exists( path.c_str() ); }
bool Delete(const iStringT& fname) { if ( !Exists(fname) ) return true; return ::DeleteFileW(fname.CStr()) ? true : false; }