Skip to content

Commit

Permalink
Add support Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
tx00100xt committed Sep 24, 2023
1 parent 3cb93e8 commit a3d9315
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 58 deletions.
92 changes: 89 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.14)

project(Serious-Runner VERSION 1.0)
project(Serious-Runner VERSION 1.1)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

Expand All @@ -11,6 +11,58 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW) #3.12.0 `find_package()`` uses ``<PackageName>_ROOT`` variables.
endif()

OPTION(ENABLE_LZMA "Enable the use of the system LZMA library if found" ON)
OPTION(ENABLE_ZLIB "Enable the use of the system ZLIB library if found" ON)
OPTION(ENABLE_BZip2 "Enable the use of the system BZip2 library if found" ON)

IF(MINGW)
ADD_DEFINITIONS(-D__USE_MINGW_ANSI_STDIO)
ADD_DEFINITIONS(-D__MINGW_USE_VC2005_COMPAT)
ENDIF()

IF(WIN32)
SET(LOCAL_INSTALL TRUE)
ENDIF()

#
# Check compress/decompress libraries
#
IF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
# GnuWin32 is only for Win32, not Win64.
SET(__GNUWIN32PATH "C:/Program Files/GnuWin32")
ENDIF(WIN32 AND NOT CMAKE_CL_64 AND NOT CYGWIN)
IF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")
# You have to add a path available DLL file into PATH environment variable.
# Maybe DLL path is "C:/Program Files/GnuWin32/bin".
# The zlib and the bzip2 Setup program have installed programs and DLLs into
# "C:/Program Files/GnuWin32" by default.
# This is convenience setting for Windows.
SET(CMAKE_PREFIX_PATH ${__GNUWIN32PATH} $(CMAKE_PREFIX_PATH))
#
# If you didn't use Setup program or installed into nonstandard path,
# cmake cannot find out your zlib or bzip2 libraries and include files,
# you should execute cmake with -DCMAKE_PREFIX_PATH option.
# e.g.
# cmake -DCMAKE_PREFIX_PATH=<your-GnuWin32-path> <path-to-source>
#
# If compiling error occurred in zconf.h, You may need patch to zconf.h.
#--- zconf.h.orig 2005-07-21 00:40:26.000000000
#+++ zconf.h 2009-01-19 11:39:10.093750000
#@@ -286,7 +286,7 @@
#
# #if 1 /* HAVE_UNISTD_H -- this line is updated by ./configure */
# # include <sys/types.h> /* for off_t */
#-# include <unistd.h> /* for SEEK_* and off_t */
#+# include <stdio.h> /* for SEEK_* and off_t */
# # ifdef VMS
# # include <unixio.h> /* for off_t */
# # endif
ENDIF(DEFINED __GNUWIN32PATH AND EXISTS "${__GNUWIN32PATH}")

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
include(CheckCXXCompilerFlag)

Expand Down Expand Up @@ -151,6 +203,14 @@ if (LINUX)
endif (DEBIAN_FOUND)
endif (LINUX)

if(WIN32)
set(CMAKE_OS_NAME "Windows")
add_definitions(-DPLATFORM_WIN32=1)
add_definitions(-DPRAGMA_ONCE=1)
add_definitions(-D_CRT_SECURE_NO_WARNINGS=1)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE=1)
endif()

message(STATUS "Operating system name: ${CMAKE_OS_NAME}")

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
Expand Down Expand Up @@ -266,7 +326,23 @@ else()
message(FATAL_ERROR "Unsupported compiler")
endif()

set(PROJECT_SOURCES
if(WIN32)
set(PROJECT_SOURCES
Resources.qrc
Main.cpp
MainWindow.cpp
MainWindow.h
MainWindow.ui
Classes/Downloader.cpp
Classes/Downloader.h
Classes/Unpacker.cpp
Classes/Unpacker.h
Classes/CopyDir.cpp
Classes/CopyDir.h
Classes/Types.h
)
else()
set(PROJECT_SOURCES
Resources.qrc
Main.cpp
MainWindow.cpp
Expand All @@ -282,6 +358,7 @@ set(PROJECT_SOURCES
Classes/CopyDir.h
Classes/Types.h
)
endif()

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(Serious-Runner
Expand All @@ -299,14 +376,23 @@ else()
)
# Define properties for Android with Qt 5 after find_package() calls as:
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
elseif(WIN32)
set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/seriousrunner.rc")
add_executable(Serious-Runner
${PROJECT_SOURCES} ${APP_ICON_RESOURCE_WINDOWS}
)
else()
add_executable(Serious-Runner
${PROJECT_SOURCES}
)
)
endif()
endif()

# Link libraries.
if(WIN32)
# uncoment this for static link
# set_target_properties(Serious-Runner PROPERTIES LINK_FLAGS "-static")
endif()

target_link_libraries(Serious-Runner PRIVATE Qt${QT_VERSION_MAJOR}::Widgets Qt5::Sql Qt5::Network LibArchive::LibArchive LibLZMA::LibLZMA BZip2::BZip2 ZLIB::ZLIB)

Expand Down
37 changes: 26 additions & 11 deletions Classes/Downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ bool Downloader::GetLevel(const QString &strTargetFolder, const QUrl &urlLevel)

bool Downloader::GetMod(const QString &strTargetFolder, const QString &strTargetGame, const QUrl &urlModBin, const QUrl &urlModData)
{
#ifdef PLATFORM_UNIX
QString strTMPDirPath = "/tmp";
#else
QString strTMPDirPath = QDir::homePath() +"/AppData/Local/Temp";
#endif
bool bResult;
// Save Taeget folders and urls
strFirstTargetFolder = strTargetFolder;
Expand All @@ -79,20 +84,25 @@ bool Downloader::GetMod(const QString &strTargetFolder, const QString &strTarget
bGameUnpack = false;
iPassCount = 0;
// Download
bResult = GetMain( "/tmp" , urlModData, true);
bResult = GetMain( strTMPDirPath , urlModData, true);
} else {
// Set type of download
bModUnpack = true;
bGameUnpack = false;
iPassCount = 1;
// Download
bResult = GetMain( "/tmp" , urlModBin, true);
bResult = GetMain( strTMPDirPath , urlModBin, true);
}
return bResult;
}

bool Downloader::GetGameSettings(const QString &strTargetFolder, const QUrl &urlGameBin, const QUrl &urlGameSettings)
{
#ifdef PLATFORM_UNIX
QString strTMPDirPath = "/tmp";
#else
QString strTMPDirPath = QDir::homePath() +"/AppData/Local/Temp";
#endif
// Save Taeget folders and urls
strFirstTargetFolder = strTargetFolder;
strFirstTargetUrl = urlGameBin;
Expand All @@ -103,7 +113,7 @@ bool Downloader::GetGameSettings(const QString &strTargetFolder, const QUrl &url
bGameUnpack = true;
iPassCount = 1;
// Download
bool bResult = GetMain( "/tmp", urlGameBin, true);
bool bResult = GetMain( strTMPDirPath, urlGameBin, true);
return bResult;
}

Expand Down Expand Up @@ -185,29 +195,34 @@ void Downloader::slotOnReply(QNetworkReply* netReply)
m_file = nullptr;
netReply->deleteLater();

#ifdef PLATFORM_UNIX
QString strTMPDirPath = "/tmp/";
#else
QString strTMPDirPath = QDir::homePath() +"/AppData/Local/Temp/";
#endif
// Download Progres End
if(bGameUnpack || bModUnpack){
if (bGameUnpack && iPassCount == 1){
m_unpack.Extract("/tmp/" + strFirstTargetUrl.fileName(), "/tmp/", 1, 0);
m_copydir.CopyAndReplaceFolderContents("/tmp/x64", strFirstTargetFolder, false);
m_unpack.Extract(strTMPDirPath + strFirstTargetUrl.fileName(), strTMPDirPath, 1, 0);
m_copydir.CopyAndReplaceFolderContents( strTMPDirPath + "x64", strFirstTargetFolder, false);
iPassCount = 0;
GetMain("/tmp/", strSecondTargetUrl, false);
GetMain(strTMPDirPath, strSecondTargetUrl, false);

} else if (bGameUnpack && iPassCount == 0){
m_unpack.Extract("/tmp/" + strSecondTargetUrl.fileName(), strSecondTargetFolder + "/", 1, 0);
m_unpack.Extract(strTMPDirPath + strSecondTargetUrl.fileName(), strSecondTargetFolder + "/", 1, 0);
bGameUnpack = bModUnpack = false;
emit signalDownloadProgressEnd();
emit signalTestGameInstall();
locked_action = false;
}
if (bModUnpack && iPassCount == 1){
m_unpack.Extract("/tmp/" + strFirstTargetUrl.fileName(), "/tmp/", 1, 0);
m_copydir.CopyAndReplaceFolderContents("/tmp/x64",strFirstTargetFolder, false);
m_unpack.Extract(strTMPDirPath + strFirstTargetUrl.fileName(), strTMPDirPath, 1, 0);
m_copydir.CopyAndReplaceFolderContents( strTMPDirPath + "x64",strFirstTargetFolder, false);
iPassCount = 0;
GetMain("/tmp/", strSecondTargetUrl, false);
GetMain(strTMPDirPath, strSecondTargetUrl, false);

} else if (bModUnpack && iPassCount == 0){
m_unpack.Extract("/tmp/" + strSecondTargetUrl.fileName(), strSecondTargetFolder + "/", 1, 0);
m_unpack.Extract(strTMPDirPath + strSecondTargetUrl.fileName(), strSecondTargetFolder + "/", 1, 0);
bGameUnpack = bModUnpack = false;
emit signalDownloadProgressEnd();
locked_action = false;
Expand Down
9 changes: 5 additions & 4 deletions Classes/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
enum MESSAGETYPE {
INFO,
WARN,
ERROR
ERR
};

enum DOWNLOADTYPE {
Expand Down Expand Up @@ -40,8 +40,8 @@ enum SE_TABLES {
};

enum BOOLTYPES {
FALSE,
TRUE
BOOLFALSE,
BOOLTRUE
};

enum PROGRESSBARINDEX {
Expand Down Expand Up @@ -71,7 +71,8 @@ enum DISTROFLAG {
FREEBSD,
ALPINE,
LINUX,
OTHER
OTHER,
WINDOWS
};

enum APPTHEMES {
Expand Down
8 changes: 5 additions & 3 deletions Classes/Unpacker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <sys/types.h>
#include <QtCore/qiodevice.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
Expand Down Expand Up @@ -45,7 +46,8 @@ void Unpacker::Extract(QString strFileName, QString strPath, int iDoExtract, int
archive_read_support_format_zip(a);
archive_read_support_filter_compress(a);
archive_read_support_format_tar(a);
archive_read_support_format_cpio(a);
archive_read_support_format_cpio(a);
archive_read_support_format_7zip(a);
archive_write_disk_set_standard_lookup(ext);

QByteArray ba1 = strFileName.toLocal8Bit();
Expand Down Expand Up @@ -130,7 +132,7 @@ void Unpacker::MsgBox(int type, QString strMessage)
case WARN:
msgBox.setIconPixmap(QPixmap(":/Images/warning.png"));
break;
case ERROR:
case 2:
msgBox.setIconPixmap(QPixmap(":/Images/error.png"));
break;
default:
Expand Down
Binary file added GnuWin/GnuWin.zip
Binary file not shown.
Binary file added Icons/seriousrunner.ico
Binary file not shown.
Loading

0 comments on commit a3d9315

Please sign in to comment.