Skip to content

Commit

Permalink
Fixed message when trying to check if any resource is found or not
Browse files Browse the repository at this point in the history
  • Loading branch information
qlrd committed Aug 10, 2023
1 parent c61c440 commit d2cc9e1
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 11 deletions.
41 changes: 30 additions & 11 deletions lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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<void> {
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<void> {
this.log(`Adding openssl in ${process.platform} environment variable PATH`)
const openssls = []
let separator = ''
Expand All @@ -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`)
Expand Down
1 change: 1 addition & 0 deletions lib/check-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions src/utils/onKruxCheckResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/utils/onKruxStoreGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d2cc9e1

Please sign in to comment.