Skip to content

Commit

Permalink
Fix download of files
Browse files Browse the repository at this point in the history
  • Loading branch information
NeKzor committed Feb 4, 2024
1 parent 5584d3e commit e4b03ab
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/cmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,33 @@ const downloadChallengeModeMod = async (game: Game, cmmFolder: string) => {
},
});

loading.stop();

const blob = await res.blob();
loading.stop();

let zip: ZipReader<BlobReader> | null = null;

try {
zip = new ZipReader(new BlobReader(blob), { useWebWorkers: false });

await Deno.mkdir(cmmFolder);

for (const entry of await zip.getEntries()) {
const data = await entry.getData!(new Uint8ArrayWriter());

await Deno.writeFile(join(cmmFolder, entry.filename), data);

console.log(
colors.white(`🗿️ Extracted file ${colors.italic.gray(entry.filename)}`),
colors.white(`Extracted file ${colors.italic.gray(entry.filename)}`),
);
}

console.info(`Downloaded contents to cmm folder.`);
} catch (err) {
verbose && console.error(err);
} finally {
zip && await zip.close();
}
} catch (err) {
verbose && console.error(err);
console.error(colors.red(`❌️ Failed to downloaded cmm contents.`));
console.error(colors.red(`❌️ Failed to download cmm contents.`));
Deno.exit(1);
}
};
Expand All @@ -100,9 +99,7 @@ const downloadSourceAutoRecord = async (sarPath: string, pdbPath: string | null)
},
);

loading.stop();

using file = await Deno.open(sarPath);
using file = await Deno.open(sarPath, { write: true, createNew: true });
res.body && await res.body?.pipeTo(file.writable);

if (pdbPath) {
Expand All @@ -112,14 +109,15 @@ const downloadSourceAutoRecord = async (sarPath: string, pdbPath: string | null)
},
});

using file = await Deno.open(pdbPath);
using file = await Deno.open(pdbPath, { write: true, createNew: true });
res.body && await res.body?.pipeTo(file.writable);
}

loading.stop();
console.info(`Downloaded SAR.`);
} catch (err) {
verbose && console.error(err);
console.error(colors.red(`❌️ Failed to downloaded SAR.`));
console.error(colors.red(`❌️ Failed to download SAR.`));
Deno.exit(1);
}
};
Expand All @@ -141,9 +139,9 @@ const validateApiKey = async (apiKey: string) => {
body,
});

loading.stop();

const validation = await res.json() as { userId: string };

loading.stop();
console.info(`Validated API key:`, validation);
} catch (err) {
verbose && console.error(err);
Expand Down Expand Up @@ -256,7 +254,7 @@ const cli = new Command()
Deno.exit(1);
}

console.info(result ? `Modified gameinfo.txt` : `Gameinfo is already modified. Skipped step.`);
console.info(result ? `Modified gameinfo.txt` : `Gameinfo is already modified. Skipping step.`);

const cmmFolder = join(gameDir, 'cmm');
if (!await exists(cmmFolder)) {
Expand All @@ -281,8 +279,8 @@ const cli = new Command()
loading.start();

await copy(portal2DlcFolder, dlcFolder);
loading.stop();

loading.stop();
console.info(`Copied portal2_dlc1 folder.`);
} else {
console.info(`The DLC folder is already copied. Skipping step.`);
Expand All @@ -292,14 +290,14 @@ const cli = new Command()
if (!await exists(sar)) {
await downloadSourceAutoRecord(sar, isWindows ? join(gameDir, 'sar.pdb') : null);
} else {
console.warn(`Detected that SAR is already installed. Please make sure you are on the latest version.`);
console.warn(`Detected that SAR is already installed. Please make sure that it is the latest version.`);
}

const autosubmitKey = join(gameDir, 'autosubmit.key');
if (await exists(autosubmitKey)) {
await validateApiKey(await Deno.readTextFile(autosubmitKey));
} else {
console.warn(`Missing autosubmit.key file. Validation step skipped.`);
console.warn(`Missing autosubmit.key file. Skipping validation step.`);
}

console.info(`Done.`);
Expand Down

0 comments on commit e4b03ab

Please sign in to comment.