API FileHelpers - shmellyorc/Box GitHub Wiki

File Helpers

Namespace: Box.Helpers

Description: A static utility class offering common file-related operations for the engine, including locating the application content root, accessing platform-specific application data paths, ensuring directories exist, retrieving file sizes, constructing save file paths, checking file existence in content or save folders, detecting file locks, and waiting for files to become available during I/O operations. These helpers centralize filesystem concerns and streamline asset and save management.


Constructors

This is a static class; there are no public constructors.


Properties

No public properties.


Methods

Method Signature Returns Description
GetApplicationContentPath static string GetApplicationContentPath() string Returns the root folder path for application content, handling macOS app bundles if necessary.
GetApplicationDataPath static string GetApplicationDataPath() string Returns the OS-specific application data folder path, optionally scoped to the app name.
EnsureDirectoryExists static void EnsureDirectoryExists(string path) void Creates the directory for the given path if it does not exist; throws if the path is invalid.
GetFileSize static long GetFileSize(string filename) long Returns file size in bytes, or 0 if the file does not exist.
SaveFilePath static string SaveFilePath(string filename) string Combines the engine's save folder path with the given filename.
SaveFileExists static bool SaveFileExists(string filename) bool Checks for the existence of a file in the save folder.
AssetFileExists static bool AssetFileExists(string filename) bool Checks if a matching content file exists in the application content path.
IsFileLocked static bool IsFileLocked(string filename) bool Returns true if the file is locked by another process (or false if missing or accessible).
WaitUntilFileUnlocked static IEnumerator WaitUntilFileUnlocked(string filename, float timeout = 0f) IEnumerator Yields until the file is unlocked or the optional timeout is reached.

Examples

// Get where game assets are packaged
string contentRoot = FileHelpers.GetApplicationContentPath();

// Ensure save directory exists before writing
FileHelpers.EnsureDirectoryExists("C:/Game/Saves");

// Save a file
string savePath = FileHelpers.SaveFilePath("settings.json");
File.WriteAllText(savePath, jsonData);

// Wait for an external process to finish writing
yield return FileHelpers.WaitUntilFileUnlocked("export.tmp", 5f);
LoadExportedData();