Skip to content

Commit 5c465a8

Browse files
committed
Improved steam path detection
1 parent aef4961 commit 5c465a8

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

mod_downloader/mod_downloader.cpp

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,7 @@ int throw_error(const char* error, int delay = 3, int clear = 0)
6464
// Positive answer
6565
bool is_answer_positive(std::string answer)
6666
{
67-
std::vector <std::string> positive_answers
68-
{
69-
"Y",
70-
"y",
71-
"+",
72-
"1",
73-
};
67+
std::vector <std::string> positive_answers { "Y", "y", "+", "1" };
7468

7569
// Characters found
7670
int hits = 0;
@@ -162,13 +156,7 @@ bool has_ending(const std::string& full_string, const std::string& ending)
162156
void deep_clean(bool log)
163157
{
164158
// Already present?
165-
std::vector<std::string> bad_ones
166-
{
167-
"out",
168-
"full_archive.zip",
169-
"_placeholder.ini",
170-
"dide_mod.ini"
171-
};
159+
std::vector<std::string> bad_ones { "out", "full_archive.zip", "_placeholder.ini", "dide_mod.ini" };
172160

173161
for (const auto& loser : bad_ones)
174162
{
@@ -190,11 +178,7 @@ void deep_clean(bool log)
190178
void verification()
191179
{
192180
// Needed things
193-
std::vector<std::string> needed
194-
{
195-
"7z.dll",
196-
"curlpp.dll"
197-
};
181+
std::vector<std::string> needed { "7z.dll", "curlpp.dll" };
198182

199183
for (const auto& file : needed)
200184
{
@@ -247,8 +231,8 @@ int main()
247231
{
248232
NEWLINE
249233

250-
// Won't bother to add automatic detection here, so just ask for it
251-
std::cout << "Uninstall chosen, enter your Dying Light's installation folder...\n(e.g C:\\Program Files (x86)\\Steam\\steamapps\\common\\Dying Light)\n(e.g C:\\Program Files\\Epic Games\\Dying Light)\n\nEnter (path): " << std::endl;
234+
// Won't bother to add automatic detection here, so just ask for it
235+
std::cout << "Uninstall chosen, enter your Dying Light's installation folder...\n(e.g C:\\Program Files (x86)\\Steam\\steamapps\\common\\Dying Light)\n(e.g C:\\Program Files\\Epic Games\\Dying Light)\n\nEnter (path): " << std::endl;
252236
std::string input_path;
253237

254238
std::getline(std::cin, input_path);
@@ -262,7 +246,7 @@ int main()
262246
// Prompt that everything is gonna go into waste
263247
NEWLINE
264248

265-
std::cout << "Do you really want to disable every mod? (yes): " << std::endl;
249+
std::cout << "Do you really want to disable every mod? (yes): " << std::endl;
266250
std::string disable_answer;
267251

268252
std::getline(std::cin, disable_answer);
@@ -497,6 +481,9 @@ int main()
497481

498482
// Open .vdf file
499483
auto root = tyti::vdf::read(main);
484+
485+
// Needed for additional verification via appmanifest
486+
bool found = false;
500487

501488
// Loop through the file
502489
for (const auto& child : root.childs)
@@ -509,11 +496,33 @@ int main()
509496
if (test.first == "239140")
510497
{
511498
if (root.childs[child.first].get()->attribs.find("path") != root.childs[child.first].get()->attribs.end())
499+
{
512500
game_path = root.childs[child.first].get()->attribs["path"];
501+
502+
found = true;
503+
}
513504
}
514505
}
515506
}
516507
}
508+
509+
510+
// This was not required in the first place, but some people had issues, and I had to do it
511+
// Attempt to read appmanifest_239140.acf
512+
if (found)
513+
{
514+
std::ifstream main_add(std::string(steam_path + "\\steamapps\\appmanifest_239140.acf"));
515+
516+
if (main_add.fail())
517+
throw_error("Dying Light's app manifest doesn't exist! Make sure 'appmanifest_239140.acf' exists in your steamapps folder.");
518+
519+
// Parse installdir
520+
auto root_add = tyti::vdf::read(main_add);
521+
522+
game_path += "\\steamapps\\common\\" + root_add.attribs["installdir"];
523+
}
524+
else
525+
throw_error("Failed to find Dying Light (239140) in your 'libraryfolders.vdf' file which is inside of the steamapps folder.");
517526
}
518527
else
519528
{
@@ -621,14 +630,12 @@ int main()
621630
}
622631
}
623632

624-
// Actual game path (steam ? steam : epic)
625-
std::filesystem::path actual_path = steam ? game_path + "\\steamapps\\common\\Dying Light" : game_path;
626-
627-
if (!std::filesystem::exists(actual_path))
633+
// Verify if we can proceed further
634+
if (!std::filesystem::exists(game_path))
628635
throw_error("Unfortunately, the program has failed to find Dying Light's directory.");
629636

630637
// DW path
631-
std::filesystem::path dw_path = actual_path;
638+
std::filesystem::path dw_path = game_path;
632639
dw_path /= "DW";
633640

634641
// Create directory if none present
@@ -663,7 +670,7 @@ int main()
663670
// 2 hits are success
664671
int hits = 0;
665672

666-
for (const auto& file : std::filesystem::directory_iterator(actual_path))
673+
for (const auto& file : std::filesystem::directory_iterator(game_path))
667674
{
668675
std::string name = file.path().filename().string();
669676

@@ -700,7 +707,7 @@ int main()
700707
std::filesystem::copy(file, copy_path, std::filesystem::copy_options::overwrite_existing);
701708
}
702709
else
703-
std::filesystem::copy(file, actual_path, std::filesystem::copy_options::overwrite_existing);
710+
std::filesystem::copy(file, game_path, std::filesystem::copy_options::overwrite_existing);
704711
}
705712
}
706713
}
@@ -725,15 +732,15 @@ int main()
725732
file.generate(ini);
726733

727734
// Replace and delete placeholder
728-
std::filesystem::path dide_path = actual_path;
735+
std::filesystem::path dide_path = game_path;
729736
dide_path /= "dide_mod.ini";
730737

731738
std::filesystem::copy("_placeholder.ini", dide_path, std::filesystem::copy_options::overwrite_existing);
732739
}
733740
else
734741
{
735742
// Dide path
736-
std::filesystem::path dide_path = actual_path;
743+
std::filesystem::path dide_path = game_path;
737744
dide_path /= "dide_mod.ini";
738745

739746
// INI

0 commit comments

Comments
 (0)