Skip to content

Commit e33d7f4

Browse files
committed
Improved steam path detection, Improved download progress
1 parent 83da145 commit e33d7f4

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

mod_downloader/mod_downloader.cpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ std::string download_copyright;
4040
std::string download_file;
4141
std::string file_name;
4242

43-
bool download_complete = false;
44-
double download_progress = 0.0;
43+
std::atomic<double> download_progress(0.0);
44+
std::atomic<bool> download_complete(false);
4545

4646
// Termination
4747
int terminate_process(int delay)
@@ -183,8 +183,7 @@ size_t write_data(void* ptr, size_t size, size_t nmemb, FILE* stream)
183183
int progress_callback(void* clientp, double dltotal, double dlnow, double ultotal, double ulnow)
184184
{
185185
if (dltotal > 0)
186-
download_progress = dlnow / dltotal * 100.0;
187-
186+
download_progress = static_cast<double>(dlnow) / static_cast<double>(dltotal) * 100.0;
188187
return 0;
189188
}
190189

@@ -193,18 +192,18 @@ void display_progress()
193192
{
194193
int width = 50;
195194
std::cout << "[";
196-
197195
int pos = static_cast<int>(width * download_progress / 100.0);
198-
for (int i = 0; i < width; ++i) {
196+
for (int i = 0; i < width; ++i)
197+
{
199198
if (i < pos) std::cout << "=";
200199
else if (i == pos) std::cout << ">";
201200
else std::cout << " ";
202201
}
203-
204-
std::cout << "] " << static_cast<int>(download_progress) << "%\r";
202+
std::cout << "] " << std::fixed << std::setprecision(1) << download_progress << "%\r";
205203
std::cout.flush();
206204
}
207205

206+
208207
bool get_bonzo(const std::string& download_file)
209208
{
210209
CURL* curl = curl_easy_init();
@@ -222,7 +221,6 @@ bool get_bonzo(const std::string& download_file)
222221
{
223222
std::cerr << "Failed to open file for writing" << std::endl;
224223
curl_easy_cleanup(curl);
225-
226224
return false;
227225
}
228226

@@ -233,7 +231,6 @@ bool get_bonzo(const std::string& download_file)
233231
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
234232

235233
CURLcode res = curl_easy_perform(curl);
236-
237234
fclose(fp);
238235
curl_easy_cleanup(curl);
239236

@@ -243,6 +240,7 @@ bool get_bonzo(const std::string& download_file)
243240
return false;
244241
}
245242

243+
download_progress = 100.0; // Ensure 100% at completion
246244
download_complete = true;
247245
return true;
248246
}
@@ -360,7 +358,7 @@ int main()
360358
std::getline(std::cin, input_path);
361359

362360
// Ask about mod usage method
363-
std::cout << "Are you using DLML or Regular Online mod usage? (dlml/regular): ";
361+
std::cout << "Are you using DLML or Regular Online mod usage? (dlml / regular): ";
364362
std::string mod_usage_method;
365363
std::getline(std::cin, mod_usage_method);
366364

@@ -491,6 +489,7 @@ int main()
491489
std::this_thread::sleep_for(std::chrono::milliseconds(100));
492490
}
493491

492+
display_progress(); // Display final progress
494493
download_thread.join();
495494

496495
std::cout << std::endl << "Download complete!" << std::endl;
@@ -550,7 +549,7 @@ int main()
550549
std::cout << std::string(std::to_string(pak.num) + ": " + pak.path.filename().string()) << std::endl;
551550

552551
// Input which one he wants
553-
std::cout << "Please enter wanted mods (separate by commas for multiple numbers): ";
552+
std::cout << "Please enter wanted mods (separate by commas ',' for multiple mods): ";
554553
std::string input_numbers;
555554

556555
std::getline(std::cin, input_numbers);
@@ -619,7 +618,7 @@ int main()
619618
// Find platform path
620619
HKEY h_key = 0;
621620

622-
std::cout << "[Steam] Attempting to find the game's installation path..." << std::endl;
621+
std::cout << "Finding the game's installation path..." << std::endl;
623622

624623
// Data
625624
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SOFTWARE\\WOW6432Node\\Valve\\Steam", 0, KEY_READ, &h_key) == ERROR_SUCCESS)
@@ -650,25 +649,29 @@ int main()
650649
// Loop through the file
651650
for (const auto& child : root.childs)
652651
{
653-
for (const auto& mini_child : root.childs[child.first].get()->childs)
652+
const auto& folder = child.second;
653+
654+
// Check if this folder has an "apps" child
655+
auto apps_it = folder->childs.find("apps");
656+
if (apps_it != folder->childs.end())
654657
{
655-
for (const auto& test : mini_child.second.get()->attribs)
658+
const auto& apps = apps_it->second;
659+
660+
// Check if Dying Light's ID (239140) is in the apps
661+
if (apps->attribs.find("239140") != apps->attribs.end())
656662
{
657-
// Dying Light's ID
658-
if (test.first == "239140")
663+
// Get the path for this folder
664+
auto path_it = folder->attribs.find("path");
665+
if (path_it != folder->attribs.end())
659666
{
660-
if (root.childs[child.first].get()->attribs.find("path") != root.childs[child.first].get()->attribs.end())
661-
{
662-
game_path = root.childs[child.first].get()->attribs["path"];
663-
664-
found = true;
665-
}
667+
game_path = path_it->second;
668+
found = true;
669+
break; // We found the game, no need to continue searching
666670
}
667671
}
668672
}
669673
}
670674

671-
672675
// This was not required in the first place, but some people had issues, and I had to do it
673676
// Attempt to read appmanifest_239140.acf
674677
if (found)
@@ -697,7 +700,7 @@ int main()
697700
// Manifest is inside thos registry keys
698701
HKEY h_key = 0;
699702

700-
std::cout << "[Epic] Attempting to detect game's installation path..." << std::endl;
703+
std::cout << "Detecting the location of the installation manifest..." << std::endl;
701704

702705
// 1st method
703706
if (RegOpenKeyEx(HKEY_CURRENT_USER, L"Software\\Epic Games\\EOS", 0, KEY_READ, &h_key) == ERROR_SUCCESS)
@@ -741,7 +744,7 @@ int main()
741744

742745
// Validate directory
743746
if (!std::filesystem::exists(manifest_path))
744-
throw_error("Epic Games manifest directory doesn't exist, please re-install the launcher in an attempt to solve this.");
747+
throw_error("Epic Games manifest directory doesn't exist, please reinstall the launcher in an attempt to solve this.");
745748

746749
// Parse directory for each item
747750
for (const auto& entry : std::filesystem::directory_iterator(manifest_path))
@@ -994,10 +997,8 @@ int main()
994997
}
995998

996999
// Another deep clean so we don't have our space being eaten
997-
std::cout << "Cleaning out the mess..." << std::endl;
998-
9991000
deep_clean(true);
10001001

10011002
// Congratulations
1002-
throw_error("@ Successfull installation! You can now enter the game.", 6);
1003+
throw_error("\nSuccessfull installation! You can now enter the game.", 6);
10031004
}

0 commit comments

Comments
 (0)