Skip to content

Commit

Permalink
Fix flash zstd image file
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulh committed Jan 30, 2024
1 parent f365b92 commit a63df67
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 14 deletions.
12 changes: 10 additions & 2 deletions machine_creator/DiskWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion machine_creator/DiskWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 1 addition & 5 deletions machine_creator/StorageDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion machine_creator/UsbMonitor_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion machine_creator/UsbMonitor_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions machine_creator/drivelist/src/windows/list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ bool GetPartitionTableType(HANDLE hPhysical, DeviceDescriptor *device) {
&diskLayoutSize,
NULL);
if (!hasDiskLayout) {
free(diskLayout);
delete(diskLayout);
return hasDiskLayout;
}
/*
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion machine_creator/machine_creator.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 10 additions & 1 deletion machine_creator/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -271,7 +280,7 @@ void MainWindow::startWriteProcess()
{
startDownloadTime = QDateTime::currentDateTime();

QtConcurrent::run([=]()
auto f = QtConcurrent::run([=]()
{
diskWriter->writeToRemovableDevice(m_decompressedFile, m_disk);
});
Expand Down

0 comments on commit a63df67

Please sign in to comment.