@ -29,6 +29,7 @@
using namespace std ;
using namespace std ;
using namespace boost ;
using namespace boost ;
std : : string strWalletFile ;
CWallet * pwalletMain ;
CWallet * pwalletMain ;
CClientUIInterface uiInterface ;
CClientUIInterface uiInterface ;
@ -169,6 +170,7 @@ std::string HelpMessage()
strUsage + = " -pid=<file> " + _ ( " Specify pid file (default: bitcoind.pid) " ) + " \n " ;
strUsage + = " -pid=<file> " + _ ( " Specify pid file (default: bitcoind.pid) " ) + " \n " ;
strUsage + = " -gen " + _ ( " Generate coins (default: 0) " ) + " \n " ;
strUsage + = " -gen " + _ ( " Generate coins (default: 0) " ) + " \n " ;
strUsage + = " -datadir=<dir> " + _ ( " Specify data directory " ) + " \n " ;
strUsage + = " -datadir=<dir> " + _ ( " Specify data directory " ) + " \n " ;
strUsage + = " -wallet=<file> " + _ ( " Specify wallet file (within data directory) " ) + " \n " ;
strUsage + = " -dbcache=<n> " + _ ( " Set database cache size in megabytes (default: 25) " ) + " \n " ;
strUsage + = " -dbcache=<n> " + _ ( " Set database cache size in megabytes (default: 25) " ) + " \n " ;
strUsage + = " -timeout=<n> " + _ ( " Specify connection timeout in milliseconds (default: 5000) " ) + " \n " ;
strUsage + = " -timeout=<n> " + _ ( " Specify connection timeout in milliseconds (default: 5000) " ) + " \n " ;
strUsage + = " -proxy=<ip:port> " + _ ( " Connect through socks proxy " ) + " \n " ;
strUsage + = " -proxy=<ip:port> " + _ ( " Connect through socks proxy " ) + " \n " ;
@ -493,10 +495,16 @@ bool AppInit2(boost::thread_group& threadGroup)
InitWarning ( _ ( " Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction. " ) ) ;
InitWarning ( _ ( " Warning: -paytxfee is set very high! This is the transaction fee you will pay if you send a transaction. " ) ) ;
}
}
strWalletFile = GetArg ( " -wallet " , " wallet.dat " ) ;
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
// ********************************************************* Step 4: application initialization: dir lock, daemonize, pidfile, debug log
std : : string strDataDir = GetDataDir ( ) . string ( ) ;
std : : string strDataDir = GetDataDir ( ) . string ( ) ;
// Wallet file must be a plain filename without a directory
if ( strWalletFile ! = boost : : filesystem : : basename ( strWalletFile ) + boost : : filesystem : : extension ( strWalletFile ) )
return InitError ( strprintf ( _ ( " Wallet %s resides outside data directory %s \n " ) , strWalletFile . c_str ( ) , strDataDir . c_str ( ) ) ) ;
// Make sure only a single Bitcoin process is using the data directory.
// Make sure only a single Bitcoin process is using the data directory.
boost : : filesystem : : path pathLockFile = GetDataDir ( ) / " .lock " ;
boost : : filesystem : : path pathLockFile = GetDataDir ( ) / " .lock " ;
FILE * file = fopen ( pathLockFile . string ( ) . c_str ( ) , " a " ) ; // empty lock file; created if it doesn't exist.
FILE * file = fopen ( pathLockFile . string ( ) . c_str ( ) , " a " ) ; // empty lock file; created if it doesn't exist.
@ -555,13 +563,13 @@ bool AppInit2(boost::thread_group& threadGroup)
if ( GetBoolArg ( " -salvagewallet " , false ) )
if ( GetBoolArg ( " -salvagewallet " , false ) )
{
{
// Recover readable keypairs:
// Recover readable keypairs:
if ( ! CWalletDB : : Recover ( bitdb , " wallet.dat " , true ) )
if ( ! CWalletDB : : Recover ( bitdb , strWalletFile , true ) )
return false ;
return false ;
}
}
if ( filesystem : : exists ( GetDataDir ( ) / " wallet.dat " ) )
if ( filesystem : : exists ( GetDataDir ( ) / strWalletFile ) )
{
{
CDBEnv : : VerifyResult r = bitdb . Verify ( " wallet.dat " , CWalletDB : : Recover ) ;
CDBEnv : : VerifyResult r = bitdb . Verify ( strWalletFile , CWalletDB : : Recover ) ;
if ( r = = CDBEnv : : RECOVER_OK )
if ( r = = CDBEnv : : RECOVER_OK )
{
{
string msg = strprintf ( _ ( " Warning: wallet.dat corrupt, data salvaged! "
string msg = strprintf ( _ ( " Warning: wallet.dat corrupt, data salvaged! "
@ -838,7 +846,7 @@ bool AppInit2(boost::thread_group& threadGroup)
nStart = GetTimeMillis ( ) ;
nStart = GetTimeMillis ( ) ;
bool fFirstRun = true ;
bool fFirstRun = true ;
pwalletMain = new CWallet ( " wallet.dat " ) ;
pwalletMain = new CWallet ( strWalletFile ) ;
DBErrors nLoadWalletRet = pwalletMain - > LoadWallet ( fFirstRun ) ;
DBErrors nLoadWalletRet = pwalletMain - > LoadWallet ( fFirstRun ) ;
if ( nLoadWalletRet ! = DB_LOAD_OK )
if ( nLoadWalletRet ! = DB_LOAD_OK )
{
{
@ -903,7 +911,7 @@ bool AppInit2(boost::thread_group& threadGroup)
pindexRescan = pindexGenesisBlock ;
pindexRescan = pindexGenesisBlock ;
else
else
{
{
CWalletDB walletdb ( " wallet.dat " ) ;
CWalletDB walletdb ( strWalletFile ) ;
CBlockLocator locator ;
CBlockLocator locator ;
if ( walletdb . ReadBestBlock ( locator ) )
if ( walletdb . ReadBestBlock ( locator ) )
pindexRescan = locator . GetBlockIndex ( ) ;
pindexRescan = locator . GetBlockIndex ( ) ;