diff --git a/LICENSE b/LICENSE
index 153d416d..0fdf6bc9 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,7 +1,7 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2023-2024 Mikhail Babynichev
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
diff --git a/README.md b/README.md
index 2bfbfca6..122b5fec 100644
--- a/README.md
+++ b/README.md
@@ -137,5 +137,5 @@ Contributions, issues and feature requests are welcome!
Feel free to check
## 📝 License
-Copyright © 2023 [Mikhail Babynichev](https://github.com/KotRikD).
-This project is [GPL--3.0](https://github.com/KotRikD/tosu/blob/master/LICENSE) licensed.
+Copyright © 2023-2024 [Mikhail Babynichev](https://github.com/KotRikD).
+This project is [LGPL-3.0](https://github.com/KotRikD/tosu/blob/master/LICENSE) licensed.
diff --git a/packages/common/utils/unzip.ts b/packages/common/utils/unzip.ts
index de68c4cb..44e36233 100644
--- a/packages/common/utils/unzip.ts
+++ b/packages/common/utils/unzip.ts
@@ -1,40 +1,8 @@
import AdmZip from 'adm-zip';
import fs from 'fs';
-import path from 'path';
import { wLogger } from './logger';
-export const unzipTosu = (
- zipPath: string,
- extractPath: string
-): Promise =>
- new Promise((resolve, reject) => {
- const zip = new AdmZip(zipPath);
-
- zip.getEntries().some((entry) => {
- if (entry.entryName === 'tosu' || entry.entryName === 'tosu.exe') {
- const fileName = path.basename(entry.entryName);
- const { name, ext } = path.parse(fileName);
- const modifyName = path.join(extractPath, `${name}_new${ext}`);
-
- return fs.writeFile(
- modifyName,
- entry.getData(),
- { flag: 'w' },
- (err) => {
- if (err) {
- return reject(err);
- }
-
- return resolve(modifyName);
- }
- );
- }
- });
-
- reject('No matching entry found in the zip file.');
- });
-
export const unzip = (zipPath: string, extractPath: string): Promise =>
new Promise((resolve, reject) => {
if (!fs.existsSync(extractPath)) {
diff --git a/packages/updater/index.ts b/packages/updater/index.ts
index 24fe19eb..68de4d77 100644
--- a/packages/updater/index.ts
+++ b/packages/updater/index.ts
@@ -2,10 +2,10 @@ import {
downloadFile,
platformResolver,
sleep,
- unzipTosu,
+ unzip,
wLogger
} from '@tosu/common';
-import { exec, spawn } from 'child_process';
+import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';
@@ -14,7 +14,6 @@ const currentVersion = require(process.cwd() + '/_version.js');
const repositoryName = 'tosu';
const fileDestination = path.join(process.cwd(), 'update.zip');
-const newExecutablePath = path.join(process.cwd(), 'tosu.exe');
const backupExecutablePath = path.join(process.cwd(), 'tosu_old.exe');
const deleteNotLocked = async (filePath: string) => {
@@ -35,9 +34,7 @@ export const autoUpdater = () =>
new Promise(async (resolve) => {
wLogger.info('Checking updates');
- const { platformType, platformFileType } = platformResolver(
- process.platform
- );
+ const { platformType } = platformResolver(process.platform);
if (platformType === '') {
wLogger.warn(
@@ -64,6 +61,7 @@ export const autoUpdater = () =>
if (fs.existsSync(fileDestination))
await deleteNotLocked(fileDestination);
+ await sleep(5 * 1000);
if (fs.existsSync(backupExecutablePath))
await deleteNotLocked(backupExecutablePath);
@@ -86,39 +84,23 @@ export const autoUpdater = () =>
fileDestination
);
- const unzipExecutable = await unzipTosu(downloadAsset, process.cwd());
-
const currentExecutablePath = process.argv[0]; // Path to the current executable
await fs.promises.rename(currentExecutablePath, backupExecutablePath);
- await fs.promises.rename(unzipExecutable, newExecutablePath);
+
+ await unzip(downloadAsset, process.cwd());
wLogger.info('Restarting program');
- // Start the updated executable
- const oldProcess = spawn(backupExecutablePath, [], {
+ spawn(process.argv[0], process.argv.slice(1), {
detached: true,
+ shell: true,
stdio: 'ignore'
- });
-
- oldProcess.unref();
+ }).unref();
- exec(
- `start "" "${newExecutablePath}"`,
- async (error, stdout, stderr) => {
- if (error) {
- console.error(`Error starting updated process: ${error}`);
- return;
- }
+ wLogger.info('Closing program');
- await sleep(2500);
+ await sleep(1000);
- wLogger.info('Closing program');
-
- await sleep(1000);
-
- oldProcess.kill();
- process.exit();
- }
- );
+ process.exit();
});