From 0b8f33f94bcf230489f6c0e8288bae7554011669 Mon Sep 17 00:00:00 2001 From: Daniel Lando Date: Thu, 12 Oct 2023 15:34:42 +0200 Subject: [PATCH] feat: allow to restore NVM raw (#3337) --- lib/ZwaveClient.ts | 19 +++++++++++++------ src/views/ControlPanel.vue | 23 +++++++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/ZwaveClient.ts b/lib/ZwaveClient.ts index a0a6ce2b26..330dd3dcc0 100644 --- a/lib/ZwaveClient.ts +++ b/lib/ZwaveClient.ts @@ -4735,16 +4735,23 @@ class ZwaveClient extends TypedEventEmitter { this._updateControllerStatus(`Backup NVM progress: ${progress}%`) } - async restoreNVM(data: Buffer) { + async restoreNVM(data: Buffer, useRaw = false) { if (!this.driverReady) { throw new DriverNotReadyError() } - await this.driver.controller.restoreNVM( - data, - this._onConvertNVMProgress.bind(this), - this._onRestoreNVMProgress.bind(this) - ) + if (useRaw) { + await this.driver.controller.restoreNVMRaw( + data, + this._onRestoreNVMProgress.bind(this) + ) + } else { + await this.driver.controller.restoreNVM( + data, + this._onConvertNVMProgress.bind(this), + this._onRestoreNVMProgress.bind(this) + ) + } } private _onConvertNVMProgress(bytesRead: number, totalBytes: number) { diff --git a/src/views/ControlPanel.vue b/src/views/ControlPanel.vue index bfabbb46fb..678b97461a 100644 --- a/src/views/ControlPanel.vue +++ b/src/views/ControlPanel.vue @@ -789,21 +789,36 @@ export default { return } } else if (action === 'restoreNVM') { - const confirm = await this.$listeners.showConfirm( + const result = await this.$listeners.showConfirm( 'NVM Restore', 'While doing the restore the Z-Wave radio will be turned on/off.\nA failure during this process may brick your controller. Use at your own risk!', 'alert', { confirmText: 'Ok', + width: 500, + inputs: [ + { + type: 'file', + label: 'File', + hint: 'NVM file', + key: 'file', + }, + { + type: 'checkbox', + label: 'Skip compatibility check', + hint: 'This needs to be checked in order to allow restoring NVM backups on older controllers, with the risk of restoring an incompatible backup', + key: 'useRaw', + }, + ], } ) - if (!confirm) { + if (!result?.file) { return } try { - const { data } = await this.$listeners.import('buffer') - args.push(data) + const data = await result.file.arrayBuffer() + args.push(data, result.useRaw) } catch (error) { return }