Skip to content

Commit 31e03fc

Browse files
committed
Improved steam path detection + improved the disable/uninstall feature
1 parent fd28303 commit 31e03fc

File tree

3 files changed

+101
-51
lines changed

3 files changed

+101
-51
lines changed

mod_downloader/mod_downloader.cpp

Lines changed: 98 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -371,25 +371,41 @@ int main()
371371

372372
if (std::filesystem::exists(custom_paks_path))
373373
{
374-
std::cout << "Do you really want to delete all mods in the CustomPaks folder? (yes/no): ";
375-
std::string confirm;
376-
std::getline(std::cin, confirm);
374+
std::vector<std::filesystem::path> pak_files;
377375

378-
if (is_answer_positive(confirm))
376+
// Collect all .pak files
377+
for (const auto& entry : std::filesystem::directory_iterator(custom_paks_path))
379378
{
380-
for (const auto& entry : std::filesystem::directory_iterator(custom_paks_path))
379+
if (entry.is_regular_file() && entry.path().extension() == ".pak")
380+
pak_files.push_back(entry.path());
381+
}
382+
383+
if (pak_files.empty())
384+
{
385+
throw_error("No .pak files found in CustomPaks folder.");
386+
}
387+
388+
std::cout << "\nFound " << pak_files.size() << " mod(s) in CustomPaks folder:\n" << std::endl;
389+
390+
int removed_count = 0;
391+
392+
for (const auto& pak_file : pak_files)
393+
{
394+
std::cout << "Delete '" << pak_file.filename().string() << "'? (y/n): ";
395+
std::string answer;
396+
std::getline(std::cin, answer);
397+
398+
if (is_answer_positive(answer))
381399
{
382-
if (entry.is_regular_file() && entry.path().extension() == ".pak")
383-
{
384-
std::filesystem::remove(entry.path());
385-
std::cout << "Deleted: " << entry.path().filename() << std::endl;
386-
}
400+
std::filesystem::remove(pak_file);
401+
removed_count++;
387402
}
388-
389-
throw_error("All .pak files have been deleted from the CustomPaks folder.", 5);
390403
}
404+
405+
if (removed_count > 0)
406+
throw_error(std::string("Removed " + std::to_string(removed_count) + " out of " + std::to_string(pak_files.size()) + " mods from CustomPaks folder.").c_str(), 5);
391407
else
392-
throw_error("Uninstall cancelled.");
408+
throw_error("No mods were removed.", 3);
393409
}
394410
else
395411
throw_error("CustomPaks folder not found. No mods to uninstall.");
@@ -402,42 +418,66 @@ int main()
402418
if (!std::filesystem::exists(dide_direct))
403419
throw_error("Failed to find dide_mod.ini inside this folder, please input a proper one");
404420

405-
// Prompt that everything is gonna go into waste
406-
NEWLINE
407-
408-
std::cout << "Do you really want to disable every mod in dide_mod.ini? (yes/no): " << std::endl;
409-
std::string disable_answer;
421+
// Read the INI file
422+
mINI::INIFile file(dide_direct);
423+
mINI::INIStructure ini;
424+
file.read(ini);
410425

411-
std::getline(std::cin, disable_answer);
426+
std::vector<std::pair<std::string, std::string>> enabled_mods;
412427

413-
// Here we go
414-
if (is_answer_positive(disable_answer))
428+
// Check if CustomPak section exists and collect enabled mods
429+
bool custompak_found = false;
430+
for (const auto& section : ini)
415431
{
416-
// Update
417-
mINI::INIFile file(dide_direct);
418-
mINI::INIStructure ini;
419-
420-
// Read
421-
file.read(ini);
422-
423-
// Disable
424-
for (auto const& it : ini)
432+
if (section.first == "custompak")
425433
{
426-
// mINI has everything in lowercase, first tried CustomPak, wasted my time...
427-
if (it.first == "custompak")
434+
custompak_found = true;
435+
for (const auto& mod : section.second)
428436
{
429-
for (auto const& it2 : it.second)
430-
ini[it.first][it2.first] = "0";
437+
if (mod.second == "1")
438+
enabled_mods.push_back({ mod.first, mod.second });
431439
}
440+
break;
432441
}
442+
}
433443

434-
// Write update to file
435-
file.write(ini);
444+
if (!custompak_found)
445+
throw_error("No CustomPak section found in dide_mod.ini");
436446

437-
throw_error("All mods have been disabled in dide_mod.ini.\nRemember, you can always enable the mods again by changing 'EnableMod' to '1' in dide_mod.ini...");
447+
if (enabled_mods.empty())
448+
throw_error("No enabled mods found in dide_mod.ini");
449+
450+
NEWLINE
451+
std::cout << "Found " << enabled_mods.size() << " enabled mod(s):\n" << std::endl;
452+
453+
int disabled_count = 0;
454+
455+
for (const auto& mod : enabled_mods)
456+
{
457+
// Extract just the filename from full path for cleaner display
458+
std::string mod_name = mod.first;
459+
size_t last_slash = mod_name.find_last_of("\\");
460+
if (last_slash != std::string::npos)
461+
mod_name = mod_name.substr(last_slash + 1);
462+
463+
std::cout << "Disable '" << mod_name << "'? (y/n): ";
464+
std::string answer;
465+
std::getline(std::cin, answer);
466+
467+
if (is_answer_positive(answer))
468+
{
469+
ini["custompak"][mod.first] = "0";
470+
disabled_count++;
471+
}
438472
}
473+
474+
// Write changes to file
475+
file.write(ini);
476+
477+
if (disabled_count > 0)
478+
throw_error(std::string("Disabled " + std::to_string(disabled_count) + " out of " + std::to_string(enabled_mods.size()) + " mods in dide_mod.ini.\nRemember, you can always enable the mods again by changing their value to '1' in dide_mod.ini.").c_str(), 5);
439479
else
440-
throw_error("Uninstall cancelled.");
480+
throw_error("No mods were disabled.", 3);
441481
}
442482
}
443483

@@ -634,11 +674,17 @@ int main()
634674
if (!std::filesystem::exists(steam_path))
635675
throw_error("Couldn't find your steam's installation path.");
636676

637-
// Read .vdf file
638-
std::ifstream main(std::string(steam_path + "\\steamapps\\libraryfolders.vdf"));
677+
// Library .vdf file should be here
678+
std::string vdf_path = steam_path + "\\steamapps\\libraryfolders.vdf";
679+
680+
// Fallback to config folder if not found in steamapps
681+
if (!std::filesystem::exists(vdf_path))
682+
vdf_path = steam_path + "\\config\\libraryfolders.vdf";
683+
684+
std::ifstream main(vdf_path);
639685

640686
if (main.fail())
641-
throw_error("Couldn't check your library's metadata, make sure 'libraryfolders.vdf' exists in your steamapps folder.");
687+
throw_error("Couldn't check your library's metadata, make sure 'libraryfolders.vdf' exists in your steamapps or config folder.");
642688

643689
// Open .vdf file
644690
auto root = tyti::vdf::read(main);
@@ -679,15 +725,19 @@ int main()
679725
std::ifstream main_add(std::string(game_path + "\\steamapps\\appmanifest_239140.acf"));
680726

681727
if (main_add.fail())
682-
throw_error("Dying Light's app manifest doesn't exist! Make sure 'appmanifest_239140.acf' exists in your steamapps folder.");
683-
684-
// Parse installdir
685-
auto root_add = tyti::vdf::read(main_add);
686-
687-
game_path += "\\steamapps\\common\\" + root_add.attribs["installdir"];
728+
{
729+
// Fallback to hardcoded directory name
730+
game_path += "\\steamapps\\common\\Dying Light";
731+
}
732+
else
733+
{
734+
// Parse installdir from manifest
735+
auto root_add = tyti::vdf::read(main_add);
736+
game_path += "\\steamapps\\common\\" + root_add.attribs["installdir"];
737+
}
688738
}
689739
else
690-
throw_error("Failed to find Dying Light (239140) in your 'libraryfolders.vdf' file which is inside of the steamapps folder.");
740+
throw_error("Failed to find Dying Light (239140) in your 'libraryfolders.vdf' file which is inside of the steamapps or config folder.");
691741
}
692742
else
693743
{

mod_downloader/mod_downloader.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@
156156
<Import Project="..\packages\openssl.1.0.1.21\build\native\openssl.targets" Condition="Exists('..\packages\openssl.1.0.1.21\build\native\openssl.targets')" />
157157
<Import Project="..\packages\libssh2.1.4.3.1\build\native\libssh2.targets" Condition="Exists('..\packages\libssh2.1.4.3.1\build\native\libssh2.targets')" />
158158
<Import Project="..\packages\curl.7.30.0.2\build\native\curl.targets" Condition="Exists('..\packages\curl.7.30.0.2\build\native\curl.targets')" />
159-
<Import Project="..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets" Condition="Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" />
160159
<Import Project="..\packages\libzip.redist.1.1.2.7\build\native\libzip.redist.targets" Condition="Exists('..\packages\libzip.redist.1.1.2.7\build\native\libzip.redist.targets')" />
161160
<Import Project="..\packages\libzip.1.1.2.7\build\native\libzip.targets" Condition="Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" />
162161
<Import Project="..\packages\curlpp.0.7.3.1\build\native\curlpp.targets" Condition="Exists('..\packages\curlpp.0.7.3.1\build\native\curlpp.targets')" />
162+
<Import Project="..\packages\nlohmann.json.3.12.0\build\native\nlohmann.json.targets" Condition="Exists('..\packages\nlohmann.json.3.12.0\build\native\nlohmann.json.targets')" />
163163
</ImportGroup>
164164
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
165165
<PropertyGroup>
@@ -175,9 +175,9 @@
175175
<Error Condition="!Exists('..\packages\openssl.1.0.1.21\build\native\openssl.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\openssl.1.0.1.21\build\native\openssl.targets'))" />
176176
<Error Condition="!Exists('..\packages\libssh2.1.4.3.1\build\native\libssh2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libssh2.1.4.3.1\build\native\libssh2.targets'))" />
177177
<Error Condition="!Exists('..\packages\curl.7.30.0.2\build\native\curl.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\curl.7.30.0.2\build\native\curl.targets'))" />
178-
<Error Condition="!Exists('..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nlohmann.json.3.11.2\build\native\nlohmann.json.targets'))" />
179178
<Error Condition="!Exists('..\packages\libzip.redist.1.1.2.7\build\native\libzip.redist.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libzip.redist.1.1.2.7\build\native\libzip.redist.targets'))" />
180179
<Error Condition="!Exists('..\packages\libzip.1.1.2.7\build\native\libzip.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\libzip.1.1.2.7\build\native\libzip.targets'))" />
181180
<Error Condition="!Exists('..\packages\curlpp.0.7.3.1\build\native\curlpp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\curlpp.0.7.3.1\build\native\curlpp.targets'))" />
181+
<Error Condition="!Exists('..\packages\nlohmann.json.3.12.0\build\native\nlohmann.json.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\nlohmann.json.3.12.0\build\native\nlohmann.json.targets'))" />
182182
</Target>
183183
</Project>

mod_downloader/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<package id="libssh2.redist" version="1.4.3.1" targetFramework="native" />
99
<package id="libzip" version="1.1.2.7" targetFramework="native" />
1010
<package id="libzip.redist" version="1.1.2.7" targetFramework="native" />
11-
<package id="nlohmann.json" version="3.11.2" targetFramework="native" />
11+
<package id="nlohmann.json" version="3.12.0" targetFramework="native" />
1212
<package id="openssl" version="1.0.1.21" targetFramework="native" />
1313
<package id="openssl.redist" version="1.0.1.21" targetFramework="native" />
1414
<package id="zlib" version="1.2.8.1" targetFramework="native" />

0 commit comments

Comments
 (0)