Skip to content

Commit

Permalink
add gui plan
Browse files Browse the repository at this point in the history
  • Loading branch information
noisecode3 committed Dec 16, 2023
1 parent 453afb2 commit d4ab050
Show file tree
Hide file tree
Showing 11 changed files with 455 additions and 140 deletions.
Binary file added TombRaiderLinuxLauncher.pdf
Binary file not shown.
Binary file added TombRaiderPWModder/3573.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified TombRaiderPWModder/TombRaiderPWModder
Binary file not shown.
9 changes: 6 additions & 3 deletions TombRaiderPWModder/TombRaiderPWModder.pro
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
QT += core gui
QT += core gui widgets webenginewidgets

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++17
LIBS += -lcurl -lzip -lssl -lcrypto

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
main.cpp \
tombraiderpwmodder.cpp
tombraiderpwmodder.cpp \
networkTR3.cpp

HEADERS += \
tombraiderpwmodder.h
tombraiderpwmodder.h \
leveldata.h

FORMS += \
tombraiderpwmodder.ui
Expand Down
84 changes: 84 additions & 0 deletions TombRaiderPWModder/leveldata.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once
#include <string>
/*
* trle.net level info data
* The data needed for the offline part of the client
* I don't think we should bother the server and its faster
* It there will be to many pictures or over 10 games I can
* move the pictures to some other download, but they are for
* testing now. The id number will be used at end of every URL
*
*/
class leveldata
{
private:
const int id;
const std::string zipMd5sum;
public:
leveldata(int& id, std::string& md5sum)
: id(id), zipMd5sum(md5sum) {}
const std::string& getZipMd5sum() const { return zipMd5sum; }
const int& getId() const { return id; }

const std::string& getTitle() const { return title; }
void setTitle(const std::string& s) { title = s; }

const std::string& getAuthor() const { return author; }
void setAuthor(const std::string& s) { author = s; }

const std::string& getType() const { return type; }
void setType(const std::string& s) { type = s; }

const std::string& getLevelclass() const { return levelclass; }
void setLevelclass(const std::string& s) { levelclass = s; }

const std::string& getReleasedate() const { return releasedate; }
void setReleasedate(const std::string& s) { releasedate = s; }

const std::string& getDifficulty() const { return difficulty; }
void setDifficulty(const std::string& s) { difficulty = s; }

const std::string& getDuration() const { return duration; }
void setDuration(const std::string& s) { duration = s; }

const std::string& getScreensLarge() const { return screensLarge; }
void setScreensLarge(const std::string& s) { screensLarge = s; }

const std::string& getBody() const { return body; }
void setBody(const std::string& s) { body = s; }

const std::string& getWalkthrough() const { return walkthrough; }
void setWalkthrough(const std::string& s) { walkthrough = s; }

const float& getZipSize() const { return zipSize; }
void setZipSize(const float& s) { zipSize = s; }

const std::string& getZipName() const { return zipName; }
void setZipName(const std::string& s) { zipName = s; }

private:
std::string title;
std::string author;
std::string type; // like TR4
std::string levelclass;
std::string releasedate;
std::string difficulty;
std::string duration;
std::string screen;
std::string screensLarge; // separated by ,
std::string body; //html
std::string walkthrough; //html
float zipSize;
std::string zipName;
};
/*
*
*
*/
class pool
{
const std::string levelUrl = "https://www.trle.net/sc/levelfeatures.php?lid=";
const std::string walkthroughUrl = "https://www.trle.net/sc/Levelwalk.php?lid=";
const std::string screensUrl = "https://www.trle.net/screens/";
const std::string screensLargeUrl = "https://www.trle.net/screens/large/";
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,63 @@

static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
size_t written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}

size_t downloadFile(const char* url, const char* filename) {
CURL *curl_handle;
static const char *pagefilename = filename;
FILE *pagefile;


curl_global_init(CURL_GLOBAL_ALL);

/* init the curl session */
curl_handle = curl_easy_init();

/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);
size_t downloadFile(const char* url, const char* filename)
{
CURL *curl_handle;
static const char *pagefilename = filename;
FILE *pagefile;
if (filename[0] == '/')
{
curl_global_init(CURL_GLOBAL_ALL);

/* Switch on full protocol/debug output while testing */
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
/* init the curl session */
curl_handle = curl_easy_init();

/* disable progress meter, set to 0L to enable it */
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, url);

/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
/* Switch on full protocol/debug output while testing */
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);

/* open the file */
pagefile = fopen(pagefilename, "wb");
if(pagefile) {
/* disable progress meter, set to 0L to enable it */
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);

/* write the page body to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);

/* get it! */
curl_easy_perform(curl_handle);
/* open the file */
pagefile = fopen(pagefilename, "wb");
if(pagefile) {

/* close the header file */
fclose(pagefile);
}
/* write the page body to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);

/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
/* get it! */
curl_easy_perform(curl_handle);

return 0;
/* close the header file */
fclose(pagefile);
}
/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
}
return 0;
}

// Function to calculate MD5 checksum of a file
std::string calculateMD5(const char* filename) {
std::string calculateMD5(const char* filename)
{
FILE* file = fopen(filename, "rb");
if (!file) {
if (!file)
{
std::cerr << "Error opening file for reading." << std::endl;
return "";
}

fseek(file, 0, SEEK_END);
rewind(file);

Expand All @@ -90,7 +91,8 @@ std::string calculateMD5(const char* filename) {
char buffer[1024];
size_t bytesRead;

while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0) {
while ((bytesRead = fread(buffer, 1, sizeof(buffer), file)) > 0)
{
EVP_DigestUpdate(md5Context, buffer, bytesRead);
}

Expand All @@ -99,17 +101,20 @@ std::string calculateMD5(const char* filename) {
fclose(file);

std::stringstream md5string;
for (int i = 0; i < EVP_MD_size(md5Type); ++i) {
for (int i = 0; i < EVP_MD_size(md5Type); ++i)
{
md5string << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(md5sum[i]);
}

return md5string.str();
}

void extractZip(const char* zipFilename, const char* extractPath) {
void extractZip(const char* zipFilename, const char* extractPath)
{
zip_t* archive = zip_open(zipFilename, 0, NULL);

if (!archive) {
if (!archive)
{
std::cerr << "Error opening ZIP file" << std::endl;
return;
}
Expand All @@ -121,21 +126,25 @@ void extractZip(const char* zipFilename, const char* extractPath) {
int numEntries = zip_get_num_entries(archive, 0);

// Extract each entry in the ZIP file
for (int i = 0; i < numEntries; ++i) {
if (zip_stat_index(archive, i, 0, &zipStat) == 0) {
for (int i = 0; i < numEntries; ++i)
{
if (zip_stat_index(archive, i, 0, &zipStat) == 0)
{
// Allocate memory for the data
char* data = new char[zipStat.size];
// Create directories if they don't exist
std::string filePath = extractPath + std::string("/") + zipStat.name;
std::string directory = filePath.substr(0, filePath.find_last_of("/\\"));
if (!std::filesystem::exists(directory)) {
if (!std::filesystem::exists(directory))
{
std::filesystem::create_directories(directory);
}

// Open the file in the ZIP archive
zip_file_t* zipFile = zip_fopen_index(archive, i, 0);

if (zipFile) {
if (zipFile)
{
// Read the data from the file in the ZIP archive
zip_fread(zipFile, data, zipStat.size);

Expand All @@ -149,18 +158,22 @@ void extractZip(const char* zipFilename, const char* extractPath) {
outFile.close();

delete[] data;// leak
} else {
}
else
{
std::cerr << "Error opening file in ZIP archive" << std::endl;
}
} else {
}
else
{
std::cerr << "Error getting information for entry " << i << std::endl;
}
}
// Close the ZIP archive
zip_close(archive);
}

int main() {
int test() {
// We need a class for hanling map download link or local file.
// Checking files checksum and or remove them
// Change to the game's directory
Expand Down Expand Up @@ -302,35 +315,41 @@ int main() {
};

// Remove files and directories
for (const char* item : filesToRemove) {
for (const char* item : filesToRemove)
{
remove(item);
}
for (const char* item : directoriesToRemove) {
for (const char* item : directoriesToRemove)
{
rmdir(item);
}

// Download file
const char* url = "https://www.trle.net/levels/levels/2023/1123/Jonson-TheInfadaCult.zip";
const char* filename = "Jonson-TheInfadaCult.zip";

if (!downloadFile(url, filename)) {
if (!downloadFile(url, filename))
{
// Check MD5sum
const char* expectedMD5 = "152d33e5c28d7db6458975a5e53a3122";
std::string md5sum = calculateMD5(filename);
std::cout << md5sum << std::endl;

if (md5sum == expectedMD5) {
if (md5sum == expectedMD5)
{
// Extract the ZIP file
const char* extractPath = "./";
extractZip(filename, extractPath);

}
else {
else
{
std::cerr << "Download problem" << std::endl;
return 1;
}
}
else {
else
{
std::cerr << "Download problem" << std::endl;
return 1;
}
Expand Down
Loading

0 comments on commit d4ab050

Please sign in to comment.