Fix up import destination indicator

This commit is contained in:
zhupengfei
2020-05-15 22:47:18 +08:00
parent 450cef3fca
commit 2fbdaaac30
4 changed files with 17 additions and 23 deletions
+10 -1
View File
@@ -694,7 +694,8 @@ std::string GetSysDirectory() {
namespace { namespace {
std::unordered_map<UserPath, std::string> g_paths; std::unordered_map<UserPath, std::string> g_paths;
} bool g_portable_user_directory = false;
} // namespace
void SetUserPath(const std::string& path) { void SetUserPath(const std::string& path) {
if (!g_paths.empty()) { if (!g_paths.empty()) {
@@ -715,6 +716,7 @@ void SetUserPath(const std::string& path) {
user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP; user_path = AppDataRoamingDirectory() + DIR_SEP EMU_DATA_DIR DIR_SEP;
} else { } else {
LOG_INFO(Common_Filesystem, "Using the local user directory"); LOG_INFO(Common_Filesystem, "Using the local user directory");
g_portable_user_directory = true;
} }
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP); g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
@@ -726,6 +728,9 @@ void SetUserPath(const std::string& path) {
user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP; user_path = ROOT_DIR DIR_SEP USERDATA_DIR DIR_SEP;
g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP); g_paths.emplace(UserPath::ConfigDir, user_path + CONFIG_DIR DIR_SEP);
g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP); g_paths.emplace(UserPath::CacheDir, user_path + CACHE_DIR DIR_SEP);
LOG_INFO(Common_Filesystem, "Using the local user directory");
g_portable_user_directory = true;
} else { } else {
std::string data_dir = GetUserDirectory("XDG_DATA_HOME"); std::string data_dir = GetUserDirectory("XDG_DATA_HOME");
std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME"); std::string config_dir = GetUserDirectory("XDG_CONFIG_HOME");
@@ -753,6 +758,10 @@ const std::string& GetUserPath(UserPath path) {
return g_paths[path]; return g_paths[path];
} }
bool IsPortableUserDirectory() {
return g_portable_user_directory;
}
std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) { std::size_t WriteStringToFile(bool text_file, const std::string& filename, std::string_view str) {
return IOFile(filename, text_file ? "w" : "wb").WriteString(str); return IOFile(filename, text_file ? "w" : "wb").WriteString(str);
} }
+3
View File
@@ -137,6 +137,9 @@ void SetUserPath(const std::string& path = "");
// directory. To be used in "multi-user" mode (that is, installed). // directory. To be used in "multi-user" mode (that is, installed).
const std::string& GetUserPath(UserPath path); const std::string& GetUserPath(UserPath path);
// Whetehr we are using the portable user directory.
bool IsPortableUserDirectory();
// Returns the path to where the sys file are // Returns the path to where the sys file are
std::string GetSysDirectory(); std::string GetSysDirectory();
+4 -8
View File
@@ -5,7 +5,6 @@
#include <regex> #include <regex>
#include <string> #include <string>
#include <QApplication> #include <QApplication>
#include <QDesktopServices>
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QStorageInfo> #include <QStorageInfo>
@@ -57,13 +56,10 @@ MainDialog::MainDialog(QWidget* parent) : QDialog(parent), ui(std::make_unique<U
} }
}); });
ui->importDestination->setText( ui->importDestination->setText(tr("Import Destination: %1")
QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir))); .arg(FileUtil::IsPortableUserDirectory()
connect(ui->importDestinationButton, &QPushButton::clicked, [this] { ? tr("Portable Citra Install")
QDesktopServices::openUrl(QUrl( : tr("User-wide Citra Install")));
QStringLiteral("file:///%1")
.arg(QString::fromStdString(FileUtil::GetUserPath(FileUtil::UserPath::UserDir)))));
});
connect(ui->main, &QTreeWidget::itemSelectionChanged, [this] { connect(ui->main, &QTreeWidget::itemSelectionChanged, [this] {
ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok) ui->buttonBox->button(QDialogButtonBox::StandardButton::Ok)
-14
View File
@@ -60,23 +60,9 @@
</item> </item>
<item> <item>
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item>
<widget class="QLabel">
<property name="text">
<string>Files will be imported to: </string>
</property>
</widget>
</item>
<item> <item>
<widget class="QLabel" name="importDestination"/> <widget class="QLabel" name="importDestination"/>
</item> </item>
<item>
<widget class="QPushButton" name="importDestinationButton">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
<item> <item>
<spacer> <spacer>
<property name="orientation"> <property name="orientation">