Aperture UI
Integration

File system

How pages read and write files through IAPCFileSystem. Roots, containment, packed assets, fonts and localStorage.

Every file a page asks for goes through one interface, aperture::core::IAPCFileSystem. The stock class reads from disk. A title that packs its content into an archive subclasses it. This page covers what the stock class does, what a subclass takes over, and the files the engine writes.

What goes through it

  • The page's stylesheets, scripts, images, SVG, Lottie JSON and fonts, whether a tag, @font-face, @import or url() asks for them.
  • localStorage, which the engine saves as a file (see localStorage).
  • The font engine's search for the bundled fallback fonts (see Fonts).
  • The top-level document that you name with loadHtmlFromFile. The engine reads it with GetFileDataTrusted, which a subclass cannot override. See Packed content.

http:// and https:// addresses do not use it. They go to the network provider you install, or fail when there is none. See Your own C++ host.

The stock class

std::string root = "C:/Games/MyGame/";  // keep this string alive: the class stores the pointer
aperture::core::IAPCFileSystem fileSystem(root.c_str());
aperture::core::IAPCPlatform::GetEnginePlatform()->SetFileSystem(&fileSystem);

The constructor takes the UI resources root and keeps the const char* you give it. It does not copy the string. SetUIResourcesPath changes it later. A relative path resolves against this root, so loadHtmlFromFile("ui/index.html") reads C:/Games/MyGame/ui/index.html. With no root, a relative path resolves against the working directory. The same root decides where V8's resources/ folder is: see Your first view.

Containment

A path that comes from page content must stay inside a permitted root. The engine blocks anything else, returns an empty buffer and logs "Blocked sandbox escape". This holds in every build configuration. The current Unreal plugin also validates its overridden reads with ResolveSandboxedPath before passing them to Unreal's file API. See Unreal Engine. . and .. segments are collapsed before the comparison, and a sibling folder that merely starts with the root's name does not pass. The permitted roots are:

RootSet by
The UI resources rootThe constructor, or SetUIResourcesPath
The loaded document's folderThe engine, when you call loadHtmlFromFile (SetHostDocumentDirectory)
Folders your host trustsAddTrustedRoot(dir), RemoveTrustedRoot(dir) and ClearTrustedRoots()
One folder trusted for the current documentSetDocumentTrustedRoot(dir). Each document replaces the previous one's folder.

SetDocumentTrustedRoot returns false and trusts nothing for a folder that is too broad to vouch for: a drive, filesystem or network-share root, the user's profile folder, or a folder above it. IsTooBroadToTrust tells you in advance. A host that really wants such a folder says so with AddTrustedRoot. APPlayer, which is in the source tree, calls SetDocumentTrustedRoot with the folder above the document and AddTrustedRoot for each --content-root.

With no root of any kind configured there is nothing to contain against, and every path is allowed. A host that renders content it does not control must set a root.

What is contained:

CallContained?
GetFileData, RequestCreateFile, GetRawFileHandle (Windows)Yes
FileExists, DirectoryExists, EnumerateFilesNo. They answer "does this exist", never "here are the bytes", and the font search needs them to look outside the root.
GetFileDataTrustedNo. Its callers are the document you named and engine files at fixed locations.

Packed content

Subclass IAPCFileSystem and override what your archive provides. These are the virtual functions:

FunctionUsed for
GetFileData(path, type)Reading a file. Page content reaches the engine through this.
FileExists(path), DirectoryExists(path), EnumerateFiles(...)Existence checks and directory listings.
RequestCreateFile(path, data, type)Writing a file. localStorage uses it.
GetFileMimeType(path)The MIME type of a file. The base class looks at the extension only and returns "BAD-MIME" for one that is not in its table (HTML, XML, CSS, JavaScript, PNG, JPEG, GIF, WebP, SVG, ICO, JSON, PDF and a few archive types).
GetFullFilePath(path)Joins a relative path to the root.
GetApplicationDirectory()Where the executable lives. The font search starts here.
FileCharset(path)The charset of a file. The base class detects it from the bytes.
class ArchiveFileSystem : public aperture::core::IAPCFileSystem
{
public:
    explicit ArchiveFileSystem(Archive& archive)
        : IAPCFileSystem(""), m_archive(archive) { }

    nsDataBuffer GetFileData(const char* path, EFileType type = EFileType::OSDependant) override
    {
        nsDataBuffer data;
        if (m_archive.IsUiContent(path))   // your containment: the base class's check is skipped
            m_archive.Read(path, data);
        return data;
    }

    bool FileExists(const nsString& path) override { return m_archive.Exists(path.GetData()); }

private:
    Archive& m_archive;
};

An override replaces the base class's containment along with its reads. Enforcing the boundary between page content and the rest of your archive is your job. A subclass can call the protected ResolveSandboxedPath to reuse the base class's rule for paths on disk.

Two limits of the base class apply to a subclass in this SDK version. They are described in Project structure: loadHtmlFromFile reads the document itself from disk through the non-virtual GetFileDataTrusted, and the destructor of IAPCFileSystem is not virtual, so own your subclass through its own type.

SetFileSystem takes a raw pointer, and the platform does not own the object.

Fonts

The engine looks for the bundled fallback fonts, with IBMPlexSans-Regular.ttf as the marker file, in this order:

  1. Base/Fonts under the UI resources root.
  2. Base/Fonts under the folder that you give to FontEngineBridge::SetFontDataPath.
  3. Relative to GetApplicationDirectory(): Data/Base/Fonts, then the same path one, two and three levels up, then Base/Fonts.

The package's data/Base/Fonts is what it finds when data/ sits beside your executable. If your layout is different, call FontEngineBridge::SetFontDataPath with the folder that contains Base/Fonts (the header needs the LINAVG_DISABLE_TEXT_SUPPORT definition from Requirements), or override GetApplicationDirectory() (the Unreal plugin returns its staged data folder). The font engine finds the files with FileExists and then reads them from disk, so keep the bundled fonts as real files even when the rest of your content is packed. The Windows system fonts that the engine registers are read with the non-virtual GetFileDataTrusted. Fonts that a page loads with @font-face come through GetFileData like any other subresource. Without a file system there is no font search, and every string lays out empty.

localStorage

localStorage persists through this interface. The engine keeps one store per origin and saves it with RequestCreateFile, using a bare file name:

  • apui_localstorage.dat for local documents. All of them share one store, the way file:// pages do in Chrome.
  • apui_localstorage_<hash>.dat for each http:// or https:// origin.

With the stock class a bare name lands in the UI resources root, so that folder must be writable. The engine reads the file back through GetFileDataTrusted, which is not virtual, from the same root. A subclass that redirects the write elsewhere, to a save folder for example, therefore loses the data at the next start unless the read finds it too. sessionStorage is never written to disk. Keep game saves, settings and profile data in your own save system, and use localStorage for interface preferences like the last open tab.

On this page