chore: continue port away from win32 api
This commit is contained in:
parent
736eda83e6
commit
7723783f3c
48
caesium.cpp
48
caesium.cpp
@ -56,8 +56,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <windows.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
|
|
||||||
QElapsedTimer t;
|
QElapsedTimer t;
|
||||||
int error_count = 0, iteration_count = 0, skipped_count;
|
int error_count = 0, iteration_count = 0, skipped_count;
|
||||||
@ -72,48 +70,6 @@ int item_count, saved_space;
|
|||||||
QImage currentImage;
|
QImage currentImage;
|
||||||
double img_ratio;
|
double img_ratio;
|
||||||
|
|
||||||
WCHAR *m_qStringToWideChar(const QString &str)
|
|
||||||
{
|
|
||||||
if (str.isNull())
|
|
||||||
return 0;
|
|
||||||
WCHAR *result = new WCHAR[str.length() + 1];
|
|
||||||
for (int i = 0; i < str.length(); ++i)
|
|
||||||
result[i] = str[i].unicode();
|
|
||||||
result[str.length()] = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void m_startProcess(QString argv)
|
|
||||||
{
|
|
||||||
WCHAR* exe = m_qStringToWideChar(argv);
|
|
||||||
STARTUPINFO si;
|
|
||||||
PROCESS_INFORMATION pi;
|
|
||||||
|
|
||||||
ZeroMemory( &si, sizeof(si) );
|
|
||||||
si.cb = sizeof(si);
|
|
||||||
ZeroMemory( &pi, sizeof(pi) );
|
|
||||||
|
|
||||||
if( !CreateProcessW( NULL,
|
|
||||||
exe,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
FALSE,
|
|
||||||
CREATE_NO_WINDOW ,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&si,
|
|
||||||
&pi )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitForSingleObject( pi.hProcess, INFINITE );
|
|
||||||
|
|
||||||
CloseHandle( pi.hProcess );
|
|
||||||
CloseHandle( pi.hThread );
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeDir(QString path)
|
void removeDir(QString path)
|
||||||
{
|
{
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
@ -1587,8 +1543,8 @@ void Caesium::runPreview()
|
|||||||
}
|
}
|
||||||
if (settings.value("Preferences/exif").value<bool>())
|
if (settings.value("Preferences/exif").value<bool>())
|
||||||
{
|
{
|
||||||
QString exec = "tools\\exif_copy.exe \"" + ui->listTreeWidget->selectedItems().at(i)->text(7) + "\" \"" + tempFolder + "/_caesium_/" + rndString + ".cae\"";
|
QString exec = "\"" + ui->listTreeWidget->selectedItems().at(i)->text(7) + "\" \"" + tempFolder + "/_caesium_/" + rndString + ".cae\"";
|
||||||
m_startProcess(exec);
|
startBlockingProcess("tools\\exif_copy.exe", exec);
|
||||||
}
|
}
|
||||||
ui->listTreeWidget->selectedItems().at(i)->setText(2, fixedSize(info.size(), 0));
|
ui->listTreeWidget->selectedItems().at(i)->setText(2, fixedSize(info.size(), 0));
|
||||||
ui->listTreeWidget->selectedItems().at(i)->setText(3, getRatio(orig.size(), info.size()));
|
ui->listTreeWidget->selectedItems().at(i)->setText(3, getRatio(orig.size(), info.size()));
|
||||||
|
@ -37,54 +37,8 @@
|
|||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#include <afxres.h>
|
|
||||||
#include <tchar.h>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
WCHAR *qStringToWideChar(const QString &str)
|
|
||||||
{
|
|
||||||
if (str.isNull())
|
|
||||||
return 0;
|
|
||||||
WCHAR *result = new WCHAR[str.length() + 1];
|
|
||||||
for (int i = 0; i < str.length(); ++i)
|
|
||||||
result[i] = str[i].unicode();
|
|
||||||
result[str.length()] = 0;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void startProcess(QString argv)
|
|
||||||
{
|
|
||||||
WCHAR* exe = qStringToWideChar(argv);
|
|
||||||
STARTUPINFO si;
|
|
||||||
PROCESS_INFORMATION pi;
|
|
||||||
|
|
||||||
ZeroMemory( &si, sizeof(si) );
|
|
||||||
si.cb = sizeof(si);
|
|
||||||
ZeroMemory( &pi, sizeof(pi) );
|
|
||||||
|
|
||||||
if( !CreateProcessW( NULL,
|
|
||||||
exe,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
FALSE,
|
|
||||||
CREATE_NO_WINDOW,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
&si,
|
|
||||||
&pi )
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
WaitForSingleObject( pi.hProcess, INFINITE );
|
|
||||||
|
|
||||||
CloseHandle( pi.hProcess );
|
|
||||||
CloseHandle( pi.hThread );
|
|
||||||
}
|
|
||||||
|
|
||||||
CompressionThread::CompressionThread(QStringList list, QString orig_dir, QString dir, QString format, QString suffix, QStringList quality, bool checked, QList<int> w, QList<int> h, bool fixed, bool keepARatio, bool notEnlarge, bool resize, bool structure,
|
CompressionThread::CompressionThread(QStringList list, QString orig_dir, QString dir, QString format, QString suffix, QStringList quality, bool checked, QList<int> w, QList<int> h, bool fixed, bool keepARatio, bool notEnlarge, bool resize, bool structure,
|
||||||
QObject *parent)
|
QObject *parent)
|
||||||
: QThread(parent)
|
: QThread(parent)
|
||||||
@ -217,8 +171,8 @@ void CompressionThread::run()
|
|||||||
|
|
||||||
if (settings.value("Preferences/exif").value<bool>() && t_format.toLower() == "jpg")
|
if (settings.value("Preferences/exif").value<bool>() && t_format.toLower() == "jpg")
|
||||||
{
|
{
|
||||||
QString exec = "tools\\exif_copy.exe \"" + t_list.at(i) + "\" \"" + t_dir + "\\" + info.completeBaseName() + t_suffix +"\"";
|
QString exec = "\"" + t_list.at(i) + "\" \"" + t_dir + "\\" + info.completeBaseName() + t_suffix +"\"";
|
||||||
startProcess(exec);
|
startBlockingProcess("tools\\exif_copy.exe", exec);
|
||||||
}
|
}
|
||||||
QFile newImage(t_dir + "/" + info.completeBaseName() + t_suffix);
|
QFile newImage(t_dir + "/" + info.completeBaseName() + t_suffix);
|
||||||
QFileInfo newInfo;
|
QFileInfo newInfo;
|
||||||
@ -329,8 +283,8 @@ void CompressionThread::noEnlarge()
|
|||||||
|
|
||||||
if (settings.value("Preferences/exif").value<bool>() && t_format.toLower() == "jpg")
|
if (settings.value("Preferences/exif").value<bool>() && t_format.toLower() == "jpg")
|
||||||
{
|
{
|
||||||
QString exec = "tools\\exif_copy.exe \"" + t_list.at(i) + "\" \"" + t_dir + "\\" + info.completeBaseName() + t_suffix + "." + t_format + "\"";
|
QString exec = "\"" + t_list.at(i) + "\" \"" + t_dir + "\\" + info.completeBaseName() + t_suffix + "." + t_format + "\"";
|
||||||
startProcess(exec);
|
startBlockingProcess("tools\\exif_copy.exe", exec);
|
||||||
}
|
}
|
||||||
|
|
||||||
QFileInfo newInfo(t_dir + "/" + info.completeBaseName() + t_suffix + "." + t_format + ".ckd");
|
QFileInfo newInfo(t_dir + "/" + info.completeBaseName() + t_suffix + "." + t_format + ".ckd");
|
||||||
@ -378,6 +332,6 @@ void CompressionThread::keepDate(const QString & orig, const QString & dest)
|
|||||||
|
|
||||||
void CompressionThread::optimizePNG(QString file, int level)
|
void CompressionThread::optimizePNG(QString file, int level)
|
||||||
{
|
{
|
||||||
QString exec = "tools\\optipng.exe -o" + QString::number(level) + " \"" + file + "\"";
|
QString exec = "-o" + QString::number(level) + " \"" + file + "\"";
|
||||||
startProcess(exec);
|
startBlockingProcess("tools\\optipng.exe", exec);
|
||||||
}
|
}
|
||||||
|
10
global.cpp
10
global.cpp
@ -27,6 +27,8 @@
|
|||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
QSettings settings(QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).at(0) + "/Caesium/settings.ini", QSettings::IniFormat);
|
QSettings settings(QStandardPaths::standardLocations(QStandardPaths::AppLocalDataLocation).at(0) + "/Caesium/settings.ini", QSettings::IniFormat);
|
||||||
QString out_folder = "";
|
QString out_folder = "";
|
||||||
bool same_folder_flag = false;
|
bool same_folder_flag = false;
|
||||||
@ -39,3 +41,11 @@ bool isJpegSuffix(const QString &suffix)
|
|||||||
const QStringList jpegSuffix({"jpg", "jpeg", "jfif"});
|
const QStringList jpegSuffix({"jpg", "jpeg", "jfif"});
|
||||||
return (jpegSuffix.contains(suffix.toLower()));
|
return (jpegSuffix.contains(suffix.toLower()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void startBlockingProcess(const QString & program, const QString & argv)
|
||||||
|
{
|
||||||
|
QProcess proc;
|
||||||
|
proc.start(program, QProcess::splitCommand(argv));
|
||||||
|
proc.waitForFinished(INT_MAX);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
1
global.h
1
global.h
@ -12,5 +12,6 @@ extern const QString version_string;
|
|||||||
extern QString opened_list;
|
extern QString opened_list;
|
||||||
|
|
||||||
bool isJpegSuffix(const QString & suffix);
|
bool isJpegSuffix(const QString & suffix);
|
||||||
|
void startBlockingProcess(const QString &program, const QString & exec);
|
||||||
|
|
||||||
#endif // GLOBAL_H
|
#endif // GLOBAL_H
|
||||||
|
Loading…
Reference in New Issue
Block a user