always use native directory separators in paths

This commit is contained in:
xiphon 2020-04-24 00:43:40 +00:00
parent 585fb2810d
commit a99eef68f5
10 changed files with 35 additions and 42 deletions

View file

@ -58,11 +58,6 @@ function switchPage(next) {
} }
function createWalletPath(isIOS, folder_path,account_name){ function createWalletPath(isIOS, folder_path,account_name){
// Remove trailing slash - (default on windows and mac)
if (folder_path.substring(folder_path.length -1) === "/"){
folder_path = folder_path.substring(0,folder_path.length -1)
}
// Store releative path on ios. // Store releative path on ios.
if(isIOS) if(isIOS)
folder_path = ""; folder_path = "";

View file

@ -214,7 +214,7 @@ ApplicationWindow {
appWindow.viewState = prevState; appWindow.viewState = prevState;
} }
}; };
passwordDialog.open(usefulName(walletPath())); passwordDialog.open(usefulName(persistentSettings.wallet_path));
} }
function initialize() { function initialize() {
@ -253,7 +253,7 @@ ApplicationWindow {
simpleModeConnectionTimer.running = true; simpleModeConnectionTimer.running = true;
// wallet already opened with wizard, we just need to initialize it // wallet already opened with wizard, we just need to initialize it
var wallet_path = walletPath(); var wallet_path = persistentSettings.wallet_path;
if(isIOS) if(isIOS)
wallet_path = moneroAccountsDir + wallet_path; wallet_path = moneroAccountsDir + wallet_path;
// console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.walletPassword); // console.log("opening wallet at: ", wallet_path, "with password: ", appWindow.walletPassword);
@ -392,11 +392,6 @@ ApplicationWindow {
return !persistentSettings.useRemoteNode || persistentSettings.is_trusted_daemon; return !persistentSettings.useRemoteNode || persistentSettings.is_trusted_daemon;
} }
function walletPath() {
var wallet_path = persistentSettings.wallet_path
return wallet_path;
}
function usefulName(path) { function usefulName(path) {
// arbitrary "short enough" limit // arbitrary "short enough" limit
if (path.length < 32) if (path.length < 32)

View file

@ -131,10 +131,11 @@ Rectangle {
} }
MoneroComponents.TextBlock { MoneroComponents.TextBlock {
id: walletLocation
Layout.fillWidth: true Layout.fillWidth: true
color: MoneroComponents.Style.dimmedFontColor color: MoneroComponents.Style.dimmedFontColor
font.pixelSize: 14 font.pixelSize: 14
property string walletPath: (isIOS ? moneroAccountsDir : "") + appWindow.walletPath() property string walletPath: (isIOS ? moneroAccountsDir : "") + persistentSettings.wallet_path
text: "\ text: "\
<style type='text/css'>\ <style type='text/css'>\
a {cursor:pointer;text-decoration: none; color: #FF6C3C}\ a {cursor:pointer;text-decoration: none; color: #FF6C3C}\
@ -389,12 +390,7 @@ Rectangle {
var data = ""; var data = "";
data += "GUI version: " + Version.GUI_VERSION + " (Qt " + qtRuntimeVersion + ")"; data += "GUI version: " + Version.GUI_VERSION + " (Qt " + qtRuntimeVersion + ")";
data += "\nEmbedded Monero version: " + Version.GUI_MONERO_VERSION; data += "\nEmbedded Monero version: " + Version.GUI_MONERO_VERSION;
data += "\nWallet path: "; data += "\nWallet path: " + walletLocation.walletPath;
var wallet_path = walletPath();
if(isIOS)
wallet_path = moneroAccountsDir + wallet_path;
data += wallet_path;
data += "\nWallet creation height: "; data += "\nWallet creation height: ";
if(currentWallet) if(currentWallet)

View file

@ -227,7 +227,7 @@ QString Wallet::address(quint32 accountIndex, quint32 addressIndex) const
QString Wallet::path() const QString Wallet::path() const
{ {
return QString::fromStdString(m_walletImpl->path()); return QDir::toNativeSeparators(QString::fromStdString(m_walletImpl->path()));
} }
bool Wallet::store(const QString &path) bool Wallet::store(const QString &path)

View file

@ -210,6 +210,7 @@ int main(int argc, char *argv[])
qCritical() << "Error: accounts root directory could not be set"; qCritical() << "Error: accounts root directory could not be set";
return 1; return 1;
} }
moneroAccountsDir = QDir::toNativeSeparators(moneroAccountsDir);
#if defined(Q_OS_LINUX) #if defined(Q_OS_LINUX)
if (isDesktop) app.setWindowIcon(QIcon(":/images/appicon.ico")); if (isDesktop) app.setWindowIcon(QIcon(":/images/appicon.ico"));
@ -241,7 +242,7 @@ Verify update binary using 'shasum'-compatible (SHA256 algo) output signed by tw
Monero::Utils::onStartup(); Monero::Utils::onStartup();
// Log settings // Log settings
const QString logPath = getLogPath(parser.value(logPathOption)); const QString logPath = QDir::toNativeSeparators(getLogPath(parser.value(logPathOption)));
Monero::Wallet::init(argv[0], "monero-wallet-gui", logPath.toStdString().c_str(), true); Monero::Wallet::init(argv[0], "monero-wallet-gui", logPath.toStdString().c_str(), true);
qInstallMessageHandler(messageHandler); qInstallMessageHandler(messageHandler);

View file

@ -43,11 +43,20 @@
#include "KeysFiles.h" #include "KeysFiles.h"
WalletKeysFiles::WalletKeysFiles(const qint64 &modified, const QString &path, const quint8 &networkType, const QString &address) WalletKeysFiles::WalletKeysFiles(const QFileInfo &info, quint8 networkType, QString address)
: m_modified(modified), m_path(path), m_networkType(networkType), m_address(address) : m_fileName(info.fileName())
, m_modified(info.lastModified().toSecsSinceEpoch())
, m_path(QDir::toNativeSeparators(info.absoluteFilePath()))
, m_networkType(networkType)
, m_address(std::move(address))
{ {
} }
QString WalletKeysFiles::fileName() const
{
return m_fileName;
}
qint64 WalletKeysFiles::modified() const qint64 WalletKeysFiles::modified() const
{ {
return m_modified; return m_modified;
@ -127,11 +136,7 @@ void WalletKeysFilesModel::findWallets(const QString &moneroAccountsDir)
file.close(); file.close();
} }
const QFileInfo info(wallet); this->addWalletKeysFile(WalletKeysFiles(wallet, networkType, std::move(address)));
const QDateTime modifiedAt = info.lastModified();
this->addWalletKeysFile(WalletKeysFiles(modifiedAt.toSecsSinceEpoch(),
info.absoluteFilePath(), networkType, address));
} }
} }
@ -152,6 +157,8 @@ QVariant WalletKeysFilesModel::data(const QModelIndex & index, int role) const {
return QVariant(); return QVariant();
const WalletKeysFiles &walletKeyFile = m_walletKeyFiles[index.row()]; const WalletKeysFiles &walletKeyFile = m_walletKeyFiles[index.row()];
if (role == FileNameRole)
return walletKeyFile.fileName();
if (role == ModifiedRole) if (role == ModifiedRole)
return walletKeyFile.modified(); return walletKeyFile.modified();
else if (role == PathRole) else if (role == PathRole)
@ -165,6 +172,7 @@ QVariant WalletKeysFilesModel::data(const QModelIndex & index, int role) const {
QHash<int, QByteArray> WalletKeysFilesModel::roleNames() const { QHash<int, QByteArray> WalletKeysFilesModel::roleNames() const {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[FileNameRole] = "fileName";
roles[ModifiedRole] = "modified"; roles[ModifiedRole] = "modified";
roles[PathRole] = "path"; roles[PathRole] = "path";
roles[NetworkTypeRole] = "networktype"; roles[NetworkTypeRole] = "networktype";

View file

@ -37,14 +37,16 @@
class WalletKeysFiles class WalletKeysFiles
{ {
public: public:
WalletKeysFiles(const qint64 &modified, const QString &path, const quint8 &networkType, const QString &address); WalletKeysFiles(const QFileInfo &info, quint8 networkType, QString address);
QString fileName() const;
qint64 modified() const; qint64 modified() const;
QString path() const; QString path() const;
quint8 networkType() const; quint8 networkType() const;
QString address() const; QString address() const;
private: private:
QString m_fileName;
qint64 m_modified; qint64 m_modified;
QString m_path; QString m_path;
quint8 m_networkType; quint8 m_networkType;
@ -56,7 +58,8 @@ class WalletKeysFilesModel : public QAbstractListModel
Q_OBJECT Q_OBJECT
public: public:
enum KeysFilesRoles { enum KeysFilesRoles {
ModifiedRole = Qt::UserRole + 1, FileNameRole = Qt::UserRole + 1,
ModifiedRole,
PathRole, PathRole,
NetworkTypeRole, NetworkTypeRole,
AddressRole AddressRole

View file

@ -371,7 +371,7 @@ Rectangle {
persistentSettings.locale = wizardController.language_locale persistentSettings.locale = wizardController.language_locale
persistentSettings.account_name = wizardController.walletOptionsName persistentSettings.account_name = wizardController.walletOptionsName
persistentSettings.wallet_path = new_wallet_filename persistentSettings.wallet_path = wizardController.m_wallet.path;
persistentSettings.restore_height = (isNaN(walletOptionsRestoreHeight))? 0 : walletOptionsRestoreHeight persistentSettings.restore_height = (isNaN(walletOptionsRestoreHeight))? 0 : walletOptionsRestoreHeight
persistentSettings.allow_background_mining = false persistentSettings.allow_background_mining = false

View file

@ -119,7 +119,7 @@ Rectangle {
delegate: Rectangle { delegate: Rectangle {
// inherited roles from walletKeysFilesModel: // inherited roles from walletKeysFilesModel:
// index, modified, accessed, path, networktype, address // index, fileName, modified, accessed, path, networktype, address
id: item id: item
height: flow.itemHeight height: flow.itemHeight
width: { width: {
@ -133,11 +133,6 @@ Rectangle {
else if(networktype === 2) return qsTr("Stagenet"); else if(networktype === 2) return qsTr("Stagenet");
return ""; return "";
} }
property string fileName: {
var spl = path.split("/");
return spl[spl.length - 1].replace(".keys", "");
}
property string filePath: { return path }
color: "transparent" color: "transparent"
Rectangle { Rectangle {
@ -202,9 +197,9 @@ Rectangle {
text: { text: {
// truncate on window width // truncate on window width
var maxLength = wizardController.layoutScale <= 1 ? 12 : 16 var maxLength = wizardController.layoutScale <= 1 ? 12 : 16
if(item.fileName.length > maxLength) if (fileName.length > maxLength)
return item.fileName.substring(0, maxLength) + "..."; return fileName.substring(0, maxLength) + "...";
return item.fileName; return fileName;
} }
Layout.preferredHeight: 26 Layout.preferredHeight: 26
@ -270,7 +265,7 @@ Rectangle {
onClicked: { onClicked: {
persistentSettings.nettype = parseInt(networktype) persistentSettings.nettype = parseInt(networktype)
wizardController.openWalletFile(item.filePath); wizardController.openWalletFile(path);
} }
} }
} }

View file

@ -55,7 +55,7 @@ GridLayout {
function reset() { function reset() {
walletName.error = !walletName.verify(); walletName.error = !walletName.verify();
walletLocation.error = walletLocation.text === ""; walletLocation.error = walletLocation.text === "";
walletLocation.text = moneroAccountsDir + "/"; walletLocation.text = moneroAccountsDir;
walletName.text = defaultAccountName; walletName.text = defaultAccountName;
} }