From d2cc9e1f89582d2c10e4a34fe1108371337a732d Mon Sep 17 00:00:00 2001 From: qlrd <106913782+qlrd@users.noreply.github.com> Date: Thu, 10 Aug 2023 10:47:43 -0300 Subject: [PATCH] Fixed message when trying to check if any resource is found or not --- lib/app.ts | 41 ++++++++++++++++++++++--------- lib/check-resource.ts | 1 + src/utils/onKruxCheckResources.ts | 24 ++++++++++++++++++ src/utils/onKruxStoreGet.ts | 4 +++ 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/lib/app.ts b/lib/app.ts index 78358db4..a3b1b626 100644 --- a/lib/app.ts +++ b/lib/app.ts @@ -2,6 +2,7 @@ import { release } from 'node:os' import { dirname, join } from 'node:path' +import { access } from 'node:fs/promises' import { app, BrowserWindow, shell, ipcMain } from 'electron' import Base from './base' @@ -111,12 +112,33 @@ export default class App extends Base { } } + /** + * This path only will exist when build occurs + * inside github-actions, once OpenSSL is built on runtime + * @param _env + * @param openssls + */ + private async setupBuiltinOpensslWin32 (_env: string[], openssls: string[], possiblePaths: string[]): Promise { + for (let i in possiblePaths) { + try { + this.debug(` trying ${possiblePaths[i]}`) + await access(possiblePaths[i]) + if (_env.indexOf(possiblePaths[i]) === -1) { + openssls.push(possiblePaths[i]) + } + break + } catch (error) { + this.debug(` OPENSSL ADD PATH WARN: ${error}`) + } + } + } + /** * Check if platform (darwin or win32) * needs and additional configuration * to add openssl binary */ - private setupOpenssl (): void { + private async setupOpenssl (): Promise { this.log(`Adding openssl in ${process.platform} environment variable PATH`) const openssls = [] let separator = '' @@ -135,16 +157,13 @@ export default class App extends Base { } else if (process.platform === 'win32') { separator = ';' const _env = (process.env.PATH as string).split(separator) - - // This path only will exist - // when build occurs - // inside github-actions - const __opensslBinDir = join(process.env.DIST, '..', '..', 'extraResources', 'OpenSSL', 'bin') - - if (_env.indexOf(__opensslBinDir) === -1) { - openssls.push(__opensslBinDir) - } - + await this.setupBuiltinOpensslWin32(_env, openssls, [ + join(process.env.DIST, '..', 'release', 'extraResources', 'OpenSSL', 'bin'), + join(process.env.DIST, '..', '..', 'extraResources', 'OpenSSL', 'bin'), + join(app.getPath('appData'), '..', 'Local', 'Programs', 'krux-installer', 'resources', 'extraResources', 'OpenSSL', 'bin'), + join(process.env.ProgramFiles, 'Git', 'usr', 'bin'), + join(process.env.ProgramFiles, 'OpenVPN', 'bin'), + ]); } for (let i in openssls) { this.log(` adding ${openssls[i]} to PATH`) diff --git a/lib/check-resource.ts b/lib/check-resource.ts index 0df29ce9..4489a8ea 100644 --- a/lib/check-resource.ts +++ b/lib/check-resource.ts @@ -42,6 +42,7 @@ export default class CheckResourcesHandler extends Handler { build () { super.build(async (options) => { try { + console.log(options) const resources = this.storage.get('resources') as string const destinationResource = join(resources, options.resource) diff --git a/src/utils/onKruxCheckResources.ts b/src/utils/onKruxCheckResources.ts index 66aeecde..01262213 100644 --- a/src/utils/onKruxCheckResources.ts +++ b/src/utils/onKruxCheckResources.ts @@ -8,8 +8,20 @@ async function onResourceExist ( let checked if (result.resourceTo.match(/^.*(zip|sha256.txt|sig|pem)$/g)){ checked = result.resourceTo.split('krux-installer/')[1] + // on Windows, the path came with inverted slashes, + // so, if the checking fails, + // check again + if (checked === undefined) { + checked = result.resourceTo.split('krux-installer\\')[1] + } } else if (result.resourceTo.match(/^.*(firmware|kboot|ktool).*$/g)) { checked = result.resourceTo.split('/main/')[1] + // on Windows, the path came with inverted slashes, + // so, if the checking fails, + // check again + if (checked === undefined) { + checked = result.resourceTo.split('\\main\\')[1] + } } await messages.add(data, `${checked} found`) data.value.proceedTo = 'ConsoleLoad' @@ -26,8 +38,20 @@ async function onResourceNotExist ( let checked if (result.resourceTo.match(/^.*(zip|sha256.txt|sig|pem)$/g)){ checked = result.resourceTo.split('krux-installer/')[1] + // on Windows, the path came with inverted slashes, + // so, if the checking fails, + // check again + if (checked === undefined) { + checked = result.resourceTo.split('krux-installer\\')[1] + } } else if (result.resourceTo.match(/^.*(firmware|kboot|ktool).*$/g)) { checked = result.resourceTo.split('/main/')[1] + // on Windows, the path came with inverted slashes, + // so, if the checking fails, + // check again + if (checked === undefined) { + checked = result.resourceTo.split('\\main\\')[1] + } } await messages.add(data, `${checked} not found`) data.value.progress = 0.0 diff --git a/src/utils/onKruxStoreGet.ts b/src/utils/onKruxStoreGet.ts index 9e380a50..08cda72a 100644 --- a/src/utils/onKruxStoreGet.ts +++ b/src/utils/onKruxStoreGet.ts @@ -15,6 +15,10 @@ async function onGetResource ( toCheck = options.resource.split('/main/')[1] } + console.log(`from: ${result.from}`) + console.log(`baseUrl: ${options.baseUrl}`) + console.log(`resource: ${options.resource}`) + await messages.add(data, `Checking ${toCheck}`) await window.api.invoke('krux:check:resource', { from: result.from,