예제 #1
0
	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);
	}
예제 #2
0
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();
	}
}
예제 #3
0
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);
}
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;
}
예제 #5
0
void frmExtract::onExtract(wxCommandEvent &e)
{
  if(m_bIsDirectory)
  {
    RainString sFolder = m_pDestinationPath->GetValue();
    if(!_ensureDirectoryExists(sFolder))
        return;

    wxSizer *pMainSizer = GetSizer();
    if(m_pButtonsSizer)
    {
      FindWindow(wxID_OK)->Hide();
      FindWindow(wxID_CANCEL)->Hide();
      pMainSizer->Detach(m_pButtonsSizer);
    }
    pMainSizer->Add(new wxStaticLine(this), 0, wxEXPAND | wxALL, 4);
    wxGauge *pProgressBar = new wxGauge(this, wxID_ANY, 1, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL | wxGA_SMOOTH);
    wxStaticText *pCurrentItem = new wxStaticText(this, wxID_ANY, L"Initialising extraction...");
    pMainSizer->Add(pProgressBar, 0, wxEXPAND | wxALL, 2);
    pMainSizer->Add(pCurrentItem, 0, wxEXPAND | wxALL, 2);
    pMainSizer->RecalcSizes();
    SetSize(pMainSizer->GetMinSize());
    Layout();
    ::wxSafeYield(this);

    int iTotalCount = 1, iDoneCount = 0;
    std::queue<IDirectory*> qTodo;
    try
    {
      qTodo.push(m_pArchive->openDirectory(m_sPathToExtract));
      iTotalCount += static_cast<int>(qTodo.front()->getItemCount());
      size_t iSkipLength = qTodo.front()->getPath().length();
      pProgressBar->SetRange(iTotalCount);
      while(!qTodo.empty())
      {
        IDirectory *pDirectory = qTodo.front();
        pCurrentItem->SetLabel(pDirectory->getPath());
        pProgressBar->SetValue(++iDoneCount);
        ::wxSafeYield(this);

        RainString sDirectoryBase = pDirectory->getPath();
        sDirectoryBase = sFolder + sDirectoryBase.mid(iSkipLength, sDirectoryBase.length() - iSkipLength);
        if(!RainDoesDirectoryExist(sDirectoryBase))
          RainCreateDirectory(sDirectoryBase);
        for(IDirectory::iterator itr = pDirectory->begin(), itrEnd = pDirectory->end(); itr != itrEnd; ++itr)
        {
          if(itr->isDirectory())
          {
            IDirectory *pChild = itr->open();
            iTotalCount += 1 + static_cast<int>(pChild->getItemCount());
            qTodo.push(pChild);
            pProgressBar->SetRange(iTotalCount);
          }
          else
          {
            std::auto_ptr<IFile> pFile;
            pCurrentItem->SetLabel(pDirectory->getPath() + itr->name());
            pProgressBar->SetValue(++iDoneCount);
            ::wxSafeYield(this);
            pFile.reset(RainOpenFile(sDirectoryBase + itr->name(), FM_Write));
            itr->pump(&*pFile);
          }
        }

        delete pDirectory;
        qTodo.pop();
      }
    }
    catch(RainException *pE)
    {
      while(!qTodo.empty())
      {
        delete qTodo.front();
        qTodo.pop();
      }
      EXCEPTION_MESSAGE_BOX_1(L"Error extracting directory \'%s\'", m_sPathToExtract.getCharacters(), pE);
      SetReturnCode(GetEscapeId());
      return;
    }
  }
  else
  {
    wxFileName oFilename(m_pDestinationPath->GetValue());
    RainString sFolder = oFilename.GetPath();
    IFile *pFile = 0;
    try
    {
      if(!_ensureDirectoryExists(sFolder))
        return;
      pFile = RainOpenFile(m_pDestinationPath->GetValue(), FM_Write);
      m_pArchive->pumpFile(m_sPathToExtract, pFile);
    }
    catch(RainException *pE)
    {
      delete pFile;
      EXCEPTION_MESSAGE_BOX_1(L"Error extracting \'%s\'", m_sPathToExtract.getCharacters(), pE);
      return;
    }
    delete pFile;
  }
  wxString sMessage = L"Extracted " + m_sPathToExtract;
  if(m_pPositiveResultNoficiationBar)
    m_pPositiveResultNoficiationBar->SetStatusText(sMessage);
  else
    ::wxMessageBox(sMessage, GetLabel(), wxOK | wxCENTER | wxICON_INFORMATION, this);
  EndModal(GetAffirmativeId());
}
예제 #6
0
	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;
	}