bool CCallsignList::LoadFromFile(const char *filename) { bool ok = false; char sz[256]; // and load std::ifstream file (filename); if ( file.is_open() ) { Lock(); // empty list clear(); // fill with file content while ( file.getline(sz, sizeof(sz)).good() ) { // remove leading & trailing spaces char *szt = TrimWhiteSpaces(sz); // and load if not comment if ( (::strlen(szt) > 0) && (szt[0] != '#') ) { push_back(CCallsignListItem(CCallsign(szt), CIp(), NULL)); } } // close file file.close(); // keep file path m_Filename = filename; // update time GetLastModTime(&m_LastModTime); // and done Unlock(); ok = true; std::cout << "Gatekeeper loaded " << size() << " lines from " << filename << std::endl; } else { std::cout << "Gatekeeper cannot find " << filename << std::endl; } return ok; }
bool CCallsignList::NeedReload(void) { bool needReload = false; time_t time; if ( GetLastModTime(&time) ) { needReload = time != m_LastModTime; } return needReload; }
static int HandleResourceExistsEvent(uintptr_t p) { char resPath[MAXPATH + 17]; ResManExistsEvent *exists = reinterpret_cast<ResManExistsEvent*>(p); const char *ext = strchr(exists->resRefWithExt, '.'); if (!ext) { return 0; } ++ext; snprintf(resPath, MAXPATH, "%s/%s/%s", resman.GetSourcePath(), ext, exists->resRefWithExt); time_t modtime = GetLastModTime(resPath); if (modtime == -1) { return 0; } exists->exists = true; exists->mtime = std::max(exists->mtime, modtime); return 0; }
static int HandleDemandResourceEvent(uintptr_t p) { char resPath[MAXPATH + 17]; ResManDemandEvent *event = reinterpret_cast<ResManDemandEvent*>(p); const char *ext = strchr(event->resRefWithExt, '.'); if (!ext) { return 0; } ++ext; snprintf(resPath, MAXPATH, "%s/%s/%s", resman.GetSourcePath(), ext, event->resRefWithExt); time_t modtime = GetLastModTime(resPath); if (modtime == -1 || event->minimum_mtime > modtime) { return 0; } FILE *pTemp = fopen(resPath, "rb"); if (pTemp == NULL) { resman.Log(3, "o Skip - Unable to open file: %s\n", resPath); return 0; } fseek(pTemp, 0, SEEK_END); unsigned long size = ftell(pTemp); fseek(pTemp, 0, SEEK_SET); char *pScriptBuffer = new char[size]; if (fread(pScriptBuffer, size, 1, pTemp) != 1) { resman.Log(3, "o Skip - Error reading file: %s\n", resPath); delete[] pScriptBuffer; pScriptBuffer = NULL; } fclose(pTemp); if (pScriptBuffer) { event->mtime = modtime; event->pData = (unsigned char*)pScriptBuffer; event->size = size; return 1; } return 0; }