Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macos not installing toolchain #248

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions src/one-click/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading