From 4ac57f013e20da2d0f87fff69625cbd4419089f3 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Sun, 1 Nov 2009 01:16:51 +0000 Subject: move debug.log and db.log to data dir, portable GetDataDir, optimize GetBalance, fix repaint bogdown, -addnode and -? switches git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@25 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- util.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 73 insertions(+), 9 deletions(-) (limited to 'util.cpp') diff --git a/util.cpp b/util.cpp index ef950920fd..23b59f11f7 100644 --- a/util.cpp +++ b/util.cpp @@ -5,9 +5,13 @@ #include "headers.h" +map mapArgs; +map > mapMultiArgs; bool fDebug = false; bool fPrintToDebugger = false; bool fPrintToConsole = false; +char pszSetDataDir[MAX_PATH] = ""; + @@ -68,6 +72,8 @@ void RandAddSeed() void RandAddSeedPerfmon() { +#ifdef __WXMSW__ + // Don't need this on Linux, OpenSSL automatically uses /dev/urandom // This can take up to 2 seconds, so only do it every 10 minutes static int64 nLastPerfmon; if (GetTime() < nLastPerfmon + 10 * 60) @@ -95,6 +101,7 @@ void RandAddSeedPerfmon() strftime(pszTime, sizeof(pszTime), "%x %H:%M:%S", ptmTime); printf("%s RandAddSeed() %d bytes\n", pszTime, nSize); } +#endif } @@ -304,6 +311,32 @@ vector ParseHex(const std::string& str) } +void ParseParameters(int argc, char* argv[]) +{ + mapArgs.clear(); + mapMultiArgs.clear(); + for (int i = 0; i < argc; i++) + { + char psz[10000]; + strlcpy(psz, argv[i], sizeof(psz)); + char* pszValue = ""; + if (strchr(psz, '=')) + { + pszValue = strchr(psz, '='); + *pszValue++ = '\0'; + } + strlwr(psz); + #ifdef __WXMSW__ + if (psz[0] == '/') + psz[0] = '-'; + #endif + mapArgs[psz] = pszValue; + mapMultiArgs[psz].push_back(pszValue); + } +} + + + @@ -346,15 +379,6 @@ void PrintException(std::exception* pex, const char* pszThread) -bool FileExists(const char* psz) -{ -#ifdef WIN32 - return GetFileAttributes(psz) != -1; -#else - return access(psz, 0) != -1; -#endif -} - int GetFilesize(FILE* file) { int nSavePos = ftell(file); @@ -365,6 +389,46 @@ int GetFilesize(FILE* file) return nFilesize; } +void GetDataDir(char* pszDir) +{ + // pszDir must be at least MAX_PATH length. + if (pszSetDataDir[0] != 0) + { + strlcpy(pszDir, pszSetDataDir, MAX_PATH); + static bool fMkdirDone; + if (!fMkdirDone) + { + fMkdirDone = true; + _mkdir(pszDir); + } + } + 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. + // wxStandardPaths::GetUserDataDir + // Return the directory for the user-dependent application data files: + // Unix: ~/.appname + // Windows: C:\Documents and Settings\username\Application Data\appname + // Mac: ~/Library/Application Support/appname + static char pszCachedDir[MAX_PATH]; + if (pszCachedDir[0] == 0) + { + strlcpy(pszCachedDir, wxStandardPaths::Get().GetUserDataDir().c_str(), sizeof(pszCachedDir)); + _mkdir(pszCachedDir); + } + strlcpy(pszDir, pszCachedDir, MAX_PATH); + } + +} + +string GetDataDir() +{ + char pszDir[MAX_PATH]; + GetDataDir(pszDir); + return pszDir; +} + -- cgit v1.2.3