Skip to content

Commit

Permalink
fix: execution file is missing (#108)
Browse files Browse the repository at this point in the history
Signed-off-by: The1111mp <[email protected]>
  • Loading branch information
1111mp committed Aug 28, 2024
1 parent 80bbb29 commit c165407
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
49 changes: 24 additions & 25 deletions src/main/utils/migration.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { exec } from "node:child_process";
import { platform, arch } from "node:process";
import { join } from "node:path";
import { pathExists, copy, readFile, readdir, writeFile, symlink, remove } from "fs-extra";
import {
pathExists,
copy,
copySync,
readFile,
readdir,
writeFile,
symlink,
remove
} from "fs-extra";
import { app } from "electron";

import { APPDIR, BIN_DIR, MIRRATION_FILE } from "../constants";
Expand Down Expand Up @@ -29,24 +38,19 @@ async function updateToSchemaVersionDefault(version: number) {

const exeSourceFile = app.isPackaged
? join(process.resourcesPath, "assets", "sources", `${arch}.exe`)
: join(__dirname, "../../..", "assets", "sources", `${arch}.exe`);
: join(__dirname, "../../", "assets", "sources", `${arch}.exe`);
const cmdSourceFile = app.isPackaged
? join(process.resourcesPath, "assets", "sources", "temp.cmd")
: join(__dirname, "../../..", "assets", "sources", "temp.cmd");
: join(__dirname, "../../", "assets", "sources", "temp.cmd");

const promises: Array<Promise<void>> = [];

promises.push(copy(exeSourceFile, join(BIN_DIR, "nvmd.exe")).catch((_err) => {}));

["node", "npm", "npx", "corepack"].forEach((name) => {
promises.push(copy(exeSourceFile, join(BIN_DIR, `${name}.exe`)).catch((_err) => {}));
await copy(exeSourceFile, join(BIN_DIR, "nvmd.exe"));

for (const name of ["node", "npm", "npx", "corepack"]) {
await copy(exeSourceFile, join(BIN_DIR, `${name}.exe`));
if (name !== "node") {
promises.push(copy(cmdSourceFile, join(BIN_DIR, `${name}.cmd`)).catch((_err) => {}));
await copy(cmdSourceFile, join(BIN_DIR, `${name}.cmd`));
}
});

await Promise.all(promises);
}

setSchemaVersion(CURRENT_MIGRATION_VERSION);
return;
Expand All @@ -67,7 +71,7 @@ async function updateToSchemaVersionDefault(version: number) {

const sourceFile = app.isPackaged
? join(process.resourcesPath, "assets", "sources", "nvmd")
: join(__dirname, "../../..", "assets", "sources", "nvmd");
: join(__dirname, "../../", "assets", "sources", "nvmd");

await copy(sourceFile, targetFile).catch((_err) => {});

Expand All @@ -90,7 +94,7 @@ async function updateToSchemaVersionLast(version: number) {

const sourceFile = app.isPackaged
? join(process.resourcesPath, "assets", "sources", "nvmd")
: join(__dirname, "../../..", "assets", "sources", "nvmd");
: join(__dirname, "../../", "assets", "sources", "nvmd");
await copy(sourceFile, targetFile).catch((_err) => {});

setSchemaVersion(CURRENT_MIGRATION_VERSION);
Expand All @@ -100,18 +104,13 @@ async function updateToSchemaVersionLast(version: number) {
// Windows
const sourceFile = app.isPackaged
? join(process.resourcesPath, "assets", "sources", `${arch}.exe`)
: join(__dirname, "../../..", "assets", "sources", `${arch}.exe`);
await copy(sourceFile, join(BIN_DIR, "nvmd.exe")).catch((_err) => {});

async function updateFile(fileName: string) {
await copy(sourceFile, join(BIN_DIR, fileName)).catch((_err) => {});
return;
}
: join(__dirname, "../../", "assets", "sources", `${arch}.exe`);
await copy(sourceFile, join(BIN_DIR, "nvmd.exe"));

const files = await readdir(BIN_DIR);
await Promise.all(
files.filter((name) => name.endsWith(".exe")).map((fileName) => updateFile(fileName))
);
for (const name of files.filter((name) => name.endsWith(".exe"))) {
await copy(sourceFile, join(BIN_DIR, name));
}

setSchemaVersion(CURRENT_MIGRATION_VERSION);
return;
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Home: React.FC = () => {

useEffect(() => {
window.Context.onRegistMigrationError(() => {
toast.warning(i18n("Migration-error"), { duration: 5000 });
toast.error(i18n("Migration-error"), { duration: 8000 });
});
}, []);

Expand Down

0 comments on commit c165407

Please sign in to comment.