diff --git a/ResourceManager.cpp b/ResourceManager.cpp index 05d382bb..2809bcff 100644 --- a/ResourceManager.cpp +++ b/ResourceManager.cpp @@ -37,6 +37,7 @@ ResourceManager::ResourceManager() /*-------------------------------------------------------------------------*\ | Initialize Detection Variables | \*-------------------------------------------------------------------------*/ + detection_enabled = true; detection_percent = 100; detection_string = ""; detection_is_required = false; @@ -356,38 +357,54 @@ void ResourceManager::Cleanup() void ResourceManager::DetectDevices() { - /*-------------------------------------------------*\ - | Do nothing is it is already detecting devices | - \*-------------------------------------------------*/ - if(detection_is_required.load()) + if(detection_enabled) { - return; - } + /*-------------------------------------------------*\ + | Do nothing is it is already detecting devices | + \*-------------------------------------------------*/ + if(detection_is_required.load()) + { + return; + } - /*-------------------------------------------------*\ - | If there's anything left from the last time, | - | we shall remove it first | - \*-------------------------------------------------*/ - detection_percent = 0; - detection_string = ""; + /*-------------------------------------------------*\ + | If there's anything left from the last time, | + | we shall remove it first | + \*-------------------------------------------------*/ + detection_percent = 0; + detection_string = ""; - DetectionProgressChanged(); + DetectionProgressChanged(); - Cleanup(); + Cleanup(); - DeviceListChanged(); + DeviceListChanged(); - /*-------------------------------------------------*\ - | Start the device detection thread | - \*-------------------------------------------------*/ - detection_is_required = true; - DetectDevicesThread = new std::thread(&ResourceManager::DetectDevicesThreadFunction, this); + /*-------------------------------------------------*\ + | Start the device detection thread | + \*-------------------------------------------------*/ + detection_is_required = true; + DetectDevicesThread = new std::thread(&ResourceManager::DetectDevicesThreadFunction, this); - /*-------------------------------------------------*\ - | Release the current thread to allow detection | - | thread to start | - \*-------------------------------------------------*/ - std::this_thread::sleep_for(1ms); + /*-------------------------------------------------*\ + | Release the current thread to allow detection | + | thread to start | + \*-------------------------------------------------*/ + std::this_thread::sleep_for(1ms); + } + else + { + /*-------------------------------------------------*\ + | Signal that detection is complete | + \*-------------------------------------------------*/ + detection_percent = 100; + DetectionProgressChanged(); + } +} + +void ResourceManager::DisableDetection() +{ + detection_enabled = false; } void ResourceManager::DetectDevicesThreadFunction() diff --git a/ResourceManager.h b/ResourceManager.h index 976ac42b..cfd6e96a 100644 --- a/ResourceManager.h +++ b/ResourceManager.h @@ -101,6 +101,8 @@ public: void DetectDevices(); + void DisableDetection(); + void StopDeviceDetection(); void WaitForDeviceDetection(); @@ -111,6 +113,11 @@ private: static std::unique_ptr instance; /*-------------------------------------------------------------------------------------*\ + | Detection enabled flag | + \*-------------------------------------------------------------------------------------*/ + bool detection_enabled; + + /*-------------------------------------------------------------------------------------*\ | Profile Manager | \*-------------------------------------------------------------------------------------*/ ProfileManager* profile_manager; diff --git a/main.cpp b/main.cpp index 5b8daff1..19a63daf 100644 --- a/main.cpp +++ b/main.cpp @@ -172,6 +172,10 @@ int main(int argc, char* argv[]) { ResourceManager::get()->DetectDevices(); } + else + { + ResourceManager::get()->DisableDetection(); + } } /*---------------------------------------------------------*\