From 56a06133d26826da092c0c4321f650b0f9c70c69 Mon Sep 17 00:00:00 2001
From: Sude <lgogdownloader@gmail.com>
Date: Mon, 17 Feb 2020 19:24:04 +0200
Subject: [PATCH] Override global config values in Downloader::checkOrphans

Previously orphan checking was limited to user selected language and platform values.
This meant that by default only English language and Windows+Linux was selected.
Overriding the global config values and clearing previously got details before starting the orphan check makes --check-orphans work as intended.
---
 src/downloader.cpp | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/src/downloader.cpp b/src/downloader.cpp
index 730b501..142b8ed 100644
--- a/src/downloader.cpp
+++ b/src/downloader.cpp
@@ -1743,11 +1743,25 @@ static int isPresent(std::vector<gameFile>& list, const boost::filesystem::path&
 void Downloader::checkOrphans()
 {
     // Always check everything when checking for orphaned files
+    Globals::globalConfig.dlConf.bInstallers = true;
+    Globals::globalConfig.dlConf.bExtras = true;
+    Globals::globalConfig.dlConf.bPatches = true;
+    Globals::globalConfig.dlConf.bLanguagePacks = true;
+    Globals::globalConfig.dlConf.bDLC = true;
+    Globals::globalConfig.dlConf.iInstallerLanguage = Util::getOptionValue("all", GlobalConstants::LANGUAGES);
+    Globals::globalConfig.dlConf.iInstallerPlatform = Util::getOptionValue("all", GlobalConstants::PLATFORMS);
+    Globals::globalConfig.dlConf.vLanguagePriority.clear();
+    Globals::globalConfig.dlConf.vPlatformPriority.clear();
     Config config = Globals::globalConfig;
-    config.dlConf.bInstallers = true;
-    config.dlConf.bExtras = true;
-    config.dlConf.bPatches = true;
-    config.dlConf.bLanguagePacks = true;
+
+    // Checking orphans after download.
+    // Game details have already been retrieved but possibly filtered.
+    // Therefore we need to clear game details and get them again.
+    if (config.bDownload)
+    {
+        this->gameItems.clear();
+        this->games.clear();
+    }
 
     if (this->games.empty())
         this->getGameDetails();