Skip to content

Commit ab5f8a1

Browse files
committed
Support experimental ArchiveData API
1 parent 9260d98 commit ab5f8a1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/ext.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,33 @@ export async function activate(context: flashpoint.ExtensionContext) {
2222
})
2323
.catch((err: any) => {
2424
flashpoint.log.error(`Failed to mount zip: ${filePath} - ${err}`);
25+
return mountArchiveDataGame(filePath);
2526
});
2627
}
2728

29+
async function mountArchiveDataGame(filePath: string) {
30+
// Check experimental archive data api is present
31+
const archiveDataNamespace = (flashpoint as any).archiveData;
32+
if (archiveDataNamespace !== undefined) {
33+
const getZipDataOffset = archiveDataNamespace.getZipDataOffset;
34+
if (getZipDataOffset !== undefined) {
35+
const archivePath = fixSlashes(path.join('Flashpoint Ultimate', path.relative(fpPath, filePath)));
36+
flashpoint.log.info(`Trying to mount archive data: ${archivePath}`);
37+
const zipInfo: any = await getZipDataOffset(archivePath);
38+
if (zipInfo !== null) {
39+
// Zip exists, try sending the archive data instead
40+
return axios.post("http://localhost:22501/fpProxy/api/mountzip", {
41+
archiveData: zipInfo
42+
})
43+
.catch((err: any) => {
44+
flashpoint.log.error(`Failed to mount zip: ${filePath} - ${err}`);
45+
return mountArchiveDataGame(filePath);
46+
});
47+
}
48+
}
49+
}
50+
}
51+
2852
flashpoint.games.onWillUninstallGameData(async (gameData) => {
2953
const filename = getGameDataFilename(gameData);
3054
const filePath: string = path.resolve(path.join(dataPacksPath, filename));
@@ -84,3 +108,7 @@ export function getGameDataFilename(data: flashpoint.GameData) {
84108
const cleanDate = (data.dateAdded as unknown as string).includes('T') ? data.dateAdded : `${data.dateAdded} +0000 UTC`;
85109
return `${data.gameId}-${(new Date(cleanDate)).getTime()}.zip`;
86110
}
111+
112+
function fixSlashes(str: string): string {
113+
return str.replace(/\\/g, '/');
114+
}

0 commit comments

Comments
 (0)