From 4ac7d81e1dc36dbf75b4e32ab5e3812dedc9213d Mon Sep 17 00:00:00 2001 From: 12944qwerty Date: Fri, 17 Jan 2025 18:59:11 -0500 Subject: [PATCH] fix macos not installing toolchain finally? --- src/one-click/download.ts | 77 ++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 34 deletions(-) diff --git a/src/one-click/download.ts b/src/one-click/download.ts index 876843f..6106a71 100644 --- a/src/one-click/download.ts +++ b/src/one-click/download.ts @@ -114,42 +114,51 @@ export async function extract( }); if (xzFile) { - await new Promise(function (resolve, reject) { - // Create our read stream - prosLogger.log("OneClick", `Creating read stream for ${storagePath}`); - const stats = fs.statSync( - path.join(globalPath, "download", storagePath) - ); - const totalSize = stats.size; - read = fs.createReadStream( - path.join(globalPath, "download", storagePath) - ); - var decompress = new lzma.createDecompressor(); - decompress.on("data", (chunk: Buffer | string | any) => { - _progress.report({ increment: (chunk.length * 100) / totalSize }); - }); - // Remove tar from the filename - storagePath = storagePath.replace(".tar.xz", ""); - // create our write stream - prosLogger.log( - "OneClick", - `Extracting ${storagePath} to install folder` - ); - extract = tar.extract(path.join(globalPath, "download", storagePath)); - // Pipe the read stream into the write stream - read.pipe(decompress).pipe(extract); - // When the write stream ends, resolve the promise - extract.on("finish", resolve); - // If there's an error, reject the promise and clean up - read.on("error", () => { - prosLogger.log("OneClick", `Error occured for ${storagePath}`); - fs.unlink( - path.join(globalPath, "download", storagePath), - (_) => null + let readPath = path.join(globalPath, "download", storagePath); + + if (readPath.includes("macos")) { + fs.mkdirSync(readPath.replace(".tar.xz", "")); + execSync(`tar -xf "${readPath}" -C "${readPath.replace(".tar.xz", "")}"`); + } else { + await new Promise(function (resolve, reject) { + // Create our read stream + prosLogger.log("OneClick", `Creating read stream for ${storagePath}`); + const stats = fs.statSync( + path.join(globalPath, "download", storagePath) + ); + const totalSize = stats.size; + read = fs.createReadStream( + path.join(globalPath, "download", storagePath) + ); + var decompress = new lzma.createDecompressor(); + decompress.on("data", (chunk: Buffer | string | any) => { + _progress.report({ increment: (chunk.length * 100) / totalSize }); + }); + // Remove tar from the filename + storagePath = storagePath.replace(".tar.xz", ""); + // create our write stream + prosLogger.log( + "OneClick", + `Extracting ${storagePath} to install folder` ); - reject(); + extract = tar.extract(path.join(globalPath, "download", storagePath)); + // Pipe the read stream into the write stream + read.pipe(decompress).pipe(extract); + // When the write stream ends, resolve the promise + extract.on("finish", resolve); + // If there's an error, reject the promise and clean up + read.on("error", () => { + prosLogger.log("OneClick", `Error occured for ${storagePath}`); + fs.unlink( + path.join(globalPath, "download", storagePath), + (_) => null + ); + reject(); + }); }); - }); + } + + storagePath = storagePath.replace(".tar.xz", ""); const files = await fs.promises.readdir( path.join(globalPath, "download", storagePath)