Skip to content

Commit

Permalink
fix: stuck on launching for several seconds, close #94
Browse files Browse the repository at this point in the history
  • Loading branch information
ResetPower committed Sep 24, 2022
1 parent d47bd34 commit d0e8d9f
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/core/launch/libraries.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fs from "fs";
import fs from "fs/promises";
import path from "path";
import { isCompliant, equalOS } from "./rules";
import { coreLogger } from "common/loggers";
Expand All @@ -14,11 +14,10 @@ import { calculateHash, downloadFile, fetchSize } from "common/utils/files";
import { MinecraftUrlUtil } from "core/url";
import { Canceller } from "common/task/cancel";

function existsAsFileSync(filepath: string): boolean {
async function existsAsFileSync(filepath: string): Promise<boolean> {
return (
fs.existsSync(filepath) &&
fs.lstatSync(filepath).isFile() &&
fs.readFileSync(filepath).toString() !== ""
(await fs.lstat(filepath)).isFile() &&
(await fs.readFile(filepath)).toString() !== ""
);
}

Expand Down Expand Up @@ -48,7 +47,7 @@ export async function analyzeLibrary(
const nativeObj = classifiers[native];
const file = `${dir}/libraries/${nativeObj.path}`;
let miss = false;
if (existsAsFileSync(file)) {
if (await existsAsFileSync(file)) {
if (
nativeObj.sha1 &&
nativeObj.sha1 !== calculateHash(file, "sha1")
Expand Down Expand Up @@ -76,7 +75,7 @@ export async function analyzeLibrary(
const ar = downloads.artifact;
const file = `${dir}/libraries/${ar.path}`;
let miss = false;
if (existsAsFileSync(file)) {
if (await existsAsFileSync(file)) {
if (ar.sha1 && ar.sha1 !== calculateHash(file, "sha1")) {
miss = true;
}
Expand Down Expand Up @@ -150,11 +149,11 @@ export async function analyzeAssets(
`${assetIndex.id}.json`
);

if (!fs.existsSync(assetIndexPath)) {
if (!(await existsAsFileSync(assetIndexPath))) {
await downloadFile(assetIndex.url, assetIndexPath, canceller);
}
const parsedAssetIndex = JSON.parse(
fs.readFileSync(assetIndexPath).toString()
(await fs.readFile(assetIndexPath)).toString()
);
for (const k in parsedAssetIndex.objects) {
// Never try to optimize here. parsedAssetIndex.objects is not iterable.
Expand All @@ -164,7 +163,7 @@ export async function analyzeAssets(
const startHash = hash.slice(0, 2);
const p = path.join(dir, "assets/objects", startHash, hash);
let miss = false;
if (fs.existsSync(p)) {
if (await existsAsFileSync(p)) {
if (hash && hash !== calculateHash(p, "sha1")) {
miss = true;
}
Expand Down

0 comments on commit d0e8d9f

Please sign in to comment.