FILE *ps2_fopen(const char *fname, const char *mode) { if (cacheListSema == -1) { ee_sema_t newSema; newSema.init_count = 1; newSema.max_count = 1; cacheListSema = CreateSema(&newSema); assert(cacheListSema >= 0); } printf("ps2_fopen: %s, %s\n", fname, mode); if (!checkedPath && g_engine) { // are we playing from cd/dvd? const char *gameDataPath = ConfMan.get("path").c_str(); printf("Read TOC dir: %s\n", gameDataPath); if (strncmp(gameDataPath, "cdfs:", 5) != 0) driveStop(); // no, we aren't. stop the drive. it's noisy. // now cache the dir tree tocManager.readEntries(gameDataPath); checkedPath = true; } if (((mode[0] != 'r') && (mode[0] != 'w')) || ((mode[1] != '\0') && (mode[1] != 'b'))) { printf("unsupported mode \"%s\" for file \"%s\"\n", mode, fname); return NULL; } bool rdOnly = (mode[0] == 'r'); int64 cacheId = -1; if (rdOnly && tocManager.haveEntries()) cacheId = tocManager.fileExists(fname); if (cacheId != 0) { Ps2File *file = findInCache(cacheId); if (file) return (FILE*)file; if (rdOnly) { bool isAudioFile = strstr(fname, ".bun") || strstr(fname, ".BUN") || strstr(fname, ".Bun"); file = new Ps2ReadFile(cacheId, isAudioFile); } else file = new Ps2WriteFile(cacheId); if (file->open(fname)) { openFileCount++; return (FILE*)file; } else delete file; } return NULL; }
VcsInfo *findUpInCache(const QString &directory) { VcsInfo *result = 0; const QChar slash = QLatin1Char('/'); // Split the path, trying to find the matching repository. We start from the reverse // in order to detected nested repositories correctly (say, a git checkout under SVN). for (int pos = directory.size() - 1; pos >= 0; pos = directory.lastIndexOf(slash, pos) - 1) { const QString directoryPart = directory.left(pos); result = findInCache(directoryPart); if (result != 0) break; } return result; }
int FXManager::putInCache(const String& filename, Gaf::Animation* anm) { // Already available in the cache ? const int is_in = findInCache(filename); if (is_in >= 0) return is_in; int idx = -1; if (cache_size + 1 > max_cache_size) { max_cache_size += 100; cache_name.resize(max_cache_size); Gaf::Animation** n_anm = new Gaf::Animation*[max_cache_size]; int *n_use = new int[max_cache_size]; for (int i = max_cache_size - 100; i < max_cache_size; ++i) { n_use[i] = 0; n_anm[i] = NULL; } if (cache_size > 0) { for(int i = 0; i < max_cache_size - 100; ++i) { n_anm[i] = cache_anm[i]; n_use[i] = use[i]; } delete[] cache_anm; delete[] use; } use=n_use; cache_anm=n_anm; idx=cache_size; } else { idx = 0; for(int i = 0; i < max_cache_size; ++i) { if(cache_anm[i]==NULL) idx=i; } } use[idx] = 1; cache_anm[idx] = anm; cache_name[idx] = filename; ++cache_size; return idx; }
void CCCSHandler::writeAMBE(CAMBEData& data, const wxString& dtmf) { if (m_state != CS_CONNECTED && m_state != CS_ACTIVE) return; if (m_state == CS_CONNECTED) { if (!dtmf.Left(1U).IsSameAs(wxT("*"))) return; wxString callsign = findInCache(dtmf.Mid(1U)); if (!callsign.IsEmpty()) { wxLogMessage(wxT("CCS: New outgoing link to %s/%s from %s"), dtmf.Mid(1U).c_str(), callsign.c_str(), m_myCall1.c_str()); m_handler->ccsLinkMade(callsign); m_yourCall = callsign; } else { wxLogMessage(wxT("CCS: New outgoing link to %s from %s"), dtmf.Mid(1U).c_str(), m_myCall1.c_str()); m_yourCall = dtmf; } m_local = m_myCall1; m_seqNo = 0U; m_time = ::time(NULL); m_stateChange = true; m_state = CS_ACTIVE; m_direction = DIR_OUTGOING; m_inactivityTimer.start(); } CAMBEData temp(data); CHeaderData& header = temp.getHeader(); header.setMyCall1(m_myCall1); header.setMyCall2(m_myCall2); header.setYourCall(m_yourCall); header.setRptCall1(m_callsign); header.setRptCall2(m_reflector); temp.setRptSeq(m_seqNo++); temp.setDestination(m_ccsAddress, CCS_PORT); m_protocol.writeData(temp); }
int playOgg(char* name) { int ret; Sound* s = findInCache(name); if (!s) { s = loadSound(name); if (s) { addToCache(s); cacheSize++; if (cacheSize > MAX_CACHE_SIZE) { deleteOldest(); cacheSize--; } } else return -1; } s->lastPlayedTime = currentTimeMillis(); return playSound(s); }