Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New bundle system support #37

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions src/Overrides/BundleLoaderOverride.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from "node:path";
import { BundleHashCacheService } from "@spt-aki/services/cache/BundleHashCacheService";
import { BundleLoader } from "@spt-aki/loaders/BundleLoader";
import { JsonUtil } from "@spt-aki/utils/JsonUtil";
import { VFS } from "@spt-aki/utils/VFS";
Expand All @@ -11,13 +13,12 @@ class BundleInfo
filepath: string;
dependencyKeys: string[];

constructor(modpath: string, bundle: any, bundlePath: string, bundleFilepath: string)
constructor(modpath: string, bundle: BundleManifestEntry, bundleHash: number)
{
this.modPath = modpath;
this.key = bundle.key;
this.path = bundlePath;
this.filepath = bundleFilepath;
this.dependencyKeys = bundle.dependencyKeys || [];
this.modpath = modpath
this.filename = bundle.key;
this.crc = bundleHash;
this.dependencies = bundle.dependencyKeys || [];
}
}

Expand All @@ -32,49 +33,48 @@ export class BundleLoaderOverride
container: DependencyContainer
)
{
this.bundleHashCacheService = container.resolve<BundleHashCacheService>("BundleHashCacheService");
this.container = container;
this.vfs = container.resolve<VFS>("VFS");
this.jsonUtil = container.resolve<JsonUtil>("JsonUtil");
}

public getBundles(local: boolean): BundleInfo[]
public getBundles(): BundleInfo[]
{
const result: BundleInfo[] = [];

for (const bundle in this.bundles)
{
result.push(this.getBundle(bundle, local));
result.push(this.getBundle(bundle));
}

return result;
}

public getBundle(key: string, local: boolean): BundleInfo
public getBundle(key: string): BundleInfo
{
//decode the bundle key name to support spaces, etc.
key = decodeURI(key);

const bundle = this.jsonUtil.clone(this.bundles[key]);

if (local)
{
bundle.path = bundle.filepath;
}

delete bundle.filepath;
return bundle;
return this.jsonUtil.clone(this.bundles[key]);
}

public addBundles(modpath: string): void
{
const manifest = this.jsonUtil.deserialize<BundleManifest>(this.vfs.readFile(`${modpath}bundles.json`)).manifest;
const bundleManifestArr = this.jsonUtil.deserialize<BundleManifest>(this.vfs.readFile(`${modpath}bundles.json`)).manifest;

for (const bundle of manifest)
for (const bundleManifest of bundleManifestArr)
{
// return a partial url. the complete url will be build on client side.
const bundlePath = `/files/bundle/${bundle.key}`;
const bundleFilepath = bundle.path || `${modpath}bundles/${bundle.key}`.replace(/\\/g, "/");
this.addBundle(bundle.key, new BundleInfo(modpath, bundle, bundlePath, bundleFilepath));
const absoluteModPath = path.join(process.cwd(), modpath).slice(0, -1).replace(/\\/g, "/");
const bundleLocalPath = `${modpath}bundles/${bundleManifest.key}`.replace(/\\/g, "/");

if (!this.bundleHashCacheService.calculateAndMatchHash(bundleLocalPath))
{
this.bundleHashCacheService.calculateAndStoreHash(bundleLocalPath);
}

const bundleHash = this.bundleHashCacheService.getStoredValue(bundleLocalPath);

this.addBundle(bundleManifest.key, new BundleInfo(absoluteModPath, bundleManifest, bundleHash));
}
}

Expand Down Expand Up @@ -106,11 +106,11 @@ export class BundleLoaderOverride

export interface BundleManifest
{
manifest: Array<BundleManifestEntry>
manifest: BundleManifestEntry[];
}

export interface BundleManifestEntry
{
key: string
path: string
key: string;
dependencyKeys: string[];
}
Loading