summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-11-27 16:06:03 -0500
committerGitHub <noreply@github.com>2019-11-27 16:06:03 -0500
commitaab91226b82563eaca16fdb7a86eb2ff1fde5a0a (patch)
tree8f80288e634e459b1b5ef80f5510f6b79b6b4be5 /src
parent23bfe4e9ffe1637ff9e4912f913567ee921c801e (diff)
parent05759c4abcae0e54c7c6fb3aac43b55ed490b6f4 (diff)
Merge pull request #910 from isanae/system-dir-checks
Added checks on startup for directories in program files
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp3
-rw-r--r--src/sanitychecks.cpp80
2 files changed, 83 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 3cccf365..1f6c57d1 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -94,6 +94,7 @@ using namespace MOShared;
void sanityChecks(const env::Environment& env);
int checkIncompatibleModule(const env::Module& m);
+int checkPathsForSanity(MOBase::IPluginGame& game, const Settings& s);
bool createAndMakeWritable(const std::wstring &subPath) {
QString const dataPath = qApp->property("dataPath").toString();
@@ -593,6 +594,8 @@ int runApplication(MOApplication &application, SingleInstance &instance,
return 1;
}
+ checkPathsForSanity(*game, settings);
+
if (splashPath.startsWith(':')) {
// currently using MO splash, see if the plugin contains one
QString pluginSplash
diff --git a/src/sanitychecks.cpp b/src/sanitychecks.cpp
index ef57a503..a767e8f9 100644
--- a/src/sanitychecks.cpp
+++ b/src/sanitychecks.cpp
@@ -1,6 +1,9 @@
#include "env.h"
#include "envmodule.h"
+#include "settings.h"
+#include <iplugingame.h>
#include <log.h>
+#include <utility.h>
using namespace MOBase;
@@ -252,6 +255,83 @@ int checkIncompatibilities(const env::Environment& e)
return n;
}
+std::vector<std::pair<QString, QString>> getSystemDirectories()
+{
+ // folder ids and display names for logging
+ const std::vector<std::pair<GUID, QString>> systemFolderIDs = {
+ {FOLDERID_ProgramFiles, "Program Files"},
+ {FOLDERID_ProgramFilesX86, "Program Files"}
+ };
+
+ std::vector<std::pair<QString, QString>> systemDirs;
+
+ for (auto&& p : systemFolderIDs) {
+ try
+ {
+ const auto dir = MOBase::getKnownFolder(p.first);
+
+ auto path = QDir::toNativeSeparators(dir.absolutePath()).toLower();
+ if (!path.endsWith("\\")) {
+ path += "\\";
+ }
+
+ systemDirs.push_back({path, p.second});
+ }
+ catch(std::exception&)
+ {
+ // ignore
+ }
+ }
+
+ return systemDirs;
+}
+
+int checkProtected(const QDir& d, const QString& what)
+{
+ static const auto systemDirs = getSystemDirectories();
+
+ const auto path = QDir::toNativeSeparators(d.absolutePath()).toLower();
+
+ log::debug(" . {}: {}", what, path);
+
+ for (auto&& sd : systemDirs) {
+ if (path.startsWith(sd.first)) {
+ log::warn(
+ "{} is in {}; this may cause issues because it's a protected "
+ "system folder",
+ what, sd.second);
+
+ log::debug("path '{}' starts with '{}'", path, sd.first);
+
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
+int checkPathsForSanity(IPluginGame& game, const Settings& s)
+{
+ log::debug("checking paths");
+
+ int n = 0;
+
+ n += checkProtected(game.gameDirectory(), "the game");
+ n += checkProtected(QApplication::applicationDirPath(), "Mod Organizer");
+
+ if (checkProtected(s.paths().base(), "the instance base directory")) {
+ ++n;
+ } else {
+ n += checkProtected(s.paths().downloads(), "the downloads directory");
+ n += checkProtected(s.paths().mods(), "the mods directory");
+ n += checkProtected(s.paths().cache(), "the cache directory");
+ n += checkProtected(s.paths().profiles(), "the profiles directory");
+ n += checkProtected(s.paths().overwrite(), "the overwrite directory");
+ }
+
+ return n;
+}
+
void sanityChecks(const env::Environment& e)
{
log::debug("running sanity checks...");