From b671bb72dc36aa94420396f2d5fe2218b2d54621 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 11 Aug 2017 14:07:53 +0300 Subject: [PATCH] Rewrite Drag&Drop classification --- rpcs3/rpcs3qt/game_list_frame.cpp | 71 ++++++++++++++----------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/rpcs3/rpcs3qt/game_list_frame.cpp b/rpcs3/rpcs3qt/game_list_frame.cpp index 9b9a05687f..7c677bbbbd 100644 --- a/rpcs3/rpcs3qt/game_list_frame.cpp +++ b/rpcs3/rpcs3qt/game_list_frame.cpp @@ -1122,62 +1122,54 @@ int game_list_frame::IsValidFile(const QMimeData& md, QStringList* dropPaths) const QList list = md.urls(); // get list of all the dropped file urls - for (int i = 0; i < list.count(); i++) // check each file in url list for valid type + for (auto&& url : list) // check each file in url list for valid type { - const QString path = list[i].toLocalFile(); // convert url to filepath + const QString path = url.toLocalFile(); // convert url to filepath + + const QFileInfo info = path; // check for directories first, only valid if all other paths led to directories until now. - if (QFileInfo(path).isDir()) + if (info.isDir()) { - if (i != 0 && dropType != DROP_DIR) return DROP_ERROR; + if (dropType != DROP_DIR && dropType != DROP_ERROR) + { + return DROP_ERROR; + } dropType = DROP_DIR; - - if (dropPaths) + } + else if (info.fileName() == "PS3UPDAT.PUP") + { + if (list.size() != 1) { - dropPaths->append(path); + return DROP_ERROR; } - continue; - } - // now that we know it has to be a file we get the file ending - QString suffix = QFileInfo(list[i].fileName()).suffix().toLower(); - - if (suffix.isEmpty()) return DROP_ERROR; // NANI the heck would you want such a file? - - QString last_suffix; - - if (i == 0) // the first item defines our file type - { - last_suffix = suffix; - } - else if (last_suffix == "pup" || last_suffix == "bin") // we only accept one firmware or eboot file - { - return list.count() != 1 ? dropType : DROP_ERROR; - } - else if (last_suffix != suffix) // we don't accept multiple file types - { - return DROP_ERROR; - } - - // set drop type by file ending - if (suffix == "pkg") - { - dropType = DROP_PKG; - } - else if (suffix == "pup") - { dropType = DROP_PUP; } - else if (suffix == "rap") + else if (info.suffix().toLower() == "pkg") { + if (dropType != DROP_PKG && dropType != DROP_ERROR) + { + return DROP_ERROR; + } + + dropType = DROP_PKG; + } + else if (info.suffix() == "rap") + { + if (dropType != DROP_RAP && dropType != DROP_ERROR) + { + return DROP_ERROR; + } + dropType = DROP_RAP; } - else if (suffix == "bin") + else if (list.size() == 1) { dropType = DROP_GAME; } - else // if (suffix == "kuso") + else { return DROP_ERROR; } @@ -1187,6 +1179,7 @@ int game_list_frame::IsValidFile(const QMimeData& md, QStringList* dropPaths) dropPaths->append(path); } } + return dropType; }