void RunThread(IThreadHandle *pHandle) { rootconsole->ConsolePrint("Accelerator upload thread started."); FILE *log = fopen(logPath, "a"); if (!log) { g_pSM->LogError(myself, "Failed to open Accelerator log file: %s", logPath); } IDirectory *dumps = libsys->OpenDirectory(dumpStoragePath); int count = 0; int failed = 0; char path[512]; char response[512]; while (dumps->MoreFiles()) { if (!dumps->IsEntryFile()) { dumps->NextEntry(); continue; } const char *name = dumps->GetEntryName(); int namelen = strlen(name); if (namelen < 4 || strcmp(&name[namelen-4], ".dmp") != 0) { dumps->NextEntry(); continue; } g_pSM->Format(path, sizeof(path), "%s/%s", dumpStoragePath, name); bool uploaded = UploadAndDeleteCrashDump(path, response, sizeof(response)); if (uploaded) { count++; g_pSM->LogError(myself, "Accelerator uploaded crash dump: %s", response); if (log) fprintf(log, "Uploaded crash dump: %s\n", response); } else { failed++; g_pSM->LogError(myself, "Accelerator failed to upload crash dump: %s", response); if (log) fprintf(log, "Failed to upload crash dump: %s\n", response); } dumps->NextEntry(); } libsys->CloseDirectory(dumps); if (log) { fclose(log); } rootconsole->ConsolePrint("Accelerator upload thread finished. (%d uploaded, %d failed)", count, failed); }
void CExtensionManager::TryAutoload() { char path[PLATFORM_MAX_PATH]; g_pSM->BuildPath(Path_SM, path, sizeof(path), "extensions"); IDirectory *pDir = libsys->OpenDirectory(path); if (!pDir) { return; } const char *lfile; size_t len; while (pDir->MoreFiles()) { if (pDir->IsEntryDirectory()) { pDir->NextEntry(); continue; } lfile = pDir->GetEntryName(); len = strlen(lfile); if (len <= 9) /* size of ".autoload" */ { pDir->NextEntry(); continue; } if (strcmp(&lfile[len - 9], ".autoload") != 0) { pDir->NextEntry(); continue; } char file[PLATFORM_MAX_PATH]; len = smcore.Format(file, sizeof(file), "%s", lfile); strcpy(&file[len - 9], ".ext"); LoadAutoExtension(file); pDir->NextEntry(); } }
static cell_t sm_ReadDirEntry(IPluginContext *pContext, const cell_t *params) { Handle_t hndl = static_cast<Handle_t>(params[1]); IDirectory *pDir; HandleError herr; HandleSecurity sec; int err; sec.pOwner = NULL; sec.pIdentity = g_pCoreIdent; if ((herr=g_HandleSys.ReadHandle(hndl, g_DirType, &sec, (void **)&pDir)) != HandleError_None) { return pContext->ThrowNativeError("Invalid file handle %x (error %d)", hndl, herr); } if (!pDir->MoreFiles()) { return false; } cell_t *filetype; if ((err=pContext->LocalToPhysAddr(params[4], &filetype)) != SP_ERROR_NONE) { pContext->ThrowNativeErrorEx(err, NULL); return 0; } if (pDir->IsEntryDirectory()) { *filetype = 1; } else if (pDir->IsEntryFile()) { *filetype = 2; } else { *filetype = 0; } const char *path = pDir->GetEntryName(); if ((err=pContext->StringToLocalUTF8(params[2], params[3], path, NULL)) != SP_ERROR_NONE) { pContext->ThrowNativeErrorEx(err, NULL); return 0; } pDir->NextEntry(); return true; }
static void add_folders(IWebForm *form, const char *root, unsigned int &num_files) { IDirectory *dir; char path[PLATFORM_MAX_PATH]; char name[PLATFORM_MAX_PATH]; smutils->BuildPath(Path_SM, path, sizeof(path), "%s", root); dir = libsys->OpenDirectory(path); if (dir == NULL) { AddUpdateError("Could not open folder: %s", path); return; } while (dir->MoreFiles()) { if (strcmp(dir->GetEntryName(), ".") == 0 || strcmp(dir->GetEntryName(), "..") == 0) { dir->NextEntry(); continue; } smutils->Format(name, sizeof(name), "%s/%s", root, dir->GetEntryName()); if (dir->IsEntryDirectory()) { add_folders(form, name, num_files); } else if (dir->IsEntryFile()) { add_file(form, name, num_files); } dir->NextEntry(); } libsys->CloseDirectory(dir); }
CellArray *UpdateMapList(CellArray *pUseArray, const char *name, int *pSerial, unsigned int flags) { int change_serial; CellArray *pNewArray = NULL; bool success, free_new_array; free_new_array = false; if ((success = GetMapList(&pNewArray, name, &change_serial)) == false) { if ((flags & MAPLIST_FLAG_NO_DEFAULT) != MAPLIST_FLAG_NO_DEFAULT) { /* If this list failed, and it's not the default, try the default. */ if (strcmp(name, "default") != 0) { success = GetMapList(&pNewArray, name, &change_serial); } /* If either of the last two conditions failed, try again if we can. */ if (!success && strcmp(name, "mapcyclefile") != 0) { success = GetMapList(&pNewArray, "mapcyclefile", &change_serial); } } } /* If there was a success, and the serial has not changed, bail out. */ if (success && *pSerial == change_serial) { return NULL; } /** * If there was a success but no map list, we need to look in the maps folder. * If there was a failure and the flag is specified, we need to look in the maps folder. */ if ((success && pNewArray == NULL) || (!success && ((flags & MAPLIST_FLAG_MAPSFOLDER) == MAPLIST_FLAG_MAPSFOLDER))) { char path[255]; IDirectory *pDir; pNewArray = new CellArray(64); free_new_array = true; g_SourceMod.BuildPath(Path_Game, path, sizeof(path), "maps"); if ((pDir = g_LibSys.OpenDirectory(path)) != NULL) { char *ptr; cell_t *blk; char buffer[PLATFORM_MAX_PATH]; while (pDir->MoreFiles()) { if (!pDir->IsEntryFile() || strcmp(pDir->GetEntryName(), ".") == 0 || strcmp(pDir->GetEntryName(), "..") == 0) { pDir->NextEntry(); continue; } strncopy(buffer, pDir->GetEntryName(), sizeof(buffer)); if ((ptr = strstr(buffer, ".bsp")) == NULL || ptr[4] != '\0') { pDir->NextEntry(); continue; } *ptr = '\0'; if (!engine->IsMapValid(buffer)) { pDir->NextEntry(); continue; } if ((blk = pNewArray->push()) == NULL) { pDir->NextEntry(); continue; } strncopy((char *)blk, buffer, 255); pDir->NextEntry(); } g_LibSys.CloseDirectory(pDir); } /* Remove the array if there were no items. */ if (pNewArray->size() == 0) { delete pNewArray; pNewArray = NULL; } else { qsort(pNewArray->base(), pNewArray->size(), pNewArray->blocksize() * sizeof(cell_t), sort_maps_in_adt_array); } change_serial = -1; } /* If there is still no array by this point, bail out. */ if (pNewArray == NULL) { *pSerial = -1; return NULL; } *pSerial = change_serial; /* If there is no input array, return something temporary. */ if (pUseArray == NULL) { if (free_new_array) { return pNewArray; } else { return pNewArray->clone(); } } /* Clear the input array if necessary. */ if ((flags & MAPLIST_FLAG_CLEARARRAY) == MAPLIST_FLAG_CLEARARRAY) { pUseArray->clear(); } /* Copy. */ cell_t *blk_dst; cell_t *blk_src; for (size_t i = 0; i < pNewArray->size(); i++) { blk_dst = pUseArray->push(); blk_src = pNewArray->at(i); strncopy((char *)blk_dst, (char *)blk_src, pUseArray->blocksize() * sizeof(cell_t)); } /* Free resources if necessary. */ if (free_new_array) { delete pNewArray; } /* Return the array we were given. */ return pUseArray; }