From a155efa8785d8a6dc4d5fab5cab358d73087f687 Mon Sep 17 00:00:00 2001 From: Sean Stangl Date: Mon, 28 Apr 2014 11:45:33 -0700 Subject: [PATCH] Simplify ResmedLoader::Detect() by avoiding manual string manipulation. Signed-off-by: Mark Watkins --- .../SleepLib/loader_plugins/resmed_loader.cpp | 29 +++++++------------ 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp index 7f4cd648..35071625 100644 --- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp +++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp @@ -370,30 +370,21 @@ const QString RMS9_STR_strfile = "STR."; bool ResmedLoader::Detect(const QString & givenpath) { - QString path = givenpath; + QDir dir(givenpath); - path.replace("\\", "/"); - - // Strip off end "/" if any - if (path.endsWith("/")) { - path = path.section("/", 0, -2); - } - - // Strip off DATALOG from path, and set newpath to the path contianing DATALOG - if (path.endsWith(RMS9_STR_datalog)) { - path = path.section("/", 0, -2); - } - - path += "/"; - - // Check DATALOG folder exists and is readable - if (!QDir().exists(path + RMS9_STR_datalog)) { + if (!dir.exists()) { return false; } - QFile str(path+"STR.edf"); - if (!str.exists()) + // ResMed drives contain a folder named "DATALOG". + if (!dir.exists(RMS9_STR_datalog)) { return false; + } + + // They also contain a file named "STR.edf". + if (!dir.exists("STR.edf")) { + return false; + } return true; }