diff --git a/README.md b/README.md index 3ab3f37..1b446b1 100644 --- a/README.md +++ b/README.md @@ -57,8 +57,8 @@ https://matsuridayo.github.io ## 运行参数 -- `-many` 无视同目录正在运行的实例,强行开启新的实例 (0.11+) -- `-appdata` 开启后配置文件会放在共享目录,无法多开和自动升级 (0.11+) +- `-many` 无视同目录正在运行的实例,强行开启新的实例 (0.11+)。 +- `-appdata` 开启后配置文件会指定目录,未指定目录则使用共享目录,无法多开和自动升级 (0.11+)。 ## Windows 运行 diff --git a/main/NekoRay_DataStore.hpp b/main/NekoRay_DataStore.hpp index 6ca68df..cc493b1 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoRay_DataStore.hpp @@ -71,6 +71,7 @@ namespace NekoRay { bool spmode_vpn = false; bool spmode_system_proxy = false; bool need_keep_vpn_off = false; + QString appdataDir = ""; QStringList ignoreConnTag = {}; Routing *routing = new Routing; diff --git a/main/main.cpp b/main/main.cpp index d31955f..20b6787 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -78,7 +78,13 @@ int main(int argc, char* argv[]) { // Flags NekoRay::dataStore->argv = QApplication::arguments(); if (NekoRay::dataStore->argv.contains("-many")) NekoRay::dataStore->flag_many = true; - if (NekoRay::dataStore->argv.contains("-appdata")) NekoRay::dataStore->flag_use_appdata = true; + if (NekoRay::dataStore->argv.contains("-appdata")) { + NekoRay::dataStore->flag_use_appdata = true; + int appdataIndex = NekoRay::dataStore->argv.indexOf("-appdata"); + if (NekoRay::dataStore->argv.size() > appdataIndex + 1 && !NekoRay::dataStore->argv.at(appdataIndex + 1).startsWith("-")) { + NekoRay::dataStore->appdataDir = NekoRay::dataStore->argv.at(appdataIndex + 1); + } + } if (NekoRay::dataStore->argv.contains("-tray")) NekoRay::dataStore->flag_tray = true; if (NekoRay::dataStore->argv.contains("-debug")) NekoRay::dataStore->flag_debug = true; if (NekoRay::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoRay::dataStore->flag_linux_run_core_as_admin = true; @@ -93,9 +99,13 @@ int main(int argc, char* argv[]) { auto wd = QDir(QApplication::applicationDirPath()); if (NekoRay::dataStore->flag_use_appdata) { QApplication::setApplicationName("nekoray"); - wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + if (!NekoRay::dataStore->appdataDir.isEmpty()) { + wd.setPath(NekoRay::dataStore->appdataDir); + } else { + wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + } } - if (!wd.exists()) wd.mkdir(wd.absolutePath()); + if (!wd.exists()) wd.mkpath(wd.absolutePath()); if (!wd.exists("config")) wd.mkdir("config"); QDir::setCurrent(wd.absoluteFilePath("config")); QDir("temp").removeRecursively();