diff --git a/machine_creator/DiskWriter.cpp b/machine_creator/DiskWriter.cpp index afd3477..8bc58a2 100644 --- a/machine_creator/DiskWriter.cpp +++ b/machine_creator/DiskWriter.cpp @@ -70,7 +70,9 @@ bool PhysicalDevice::open(OpenMode flags) } else { + qWarning() << "Closing handle :("; CloseHandle(m_fileHandle); + m_fileHandle = INVALID_HANDLE_VALUE; return false; } #elif defined(Q_OS_LINUX) @@ -160,7 +162,8 @@ void PhysicalDevice::lockVolume() { qDebug() << "Locking volume" << fileName(); - if (DeviceIoControl(m_fileHandle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &bytesRet, NULL)) + auto ret = DeviceIoControl(m_fileHandle, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &bytesRet, NULL); + if (ret) { handleLocked = true; qDebug() << "Locked volume"; @@ -540,7 +543,10 @@ void DiskWriter::writeToRemovableDevice(const QString &filename, UsbDisk *d) #endif } - if (writtenBytes != totalBytes) + if (writtenBytes != totalBytes && + totalBytes > 0) //when totalBytes is 0, it can be because the + // source is compressed and KArchive can't know the final size. + // Do not fail with error in that case { emit error("Writing failed"); return; @@ -559,6 +565,8 @@ void DiskWriter::writeToRemovableDevice(const QString &filename, UsbDisk *d) //Verification step qDebug() << "Verify..."; + if (totalBytes == 0) + totalBytes = writtenBytes; writtenBytes = 0; timer.restart(); new (&blake2bContext) blake2b_state; diff --git a/machine_creator/DiskWriter.h b/machine_creator/DiskWriter.h index 593eaf4..0d00082 100644 --- a/machine_creator/DiskWriter.h +++ b/machine_creator/DiskWriter.h @@ -29,7 +29,7 @@ class PhysicalDevice : public QFile protected: #if defined(Q_OS_WIN) - HANDLE m_fileHandle; + HANDLE m_fileHandle = INVALID_HANDLE_VALUE; bool handleLocked = false; void lockVolume(); diff --git a/machine_creator/StorageDelegate.cpp b/machine_creator/StorageDelegate.cpp index f5d1028..6297b78 100644 --- a/machine_creator/StorageDelegate.cpp +++ b/machine_creator/StorageDelegate.cpp @@ -62,11 +62,7 @@ void StorageDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio painter->setFont(subFont); if (!(opt.state & QStyle::State_Selected)) - { - QColor penColor = painter->pen().color(); - penColor.setNamedColor("#A0A0A0"); - painter->setPen(penColor); - } + painter->setPen(QColor::fromString("#A0A0A0")); painter->drawText(QRect(rect.left() + iconsize.width() + 8, rect.top()+rect.height()/2, rect.width() - iconsize.width() - 8, rect.height()/2), opt.displayAlignment, subText); diff --git a/machine_creator/UsbMonitor_win.cpp b/machine_creator/UsbMonitor_win.cpp index f19fc4c..beb2762 100644 --- a/machine_creator/UsbMonitor_win.cpp +++ b/machine_creator/UsbMonitor_win.cpp @@ -40,7 +40,7 @@ UsbMonitor_win::~UsbMonitor_win() qWarning() << "Unable to unregister for device notifications"; } -bool UsbMonitor_win::nativeEvent(const QByteArray &eventType, void *message, long *result) +bool UsbMonitor_win::nativeEvent(const QByteArray &eventType, void *message, qintptr *result) { Q_UNUSED(eventType); Q_UNUSED(result); diff --git a/machine_creator/UsbMonitor_win.h b/machine_creator/UsbMonitor_win.h index e8c826a..0eeee8c 100644 --- a/machine_creator/UsbMonitor_win.h +++ b/machine_creator/UsbMonitor_win.h @@ -44,7 +44,7 @@ class UsbMonitor_win: public QWidget HDEVNOTIFY notifyHandle = nullptr; - virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result); + virtual bool nativeEvent(const QByteArray &eventType, void *message, qintptr *result) override; }; #endif // USBMONITOR_WIN_H diff --git a/machine_creator/drivelist/src/windows/list.cpp b/machine_creator/drivelist/src/windows/list.cpp index 4947560..a063e87 100644 --- a/machine_creator/drivelist/src/windows/list.cpp +++ b/machine_creator/drivelist/src/windows/list.cpp @@ -397,7 +397,7 @@ bool GetPartitionTableType(HANDLE hPhysical, DeviceDescriptor *device) { &diskLayoutSize, NULL); if (!hasDiskLayout) { - free(diskLayout); + delete(diskLayout); return hasDiskLayout; } /* @@ -442,7 +442,7 @@ bool GetPartitionTableType(HANDLE hPhysical, DeviceDescriptor *device) { } else if (diskLayout->PartitionStyle == PARTITION_STYLE_GPT) { device->partitionTableType = "gpt"; } - free(diskLayout); + delete(diskLayout); return hasDiskLayout; } diff --git a/machine_creator/machine_creator.pro b/machine_creator/machine_creator.pro index ac34511..c65d073 100755 --- a/machine_creator/machine_creator.pro +++ b/machine_creator/machine_creator.pro @@ -105,7 +105,8 @@ win32 { LIBS += -lole32 -loleaut32 -luuid -lsetupapi #KArchive - INCLUDEPATH += C:/kderoot/include/KF5/KArchive \ + INCLUDEPATH += C:/kderoot/include/KF5/ \ + C:/kderoot/include/KF5/KArchive \ /mxe/usr/i686-w64-mingw32.shared.posix/include/KF5/KArchive \ /mxe/usr/i686-w64-mingw32.shared.posix/include/KF6/KArchive LIBS += -LC:/kderoot/lib \ diff --git a/machine_creator/mainwindow.cpp b/machine_creator/mainwindow.cpp index 280fe78..f8cfc66 100755 --- a/machine_creator/mainwindow.cpp +++ b/machine_creator/mainwindow.cpp @@ -241,6 +241,8 @@ void MainWindow::writeError(QString error) void MainWindow::writeProgress(QString status, qint64 bytesReceived, qint64 bytesTotal, qint64 elapsedMs) { + //qDebug() << "writeProgress: " << status << bytesReceived << bytesTotal << elapsedMs; + if (bytesTotal > 0) { ui->writeProgress->setMinimum (0); @@ -256,6 +258,13 @@ void MainWindow::writeProgress(QString status, qint64 bytesReceived, qint64 byte double speed = bytesReceived * 1000.0 / elapsedMs; ui->speedWriteLabel->setText(tr("Speed: %1/s").arg(Utils::sizeHuman(speed))); } + else if (bytesTotal == 0 && bytesReceived > 0) + { + ui->writeLabel->setText(tr("%1 %2") + .arg(status, Utils::sizeHuman(bytesReceived))); + double speed = bytesReceived * 1000.0 / elapsedMs; + ui->speedWriteLabel->setText(tr("Speed: %1/s").arg(Utils::sizeHuman(speed))); + } else { ui->writeProgress->setMinimum(0); @@ -271,7 +280,7 @@ void MainWindow::startWriteProcess() { startDownloadTime = QDateTime::currentDateTime(); - QtConcurrent::run([=]() + auto f = QtConcurrent::run([=]() { diskWriter->writeToRemovableDevice(m_decompressedFile, m_disk); });