mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-16 06:18:42 +02:00
MISC: Support importing Steam Cloud save file manually (#2583)
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const fs = require("fs").promises;
|
||||
const path = require("path");
|
||||
const { isBinaryFormat } = require("../electron/saveDataBinaryFormat");
|
||||
const { decodeBase64BytesToBytes, isBinaryFormat, isSteamCloudFormat } = require("../electron/saveDataBinaryFormat");
|
||||
|
||||
async function decompress(data) {
|
||||
const decompressedReadableStream = new Blob([data]).stream().pipeThrough(new DecompressionStream("gzip"));
|
||||
return await new Response(decompressedReadableStream).text();
|
||||
}
|
||||
|
||||
async function getSave(file) {
|
||||
const data = await fs.readFile(file);
|
||||
|
||||
let jsonSaveString;
|
||||
if (isBinaryFormat(data)) {
|
||||
const decompressedReadableStream = new Blob([data]).stream().pipeThrough(new DecompressionStream("gzip"));
|
||||
jsonSaveString = await new Response(decompressedReadableStream).text();
|
||||
jsonSaveString = await decompress(data);
|
||||
} else if (isSteamCloudFormat(data)) {
|
||||
jsonSaveString = await decompress(decodeBase64BytesToBytes(data));
|
||||
} else {
|
||||
jsonSaveString = decodeURIComponent(escape(atob(data)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user