Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Debug/
Release/
build-*/
build*/
*.exe
*.pro.user*
*dll
Expand Down
51 changes: 29 additions & 22 deletions src/disk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <windows.h>
#include <winioctl.h>
#include "disk.h"
#include "mainwindow.h"


void ShowCriticalMessage(QString title, QString text)
{
Expand Down Expand Up @@ -94,11 +94,12 @@ HANDLE getHandleOnFile(LPCWSTR filelocation, DWORD access)
wchar_t *errormessage=NULL;
::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0,
(LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
QString fileloc = QString::fromUtf16((const char16_t *)filelocation);
ShowCriticalMessage(
QObject::tr("File Error"),
QObject::tr("An error occurred when attempting to get a handle on the file.\n"
"Error %1: %2").arg(GetLastError()).arg(errText));
QObject::tr("An error occurred when attempting to get a handle on the file `%1`.\n"
"Error %2: %3").arg(fileloc).arg(GetLastError()).arg(errText));
LocalFree(errormessage);
}
return hFile;
Expand All @@ -113,7 +114,7 @@ DWORD getDeviceID(HANDLE hVolume)
wchar_t *errormessage=NULL;
::FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0,
(LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Volume Error"),
QObject::tr("An error occurred when attempting to get information on volume.\n"
Expand All @@ -132,7 +133,7 @@ HANDLE getHandleOnDevice(int device, DWORD access)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Device Error"),
QObject::tr("An error occurred when attempting to get a handle on the device.\n"
Expand All @@ -152,7 +153,7 @@ HANDLE getHandleOnVolume(int volume, DWORD access)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Volume Error"),
QObject::tr("An error occurred when attempting to get a handle on the volume.\n"
Expand All @@ -171,7 +172,7 @@ bool getLockOnVolume(HANDLE handle)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Lock Error"),
QObject::tr("An error occurred when attempting to lock the volume.\n"
Expand All @@ -190,7 +191,7 @@ bool removeLockOnVolume(HANDLE handle)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Unlock Error"),
QObject::tr("An error occurred when attempting to unlock the volume.\n"
Expand All @@ -209,7 +210,7 @@ bool unmountVolume(HANDLE handle)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Dismount Error"),
QObject::tr("An error occurred when attempting to dismount the volume.\n"
Expand Down Expand Up @@ -238,7 +239,7 @@ char *readSectorDataFromHandle(HANDLE handle, unsigned long long startsector, un
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Read Error"),
QObject::tr("An error occurred when attempting to read data from handle.\n"
Expand Down Expand Up @@ -266,7 +267,7 @@ bool writeSectorDataToHandle(HANDLE handle, char *data, unsigned long long start
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Write Error"),
QObject::tr("An error occurred when attempting to write data to handle.\n"
Expand All @@ -286,7 +287,7 @@ unsigned long long getNumberOfSectors(HANDLE handle, unsigned long long *sectors
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Device Error"),
QObject::tr("An error occurred when attempting to get the device's geometry.\n"
Expand All @@ -312,7 +313,7 @@ unsigned long long getFileSizeInSectors(HANDLE handle, unsigned long long sector
// error
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("File Error"),
QObject::tr("An error occurred while getting the file size.\n"
Expand All @@ -337,7 +338,7 @@ bool spaceAvailable(char *location, unsigned long long spaceneeded)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Free Space Error"),
QObject::tr("Failed to get the free space on drive %1.\n"
Expand Down Expand Up @@ -404,7 +405,7 @@ BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc,
retVal = false;
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("File Error"),
QObject::tr("An error occurred while getting the device number.\n"
Expand All @@ -426,7 +427,7 @@ BOOL GetDisksProperty(HANDLE hDevice, PSTORAGE_DEVICE_DESCRIPTOR pDevDesc,
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("File Error"),
QObject::tr("An error occurred while querying the properties.\n"
Expand Down Expand Up @@ -498,14 +499,20 @@ bool checkDriveType(char *name, ULONG *pid, char* extra_info, int extra_len)
PSTORAGE_DEVICE_DESCRIPTOR pDevDesc;
DEVICE_NUMBER deviceInfo;
bool retVal = false;
char *nameWithSlash;
char *nameNoSlash;
char *nameWithSlash = nullptr;
char *nameNoSlash = nullptr;
int driveType;
DWORD cbBytesReturned;

// some calls require no tailing slash, some require a trailing slash...
if ( !(slashify(name, &nameWithSlash, &nameNoSlash)) )
{
if(nameWithSlash) {
free(nameWithSlash);
}
if(nameNoSlash) {
free(nameNoSlash);
}
return(retVal);
}

Expand All @@ -519,7 +526,7 @@ bool checkDriveType(char *name, ULONG *pid, char* extra_info, int extra_len)
{
wchar_t *errormessage=NULL;
FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, GetLastError(), 0, (LPWSTR)&errormessage, 0, NULL);
QString errText = QString::fromUtf16((const ushort *)errormessage);
QString errText = QString::fromUtf16((const char16_t *)errormessage);
ShowCriticalMessage(
QObject::tr("Volume Error"),
QObject::tr("An error occurred when attempting to get a handle on %3.\n"
Expand Down Expand Up @@ -564,8 +571,8 @@ bool checkDriveType(char *name, ULONG *pid, char* extra_info, int extra_len)
PARTITION_INFORMATION_EX partInfo;

offs += snprintf(extra_info, extra_len, "Disk%d.Part%d",
deviceInfo.DeviceNumber,
deviceInfo.PartitionNumber);
(int)deviceInfo.DeviceNumber,
(int)deviceInfo.PartitionNumber);

if (DeviceIoControl(
hDevice,
Expand Down
2 changes: 1 addition & 1 deletion src/elapsedtimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
ElapsedTimer::ElapsedTimer(QWidget *parent)
: QLabel(parent)
{
timer = new QTime();
timer = new QElapsedTimer();
setTextFormat(Qt::PlainText);
setTextInteractionFlags(Qt::NoTextInteraction);
setText(QString("0:00/0:00"));
Expand Down
2 changes: 1 addition & 1 deletion src/elapsedtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ElapsedTimer : public QLabel
unsigned short sec = 0;
};

QTime *timer;
QElapsedTimer *timer;
void secsToHMS(unsigned int secs, timeStruct_t *ts);
static const unsigned short MS_PER_SEC = 1000;
static const unsigned short SECS_PER_MIN = 60;
Expand Down
12 changes: 5 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
#endif

#include <QApplication>
#include <cstdio>
#include <cstdlib>
#include <windows.h>
#include <winioctl.h>
#include "disk.h"
#include "mainwindow.h"


Expand All @@ -35,11 +30,14 @@ int main(int argc, char *argv[])
QApplication app(argc, argv);
app.setApplicationDisplayName(VER);
app.setAttribute(Qt::AA_UseDesktopOpenGL);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
app.setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

QTranslator translator;
translator.load("translations/diskimager_" + QLocale::system().name());
app.installTranslator(&translator);
if (translator.load("translations/diskimager_" + QLocale::system().name())) {
app.installTranslator(&translator);
};

MainWindow* mainwindow = MainWindow::getInstance();
mainwindow->show();
Expand Down
8 changes: 4 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ void MainWindow::loadSettings()
void MainWindow::initializeHomeDir()
{
myHomeDir = QDir::homePath();
if (myHomeDir == NULL){
if (QDir(myHomeDir).exists()){
myHomeDir = qgetenv("USERPROFILE");
}
/* Get Downloads the Windows way */
Expand Down Expand Up @@ -221,7 +221,7 @@ void MainWindow::on_tbBrowse_clicked()
dialog.setNameFilter(fileType);
dialog.setFileMode(QFileDialog::AnyFile);
dialog.setViewMode(QFileDialog::Detail);
dialog.setConfirmOverwrite(false);
dialog.setOption(QFileDialog::DontConfirmOverwrite);
if (fileinfo.exists())
{
dialog.selectFile(fileLocation);
Expand Down Expand Up @@ -331,7 +331,7 @@ void MainWindow::on_bWrite_clicked()
// build the drive letter as a const char *
// (without the surrounding brackets)
QString qs = cboxDevice->currentText();
qs.replace(QRegExp("[\\[\\]]"), "");
qs.replace(QRegularExpression("[\\[\\]]"), ""); //TODO: check
QByteArray qba = qs.toLocal8Bit();
const char *ltr = qba.data();
if (QMessageBox::warning(this, tr("Confirm overwrite"), tr("Writing to a physical device can corrupt the device.\n"
Expand Down Expand Up @@ -1139,7 +1139,7 @@ char FirstDriveFromMask (ULONG unitmask)

// register to receive notifications when USB devices are inserted or removed
// adapted from http://www.known-issues.net/qt/qt-detect-event-windows.html
bool MainWindow::nativeEvent(const QByteArray &type, void *vMsg, long *result)
bool MainWindow::nativeEvent(const QByteArray &type, void *vMsg, qintptr *result)
{
Q_UNUSED(type);
MSG *msg = (MSG*)vMsg;
Expand Down
7 changes: 4 additions & 3 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class MainWindow : public QMainWindow, public Ui::MainWindow
}

~MainWindow();
void closeEvent(QCloseEvent *event);
void closeEvent(QCloseEvent *event) override;
enum Status {STATUS_IDLE=0, STATUS_READING, STATUS_WRITING, STATUS_VERIFYING, STATUS_EXIT, STATUS_CANCELED};
bool nativeEvent(const QByteArray &type, void *vMsg, long *result);
protected:
bool nativeEvent(const QByteArray &type, void *vMsg, qintptr *result) override;
protected slots:
void on_tbBrowse_clicked();
void on_bCancel_clicked();
Expand Down Expand Up @@ -78,7 +79,7 @@ private slots:
int status;
char *sectorData;
char *sectorData2; //for verify
QTime update_timer;
QElapsedTimer update_timer;
ElapsedTimer *elapsed_timer = NULL;
QClipboard *clipboard;
void generateHash(char *filename, int hashish);
Expand Down