@ -6,6 +6,7 @@
# include <QFileDialog>
# include <QFile>
# include <QProcess>
# include <QDebug>
# include <vector>
# include <string>
@ -89,7 +90,7 @@ void GiantsWdefImporter::revertFile(const std::filesystem::path& path)
}
// TODO implement error handling
fs : : copy ( dest , path );
fs : : copy ( dest , path , fs : : copy_options : : overwrite_existing );
}
void GiantsWdefImporter : : setParent ( QObject * parent )
@ -99,6 +100,8 @@ void GiantsWdefImporter::setParent(QObject* parent)
QByteArray GiantsWdefImporter : : newExeBytes ( const QByteArray & wdefsBytes , const std : : filesystem : : path & giantsMainPath )
{
// Look for checksum in exe file
QByteArray checksum { " \x78 \x05 \x44 \xb6 " } ; // should be at offset 0x152bff in giantsmain.exe
QFile exeFile { QString : : fromStdString ( giantsMainPath . string ( ) ) } ;
@ -128,7 +131,9 @@ QByteArray GiantsWdefImporter::newExeBytes(const QByteArray& wdefsBytes, const s
GiantsWdefImporter : : StartResult GiantsWdefImporter : : startGiantsWithWdefsBytes ( QByteArray const & wdefsBytes , fs : : path const & wdefsPath , fs : : path const & giantsMainPath , QPushButton * button )
{
// switching to QFile here from filesystem for ease of use
// Try writing the wdefs file
// Switching to QFile here from filesystem for ease of use
QFile wdefsFile ( QString : : fromStdString ( wdefsPath . string ( ) ) ) ;
wdefsFile . open ( QIODevice : : WriteOnly ) ;
@ -138,6 +143,8 @@ GiantsWdefImporter::StartResult GiantsWdefImporter::startGiantsWithWdefsBytes(QB
return StartResult : : FAILURE ;
}
// Try writing the exe file
QByteArray newBytes = newExeBytes ( wdefsBytes , giantsMainPath ) ;
QFile exeFile ( QString : : fromStdString ( giantsMainPath . string ( ) ) ) ;
@ -149,6 +156,14 @@ GiantsWdefImporter::StartResult GiantsWdefImporter::startGiantsWithWdefsBytes(QB
return StartResult : : FAILURE ;
}
// Try starting GiantsMain.exe
if ( QOperatingSystemVersion : : Windows ! = QOperatingSystemVersion : : currentType ( ) ) {
QMessageBox : : warning ( nullptr , " wdefs " , " For now, this program only works on Windows. Please consider contacting taibsu#1841 or Amazed#0001 in the GiantsWD Discord channel for further usage. " ) ;
return StartResult : : FAILURE ;
}
auto giantsFinished = [ & ] ( ) {
revertFile ( giantsMainPath ) ;
revertFile ( wdefsPath ) ;
@ -161,20 +176,26 @@ GiantsWdefImporter::StartResult GiantsWdefImporter::startGiantsWithWdefsBytes(QB
QProcess process ( _parent ) ;
QObject : : connect ( & process , static_cast < void ( QProcess : : * ) ( int , QProcess : : ExitStatus ) > ( & QProcess : : finished ) , [ & ] ( ) {
giantsFinished ( ) ;
QObject : : connect ( & process , & QProcess : : stateChanged , [ & ] ( QProcess : : ProcessState state ) {
switch ( state ) {
case QProcess : : ProcessState : : Running :
qDebug ( ) < < " Running " ;
button - > setText ( " Game started " ) ;
break ;
default :
button - > setText ( " Game not running " ) ;
break ;
}
} ) ;
process . setWorkingDirectory ( QString : : fromStdString ( giantsMainPath . parent_path ( ) . string ( ) ) ) ;
if ( QOperatingSystemVersion : : Windows ! = QOperatingSystemVersion : : currentType ( ) ) {
QMessageBox : : warning ( nullptr , " wdefs " , " For now, this program only works on Windows. Please consider contacting taibsu#1841 or Amazed#0001 in the GiantsWD Discord channel for further usage. " ) ;
return StartResult : : FAILURE ;
}
button - > setText ( " Game started " ) ;
QObject : : connect ( & process , QOverload < int , QProcess : : ExitStatus > : : of ( & QProcess : : finished ) ,
[ & ] ( ) { giantsFinished ( ) ; }
) ;
QObject : : connect ( & process , & QProcess : : errorOccurred ,
[ & ] ( ) { giantsFinished ( ) ; }
) ;
process . setWorkingDirectory ( QString : : fromStdString ( giantsMainPath . parent_path ( ) . string ( ) ) ) ;
process . start ( QString : : fromStdString ( giantsMainPath . string ( ) ) , { " -launcher " } ) ;
return StartResult : : SUCCESS ;