@ -30,77 +30,69 @@ AppContext::AppContext(QCommandLineParser *cmdargs) {
this - > cmdargs = cmdargs ;
this - > cmdargs = cmdargs ;
AppContext : : isQML = false ;
AppContext : : isQML = false ;
// OS & env
# if defined(Q_OS_MAC)
# if defined(Q_OS_MAC)
this - > isMac = true ;
this - > isTorSocks = qgetenv ( " DYLD_INSERT_LIBRARIES " ) . indexOf ( " libtorsocks " ) > = 0 ;
this - > isTorSocks = qgetenv ( " DYLD_INSERT_LIBRARIES " ) . indexOf ( " libtorsocks " ) > = 0 ;
# elif __ANDROID__
this - > isAndroid = true ;
# elif defined(Q_OS_LINUX)
# elif defined(Q_OS_LINUX)
this - > isLinux = true ;
this - > isTorSocks = qgetenv ( " LD_PRELOAD " ) . indexOf ( " libtorsocks " ) > = 0 ;
this - > isTorSocks = qgetenv ( " LD_PRELOAD " ) . indexOf ( " libtorsocks " ) > = 0 ;
this - > isTails = TailsOS : : detect ( ) ;
this - > isWhonix = WhonixOS : : detect ( ) ;
# elif defined(Q_OS_WIN)
# elif defined(Q_OS_WIN)
this - > isWindows = true ;
this - > isTorSocks = false ;
this - > isTorSocks = false ;
# endif
# endif
this - > androidDebug = cmdargs - > isSet ( " android-debug " ) ;
this - > isTails = TailsOS : : detect ( ) ;
// Paths
this - > isWhonix = WhonixOS : : detect ( ) ;
this - > pathGenericData = QStandardPaths : : writableLocation ( QStandardPaths : : GenericDataLocation ) ;
//Paths
this - > configRoot = QDir : : homePath ( ) ;
this - > configRoot = QDir : : homePath ( ) ;
if ( isTails ) { // #if defined(PORTABLE)
QString portablePath = [ ] {
QString appImagePath = qgetenv ( " APPIMAGE " ) ;
if ( appImagePath . isEmpty ( ) ) {
qDebug ( ) < < " Not an appimage, using currentPath() " ;
return QDir : : currentPath ( ) + " /.wowlet " ;
}
QFileInfo appImageDir ( appImagePath ) ;
return appImageDir . absoluteDir ( ) . path ( ) + " /.wowlet " ;
} ( ) ;
if ( QDir ( ) . mkpath ( portablePath ) ) {
this - > configRoot = portablePath ;
} else {
qCritical ( ) < < " Unable to create portable directory: " < < portablePath ;
}
}
this - > accountName = Utils : : getUnixAccountName ( ) ;
this - > accountName = Utils : : getUnixAccountName ( ) ;
this - > homeDir = QDir : : homePath ( ) ;
this - > homeDir = QDir : : homePath ( ) ;
this - > configDirectory = QString ( " %1/.config/wowlet/ " ) . arg ( this - > configRoot ) ;
this - > configDirectoryVR = QString ( " %1%2 " ) . arg ( this - > configDirectory , " vr " ) ;
if ( isTails ) this - > setupPathsTails ( ) ;
QString walletDir = config ( ) - > get ( Config : : walletDirectory ) . toString ( ) ;
QString walletDir = config ( ) - > get ( Config : : walletDirectory ) . toString ( ) ;
if ( walletDir . isEmpty ( ) ) {
if ( walletDir . isEmpty ( ) ) {
# if defined(Q_OS_LINUX) or defined(Q_OS_MAC)
if ( isAndroid & & ! androidDebug ) setupPathsAndroid ( ) ;
this - > defaultWalletDir = QString ( " %1/Wownero/wallets " ) . arg ( this - > configRoot ) ;
else if ( isWindows ) setupPathsWindows ( ) ;
this - > defaultWalletDirRoot = QString ( " %1/Wownero " ) . arg ( this - > configRoot ) ;
else if ( isLinux | | isMac ) setupPathsUnix ( ) ;
# elif defined(Q_OS_WIN)
this - > defaultWalletDir = QStandardPaths : : writableLocation ( QStandardPaths : : DocumentsLocation ) + " /Wownero " ;
this - > defaultWalletDirRoot = QStandardPaths : : writableLocation ( QStandardPaths : : DocumentsLocation ) ;
# endif
} else {
} else {
this - > defaultWalletDir = walletDir ;
this - > defaultWalletDir = walletDir ;
this - > defaultWalletDirRoot = walletDir ;
this - > defaultWalletDirRoot = walletDir ;
}
}
# ifdef __ANDROID__
// can haz disk I/O?
QVector < QString > perms = {
" android.permission.WRITE_EXTERNAL_STORAGE " ,
" android.permission.READ_EXTERNAL_STORAGE "
} ;
Utils : : androidAskPermissions ( perms ) ;
# endif
// Create wallet dirs
// Create wallet dirs
qDebug ( ) < < " creating " < < defaultWalletDir ;
if ( ! QDir ( ) . mkpath ( defaultWalletDir ) )
if ( ! QDir ( ) . mkpath ( defaultWalletDir ) )
qCritical ( ) < < " Unable to create dir: " < < defaultWalletDir ;
qCritical ( ) < < " Unable to create dir: " < < defaultWalletDir ;
this - > configDirectory = QString ( " %1/.config/wowlet/ " ) . arg ( this - > configRoot ) ;
# if defined(Q_OS_UNIX)
if ( ! this - > configDirectory . endsWith ( ' / ' ) )
this - > configDirectory = QString ( " %1/ " ) . arg ( this - > configDirectory ) ;
# endif
this - > configDirectoryVR = QString ( " %1%2 " ) . arg ( this - > configDirectory , " vr " ) ;
// Create some directories
// Create some directories
createConfigDirectory ( this - > configDirectory ) ;
createConfigDirectory ( this - > configDirectory ) ;
// if(this->cmdargs->isSet("stagenet"))
// this->networkType = NetworkType::STAGENET;
// else if(this->cmdargs->isSet("testnet"))
// this->networkType = NetworkType::TESTNET;
// else
this - > networkType = NetworkType : : MAINNET ;
this - > networkType = NetworkType : : MAINNET ;
qDebug ( ) < < " configRoot: " < < this - > configRoot ;
qDebug ( ) < < " homeDir: " < < this - > homeDir ;
qDebug ( ) < < " customWalletDir: " < < walletDir ;
qDebug ( ) < < " defaultWalletDir: " < < this - > defaultWalletDir ;
qDebug ( ) < < " defaultWalletDirRoot: " < < this - > defaultWalletDirRoot ;
qDebug ( ) < < " configDirectory: " < < this - > configDirectory ;
// auto nodeSourceUInt = config()->get(Config::nodeSource).toUInt();
// auto nodeSourceUInt = config()->get(Config::nodeSource).toUInt();
// AppContext::nodeSource = static_cast<NodeSource>(nodeSourceUInt);
// AppContext::nodeSource = static_cast<NodeSource>(nodeSourceUInt);
this - > nodes = new Nodes ( this , this - > networkClearnet ) ;
this - > nodes = new Nodes ( this , this - > networkClearnet ) ;
@ -558,12 +550,14 @@ void AppContext::createConfigDirectory(const QString &dir) {
}
}
}
}
# ifdef HAS_OPENVR
auto config_dir_vr = QString ( " %1%2 " ) . arg ( dir , " vr " ) ;
auto config_dir_vr = QString ( " %1%2 " ) . arg ( dir , " vr " ) ;
if ( ! Utils : : dirExists ( config_dir_vr ) ) {
if ( ! Utils : : dirExists ( config_dir_vr ) ) {
qDebug ( ) < < QString ( " Creating directory: %1 " ) . arg ( config_dir_vr ) ;
qDebug ( ) < < QString ( " Creating directory: %1 " ) . arg ( config_dir_vr ) ;
if ( ! QDir ( ) . mkpath ( config_dir_vr ) )
if ( ! QDir ( ) . mkpath ( config_dir_vr ) )
throw std : : runtime_error ( " Could not create directory " + config_dir_vr . toStdString ( ) ) ;
throw std : : runtime_error ( " Could not create directory " + config_dir_vr . toStdString ( ) ) ;
}
}
# endif
}
}
void AppContext : : createWalletWithoutSpecifyingSeed ( const QString & name , const QString & password ) {
void AppContext : : createWalletWithoutSpecifyingSeed ( const QString & name , const QString & password ) {
@ -949,3 +943,38 @@ void AppContext::refreshModels() {
this - > currentWallet - > coins ( ) - > refresh ( this - > currentWallet - > currentSubaddressAccount ( ) ) ;
this - > currentWallet - > coins ( ) - > refresh ( this - > currentWallet - > currentSubaddressAccount ( ) ) ;
// Todo: set timer for refreshes
// Todo: set timer for refreshes
}
}
void AppContext : : setupPathsUnix ( ) {
this - > defaultWalletDir = QString ( " %1/Wownero/wallets " ) . arg ( this - > configRoot ) ;
this - > defaultWalletDirRoot = QString ( " %1/Wownero " ) . arg ( this - > configRoot ) ;
}
void AppContext : : setupPathsWindows ( ) {
this - > defaultWalletDir = QStandardPaths : : writableLocation ( QStandardPaths : : DocumentsLocation ) + " /Wownero " ;
this - > defaultWalletDirRoot = QStandardPaths : : writableLocation ( QStandardPaths : : DocumentsLocation ) ;
}
void AppContext : : setupPathsAndroid ( ) {
this - > defaultWalletDir = QString ( " %1/Wownero/wallets " ) . arg ( this - > pathGenericData ) ;
this - > defaultWalletDirRoot = QString ( " %1/Wownero " ) . arg ( this - > pathGenericData ) ;
}
void AppContext : : setupPathsTails ( ) {
QString portablePath = [ ] {
QString appImagePath = qgetenv ( " APPIMAGE " ) ;
if ( appImagePath . isEmpty ( ) ) {
qDebug ( ) < < " Not an appimage, using currentPath() " ;
return QDir : : currentPath ( ) + " /.wowlet " ;
}
QFileInfo appImageDir ( appImagePath ) ;
return appImageDir . absoluteDir ( ) . path ( ) + " /.wowlet " ;
} ( ) ;
if ( QDir ( ) . mkpath ( portablePath ) ) {
this - > configRoot = portablePath ;
} else {
qCritical ( ) < < " Unable to create portable directory: " < < portablePath ;
}
}