Skip to content

Commit

Permalink
Merge pull request #37 from JimWails/new-bundle-system-support
Browse files Browse the repository at this point in the history
New bundle system support
  • Loading branch information
paulov-t authored Apr 1, 2024
2 parents 8a5639e + cbe50cc commit 54f7b0b
Showing 1 changed file with 28 additions and 28 deletions.
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[];
}

0 comments on commit 54f7b0b

Please sign in to comment.