Legacy Reference

Modifying Paks With CryArchive

This section contains a short example that shows how files are added, updated and removed from an archive. The example intentionally uses the USER folder instead of the GameSDK folder because the .pak files inside the GameSDK folder are loaded by default at startup and therefore are marked as Read-Only. (Files in the USER folder are not loaded by default at startup.)

string pakFilename = PathUtil::AddSlash("@USER@") + "Examples.pak"; const char* filename = "Examples/ExampleText.txt"; char* text = "File has been modified by CryArchive"; unsigned length = strlen(text); _smart_ptr<ICryArchive> pCryArchive = gEnv->pCryPak->OpenArchive(pakFilename.c_str(), ICryArchive::FLAGS_RELATIVE_PATHS_ONLY | ICryArchive::FLAGS_CREATE_NEW); if (pCryArchive) { pCryArchive->UpdateFile(filename, text, length, ICryArchive::METHOD_STORE, 0); }
  • UpdateFile() - Modifies an existing file inside the .pak archive or creates a new one if it does not exist.

  • ICryArchive::FLAGS_CREATE_NEW - Forces a new .pak file to be created. If you want to add (append) files, remove this flag.

  • To remove files or folders from an archive, use one of the following commands in place of UpdateFile(): RemoveFile(), RemoveDir() or RemoveAll().