Skip to content

Commit 02d60e5

Browse files
committed
Added web server configuration
1 parent 363cc3a commit 02d60e5

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

mod_downloader/mod_downloader.cpp

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
#include "ini.hpp"
2121

2222
#define NEWLINE std::cout << std::endl;
23+
#define DEFAULT_CONFIG "[Config]\ndownload_server=https://www.nlog.us/downloads/\ndownload_file=full_archive.zip"
2324

2425
// Needed
26+
std::string download_server;
27+
std::string download_file;
2528
bool download_complete = false;
2629

2730
// Termination
@@ -88,7 +91,7 @@ std::size_t write_data(void* ptr, std::size_t size, std::size_t nmemb, FILE* str
8891
void get_bonzo()
8992
{
9093
// Folder/file
91-
std::string site("https://nlog.us/downloads/full_archive.zip");
94+
std::string site(download_server + download_file);
9295

9396
// File variable
9497
FILE* fp;
@@ -102,7 +105,7 @@ void get_bonzo()
102105
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
103106

104107
// Open
105-
fp = fopen("full_archive.zip", "wb");
108+
fp = fopen(download_file.c_str(), "wb");
106109
if (fp)
107110
{
108111
// Write
@@ -180,6 +183,34 @@ int main()
180183
// Do a cleaning before downloading anything
181184
deep_clean(false);
182185

186+
// We don't have a config?
187+
if (!std::filesystem::exists("config.ini"))
188+
{
189+
// Create
190+
std::ofstream file("config.ini");
191+
file << DEFAULT_CONFIG << std::endl;
192+
193+
// Close
194+
file.close();
195+
}
196+
197+
// Read download information
198+
{
199+
mINI::INIFile file("config.ini");
200+
mINI::INIStructure ini;
201+
202+
// Read
203+
file.read(ini);
204+
205+
// Server information
206+
download_server = ini["Config"]["download_server"];
207+
download_file = ini["Config"]["download_file"];
208+
209+
// Validation
210+
if (download_server.empty()) throw_error("Missing download_server in config.ini, please make a proper configuration.");
211+
if (download_file.empty()) throw_error("Missing download_file in config.ini, please make a proper configuration.");
212+
}
213+
183214
// Download
184215
get_bonzo();
185216

@@ -283,15 +314,15 @@ int main()
283314
NEWLINE
284315

285316
// Ask about the platform
286-
std::cout << "Steam or Epic Games? (steam / epic): ";
317+
std::cout << "Steam or Other platform? (steam / other): ";
287318
std::string input_platform;
288319

289320
std::getline(std::cin, input_platform);
290321

291322
// Choice
292-
bool steam = true;
323+
bool steam = false;
293324

294-
if (input_platform.find("epic") != std::string::npos) steam = false;
325+
if (input_platform.find("steam") != std::string::npos) steam = true;
295326

296327
// Variable, will be used later
297328
std::string game_path;

0 commit comments

Comments
 (0)