Skip to content

Commit

Permalink
setup testbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Dec 10, 2024
1 parent cc10a16 commit 065f20e
Show file tree
Hide file tree
Showing 10 changed files with 614 additions and 276 deletions.
103 changes: 55 additions & 48 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)

project(TombRaiderLinuxLauncher)

option(TEST "Enable building test" OFF)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
Expand Down Expand Up @@ -29,11 +31,10 @@ endif()

add_subdirectory(libs/miniz)

# suppress ZERO_CHECK dont think its needed
#set(CMAKE_SUPPRESS_REGENERATION true)

set(SOURCES
src/main.cpp
src/binary.h
src/gameTree.h
src/staticData.h
src/Network.h
src/Network.cpp
Expand All @@ -45,14 +46,14 @@ set(SOURCES
src/Model.cpp
src/Data.h
src/Data.cpp
src/TombRaiderLinuxLauncher.h
src/TombRaiderLinuxLauncher.cpp
src/TombRaiderLinuxLauncher.ui
src/resources.qrc
)

set(TEST_SOURCES
src/main.cpp
test/main.cpp
test/test.h
src/binary.h
src/gameTree.h
src/staticData.h
src/Network.h
src/Network.cpp
src/Controller.h
Expand All @@ -65,55 +66,61 @@ set(TEST_SOURCES
src/Data.cpp
)

add_executable(${PROJECT_NAME} ${SOURCES})

# create the test executable
#enable_testing(false)
#add_executable(${PROJECT_NAME}Test ${TEST_SOURCES})
#add_test(NAME ${PROJECT_NAME}Test COMMAND ${PROJECT_NAME}Test)

# I think it should link to miniz here also
target_link_libraries(${PROJECT_NAME} PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::WebEngineWidgets
Qt5::Sql
miniz
${CURL_LIBRARY}
OpenSSL::SSL
Boost::system
Boost::filesystem
)
# link to Qt5::Test
# the test will be a console qt application
#target_link_libraries(${PROJECT_NAME}Test PUBLIC
# Qt5::Core
# Qt5::Gui
# Qt5::Test
# Qt5::Widgets
# Qt5::Sql
# miniz
# ${CURL_LIBRARY}
#)

target_include_directories(${PROJECT_NAME} PRIVATE
if(TEST)
enable_testing()
set(PROJECT_NAME_POST "${PROJECT_NAME}Test")
add_executable(${PROJECT_NAME_POST} ${TEST_SOURCES})
target_link_libraries(${PROJECT_NAME_POST} PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Test
Qt5::Widgets
Qt5::WebEngineWidgets
Qt5::Sql
miniz
${CURL_LIBRARY}
OpenSSL::SSL
Boost::system
Boost::filesystem
)
add_test(NAME ${PROJECT_NAME_POST} COMMAND ${PROJECT_NAME_POST})
else()
set(PROJECT_NAME_POST "${PROJECT_NAME}")
add_executable(${PROJECT_NAME_POST} ${SOURCES})
target_link_libraries(${PROJECT_NAME_POST} PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::WebEngineWidgets
Qt5::Sql
miniz
${CURL_LIBRARY}
OpenSSL::SSL
Boost::system
Boost::filesystem
)
endif()

target_include_directories(${PROJECT_NAME_POST} PRIVATE
${CURL_INCLUDE_DIR}
${Boost_INCLUDE_DIRS}
libs/miniz
src
test
)

set_target_properties(${PROJECT_NAME} PROPERTIES
set_target_properties(${PROJECT_NAME_POST} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)

install(TARGETS ${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)
if(NOT TEST)
install(TARGETS ${PROJECT_NAME_POST}
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
)

install(FILES ${CMAKE_SOURCE_DIR}/database/tombll.db
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}
)
install(FILES ${CMAKE_SOURCE_DIR}/database/tombll.db
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}
)
endif()

2 changes: 1 addition & 1 deletion setup_nvim_lsp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ rm -fr build
mkdir build
cd build || exit 1

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=Debug "$@" ..
cd ..
ln -s build/compile_commands.json compile_commands.json
4 changes: 4 additions & 0 deletions src/FileManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QtCore>
#include <QByteArray>
#include <QDataStream>
#include "gameTree.h"

bool FileManager::setUpCamp(const QString& levelDir, const QString& gameDir) {
QDir levelDirPath(levelDir);
Expand Down Expand Up @@ -212,6 +213,9 @@ int FileManager::checkFileInfo(const QString& file, bool lookGameDir) {
bool FileManager::linkGameDir(const QString& levelDir, const QString& gameDir) {
const QString& l = levelDir_m.absolutePath() + levelDir;
const QString& g = gameDir_m.absolutePath() + gameDir;

test(l);

if (QFile::link(l, g)) {
qDebug() << "Symbolic link created successfully.";
return 0;
Expand Down
93 changes: 30 additions & 63 deletions src/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ bool Model::setDirectory(const QString& level, const QString& game) {
return false;
}

void Model::checkCommonFiles()
{
void Model::checkCommonFiles() {
int index = checkCommonFilesIndex_m;
assert(index >= 1 && index <= 5);
for (int i = index; i <= 5; i++)
{
if (checkGameDirectory(i) == 2)
{
for (int i = index; i <= 5; i++) {
if (checkGameDirectory(i) == 2) {
checkCommonFilesIndex_m = i+1;
emit askGameSignal(i);
QCoreApplication::processEvents();
Expand All @@ -77,11 +74,9 @@ void Model::checkCommonFiles()
QCoreApplication::processEvents();
}

QString Model::getGameDirectory(int id)
{
QString Model::getGameDirectory(int id) {
struct FolderNames folder;
switch (id)
{
switch (id) {
case 1:
return folder.TR1;
case 2:
Expand All @@ -98,25 +93,21 @@ QString Model::getGameDirectory(int id)
}
}

int Model::checkGameDirectory(int id)
{
int Model::checkGameDirectory(int id) {
const QString s = getGameDirectory(id);
if (s != "")
return fileManager.checkFileInfo(s, true);
return -1;
}

void Model::getList(QVector<ListItemData>* list)
{
void Model::getList(QVector<ListItemData>* list) {
*list = data.getListItems();
}

int Model::getItemState(int id)
{
if (id < 0)
int Model::getItemState(int id) {
if (id < 0) {
return 1;
else if (id > 0)
{
} else if (id > 0) {
QString map(QString::number(id) + ".TRLE");
if (fileManager.checkDir(map, false))
return 2;
Expand All @@ -126,17 +117,13 @@ int Model::getItemState(int id)
return -1;
}

bool Model::setLink(int id)
{
if (id < 0)
{
bool Model::setLink(int id) {
if (id < 0) {
id = -id;
const QString s = "/Original.TR" + QString::number(id);
if (fileManager.checkDir(s, false ))
return fileManager.linkGameDir(s, getGameDirectory(id));
}
else if (id > 0)
{
} else if (id > 0) {
const QString s = "/"+QString::number(id) + ".TRLE";
const int t = data.getType(id);

Expand All @@ -146,88 +133,70 @@ bool Model::setLink(int id)
return false;
}

void Model::setupGame(int id)
{
void Model::setupGame(int id) {
std::array<QVector<QString>, 2> list = data.getFileList(id, false);
const size_t s = list[0].size();
const size_t sm = list[1].size();
if (s != sm)
{
if (s != sm) {
qDebug()
<< "Corrupt list, there seems to bee"
<< " more or less checksums for the files\n";
assert(false);
}
const QString& sd = "/Original.TR" + QString::number(id) +"/";
const QString& sg = getGameDirectory(id) + "/";
for (size_t i = 0; i < s; i++)
{
for (size_t i = 0; i < s; i++) {
const QString& fFile = list[0][i];
const QString& fMd5sum = list[1][i];
const QString& calculated = fileManager.calculateMD5(sg+fFile, true);
if (fMd5sum == calculated)
{
if (fMd5sum == calculated) {
fileManager.copyFile(sg+fFile, sd+fFile, true);
}
else
{
} else {
qDebug() << "Original file was modified, had" << fMd5sum
<< " got " << calculated << " for file "
<< fFile << Qt::endl;
fileManager.cleanWorkingDir(sd + fFile);
break;
}
}
if (fileManager.backupGameDir(sg))
{
if (fileManager.backupGameDir(sg)) {
const QString& src = sd.chopped(1);
const QString& des = sg.chopped(1);
if (!fileManager.linkGameDir(src, des))
{
if (!fileManager.linkGameDir(src, des)) {
checkCommonFiles();
return;
}
}
checkCommonFiles();
}

bool Model::getGame(int id)
{
bool Model::getGame(int id) {
assert(id > 0);
if (id)
{
if (id) {
int status = 0;
ZipData zipData = data.getDownload(id);
downloader.setUrl(zipData.url);
downloader.setSaveFile(zipData.name);

if (fileManager.checkFile(zipData.name, false))
{
if (fileManager.checkFile(zipData.name, false)) {
qDebug() << "File exists:" << zipData.name;
const QString& sum = fileManager.calculateMD5(zipData.name, false);
if (sum != zipData.md5sum)
{
if (sum != zipData.md5sum) {
downloader.run();
status = downloader.getStatus();
}
else
{
} else {
// send 50% signal here
for (int i=0; i < 50; i++)
{
for (int i=0; i < 50; i++) {
emit this->modelTickSignal();
QCoreApplication::processEvents();
}
}
}
else
{
} else {
qWarning() << "File does not exist:" << zipData.name;
downloader.run();
status = downloader.getStatus();
}
if (status == 0)
{
if (status == 0) {
fileManager.extractZip(zipData.name, QString::number(id)+".TRLE");
instructionManager.executeInstruction(id);
return true;
Expand All @@ -236,12 +205,10 @@ bool Model::getGame(int id)
return false;
}

const InfoData Model::getInfo(int id)
{
const InfoData Model::getInfo(int id) {
return data.getInfo(id);
}

const QString Model::getWalkthrough(int id)
{
const QString Model::getWalkthrough(int id) {
return data.getWalkthrough(id);
}
2 changes: 1 addition & 1 deletion src/TombRaiderLinuxLauncher.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:12pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;h3 style=&quot; margin-top:14px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:large; font-weight:600;&quot;&gt;About&lt;/span&gt;&lt;/h3&gt;
&lt;h4 style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-size:medium; font-weight:600;&quot;&gt;Tomb Raider Linux Launcher&lt;/span&gt;&lt;/h4&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Welcome to the &lt;span style=&quot; font-weight:600;&quot;&gt;Tomb Raider Linux Launcher&lt;/span&gt;! This application is designed to provide a streamlined and convenient way to launch your favorite Tomb Raider games on Linux. Currently, the launcher supports Tomb Raider III and Tomb Raider: The Last Revelation (Tomb Raider IV).&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Welcome to the &lt;span style=&quot; font-weight:600;&quot;&gt;Tomb Raider Linux Launcher&lt;/span&gt;! This application is designed to provide a streamlined and convenient way to launch your favorite Tomb Raider games on Linux. Currently, the launcher supports Tomb Raider 1-5 and trle.net but not TEN at the moment.&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Our aim is to enhance your gaming experience by offering a user-friendly interface that simplifies game management and launching. The launcher is still a work in progress, and we are actively working on adding support for more games and improving functionality.&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Stay tuned for updates and new features as we continue to develop and refine the Tomb Raider Linux Launcher. Your feedback and suggestions are always welcome to help us create the best possible tool for Tomb Raider fans.&lt;/p&gt;
&lt;p style=&quot; margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Thank you for using the Tomb Raider Linux Launcher!&lt;/p&gt;
Expand Down
Loading

0 comments on commit 065f20e

Please sign in to comment.