--- /dev/null
+src/version.cpp export-subst
src/*.exe
src/bitcoin
src/bitcoind
+src/build.h
.*.swp
*.*~*
*.bak
# do not enable this on windows, as it will result in a non-working executable!
}
+# regenerate src/build.h
+!windows || contains(USE_BUILD_INFO, 1) {
+ genbuild.depends = FORCE
+ genbuild.commands = cd $$PWD; share/genbuild.sh $$OUT_PWD/build/build.h
+ genbuild.target = genbuildhook
+ PRE_TARGETDEPS += genbuildhook
+ QMAKE_EXTRA_TARGETS += genbuild
+ DEFINES += HAVE_BUILD_INFO
+}
+
# disable quite some warnings because bitcoin core "sins" a lot
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wno-strict-aliasing -Wno-invalid-offsetof -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare -Wno-char-subscripts -Wno-unused-value -Wno-sequence-point -Wno-parentheses -Wno-unknown-pragmas -Wno-switch
src/qt/aboutdialog.cpp \
src/qt/editaddressdialog.cpp \
src/qt/bitcoinaddressvalidator.cpp \
+ src/version.cpp \
src/util.cpp \
src/netbase.cpp \
src/key.cpp \
#
cd bitcoin
mkdir -p $OUTDIR/src
- cp -a . $OUTDIR/src
- rm -rf $OUTDIR/src/.git
+ git archive HEAD | tar -x -C $OUTDIR/src
cp $OUTDIR/src/doc/README_windows.txt $OUTDIR/readme.txt
cp $OUTDIR/src/COPYING $OUTDIR/license.txt
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
export FAKETIME=$REFERENCE_DATETIME
export TZ=UTC
- $HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.0e OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.0e/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin
+ $HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.0e OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.0e/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin USE_BUILD_INFO=1
make $MAKEOPTS
cp release/bitcoin-qt.exe $OUTDIR/
#
cd src
- sed 's/$(DEBUGFLAGS)/-frandom-seed=bitcoin/' -i makefile.linux-mingw
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
export FAKETIME=$REFERENCE_DATETIME
export TZ=UTC
- make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_UPNP=0
+ make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_UPNP=0 DEBUGFLAGS="-frandom-seed=bitcoin"
i586-mingw32msvc-strip bitcoind.exe
- makensis ../share/setup.nsi
- cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/
mkdir $OUTDIR/daemon
cp bitcoind.exe $OUTDIR/daemon
+ cd ..
+ mkdir nsis
+ git archive HEAD | tar -x -C nsis
+ cd nsis/src
+ mkdir ../release
+ cp ../../release/* ../release/
+ cp ../../src/*.exe .
+ makensis ../share/setup.nsi
+ cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/
#
cd bitcoin
mkdir -p $OUTDIR/src
- cp -a . $OUTDIR/src
- rm -rf $OUTDIR/src/.git
+ git archive HEAD | tar -x -C $OUTDIR/src
cp $OUTDIR/src/doc/README $OUTDIR
cp $OUTDIR/src/COPYING $OUTDIR
cd src
- sed 's/$(DEBUGFLAGS)//' -i makefile.unix
- make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0
+ make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0 DEBUGFLAGS=
mkdir -p $OUTDIR/bin/$GBUILD_BITS
install -s bitcoind $OUTDIR/bin/$GBUILD_BITS
cd ..
* update (commit) version in sources
bitcoin-qt.pro
- src/main.h (CLIENT_VERSION : PROTOCOL_VERSION in serialize.h is updated only on protocol changes)
+ src/version.cpp
share/setup.nsi
doc/README*
--- /dev/null
+#!/bin/sh
+
+if [ $# -gt 0 ]; then
+ FILE="$1"
+ shift
+ if [ -f "$FILE" ]; then
+ INFO="$(head -n 1 "$FILE")"
+ fi
+else
+ echo "Usage: $0 <filename>"
+ exit 1
+fi
+
+if [ -e "$(which git)" ]; then
+ # clean 'dirty' status of touched files that haven't been modified
+ git diff >/dev/null 2>/dev/null
+
+ # get a string like "v0.6.0-66-g59887e8-dirty"
+ DESC="$(git describe --dirty 2>/dev/null)"
+
+ # get a string like "2012-04-10 16:27:19 +0200"
+ TIME="$(git log -n 1 --format="%ci")"
+fi
+
+if [ -n "$DESC" ]; then
+ NEWINFO="#define BUILD_DESC \"$DESC\""
+else
+ NEWINFO="// No build information available"
+fi
+
+# only update build.h if necessary
+if [ "$INFO" != "$NEWINFO" ]; then
+ echo "$NEWINFO" >"$FILE"
+ echo "#define BUILD_DATE \"$TIME\"" >>"$FILE"
+fi
"(you do not need to remember this password)\n"
"If the file does not exist, create it with owner-readable-only file permissions.\n"),
strWhatAmI.c_str(),
- GetConfigFile().c_str(),
+ GetConfigFile().string().c_str(),
EncodeBase58(&rand_pwd[0],&rand_pwd[0]+32).c_str()),
_("Error"), wxOK | wxMODAL);
QueueShutdown();
asio::io_service io_service;
ip::tcp::endpoint endpoint(bindAddress, GetArg("-rpcport", 8332));
- ip::tcp::acceptor acceptor(io_service, endpoint);
-
- acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
+ ip::tcp::acceptor acceptor(io_service);
+ try
+ {
+ acceptor.open(endpoint.protocol());
+ acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
+ acceptor.bind(endpoint);
+ acceptor.listen(socket_base::max_connections);
+ }
+ catch(boost::system::system_error &e)
+ {
+ ThreadSafeMessageBox(strprintf(_("An error occured while setting up the RPC port %i for listening: %s"), endpoint.port(), e.what()),
+ _("Error"), wxOK | wxMODAL);
+ QueueShutdown();
+ return;
+ }
ssl::context context(io_service, ssl::context::sslv23);
if (fUseSSL)
filesystem::path pathCertFile(GetArg("-rpcsslcertificatechainfile", "server.cert"));
if (!pathCertFile.is_complete()) pathCertFile = filesystem::path(GetDataDir()) / pathCertFile;
- pathCertFile.make_preferred();
- if (filesystem::exists(pathCertFile)) context.use_certificate_chain_file(pathCertFile.string().c_str());
+ if (filesystem::exists(pathCertFile)) context.use_certificate_chain_file(pathCertFile.string());
else printf("ThreadRPCServer ERROR: missing server certificate file %s\n", pathCertFile.string().c_str());
filesystem::path pathPKFile(GetArg("-rpcsslprivatekeyfile", "server.pem"));
if (!pathPKFile.is_complete()) pathPKFile = filesystem::path(GetDataDir()) / pathPKFile;
- pathPKFile.make_preferred();
- if (filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string().c_str(), ssl::context::pem);
+ if (filesystem::exists(pathPKFile)) context.use_private_key_file(pathPKFile.string(), ssl::context::pem);
else printf("ThreadRPCServer ERROR: missing server private key file %s\n", pathPKFile.string().c_str());
string strCiphers = GetArg("-rpcsslciphers", "TLSv1+HIGH:!SSLv2:!aNULL:!eNULL:!AH:!3DES:@STRENGTH");
throw runtime_error(strprintf(
_("You must set rpcpassword=<password> in the configuration file:\n%s\n"
"If the file does not exist, create it with owner-readable-only file permissions."),
- GetConfigFile().c_str()));
+ GetConfigFile().string().c_str()));
// Connect to localhost
bool fUseSSL = GetBoolArg("-rpcssl");
{
printf("EnvShutdown exception: %s (%d)\n", e.what(), e.get_errno());
}
- DbEnv(0).remove(GetDataDir().c_str(), 0);
+ DbEnv(0).remove(GetDataDir().string().c_str(), 0);
}
class CDBInit
instance_of_cdbinit;
-CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
+CDB::CDB(const char *pszFile, const char* pszMode) : pdb(NULL)
{
int ret;
if (pszFile == NULL)
{
if (fShutdown)
return;
- string strDataDir = GetDataDir();
- filesystem::path pathLogDir(strDataDir + "/database");
- pathLogDir.make_preferred();
+ filesystem::path pathDataDir = GetDataDir();
+ filesystem::path pathLogDir = pathDataDir / "database";
filesystem::create_directory(pathLogDir);
- filesystem::path pathErrorFile(strDataDir + "/db.log");
- pathErrorFile.make_preferred();
+ filesystem::path pathErrorFile = pathDataDir / "db.log";
printf("dbenv.open LogDir=%s ErrorFile=%s\n", pathLogDir.string().c_str(), pathErrorFile.string().c_str());
int nDbCache = GetArg("-dbcache", 25);
dbenv.set_errfile(fopen(pathErrorFile.string().c_str(), "a")); /// debug
dbenv.set_flags(DB_AUTO_COMMIT, 1);
dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1);
- ret = dbenv.open(strDataDir.c_str(),
+ ret = dbenv.open(pathDataDir.string().c_str(),
DB_CREATE |
DB_INIT_LOCK |
DB_INIT_LOG |
return DB_NEED_REWRITE;
if (nFileVersion < CLIENT_VERSION) // Update
- {
- // Get rid of old debug.log file in current directory
- if (nFileVersion <= 105 && !pszSetDataDir[0])
- unlink("debug.log");
-
WriteVersion(CLIENT_VERSION);
- }
return DB_LOAD_OK;
}
mapFileUseCount.erase(wallet.strWalletFile);
// Copy wallet.dat
- filesystem::path pathSrc(GetDataDir() + "/" + wallet.strWalletFile);
- pathSrc.make_preferred();
+ filesystem::path pathSrc = GetDataDir() / wallet.strWalletFile;
filesystem::path pathDest(strDest);
- pathDest.make_preferred();
if (filesystem::is_directory(pathDest))
- pathDest = pathDest / wallet.strWalletFile;
+ pathDest /= wallet.strWalletFile;
try {
#if BOOST_VERSION >= 104000
}
#endif
- if (!fDebug && !pszSetDataDir[0])
+ if (!fDebug)
ShrinkDebugFile();
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- printf("Bitcoin version %s\n", FormatFullVersion().c_str());
- printf("Default data directory %s\n", GetDefaultDataDir().c_str());
+ printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
+ printf("Default data directory %s\n", GetDefaultDataDir().string().c_str());
if (GetBoolArg("-loadblockindextest"))
{
}
// Make sure only a single bitcoin process is using the data directory.
- string strLockFile = GetDataDir() + "/.lock";
- FILE* file = fopen(strLockFile.c_str(), "a"); // empty lock file; created if it doesn't exist.
+ boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
+ FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
if (file) fclose(file);
- static boost::interprocess::file_lock lock(strLockFile.c_str());
+ static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
if (!lock.try_lock())
{
- ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().c_str()), _("Bitcoin"), wxOK|wxMODAL);
+ ThreadSafeMessageBox(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin is probably already running."), GetDataDir().string().c_str()), _("Bitcoin"), wxOK|wxMODAL);
return false;
}
}
#ifdef WIN32
-string StartupShortcutPath()
+boost::filesystem::path StartupShortcutPath()
{
- return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";
+ return MyGetSpecialFolderPath(CSIDL_STARTUP, true) / "Bitcoin.lnk";
}
bool GetStartOnSystemStartup()
{
- return filesystem::exists(StartupShortcutPath().c_str());
+ return filesystem::exists(StartupShortcutPath());
}
bool SetStartOnSystemStartup(bool fAutoStart)
{
// If the shortcut exists already, remove it for updating
- remove(StartupShortcutPath().c_str());
+ boost::filesystem::remove(StartupShortcutPath());
if (fAutoStart)
{
{
WCHAR pwsz[MAX_PATH];
// Ensure that the string is ANSI.
- MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);
+ MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().string().c_str(), -1, pwsz, MAX_PATH);
// Save the link by calling IPersistFile::Save.
hres = ppf->Save(pwsz, TRUE);
ppf->Release();
namespace fs = boost::filesystem;
char* pszConfigHome = getenv("XDG_CONFIG_HOME");
- if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");
+ if (pszConfigHome) return fs::path(pszConfigHome) / "autostart";
char* pszHome = getenv("HOME");
- if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");
+ if (pszHome) return fs::path(pszHome) / ".config" / "autostart";
return fs::path();
}
boost::filesystem::path GetAutostartFilePath()
{
- return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");
+ return GetAutostartDir() / "bitcoin.desktop";
}
bool GetStartOnSystemStartup()
bool SetStartOnSystemStartup(bool fAutoStart)
{
if (!fAutoStart)
- {
-#if defined(BOOST_FILESYSTEM_VERSION) && BOOST_FILESYSTEM_VERSION >= 3
- unlink(GetAutostartFilePath().string().c_str());
-#else
- unlink(GetAutostartFilePath().native_file_string().c_str());
-#endif
- }
+ boost::filesystem::remove(GetAutostartFilePath());
else
{
char pszExePath[MAX_PATH+1];
// Global state
//
-// Name of client reported in the 'version' message. Report the same name
-// for both bitcoind and bitcoin-qt, to make it harder for attackers to
-// target servers or GUI users specifically.
-const std::string CLIENT_NAME("Satoshi");
-
CCriticalSection cs_setpwalletRegistered;
set<CWallet*> setpwalletRegistered;
{
if (nFile == -1)
return NULL;
- FILE* file = fopen(strprintf("%s/blk%04d.dat", GetDataDir().c_str(), nFile).c_str(), pszMode);
+ FILE* file = fopen((GetDataDir() / strprintf("blk%04d.dat", nFile)).string().c_str(), pszMode);
if (!file)
return NULL;
if (nBlockPos != 0 && !strchr(pszMode, 'a') && !strchr(pszMode, 'w'))
#include "key.h"
#include "script.h"
#include "db.h"
+#include "version.h"
#ifdef WIN32
#include <io.h> /* for _commit */
class CRequestTracker;
class CNode;
-static const int CLIENT_VERSION = 60099;
-static const bool VERSION_IS_BETA = true;
-extern const std::string CLIENT_NAME;
-
static const unsigned int MAX_BLOCK_SIZE = 1000000;
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
-I"$(DEPSDIR)/boost_1_47_0" \
-I"$(DEPSDIR)/db-4.8.30.NC/build_unix" \
-I"$(DEPSDIR)/openssl-1.0.0e/include" \
- -I"$(DEPSDIR)"
+ -I"$(DEPSDIR)" \
+ -I"$(CURDIR)"/obj \
LIBPATHS= \
-L"$(DEPSDIR)/boost_1_47_0/stage/lib" \
HEADERS = $(wildcard *.h)
OBJS= \
+ obj/version.o \
obj/checkpoints.o \
obj/netbase.o \
obj/addrman.o \
all: bitcoind.exe
+obj/build.h: FORCE
+ ../share/genbuild.sh obj/build.h
+version.cpp: obj/build.h
+DEFS += -DHAVE_BUILD_INFO
+
obj/%.o: %.cpp $(HEADERS)
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
-rm -f headers.h.gch
-rm -f bitcoind.exe
-rm -f test_bitcoin.exe
+ -rm -f src/build.h
+
+FORCE:
HEADERS = $(wildcard *.h)
OBJS= \
+ obj/version.o \
obj/checkpoints.o \
obj/netbase.o \
obj/addrman.o \
-del /Q obj\test\*
-del /Q test\*.o
-del /Q headers.h.gch
+ -del /Q build.h
INCLUDEPATHS= \
-I"$(CURDIR)" \
+ -I"$(CURDIR)"/obj \
-I"$(DEPSDIR)/include" \
-I"$(DEPSDIR)/include/db48"
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
OBJS= \
+ obj/version.o \
obj/checkpoints.o \
obj/netbase.o \
obj/addrman.o \
-include obj/*.P
-include obj-test/*.P
+obj/build.h: FORCE
+ ../share/genbuild.sh obj/build.h
+version.cpp: obj/build.h
+DEFS += -DHAVE_BUILD_INFO
+
obj/%.o: %.cpp
$(CXX) -c $(CFLAGS) -MMD -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
-rm -f obj-test/*.o
-rm -f obj/*.P
-rm -f obj-test/*.P
+ -rm -f src/build.h
+
+FORCE:
DEFS=-DNOPCH
-DEFS += $(addprefix -I,$(CURDIR) $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
+DEFS += $(addprefix -I,$(CURDIR) $(CURDIR)/obj $(BOOST_INCLUDE_PATH) $(BDB_INCLUDE_PATH) $(OPENSSL_INCLUDE_PATH))
LIBS = $(addprefix -L,$(BOOST_LIB_PATH) $(BDB_LIB_PATH) $(OPENSSL_LIB_PATH))
LMODE = dynamic
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
OBJS= \
+ obj/version.o \
obj/checkpoints.o \
obj/netbase.o \
obj/addrman.o \
-include obj/*.P
-include obj-test/*.P
+obj/build.h: FORCE
+ ../share/genbuild.sh obj/build.h
+version.cpp: obj/build.h
+DEFS += -DHAVE_BUILD_INFO
+
obj/%.o: %.cpp
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
-rm -f obj-test/*.o
-rm -f obj/*.P
-rm -f obj-test/*.P
+ -rm -f src/build.h
+
+FORCE:
#include "ui_aboutdialog.h"
#include "clientmodel.h"
+#include "version.h"
+
AboutDialog::AboutDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AboutDialog)
{
return QString::fromStdString(FormatFullVersion());
}
+
+QString ClientModel::formatBuildDate() const
+{
+ return QString::fromStdString(CLIENT_DATE);
+}
QString getStatusBarWarnings() const;
QString formatFullVersion() const;
+ QString formatBuildDate() const;
private:
OptionsModel *optionsModel;
bool fDebug = false;
bool fPrintToConsole = false;
bool fPrintToDebugger = false;
-char pszSetDataDir[MAX_PATH] = "";
bool fRequestShutdown = false;
bool fShutdown = false;
bool fDaemon = false;
if (!fileout)
{
- char pszFile[MAX_PATH+100];
- GetDataDir(pszFile);
- strlcat(pszFile, "/debug.log", sizeof(pszFile));
- fileout = fopen(pszFile, "a");
+ boost::filesystem::path pathDebug = GetDataDir() / "debug.log";
+ fileout = fopen(pathDebug.string().c_str(), "a");
if (fileout) setbuf(fileout, NULL); // unbuffered
}
if (fileout)
}
#ifdef WIN32
-string MyGetSpecialFolderPath(int nFolder, bool fCreate)
+boost::filesystem::path MyGetSpecialFolderPath(int nFolder, bool fCreate)
{
+ namespace fs = boost::filesystem;
+
char pszPath[MAX_PATH] = "";
if(SHGetSpecialFolderPathA(NULL, pszPath, nFolder, fCreate))
{
- return pszPath;
+ return fs::path(pszPath);
}
else if (nFolder == CSIDL_STARTUP)
{
- return string(getenv("USERPROFILE")) + "\\Start Menu\\Programs\\Startup";
+ return fs::path(getenv("USERPROFILE")) / "Start Menu" / "Programs" / "Startup";
}
else if (nFolder == CSIDL_APPDATA)
{
- return getenv("APPDATA");
+ return fs::path(getenv("APPDATA"));
}
- return "";
+ return fs::path("");
}
#endif
-string GetDefaultDataDir()
+boost::filesystem::path GetDefaultDataDir()
{
+ namespace fs = boost::filesystem;
+
// Windows: C:\Documents and Settings\username\Application Data\Bitcoin
// Mac: ~/Library/Application Support/Bitcoin
// Unix: ~/.bitcoin
#ifdef WIN32
// Windows
- return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
+ return MyGetSpecialFolderPath(CSIDL_APPDATA, true) / "Bitcoin";
#else
+ fs::path pathRet;
char* pszHome = getenv("HOME");
if (pszHome == NULL || strlen(pszHome) == 0)
- pszHome = (char*)"/";
- string strHome = pszHome;
- if (strHome[strHome.size()-1] != '/')
- strHome += '/';
+ pathRet = fs::path("/");
+ else
+ pathRet = fs::path(pszHome);
#ifdef MAC_OSX
// Mac
- strHome += "Library/Application Support/";
- filesystem::create_directory(strHome.c_str());
- return strHome + "Bitcoin";
+ pathRet /= "Library" / "Application Support";
+ filesystem::create_directory(pathRet);
+ return pathRet / "Bitcoin";
#else
// Unix
- return strHome + ".bitcoin";
+ return pathRet / ".bitcoin";
#endif
#endif
}
-void GetDataDir(char* pszDir)
+const boost::filesystem::path &GetDataDir(bool fNetSpecific)
{
- // pszDir must be at least MAX_PATH length.
- int nVariation;
- if (pszSetDataDir[0] != 0)
- {
- strlcpy(pszDir, pszSetDataDir, MAX_PATH);
- nVariation = 0;
- }
- else
- {
- // This can be called during exceptions by printf, so we cache the
- // value so we don't have to do memory allocations after that.
- static char pszCachedDir[MAX_PATH];
- if (pszCachedDir[0] == 0)
- strlcpy(pszCachedDir, GetDefaultDataDir().c_str(), sizeof(pszCachedDir));
- strlcpy(pszDir, pszCachedDir, MAX_PATH);
- nVariation = 1;
- }
- if (fTestNet)
- {
- char* p = pszDir + strlen(pszDir);
- if (p > pszDir && p[-1] != '/' && p[-1] != '\\')
- *p++ = '/';
- strcpy(p, "testnet");
- nVariation += 2;
- }
- static bool pfMkdir[4];
- if (!pfMkdir[nVariation])
- {
- pfMkdir[nVariation] = true;
- boost::filesystem::create_directory(pszDir);
+ namespace fs = boost::filesystem;
+
+ static fs::path pathCached[2];
+ static CCriticalSection csPathCached;
+ static bool cachedPath[2] = {false, false};
+
+ fs::path &path = pathCached[fNetSpecific];
+
+ // This can be called during exceptions by printf, so we cache the
+ // value so we don't have to do memory allocations after that.
+ if (cachedPath[fNetSpecific])
+ return path;
+
+ LOCK(csPathCached);
+
+ if (mapArgs.count("-datadir")) {
+ path = mapArgs["-datadir"];
+ } else {
+ path = GetDefaultDataDir();
+ if (fNetSpecific && GetBoolArg("-testnet", false))
+ path /= "testnet";
}
-}
-string GetDataDir()
-{
- char pszDir[MAX_PATH];
- GetDataDir(pszDir);
- return pszDir;
+ fs::create_directory(path);
+
+ cachedPath[fNetSpecific]=true;
+ return path;
}
-string GetConfigFile()
+boost::filesystem::path GetConfigFile()
{
namespace fs = boost::filesystem;
fs::path pathConfigFile(GetArg("-conf", "bitcoin.conf"));
- if (!pathConfigFile.is_complete()) pathConfigFile = fs::path(GetDataDir()) / pathConfigFile;
- pathConfigFile.make_preferred();
- return pathConfigFile.string();
+ if (!pathConfigFile.is_complete()) pathConfigFile = GetDataDir(false) / pathConfigFile;
+ return pathConfigFile;
}
bool ReadConfigFile(map<string, string>& mapSettingsRet,
namespace fs = boost::filesystem;
namespace pod = boost::program_options::detail;
- if (mapSettingsRet.count("-datadir"))
- {
- if (fs::is_directory(fs::system_complete(mapSettingsRet["-datadir"])))
- {
- fs::path pathDataDir(fs::system_complete(mapSettingsRet["-datadir"]));
- pathDataDir.make_preferred();
-
- strlcpy(pszSetDataDir, pathDataDir.string().c_str(), sizeof(pszSetDataDir));
- }
- else
- {
- return false;
- }
- }
-
fs::ifstream streamConfig(GetConfigFile());
if (!streamConfig.good())
return true; // No bitcoin.conf file is OK
set<string> setOptions;
setOptions.insert("*");
-
+
for (pod::config_file_iterator it(streamConfig, setOptions), end; it != end; ++it)
{
// Don't overwrite existing settings so command line settings override bitcoin.conf
return true;
}
-string GetPidFile()
+boost::filesystem::path GetPidFile()
{
namespace fs = boost::filesystem;
fs::path pathPidFile(GetArg("-pid", "bitcoind.pid"));
- if (!pathPidFile.is_complete()) pathPidFile = fs::path(GetDataDir()) / pathPidFile;
- pathPidFile.make_preferred();
- return pathPidFile.string();
+ if (!pathPidFile.is_complete()) pathPidFile = GetDataDir() / pathPidFile;
+ return pathPidFile;
}
-void CreatePidFile(string pidFile, pid_t pid)
+void CreatePidFile(const boost::filesystem::path &path, pid_t pid)
{
- FILE* file = fopen(pidFile.c_str(), "w");
+ FILE* file = fopen(path.string().c_str(), "w");
if (file)
{
fprintf(file, "%d\n", pid);
void ShrinkDebugFile()
{
// Scroll debug.log if it's getting too big
- string strFile = GetDataDir() + "/debug.log";
- FILE* file = fopen(strFile.c_str(), "r");
+ boost::filesystem::path pathLog = GetDataDir() / "debug.log";
+ FILE* file = fopen(pathLog.string().c_str(), "r");
if (file && GetFilesize(file) > 10 * 1000000)
{
// Restart the file with some of the end
int nBytes = fread(pch, 1, sizeof(pch), file);
fclose(file);
- file = fopen(strFile.c_str(), "w");
+ file = fopen(pathLog.string().c_str(), "w");
if (file)
{
fwrite(pch, 1, nBytes, file);
string FormatFullVersion()
{
- string s = FormatVersion(CLIENT_VERSION);
- if (VERSION_IS_BETA) {
- s += "-";
- s += _("beta");
- }
- return s;
+ return CLIENT_BUILD;
}
// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014)
#include <string>
#include <boost/thread.hpp>
+#include <boost/filesystem.hpp>
+#include <boost/filesystem/path.hpp>
#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
#include <boost/interprocess/sync/scoped_lock.hpp>
#include <boost/interprocess/sync/interprocess_condition.hpp>
extern bool fDebug;
extern bool fPrintToConsole;
extern bool fPrintToDebugger;
-extern char pszSetDataDir[MAX_PATH];
extern bool fRequestShutdown;
extern bool fShutdown;
extern bool fDaemon;
bool WildcardMatch(const char* psz, const char* mask);
bool WildcardMatch(const std::string& str, const std::string& mask);
int GetFilesize(FILE* file);
-void GetDataDir(char* pszDirRet);
-std::string GetConfigFile();
-std::string GetPidFile();
-void CreatePidFile(std::string pidFile, pid_t pid);
+boost::filesystem::path GetDefaultDataDir();
+const boost::filesystem::path &GetDataDir(bool fNetSpecific = true);
+boost::filesystem::path GetConfigFile();
+boost::filesystem::path GetPidFile();
+void CreatePidFile(const boost::filesystem::path &path, pid_t pid);
bool ReadConfigFile(std::map<std::string, std::string>& mapSettingsRet, std::map<std::string, std::vector<std::string> >& mapMultiSettingsRet);
#ifdef WIN32
-std::string MyGetSpecialFolderPath(int nFolder, bool fCreate);
+boost::filesystem::path MyGetSpecialFolderPath(int nFolder, bool fCreate);
#endif
-std::string GetDefaultDataDir();
-std::string GetDataDir();
void ShrinkDebugFile();
int GetRandInt(int nMax);
uint64 GetRand(uint64 nMax);
--- /dev/null
+// Copyright (c) 2012 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file license.txt or http://www.opensource.org/licenses/mit-license.php.
+#include <string>
+
+#include "version.h"
+
+// Name of client reported in the 'version' message. Report the same name
+// for both bitcoind and bitcoin-qt, to make it harder for attackers to
+// target servers or GUI users specifically.
+const std::string CLIENT_NAME("Satoshi");
+
+// Client version number
+#define CLIENT_VERSION_MAJOR 0
+#define CLIENT_VERSION_MINOR 6
+#define CLIENT_VERSION_REVISION 0
+#define CLIENT_VERSION_BUILD 99
+#define CLIENT_VERSION_SUFFIX "-beta"
+
+const int CLIENT_VERSION = 1000000 * CLIENT_VERSION_MAJOR
+ + 10000 * CLIENT_VERSION_MINOR
+ + 100 * CLIENT_VERSION_REVISION
+ + 1 * CLIENT_VERSION_BUILD;
+
+
+
+// The following part of the code determines the CLIENT_BUILD variable.
+// Several mechanisms are used for this:
+// * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
+// generated by the build environment, possibly containing the output
+// of git-describe in a macro called BUILD_DESC
+// * secondly, if this is an exported version of the code, GIT_ARCHIVE will
+// be defined (automatically using the export-subst git attribute), and
+// GIT_COMMIT will contain the commit id.
+// * then, three options exist for determining CLIENT_BUILD:
+// * if BUILD_DESC is defined, use that literally (output of git-describe)
+// * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
+// * otherwise, use v[maj].[min].[rev].[build]-unk
+// finally CLIENT_VERSION_SUFFIX is added
+
+// First, include build.h if requested
+#ifdef HAVE_BUILD_INFO
+# include "build.h"
+#endif
+
+// git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
+#ifdef GIT_ARCHIVE
+# define GIT_COMMIT_ID "$Format:%h$"
+# define GIT_COMMIT_DATE "$Format:%cD"
+#endif
+
+#define STRINGIFY(s) #s
+
+#define BUILD_DESC_FROM_COMMIT(maj,min,rev,build,commit) \
+ "v" STRINGIFY(maj) "." STRINGIFY(min) "." STRINGIFY(rev) "." STRINGIFY(build) "-g" commit
+
+#define BUILD_DESC_FROM_UNKNOWN(maj,min,rev,build) \
+ "v" STRINGIFY(maj) "." STRINGIFY(min) "." STRINGIFY(rev) "." STRINGIFY(build) "-unk"
+
+#ifndef BUILD_DESC
+# ifdef GIT_COMMIT_ID
+# define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
+# else
+# define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
+# endif
+#endif
+
+#ifndef BUILD_DATE
+# ifdef GIT_COMMIT_DATE
+# define BUILD_DATE GIT_COMMIT_DATE
+# else
+# define BUILD_DATE __DATE__ ", " __TIME__
+# endif
+#endif
+
+const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
+const std::string CLIENT_DATE(BUILD_DATE);
--- /dev/null
+// Copyright (c) 2012 The Bitcoin developers
+// Distributed under the MIT/X11 software license, see the accompanying
+// file license.txt or http://www.opensource.org/licenses/mit-license.php.
+#ifndef BITCOIN_VERSION_H
+#define BITCOIN_VERSION_H
+
+#include <string>
+
+extern const std::string CLIENT_NAME;
+extern const std::string CLIENT_BUILD;
+extern const std::string CLIENT_DATE;
+extern const int CLIENT_VERSION;
+
+#endif