Skip to content

File Providers

Valentin edited this page Jul 8, 2023 · 13 revisions

Introduction

File providers are essential components within CUE4Parse that facilitate convenient access to game directories, reading of archives and packages, and provide developers with a range of methods to efficiently manipulate and work with this data efficiently. CUE4Parse offers three built-in providers and two additional options for custom implementation.


Default 🪲

The default file provider is a pre-configured file provider designed for accessing archives within a local directory.

var provider = new DefaultFileProvider(
    directory: "D:\\Games\\PC\\XXXXXXX\\XXXXXXX\\Content\\Paks",
    searchOption: SearchOption.TopDirectoryOnly,
    isCaseInsensitive: true,
    versions: new VersionContainer(EGame.GAME_UE4_LATEST));

Additionally, you can specify multiple directories to include archives that may be remotely written in %localappdata% for example.

var provider = new DefaultFileProvider(
    directory: new DirectoryInfo("D:\\Games\\PC\\XXXXXXX\\XXXXXXX\\Content\\Paks"),
    extraDirectories: new DirectoryInfo[]
    {
        new(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\XXXXXXX\\Saved\\Paks"),
        new(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\XXXXXXX\\Saved\\DisabledPaks")
    },
    searchOption: SearchOption.TopDirectoryOnly,
    isCaseInsensitive: true,
    versions: new VersionContainer(EGame.GAME_UE4_LATEST));

APK 🪲

The APK file provider is another pre-configured file provider designed for parsing APK files and retrieving archives within them.

var provider = new ApkFileProvider(
    file: "D:\\Games\\Android\\XXXXXXX.apk",
    isCaseInsensitive: true,
    versions: new VersionContainer(EGame.GAME_UE4_LATEST));

Streamed 🪲

The streamed file provider is a built-in file provider specifically designed for accessing archives within a remote directory, a manifest file, or any data source that provides stream access to these archives, while offering flexibility in handling different project requirements. Thus, the provider does not automatically register archives, you need to manually do so using the provider.RegisterVfs method, so that the provider can access and work with the packages contained within them.

var provider = new StreamedFileProvider(
    liveGame: "XXXXXXX",    // can be useful in some cases
    isCaseInsensitive: true,
    versions: new VersionContainer(EGame.GAME_UE4_LATEST));

foreach (var archive in manifestInfo.Archives)
{
    provider.RegisterVfs(
        file: archive.GetFullName(),
        stream: new[] { archive.GetStream() });
}

Abstract 🪲

TODO

Interface 🪲

TODO


To ensure the proper initialization of all providers (except for the streamed provider), it is recommended to invoke the provider.Initialize method. This approach allows developers to have control over when the scanning of archives occurs, rather than performing it within a constructor. Once the initialization process is complete, the resulting archives can be accessed through the provider.UnloadedVfs field and can be mounted as needed. It is worth noting that both the default and APK file providers have the capability to load external packages as long as they are located within the specified directory or APK file.

Please note that the provided examples utilize an arbitrary version container. It is important to set up the versioning settings according to your specific requirements to ensure proper parsing of archives and packages. For more information about versioning settings, please refer to the documentation here.

Please refer to the respective source code files linked above (🪲) for more detailed information and implementation specifics.