From 3365c816d752ba990559086fb19d370caa44b86f Mon Sep 17 00:00:00 2001 From: Jan Grulich Date: Tue, 29 Oct 2024 19:56:40 +0100 Subject: [PATCH] Show the warning dialog with erase confirmation everytime (#750) Make the dialog to appear all the time and not only for drives bigger than 32GB. --- src/app/qml/DeviceWarningDialog.qml | 18 +++++++++++++++++- src/app/qml/DrivePage.qml | 10 +--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/app/qml/DeviceWarningDialog.qml b/src/app/qml/DeviceWarningDialog.qml index a3cdcd01..0431ac0f 100644 --- a/src/app/qml/DeviceWarningDialog.qml +++ b/src/app/qml/DeviceWarningDialog.qml @@ -51,7 +51,7 @@ ApplicationWindow { Label { Layout.fillWidth: true - text: qsTr("The device you have selected appears to be larger than 32GB. Are you sure you want to completely erase all the data on it?") + text: qsTr("The entire device (all of %1) will be erased and the selected image will be written to it. Do you want to continue?").arg(formatSize(drives.selected.size)) wrapMode: Label.Wrap } @@ -87,5 +87,21 @@ ApplicationWindow { } } } + + function formatSize(bytes) { + const kb = 1024; + const mb = kb * 1024; + const gb = mb * 1024; + + if (bytes >= gb) { + return (bytes / gb).toFixed(2) + " " + qsTr("GB"); + } else if (bytes >= mb) { + return (bytes / mb).toFixed(2) + " " + qsTr("MB"); + } else if (bytes >= kb) { + return (bytes / kb).toFixed(2) + " " + qsTr("KB"); + } else { + return bytes + " " + qsTr("Bytes"); + } + } } diff --git a/src/app/qml/DrivePage.qml b/src/app/qml/DrivePage.qml index 40d9f77f..6d7a5326 100644 --- a/src/app/qml/DrivePage.qml +++ b/src/app/qml/DrivePage.qml @@ -190,14 +190,6 @@ Page { return; } - // Better check for > 33GB as the device size is not exactly 32GB for "32GB" USB drive - if (drives.selected.size > 33000000000) { - deviceWarningDialog.show(); - return - } - - selectedPage = Units.Page.DownloadPage - drives.selected.setImage(releases.variant) - drives.selected.write(releases.variant) + deviceWarningDialog.show(); } }