summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-06 14:12:57 -0400
committerGravatar Lioncash2018-08-06 14:17:13 -0400
commit2b2dc00bfd3410bdce16966b1448fac36dd3126d (patch)
tree19a37e3239029a34164807362d16714edad34b0e /src
parentMerge pull request #933 from lioncash/memory (diff)
downloadyuzu-2b2dc00bfd3410bdce16966b1448fac36dd3126d.tar.gz
yuzu-2b2dc00bfd3410bdce16966b1448fac36dd3126d.tar.xz
yuzu-2b2dc00bfd3410bdce16966b1448fac36dd3126d.zip
qt/main: Better file-existence checking within OnMenuRecentFile() and UpdateUITheme()
In OnMenuRecentFile() we don't need to construct a QFileInfo instance just to check if a file exists, we can just use the static member function to do that (which Qt's documentation also notes as quicker than constructing an instance). In UpdateUITheme(), we just want to try and open the file and check the success of that operation. Technically speaking, between the existence check and the open call, the file can be deleted or moved, but still appear to succeed in code. i.e. 1. Existence check -> Returns true 2. File is moved/deleted 3. Open is called, the return value of which isn't checked 4. Nonsense behavior This way we combine the existence check and the open into one.
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index e28679cd1..d0415a7dc 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -654,9 +654,8 @@ void GMainWindow::OnMenuRecentFile() {
654 QAction* action = qobject_cast<QAction*>(sender()); 654 QAction* action = qobject_cast<QAction*>(sender());
655 assert(action); 655 assert(action);
656 656
657 QString filename = action->data().toString(); 657 const QString filename = action->data().toString();
658 QFileInfo file_info(filename); 658 if (QFileInfo::exists(filename)) {
659 if (file_info.exists()) {
660 BootGame(filename); 659 BootGame(filename);
661 } else { 660 } else {
662 // Display an error message and remove the file from the list. 661 // Display an error message and remove the file from the list.
@@ -947,15 +946,14 @@ void GMainWindow::UpdateUITheme() {
947 QStringList theme_paths(default_theme_paths); 946 QStringList theme_paths(default_theme_paths);
948 if (UISettings::values.theme != UISettings::themes[0].second && 947 if (UISettings::values.theme != UISettings::themes[0].second &&
949 !UISettings::values.theme.isEmpty()) { 948 !UISettings::values.theme.isEmpty()) {
950 QString theme_uri(":" + UISettings::values.theme + "/style.qss"); 949 const QString theme_uri(":" + UISettings::values.theme + "/style.qss");
951 QFile f(theme_uri); 950 QFile f(theme_uri);
952 if (!f.exists()) { 951 if (f.open(QFile::ReadOnly | QFile::Text)) {
953 LOG_ERROR(Frontend, "Unable to set style, stylesheet file not found");
954 } else {
955 f.open(QFile::ReadOnly | QFile::Text);
956 QTextStream ts(&f); 952 QTextStream ts(&f);
957 qApp->setStyleSheet(ts.readAll()); 953 qApp->setStyleSheet(ts.readAll());
958 GMainWindow::setStyleSheet(ts.readAll()); 954 GMainWindow::setStyleSheet(ts.readAll());
955 } else {
956 LOG_ERROR(Frontend, "Unable to set style, stylesheet file not found");
959 } 957 }
960 theme_paths.append(QStringList{":/icons/default", ":/icons/" + UISettings::values.theme}); 958 theme_paths.append(QStringList{":/icons/default", ":/icons/" + UISettings::values.theme});
961 QIcon::setThemeName(":/icons/" + UISettings::values.theme); 959 QIcon::setThemeName(":/icons/" + UISettings::values.theme);