bitcoind now compiles without wxWidgets or wxBase
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Mon, 26 Jul 2010 17:15:18 +0000 (17:15 +0000)
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
Mon, 26 Jul 2010 17:15:18 +0000 (17:15 +0000)
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@112 1a98c847-1fd6-4fd8-948a-caf3550aa51b

18 files changed:
build-unix.txt
db.cpp
headers.h
init.cpp
init.h
main.cpp
makefile.mingw
makefile.osx
makefile.unix
makefile.vc
net.cpp
noui.h [new file with mode: 0644]
rpc.cpp
serialize.h
ui.cpp
ui.h
util.cpp
util.h

index 30a4a36..fad502a 100644 (file)
@@ -18,11 +18,8 @@ sudo apt-get install libdb4.7-dev
 sudo apt-get install libdb4.7++-dev\r
 sudo apt-get install libboost-all-dev\r
 \r
-We're now using wxWidgets 2.9, which uses UTF-8.\r
-\r
-There isn't currently a debian package of wxWidgets we can use.  The 2.8\r
-packages for Karmic are UTF-16 unicode and won't work for us, and we've had\r
-trouble building 2.8 on 64-bit.\r
+We're now using wxWidgets 2.9, which uses UTF-8.  Don't try to use 2.8, it\r
+won't work.\r
 \r
 You need to download wxWidgets from http://www.wxwidgets.org/downloads/\r
 and build it yourself.  See the build instructions and configure parameters\r
@@ -63,15 +60,6 @@ make
 sudo su\r
 make install\r
 ldconfig\r
-su <username>\r
-cd ..\r
-mkdir buildbase\r
-cd buildbase\r
-../configure --disable-gui --enable-debug --disable-shared --enable-monolithic\r
-make\r
-sudo su\r
-make install\r
-ldconfig\r
 \r
 \r
 Boost\r
diff --git a/db.cpp b/db.cpp
index ea0b581..5096566 100644 (file)
--- a/db.cpp
+++ b/db.cpp
@@ -60,7 +60,7 @@ CDB::CDB(const char* pszFile, const char* pszMode) : pdb(NULL)
                 return;\r
             string strDataDir = GetDataDir();\r
             string strLogDir = strDataDir + "/database";\r
-            _mkdir(strLogDir.c_str());\r
+            filesystem::create_directory(strLogDir.c_str());\r
             string strErrorFile = strDataDir + "/db.log";\r
             printf("dbenv.open strLogDir=%s strErrorFile=%s\n", strLogDir.c_str(), strErrorFile.c_str());\r
 \r
index f920fd3..a0b4c5e 100644 (file)
--- a/headers.h
+++ b/headers.h
 #define _WIN32_IE 0x0400\r
 #define WIN32_LEAN_AND_MEAN 1\r
 #define __STDC_LIMIT_MACROS // to enable UINT64_MAX from stdint.h\r
+#ifdef GUI\r
 #include <wx/wx.h>\r
 #include <wx/stdpaths.h>\r
 #include <wx/snglinst.h>\r
-#if wxUSE_GUI\r
 #include <wx/utils.h>\r
 #include <wx/clipbrd.h>\r
 #include <wx/taskbar.h>\r
+#else\r
+#ifdef __WXMAC_OSX__\r
+#define __WXMAC__ 1\r
+#define __WXOSX__ 1\r
+#define __BSD__ 1\r
+#endif\r
 #endif\r
 #include <openssl/buffer.h>\r
 #include <openssl/ecdsa.h>\r
@@ -61,6 +67,7 @@
 #include <boost/filesystem.hpp>\r
 #include <boost/filesystem/fstream.hpp>\r
 #include <boost/algorithm/string.hpp>\r
+#include <boost/thread.hpp>\r
 #include <boost/interprocess/sync/interprocess_mutex.hpp>\r
 #include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>\r
 #include <boost/date_time/gregorian/gregorian_types.hpp>\r
 #include <sys/time.h>\r
 #include <sys/resource.h>\r
 #include <sys/socket.h>\r
+#include <sys/stat.h>\r
 #include <arpa/inet.h>\r
 #include <netdb.h>\r
 #include <unistd.h>\r
 #include <errno.h>\r
 #include <net/if.h>\r
 #include <ifaddrs.h>\r
+#include <fcntl.h>\r
 #endif\r
 #ifdef __BSD__\r
 #include <netinet/in.h>\r
@@ -111,10 +120,12 @@ using namespace boost;
 #include "irc.h"\r
 #include "main.h"\r
 #include "rpc.h"\r
-#if wxUSE_GUI\r
+#ifdef GUI\r
 #include "uibase.h"\r
-#endif\r
 #include "ui.h"\r
+#else\r
+#include "noui.h"\r
+#endif\r
 #include "init.h"\r
 \r
 #include "xpm/addressbook16.xpm"\r
index d6d4562..b8df26c 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -7,6 +7,15 @@
 \r
 \r
 \r
+\r
+\r
+\r
+\r
+//////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Shutdown\r
+//\r
+\r
 void ExitTimeout(void* parg)\r
 {\r
 #ifdef __WXMSW__\r
@@ -55,273 +64,59 @@ void Shutdown(void* parg)
 \r
 //////////////////////////////////////////////////////////////////////////////\r
 //\r
-// Startup folder\r
-//\r
-\r
-#ifdef __WXMSW__\r
-string StartupShortcutPath()\r
-{\r
-    return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";\r
-}\r
-\r
-bool GetStartOnSystemStartup()\r
-{\r
-    return filesystem::exists(StartupShortcutPath().c_str());\r
-}\r
-\r
-void SetStartOnSystemStartup(bool fAutoStart)\r
-{\r
-    // If the shortcut exists already, remove it for updating\r
-    remove(StartupShortcutPath().c_str());\r
-\r
-    if (fAutoStart)\r
-    {\r
-        CoInitialize(NULL);\r
-\r
-        // Get a pointer to the IShellLink interface.\r
-        IShellLink* psl = NULL;\r
-        HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,\r
-                                CLSCTX_INPROC_SERVER, IID_IShellLink,\r
-                                reinterpret_cast<void**>(&psl));\r
-\r
-        if (SUCCEEDED(hres))\r
-        {\r
-            // Get the current executable path\r
-            TCHAR pszExePath[MAX_PATH];\r
-            GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));\r
-\r
-            // Set the path to the shortcut target\r
-            psl->SetPath(pszExePath);\r
-            PathRemoveFileSpec(pszExePath);\r
-            psl->SetWorkingDirectory(pszExePath);\r
-            psl->SetShowCmd(SW_SHOWMINNOACTIVE);\r
-\r
-            // Query IShellLink for the IPersistFile interface for\r
-            // saving the shortcut in persistent storage.\r
-            IPersistFile* ppf = NULL;\r
-            hres = psl->QueryInterface(IID_IPersistFile,\r
-                                       reinterpret_cast<void**>(&ppf));\r
-            if (SUCCEEDED(hres))\r
-            {\r
-                WCHAR pwsz[MAX_PATH];\r
-                // Ensure that the string is ANSI.\r
-                MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);\r
-                // Save the link by calling IPersistFile::Save.\r
-                hres = ppf->Save(pwsz, TRUE);\r
-                ppf->Release();\r
-            }\r
-            psl->Release();\r
-        }\r
-        CoUninitialize();\r
-    }\r
-}\r
-\r
-#elif defined(__WXGTK__)\r
-\r
-//\r
-// Follow the Desktop Application Autostart Spec:\r
-//  http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html\r
-//\r
-\r
-boost::filesystem::path GetAutostartDir()\r
-{\r
-    namespace fs = boost::filesystem;\r
-\r
-    char* pszConfigHome = getenv("XDG_CONFIG_HOME");\r
-    if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");\r
-    char* pszHome = getenv("HOME");\r
-    if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");\r
-    return fs::path();\r
-}\r
-\r
-boost::filesystem::path GetAutostartFilePath()\r
-{\r
-    return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");\r
-}\r
-\r
-bool GetStartOnSystemStartup()\r
-{\r
-    boost::filesystem::ifstream optionFile(GetAutostartFilePath());\r
-    if (!optionFile.good())\r
-        return false;\r
-    // Scan through file for "Hidden=true":\r
-    string line;\r
-    while (!optionFile.eof())\r
-    {\r
-        getline(optionFile, line);\r
-        if (line.find("Hidden") != string::npos &&\r
-            line.find("true") != string::npos)\r
-            return false;\r
-    }\r
-    optionFile.close();\r
-\r
-    return true;\r
-}\r
-\r
-void SetStartOnSystemStartup(bool fAutoStart)\r
-{\r
-    if (!fAutoStart)\r
-    {\r
-        unlink(GetAutostartFilePath().native_file_string().c_str());\r
-    }\r
-    else\r
-    {\r
-        boost::filesystem::create_directories(GetAutostartDir());\r
-\r
-        boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);\r
-        if (!optionFile.good())\r
-        {\r
-            wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");\r
-            return;\r
-        }\r
-        // Write a bitcoin.desktop file to the autostart directory:\r
-        char pszExePath[MAX_PATH+1];\r
-        memset(pszExePath, 0, sizeof(pszExePath));\r
-        readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);\r
-        optionFile << "[Desktop Entry]\n";\r
-        optionFile << "Type=Application\n";\r
-        optionFile << "Name=Bitcoin\n";\r
-        optionFile << "Exec=" << pszExePath << "\n";\r
-        optionFile << "Terminal=false\n";\r
-        optionFile << "Hidden=false\n";\r
-        optionFile.close();\r
-    }\r
-}\r
-#else\r
-\r
-// TODO: OSX startup stuff; see:\r
-// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html\r
-\r
-bool GetStartOnSystemStartup() { return false; }\r
-void SetStartOnSystemStartup(bool fAutoStart) { }\r
-\r
-#endif\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-//////////////////////////////////////////////////////////////////////////////\r
-//\r
-// CMyApp\r
+// Start\r
 //\r
 \r
-// Define a new application\r
-class CMyApp : public wxApp\r
-{\r
-public:\r
-    wxLocale m_locale;\r
-\r
-    CMyApp(){};\r
-    ~CMyApp(){};\r
-    bool OnInit();\r
-    bool OnInit2();\r
-    int OnExit();\r
-\r
-    // Hook Initialize so we can start without GUI\r
-    virtual bool Initialize(int& argc, wxChar** argv);\r
-\r
-    // 2nd-level exception handling: we get all the exceptions occurring in any\r
-    // event handler here\r
-    virtual bool OnExceptionInMainLoop();\r
-\r
-    // 3rd, and final, level exception handling: whenever an unhandled\r
-    // exception is caught, this function is called\r
-    virtual void OnUnhandledException();\r
-\r
-    // and now for something different: this function is called in case of a\r
-    // crash (e.g. dereferencing null pointer, division by 0, ...)\r
-    virtual void OnFatalException();\r
-};\r
-\r
-IMPLEMENT_APP(CMyApp)\r
-\r
-bool CMyApp::Initialize(int& argc, wxChar** argv)\r
+#ifndef GUI\r
+int main(int argc, char* argv[])\r
 {\r
     for (int i = 1; i < argc; i++)\r
         if (!IsSwitchChar(argv[i][0]))\r
             fCommandLine = true;\r
-\r
-    if (!fCommandLine)\r
-    {\r
-        if (!fGUI)\r
-        {\r
-            fDaemon = true;\r
-        }\r
-        else\r
-        {\r
-            // wxApp::Initialize will remove environment-specific parameters,\r
-            // so it's too early to call ParseParameters yet\r
-            for (int i = 1; i < argc; i++)\r
-            {\r
-                wxString str = argv[i];\r
-                #ifdef __WXMSW__\r
-                if (str.size() >= 1 && str[0] == '/')\r
-                    str[0] = '-';\r
-                char pszLower[MAX_PATH];\r
-                strlcpy(pszLower, str.c_str(), sizeof(pszLower));\r
-                strlwr(pszLower);\r
-                str = pszLower;\r
-                #endif\r
-                if (str == "-daemon")\r
-                    fDaemon = true;\r
-            }\r
-        }\r
-    }\r
+    fDaemon = !fCommandLine;\r
 \r
 #ifdef __WXGTK__\r
-    if (fDaemon || fCommandLine)\r
+    if (!fCommandLine)\r
     {\r
-        // Call the original Initialize while suppressing error messages\r
-        // and ignoring failure.  If unable to initialize GTK, it fails\r
-        // near the end so hopefully the last few things don't matter.\r
+        // Daemonize\r
+        pid_t pid = fork();\r
+        if (pid < 0)\r
         {\r
-            wxLogNull logNo;\r
-            wxApp::Initialize(argc, argv);\r
+            fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);\r
+            return 1;\r
         }\r
-\r
-        if (fDaemon)\r
-        {\r
-            // Daemonize\r
-            pid_t pid = fork();\r
-            if (pid < 0)\r
-            {\r
-                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);\r
-                return false;\r
-            }\r
-            if (pid > 0)\r
-                pthread_exit((void*)0);\r
-        }\r
-\r
-        return true;\r
+        if (pid > 0)\r
+            pthread_exit((void*)0);\r
     }\r
 #endif\r
 \r
-    return wxApp::Initialize(argc, argv);\r
+    if (!AppInit(argc, argv))\r
+        return 1;\r
+\r
+    while (!fShutdown)\r
+        Sleep(1000000);\r
+    return 0;\r
 }\r
+#endif\r
 \r
-bool CMyApp::OnInit()\r
+bool AppInit(int argc, char* argv[])\r
 {\r
     bool fRet = false;\r
     try\r
     {\r
-        fRet = OnInit2();\r
+        fRet = AppInit2(argc, argv);\r
     }\r
     catch (std::exception& e) {\r
-        PrintException(&e, "OnInit()");\r
+        PrintException(&e, "AppInit()");\r
     } catch (...) {\r
-        PrintException(NULL, "OnInit()");\r
+        PrintException(NULL, "AppInit()");\r
     }\r
     if (!fRet)\r
         Shutdown(NULL);\r
     return fRet;\r
 }\r
 \r
-extern int g_isPainting;\r
-\r
-bool CMyApp::OnInit2()\r
+bool AppInit2(int argc, char* argv[])\r
 {\r
 #ifdef _MSC_VER\r
     // Turn off microsoft heap dump noise\r
@@ -332,46 +127,9 @@ bool CMyApp::OnInit2()
     // Disable confusing "helpful" text message on abort, ctrl-c\r
     _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);\r
 #endif\r
-#if defined(__WXMSW__) && defined(__WXDEBUG__) && wxUSE_GUI\r
-    // Disable malfunctioning wxWidgets debug assertion\r
-    g_isPainting = 10000;\r
-#endif\r
-#if wxUSE_GUI\r
-    wxImage::AddHandler(new wxPNGHandler);\r
-#endif\r
-#if defined(__WXMSW__ ) || defined(__WXMAC__)\r
-    SetAppName("Bitcoin");\r
-#else\r
-    SetAppName("bitcoin");\r
-#endif\r
 #ifndef __WXMSW__\r
     umask(077);\r
 #endif\r
-#ifdef __WXMSW__\r
-#if wxUSE_UNICODE\r
-    // Hack to set wxConvLibc codepage to UTF-8 on Windows,\r
-    // may break if wxMBConv_win32 implementation in strconv.cpp changes.\r
-    class wxMBConv_win32 : public wxMBConv\r
-    {\r
-    public:\r
-        long m_CodePage;\r
-        size_t m_minMBCharWidth;\r
-    };\r
-    if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)\r
-        ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;\r
-#endif\r
-#endif\r
-\r
-    // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file\r
-    m_locale.Init(wxLANGUAGE_DEFAULT, 0);\r
-    m_locale.AddCatalogLookupPathPrefix("locale");\r
-    if (!fWindows)\r
-    {\r
-        m_locale.AddCatalogLookupPathPrefix("/usr/share/locale");\r
-        m_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");\r
-    }\r
-    m_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any\r
-    m_locale.AddCatalog("bitcoin");\r
 \r
     //\r
     // Parameters\r
@@ -385,7 +143,7 @@ bool CMyApp::OnInit2()
 \r
     if (mapArgs.count("-?") || mapArgs.count("--help"))\r
     {\r
-        wxString strUsage = string() +\r
+        string strUsage = string() +\r
           _("Usage:") + "\t\t\t\t\t\t\t\t\t\t\n" +\r
             "  bitcoin [options]                   \t  " + "\n" +\r
             "  bitcoin [options] <command> [params]\t  " + _("Send command to -server or bitcoind\n") +\r
@@ -404,13 +162,13 @@ bool CMyApp::OnInit2()
             "  -daemon         \t  " + _("Run in the background as a daemon and accept commands\n") +\r
             "  -?              \t  " + _("This help message\n");\r
 \r
-#if defined(__WXMSW__) && wxUSE_GUI\r
+#if defined(__WXMSW__) && defined(GUI)\r
         // Tabs make the columns line up in the message box\r
         wxMessageBox(strUsage, "Bitcoin", wxOK);\r
 #else\r
         // Remove tabs\r
-        strUsage.Replace("\t", "");\r
-        fprintf(stderr, "%s", ((string)strUsage).c_str());\r
+        strUsage.erase(std::remove(strUsage.begin(), strUsage.end(), '\t'), strUsage.end());\r
+        fprintf(stderr, "%s", strUsage.c_str());\r
 #endif\r
         return false;\r
     }\r
@@ -430,9 +188,12 @@ bool CMyApp::OnInit2()
     if (!fDebug && !pszSetDataDir[0])\r
         ShrinkDebugFile();\r
     printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");\r
-    printf("Bitcoin version %d.%d.%d%s beta, OS version %s\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer, ((string)wxGetOsDescription()).c_str());\r
-    printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str());\r
-    printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str());\r
+    printf("Bitcoin version %d.%d.%d%s beta\n", VERSION/10000, (VERSION/100)%100, VERSION%100, pszSubVer);\r
+#ifdef GUI\r
+    printf("OS version %s\n", ((string)wxGetOsDescription()).c_str());\r
+    printf("System default language is %d %s\n", g_locale.GetSystemLanguage(), ((string)g_locale.GetSysName()).c_str());\r
+    printf("Language file %s (%s)\n", (string("locale/") + (string)g_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)g_locale.GetLocale()).c_str());\r
+#endif\r
     printf("Default data directory %s\n", GetDefaultDataDir().c_str());\r
 \r
     if (mapArgs.count("-loadblockindextest"))\r
@@ -447,7 +208,7 @@ bool CMyApp::OnInit2()
     // Limit to single instance per user\r
     // Required to protect the database files if we're going to keep deleting log.*\r
     //\r
-#ifdef __WXMSW__\r
+#if defined(__WXMSW__) && defined(GUI)\r
     // todo: wxSingleInstanceChecker wasn't working on Linux, never deleted its lock file\r
     //  maybe should go by whether successfully bind port 8333 instead\r
     wxString strMutexName = wxString("bitcoin_running.") + getenv("HOMEPATH");\r
@@ -605,8 +366,10 @@ bool CMyApp::OnInit2()
     //\r
     // Create the main window and start the node\r
     //\r
+#ifdef GUI\r
     if (!fDaemon)\r
         CreateMainWindow();\r
+#endif\r
 \r
     if (!CheckDiskSpace())\r
         return false;\r
@@ -619,65 +382,10 @@ bool CMyApp::OnInit2()
     if (mapArgs.count("-server") || fDaemon)\r
         CreateThread(ThreadRPCServer, NULL);\r
 \r
+#ifdef GUI\r
     if (fFirstRun)\r
         SetStartOnSystemStartup(true);\r
+#endif\r
 \r
     return true;\r
 }\r
-\r
-int CMyApp::OnExit()\r
-{\r
-    Shutdown(NULL);\r
-    return wxApp::OnExit();\r
-}\r
-\r
-bool CMyApp::OnExceptionInMainLoop()\r
-{\r
-    try\r
-    {\r
-        throw;\r
-    }\r
-    catch (std::exception& e)\r
-    {\r
-        PrintException(&e, "CMyApp::OnExceptionInMainLoop()");\r
-        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());\r
-        Sleep(1000);\r
-        throw;\r
-    }\r
-    catch (...)\r
-    {\r
-        PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");\r
-        wxLogWarning("Unknown exception");\r
-        Sleep(1000);\r
-        throw;\r
-    }\r
-    return true;\r
-}\r
-\r
-void CMyApp::OnUnhandledException()\r
-{\r
-    // this shows how we may let some exception propagate uncaught\r
-    try\r
-    {\r
-        throw;\r
-    }\r
-    catch (std::exception& e)\r
-    {\r
-        PrintException(&e, "CMyApp::OnUnhandledException()");\r
-        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());\r
-        Sleep(1000);\r
-        throw;\r
-    }\r
-    catch (...)\r
-    {\r
-        PrintException(NULL, "CMyApp::OnUnhandledException()");\r
-        wxLogWarning("Unknown exception");\r
-        Sleep(1000);\r
-        throw;\r
-    }\r
-}\r
-\r
-void CMyApp::OnFatalException()\r
-{\r
-    wxMessageBox(_("Program has crashed and will terminate.  "), "Bitcoin", wxOK | wxICON_ERROR);\r
-}\r
diff --git a/init.h b/init.h
index bd5e365..fd1fabd 100644 (file)
--- a/init.h
+++ b/init.h
@@ -3,5 +3,5 @@
 // file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
 \r
 void Shutdown(void* parg);\r
-bool GetStartOnSystemStartup();\r
-void SetStartOnSystemStartup(bool fAutoStart);\r
+bool AppInit(int argc, char* argv[]);\r
+bool AppInit2(int argc, char* argv[]);\r
index afa7add..34ac299 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -83,6 +83,7 @@ bool AddKey(const CKey& key)
 \r
 vector<unsigned char> GenerateNewKey()\r
 {\r
+    RandAddSeedPerfmon();\r
     CKey key;\r
     key.MakeNewKey();\r
     if (!AddKey(key))\r
@@ -1506,7 +1507,7 @@ bool CheckDiskSpace(int64 nAdditionalBytes)
     {\r
         fShutdown = true;\r
         printf("***  %s***\n", _("Warning: Disk space is low  "));\r
-#if wxUSE_GUI\r
+#ifdef GUI\r
         ThreadSafeMessageBox(_("Warning: Disk space is low  "), "Bitcoin", wxOK | wxICON_EXCLAMATION);\r
 #endif\r
         CreateThread(Shutdown, NULL);\r
@@ -2494,7 +2495,7 @@ void GenerateBitcoins(bool fGenerate)
     }\r
     if (fGenerateBitcoins)\r
     {\r
-        int nProcessors = wxThread::GetCPUCount();\r
+        int nProcessors = boost::thread::hardware_concurrency();\r
         printf("%d processors\n", nProcessors);\r
         if (nProcessors < 1)\r
             nProcessors = 1;\r
index 26944df..2cceca5 100644 (file)
@@ -3,8 +3,6 @@
 # file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
 \r
 \r
-# for wxWidgets-2.8.x, search and replace "mswud"->"mswd" and "29u"->"28"\r
-\r
 INCLUDEPATHS= \\r
  -I"/boost" \\r
  -I"/db/build_unix" \\r
@@ -22,32 +20,32 @@ WXLIBS= \
  -l wxmsw29ud_html -l wxmsw29ud_core -l wxmsw29ud_adv -l wxbase29ud -l wxtiffd -l wxjpegd -l wxpngd -l wxzlibd\r
 \r
 LIBS= \\r
- -l libboost_system-mgw34-mt-d -l libboost_filesystem-mgw34-mt-d -l libboost_program_options-mgw34-mt-d \\r
+ -l libboost_system-mgw34-mt-d \\r
+ -l libboost_filesystem-mgw34-mt-d \\r
+ -l libboost_program_options-mgw34-mt-d \\r
+ -l libboost_thread-mgw34-mt-d \\r
  -l db_cxx \\r
  -l eay32 \\r
  -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell32 -l comctl32 -l ole32 -l oleaut32 -l uuid -l rpcrt4 -l advapi32 -l ws2_32 -l shlwapi\r
 \r
-WXDEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH\r
+DEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH\r
 DEBUGFLAGS=-g -D__WXDEBUG__\r
-CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)\r
+CFLAGS=-mthreads -O2 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)\r
 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \\r
-    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h\r
+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h sha.h\r
 \r
 \r
 all: bitcoin.exe\r
 \r
 \r
-headers.h.gch: headers.h $(HEADERS)\r
-       g++ -c $(CFLAGS) -o $@ $<\r
-\r
-obj/%.o: %.cpp $(HEADERS) headers.h.gch\r
-       g++ -c $(CFLAGS) -o $@ $<\r
+obj/%.o: %.cpp $(HEADERS)\r
+       g++ -c $(CFLAGS) -DGUI -o $@ $<\r
 \r
 obj/sha.o: sha.cpp sha.h\r
        g++ -c $(CFLAGS) -O3 -o $@ $<\r
 \r
 obj/ui_res.o: ui.rc  rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp\r
-       windres $(WXDEFS) $(INCLUDEPATHS) -o $@ -i $<\r
+       windres $(DEFS) $(INCLUDEPATHS) -o $@ -i $<\r
 \r
 OBJS= \\r
     obj/util.o \\r
@@ -64,10 +62,10 @@ bitcoin.exe: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o obj/ui_res.o
 \r
 \r
 obj/nogui/%.o: %.cpp $(HEADERS)\r
-       g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/sha.o obj/ui_res.o\r
-       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wxbase29ud $(LIBS)\r
+       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)\r
 \r
 \r
 clean:\r
index 3f5be73..28d14be 100644 (file)
@@ -20,22 +20,23 @@ LIBS= -dead_strip \
  $(DEPSDIR)/lib/libboost_system.a \\r
  $(DEPSDIR)/lib/libboost_filesystem.a \\r
  $(DEPSDIR)/lib/libboost_program_options.a \\r
+ $(DEPSDIR)/lib/libboost_thread.a \\r
  $(DEPSDIR)/lib/libcrypto.a \r
 \r
-WXDEFS=$(shell $(DEPSDIR)/bin/wx-config --cxxflags) -DNOPCH -DMSG_NOSIGNAL=0\r
+DEFS=$(shell $(DEPSDIR)/bin/wx-config --cxxflags) -D__WXMAC_OSX__ -DNOPCH -DMSG_NOSIGNAL=0\r
 \r
 DEBUGFLAGS=-g -DwxDEBUG_LEVEL=0\r
 # ppc doesn't work because we don't support big-endian\r
-CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)\r
+CFLAGS=-mmacosx-version-min=10.5 -arch i386 -arch x86_64 -O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)\r
 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \\r
-    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h\r
+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h sha.h\r
 \r
 \r
 all: bitcoin\r
 \r
 \r
 obj/%.o: %.cpp $(HEADERS)\r
-       g++ -c $(CFLAGS) -o $@ $<\r
+       g++ -c $(CFLAGS) -DGUI -o $@ $<\r
 \r
 obj/sha.o: sha.cpp sha.h\r
        g++ -c $(CFLAGS) -O3 -o $@ $<\r
@@ -55,10 +56,10 @@ bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o
 \r
 \r
 obj/nogui/%.o: %.cpp $(HEADERS)\r
-       g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o\r
-       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)\r
+       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)\r
 \r
 \r
 clean:\r
index cc5111b..0b54962 100644 (file)
@@ -3,7 +3,6 @@
 # file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
 \r
 \r
-\r
 INCLUDEPATHS= \\r
  -I"/usr/include" \\r
  -I"/usr/local/include/wx-2.9" \\r
@@ -21,27 +20,30 @@ WXLIBS= \
 \r
 LIBS= \\r
  -Wl,-Bstatic \\r
-   -l boost_system -l boost_filesystem -l boost_program_options \\r
+   -l boost_system \\r
+   -l boost_filesystem \\r
+   -l boost_program_options \\r
+   -l boost_thread \\r
    -l db_cxx \\r
    -l crypto \\r
  -Wl,-Bdynamic \\r
    -l gthread-2.0\r
 \r
-WXDEFS=-D__WXGTK__ -DNOPCH\r
+DEFS=-D__WXGTK__ -DNOPCH\r
 DEBUGFLAGS=-g -D__WXDEBUG__\r
-CFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)\r
+CFLAGS=-O2 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)\r
 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \\r
-    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h\r
+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h sha.h\r
 \r
 \r
 all: bitcoin\r
 \r
 \r
 headers.h.gch: headers.h $(HEADERS)\r
-       g++ -c $(CFLAGS) -o $@ $<\r
+       g++ -c $(CFLAGS) -DGUI -o $@ $<\r
 \r
 obj/%.o: %.cpp $(HEADERS) headers.h.gch\r
-       g++ -c $(CFLAGS) -o $@ $<\r
+       g++ -c $(CFLAGS) -DGUI -o $@ $<\r
 \r
 obj/sha.o: sha.cpp sha.h\r
        g++ -c $(CFLAGS) -O3 -o $@ $<\r
@@ -61,10 +63,10 @@ bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o
 \r
 \r
 obj/nogui/%.o: %.cpp $(HEADERS)\r
-       g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<\r
+       g++ -c $(CFLAGS) -o $@ $<\r
 \r
 bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o\r
-       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wx_baseud-2.9 $(LIBS)\r
+       g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)\r
 \r
 \r
 clean:\r
index f5452f4..d6fd319 100644 (file)
@@ -3,8 +3,6 @@
 # file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
 \r
 \r
-# for wxWidgets-2.8.x, search and replace "mswud"->"mswd" and "29u"->"28"\r
-\r
 INCLUDEPATHS= \\r
   /I"/boost" \\r
   /I"/db/build_windows" \\r
@@ -18,25 +16,29 @@ LIBPATHS= \
   /LIBPATH:"/openssl/out" \\r
   /LIBPATH:"/wxwidgets/lib/vc_lib"\r
 \r
+WXLIBS=wxmsw29ud_html.lib wxmsw29ud_core.lib wxmsw29ud_adv.lib wxbase29ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib\r
+\r
 LIBS= \\r
-  libboost_system-vc80-mt-gd.lib libboost_filesystem-vc80-mt-gd.lib libboost_program_options-vc80-mt-gd.lib \\r
+  libboost_system-vc80-mt-gd.lib \\r
+  libboost_filesystem-vc80-mt-gd.lib \\r
+  libboost_program_options-vc80-mt-gd.lib \\r
+  libboost_thread-vc80-mt-gd.lib \\r
   libdb47sd.lib \\r
   libeay32.lib \\r
-  wxmsw29ud_html.lib wxmsw29ud_core.lib wxmsw29ud_adv.lib wxbase29ud.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib \\r
   kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib ws2_32.lib shlwapi.lib\r
 \r
-WXDEFS=/DWIN32 /D__WXMSW__ /D_WINDOWS /DNOPCH\r
+DEFS=/DWIN32 /D__WXMSW__ /D_WINDOWS /DNOPCH\r
 DEBUGFLAGS=/Zi /Od /D__WXDEBUG__\r
-CFLAGS=/c /nologo /Ob0 /MDd /EHsc /GR /Zm300 $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)\r
+CFLAGS=/c /nologo /MDd /EHsc /GR /Zm300 $(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)\r
 HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \\r
-    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h\r
+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h noui.h init.h sha.h\r
 \r
 \r
 all: bitcoin.exe\r
 \r
 \r
 .cpp{obj}.obj:\r
-    cl $(CFLAGS) /Fo$@ %s\r
+       cl $(CFLAGS) /DGUI /Fo$@ %s\r
 \r
 obj\util.obj: $(HEADERS)\r
 \r
@@ -59,10 +61,10 @@ obj\ui.obj: $(HEADERS)
 obj\uibase.obj: $(HEADERS)\r
 \r
 obj\sha.obj: sha.cpp sha.h\r
-    cl $(CFLAGS) /O2 /Fo$@ %s\r
+       cl $(CFLAGS) /O2 /Fo$@ %s\r
 \r
 obj\ui.res: ui.rc  rc/bitcoin.ico rc/check.ico rc/send16.bmp rc/send16mask.bmp rc/send16masknoshadow.bmp rc/send20.bmp rc/send20mask.bmp rc/addressbook16.bmp rc/addressbook16mask.bmp rc/addressbook20.bmp rc/addressbook20mask.bmp\r
-    rc $(INCLUDEPATHS) $(WXDEFS) /Fo$@ %s\r
+       rc $(INCLUDEPATHS) $(DEFS) /Fo$@ %s\r
 \r
 OBJS= \\r
     obj\util.obj \\r
@@ -75,11 +77,11 @@ OBJS= \
     obj\init.obj\r
 \r
 bitcoin.exe: $(OBJS) obj\ui.obj obj\uibase.obj obj\sha.obj obj\ui.res\r
-    link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(LIBS)\r
+    link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(WXLIBS) $(LIBS)\r
 \r
 \r
 .cpp{obj\nogui}.obj:\r
-    cl $(CFLAGS) /DwxUSE_GUI=0 /Fo$@ %s\r
+       cl $(CFLAGS) /Fo$@ %s\r
 \r
 obj\nogui\util.obj: $(HEADERS)\r
 \r
@@ -98,10 +100,10 @@ obj\nogui\rpc.obj: $(HEADERS)
 obj\nogui\init.obj: $(HEADERS)\r
 \r
 bitcoind.exe: $(OBJS:obj\=obj\nogui\) obj\sha.obj obj\ui.res\r
-    link /nologo /DEBUG /OUT:$@ $(LIBPATHS) $** $(LIBS)\r
+       link /nologo /DEBUG /OUT:$@ $(LIBPATHS) $** $(LIBS)\r
 \r
 \r
 clean:\r
-    -del /Q obj\*\r
-    -del *.ilk\r
-    -del *.pdb\r
+       -del /Q obj\*\r
+       -del *.ilk\r
+       -del *.pdb\r
diff --git a/net.cpp b/net.cpp
index dc1debd..c4a2cab 100644 (file)
--- a/net.cpp
+++ b/net.cpp
@@ -64,7 +64,7 @@ bool ConnectSocket(const CAddress& addrConnect, SOCKET& hSocketRet)
     SOCKET hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\r
     if (hSocket == INVALID_SOCKET)\r
         return false;\r
-#if defined(__BSD__) || defined(__WXOSX__)\r
+#if defined(__BSD__) || defined(__WXMAC_OSX__)\r
     int set = 1;\r
     setsockopt(hSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&set, sizeof(int));\r
 #endif\r
@@ -1163,7 +1163,7 @@ bool BindListenPort(string& strError)
         return false;\r
     }\r
 \r
-#if defined(__BSD__) || defined(__WXOSX__)\r
+#if defined(__BSD__) || defined(__WXMAC_OSX__)\r
     // Different way of disabling SIGPIPE on BSD\r
     setsockopt(hListenSocket, SOL_SOCKET, SO_NOSIGPIPE, (void*)&nOne, sizeof(int));\r
 #endif\r
diff --git a/noui.h b/noui.h
new file mode 100644 (file)
index 0000000..45ef4bc
--- /dev/null
+++ b/noui.h
@@ -0,0 +1,34 @@
+// Copyright (c) 2010 Satoshi Nakamoto\r
+// Distributed under the MIT/X11 software license, see the accompanying\r
+// file license.txt or http://www.opensource.org/licenses/mit-license.php.\r
+\r
+\r
+inline int MyMessageBox(const string& message, const string& caption="Message", int style=4, void* parent=NULL, int x=-1, int y=-1)\r
+{\r
+    printf("%s: %s\n", caption.c_str(), message.c_str());\r
+    fprintf(stderr, "%s: %s\n", caption.c_str(), message.c_str());\r
+    return 4;\r
+}\r
+#define wxMessageBox  MyMessageBox\r
+\r
+inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, void* parent, int x, int y)\r
+{\r
+    return MyMessageBox(message, caption, style, parent, x, y);\r
+}\r
+\r
+inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, void* parent)\r
+{\r
+    return true;\r
+}\r
+\r
+inline void CalledSetStatusBar(const string& strText, int nField)\r
+{\r
+}\r
+\r
+inline void UIThreadCall(boost::function0<void> fn)\r
+{\r
+}\r
+\r
+inline void MainFrameRepaint()\r
+{\r
+}\r
diff --git a/rpc.cpp b/rpc.cpp
index ee5e846..52bdece 100644 (file)
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -36,7 +36,7 @@ void PrintConsole(const char* format, ...)
         ret = limit - 1;\r
         buffer[limit-1] = 0;\r
     }\r
-#if defined(__WXMSW__) && wxUSE_GUI\r
+#if defined(__WXMSW__) && defined(GUI)\r
     MyMessageBox(buffer, "Bitcoin", wxOK | wxICON_EXCLAMATION);\r
 #else\r
     fprintf(stdout, "%s", buffer);\r
@@ -1111,7 +1111,7 @@ int CommandLineRPC(int argc, char *argv[])
         string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true));\r
         if (result.type() != null_type)\r
         {\r
-#if defined(__WXMSW__) && wxUSE_GUI\r
+#if defined(__WXMSW__) && defined(GUI)\r
             // Windows GUI apps can't print to command line,\r
             // so settle for a message box yuck\r
             MyMessageBox(strResult.c_str(), "Bitcoin", wxOK);\r
@@ -1122,7 +1122,7 @@ int CommandLineRPC(int argc, char *argv[])
         return 0;\r
     }\r
     catch (std::exception& e) {\r
-#if defined(__WXMSW__) && wxUSE_GUI\r
+#if defined(__WXMSW__) && defined(GUI)\r
         MyMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK);\r
 #else\r
         fprintf(stderr, "error: %s\n", e.what());\r
index dd2127c..7cf002e 100644 (file)
@@ -19,8 +19,8 @@ class CScript;
 class CDataStream;\r
 class CAutoFile;\r
 \r
-static const int VERSION = 303;\r
-static const char* pszSubVer = "";\r
+static const int VERSION = 304;\r
+static const char* pszSubVer = ".0";\r
 \r
 \r
 \r
diff --git a/ui.cpp b/ui.cpp
index 0ba6a10..e457d10 100644 (file)
--- a/ui.cpp
+++ b/ui.cpp
@@ -14,6 +14,7 @@ DEFINE_EVENT_TYPE(wxEVT_UITHREADCALL)
 CMainFrame* pframeMain = NULL;\r
 CMyTaskBarIcon* ptaskbaricon = NULL;\r
 bool fClosedToTray = false;\r
+wxLocale g_locale;\r
 \r
 \r
 \r
@@ -263,7 +264,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
     m_staticTextBalance->SetLabel(FormatMoney(GetBalance()) + "  ");\r
     m_listCtrl->SetFocus();\r
     ptaskbaricon = new CMyTaskBarIcon();\r
-#ifdef __WXMAC__\r
+#ifdef __WXMAC_OSX__\r
     // Mac automatically moves wxID_EXIT, wxID_PREFERENCES and wxID_ABOUT\r
     // to their standard places, leaving these menus empty.\r
     GetMenuBar()->Remove(2); // remove Help menu\r
@@ -274,7 +275,7 @@ CMainFrame::CMainFrame(wxWindow* parent) : CMainFrameBase(parent)
     int nDateWidth = DateTimeStr(1229413914).size() * 6 + 8;\r
     if (!strstr(DateTimeStr(1229413914).c_str(), "2008"))\r
         nDateWidth += 12;\r
-#ifdef __WXMAC__\r
+#ifdef __WXMAC_OSX__\r
     nDateWidth += 5;\r
     dResize -= 0.01;\r
 #endif\r
@@ -1437,6 +1438,154 @@ void CTxDetailsDialog::OnButtonOK(wxCommandEvent& event)
 \r
 \r
 \r
+\r
+//////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Startup folder\r
+//\r
+\r
+#ifdef __WXMSW__\r
+string StartupShortcutPath()\r
+{\r
+    return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";\r
+}\r
+\r
+bool GetStartOnSystemStartup()\r
+{\r
+    return filesystem::exists(StartupShortcutPath().c_str());\r
+}\r
+\r
+void SetStartOnSystemStartup(bool fAutoStart)\r
+{\r
+    // If the shortcut exists already, remove it for updating\r
+    remove(StartupShortcutPath().c_str());\r
+\r
+    if (fAutoStart)\r
+    {\r
+        CoInitialize(NULL);\r
+\r
+        // Get a pointer to the IShellLink interface.\r
+        IShellLink* psl = NULL;\r
+        HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,\r
+                                CLSCTX_INPROC_SERVER, IID_IShellLink,\r
+                                reinterpret_cast<void**>(&psl));\r
+\r
+        if (SUCCEEDED(hres))\r
+        {\r
+            // Get the current executable path\r
+            TCHAR pszExePath[MAX_PATH];\r
+            GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));\r
+\r
+            // Set the path to the shortcut target\r
+            psl->SetPath(pszExePath);\r
+            PathRemoveFileSpec(pszExePath);\r
+            psl->SetWorkingDirectory(pszExePath);\r
+            psl->SetShowCmd(SW_SHOWMINNOACTIVE);\r
+\r
+            // Query IShellLink for the IPersistFile interface for\r
+            // saving the shortcut in persistent storage.\r
+            IPersistFile* ppf = NULL;\r
+            hres = psl->QueryInterface(IID_IPersistFile,\r
+                                       reinterpret_cast<void**>(&ppf));\r
+            if (SUCCEEDED(hres))\r
+            {\r
+                WCHAR pwsz[MAX_PATH];\r
+                // Ensure that the string is ANSI.\r
+                MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);\r
+                // Save the link by calling IPersistFile::Save.\r
+                hres = ppf->Save(pwsz, TRUE);\r
+                ppf->Release();\r
+            }\r
+            psl->Release();\r
+        }\r
+        CoUninitialize();\r
+    }\r
+}\r
+\r
+#elif defined(__WXGTK__)\r
+\r
+// Follow the Desktop Application Autostart Spec:\r
+//  http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html\r
+\r
+boost::filesystem::path GetAutostartDir()\r
+{\r
+    namespace fs = boost::filesystem;\r
+\r
+    char* pszConfigHome = getenv("XDG_CONFIG_HOME");\r
+    if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");\r
+    char* pszHome = getenv("HOME");\r
+    if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");\r
+    return fs::path();\r
+}\r
+\r
+boost::filesystem::path GetAutostartFilePath()\r
+{\r
+    return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");\r
+}\r
+\r
+bool GetStartOnSystemStartup()\r
+{\r
+    boost::filesystem::ifstream optionFile(GetAutostartFilePath());\r
+    if (!optionFile.good())\r
+        return false;\r
+    // Scan through file for "Hidden=true":\r
+    string line;\r
+    while (!optionFile.eof())\r
+    {\r
+        getline(optionFile, line);\r
+        if (line.find("Hidden") != string::npos &&\r
+            line.find("true") != string::npos)\r
+            return false;\r
+    }\r
+    optionFile.close();\r
+\r
+    return true;\r
+}\r
+\r
+void SetStartOnSystemStartup(bool fAutoStart)\r
+{\r
+    if (!fAutoStart)\r
+    {\r
+        unlink(GetAutostartFilePath().native_file_string().c_str());\r
+    }\r
+    else\r
+    {\r
+        boost::filesystem::create_directories(GetAutostartDir());\r
+\r
+        boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);\r
+        if (!optionFile.good())\r
+        {\r
+            wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");\r
+            return;\r
+        }\r
+        // Write a bitcoin.desktop file to the autostart directory:\r
+        char pszExePath[MAX_PATH+1];\r
+        memset(pszExePath, 0, sizeof(pszExePath));\r
+        readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);\r
+        optionFile << "[Desktop Entry]\n";\r
+        optionFile << "Type=Application\n";\r
+        optionFile << "Name=Bitcoin\n";\r
+        optionFile << "Exec=" << pszExePath << "\n";\r
+        optionFile << "Terminal=false\n";\r
+        optionFile << "Hidden=false\n";\r
+        optionFile.close();\r
+    }\r
+}\r
+#else\r
+\r
+// TODO: OSX startup stuff; see:\r
+// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html\r
+\r
+bool GetStartOnSystemStartup() { return false; }\r
+void SetStartOnSystemStartup(bool fAutoStart) { }\r
+\r
+#endif\r
+\r
+\r
+\r
+\r
+\r
+\r
 //////////////////////////////////////////////////////////////////////////////\r
 //\r
 // COptionsDialog\r
@@ -1606,6 +1755,7 @@ void COptionsDialog::OnButtonApply(wxCommandEvent& event)
 \r
 \r
 \r
+\r
 //////////////////////////////////////////////////////////////////////////////\r
 //\r
 // CAboutDialog\r
@@ -2538,12 +2688,10 @@ wxMenu* CMyTaskBarIcon::CreatePopupMenu()
 \r
 \r
 \r
-\r
-\r
-\r
-\r
-\r
-\r
+//////////////////////////////////////////////////////////////////////////////\r
+//\r
+// CMyApp\r
+//\r
 \r
 void CreateMainWindow()\r
 {\r
@@ -2561,3 +2709,189 @@ void CreateMainWindow()
     ptaskbaricon->Show(fMinimizeToTray || fClosedToTray);\r
     CreateThread(ThreadDelayedRepaint, NULL);\r
 }\r
+\r
+\r
+// Define a new application\r
+class CMyApp : public wxApp\r
+{\r
+public:\r
+    CMyApp(){};\r
+    ~CMyApp(){};\r
+    bool OnInit();\r
+    bool OnInit2();\r
+    int OnExit();\r
+\r
+    // Hook Initialize so we can start without GUI\r
+    virtual bool Initialize(int& argc, wxChar** argv);\r
+\r
+    // 2nd-level exception handling: we get all the exceptions occurring in any\r
+    // event handler here\r
+    virtual bool OnExceptionInMainLoop();\r
+\r
+    // 3rd, and final, level exception handling: whenever an unhandled\r
+    // exception is caught, this function is called\r
+    virtual void OnUnhandledException();\r
+\r
+    // and now for something different: this function is called in case of a\r
+    // crash (e.g. dereferencing null pointer, division by 0, ...)\r
+    virtual void OnFatalException();\r
+};\r
+\r
+IMPLEMENT_APP(CMyApp)\r
+\r
+bool CMyApp::Initialize(int& argc, wxChar** argv)\r
+{\r
+    for (int i = 1; i < argc; i++)\r
+        if (!IsSwitchChar(argv[i][0]))\r
+            fCommandLine = true;\r
+\r
+    if (!fCommandLine)\r
+    {\r
+        // wxApp::Initialize will remove environment-specific parameters,\r
+        // so it's too early to call ParseParameters yet\r
+        for (int i = 1; i < argc; i++)\r
+        {\r
+            wxString str = argv[i];\r
+            #ifdef __WXMSW__\r
+            if (str.size() >= 1 && str[0] == '/')\r
+                str[0] = '-';\r
+            char pszLower[MAX_PATH];\r
+            strlcpy(pszLower, str.c_str(), sizeof(pszLower));\r
+            strlwr(pszLower);\r
+            str = pszLower;\r
+            #endif\r
+            if (str == "-daemon")\r
+                fDaemon = true;\r
+        }\r
+    }\r
+\r
+#ifdef __WXGTK__\r
+    if (fDaemon || fCommandLine)\r
+    {\r
+        // Call the original Initialize while suppressing error messages\r
+        // and ignoring failure.  If unable to initialize GTK, it fails\r
+        // near the end so hopefully the last few things don't matter.\r
+        {\r
+            wxLogNull logNo;\r
+            wxApp::Initialize(argc, argv);\r
+        }\r
+\r
+        if (fDaemon)\r
+        {\r
+            // Daemonize\r
+            pid_t pid = fork();\r
+            if (pid < 0)\r
+            {\r
+                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);\r
+                return false;\r
+            }\r
+            if (pid > 0)\r
+                pthread_exit((void*)0);\r
+        }\r
+\r
+        return true;\r
+    }\r
+#endif\r
+\r
+    return wxApp::Initialize(argc, argv);\r
+}\r
+\r
+bool CMyApp::OnInit()\r
+{\r
+#if defined(__WXMSW__) && defined(__WXDEBUG__) && defined(GUI)\r
+    // Disable malfunctioning wxWidgets debug assertion\r
+    extern int g_isPainting;\r
+    g_isPainting = 10000;\r
+#endif\r
+#ifdef GUI\r
+    wxImage::AddHandler(new wxPNGHandler);\r
+#endif\r
+#if defined(__WXMSW__ ) || defined(__WXMAC_OSX__)\r
+    SetAppName("Bitcoin");\r
+#else\r
+    SetAppName("bitcoin");\r
+#endif\r
+#ifdef __WXMSW__\r
+#if wxUSE_UNICODE\r
+    // Hack to set wxConvLibc codepage to UTF-8 on Windows,\r
+    // may break if wxMBConv_win32 implementation in strconv.cpp changes.\r
+    class wxMBConv_win32 : public wxMBConv\r
+    {\r
+    public:\r
+        long m_CodePage;\r
+        size_t m_minMBCharWidth;\r
+    };\r
+    if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)\r
+        ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;\r
+#endif\r
+#endif\r
+\r
+    // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file\r
+    g_locale.Init(wxLANGUAGE_DEFAULT, 0);\r
+    g_locale.AddCatalogLookupPathPrefix("locale");\r
+#ifndef __WXMSW__\r
+    g_locale.AddCatalogLookupPathPrefix("/usr/share/locale");\r
+    g_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");\r
+#endif\r
+    g_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any\r
+    g_locale.AddCatalog("bitcoin");\r
+\r
+    return AppInit(argc, argv);\r
+}\r
+\r
+int CMyApp::OnExit()\r
+{\r
+    Shutdown(NULL);\r
+    return wxApp::OnExit();\r
+}\r
+\r
+bool CMyApp::OnExceptionInMainLoop()\r
+{\r
+    try\r
+    {\r
+        throw;\r
+    }\r
+    catch (std::exception& e)\r
+    {\r
+        PrintException(&e, "CMyApp::OnExceptionInMainLoop()");\r
+        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());\r
+        Sleep(1000);\r
+        throw;\r
+    }\r
+    catch (...)\r
+    {\r
+        PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");\r
+        wxLogWarning("Unknown exception");\r
+        Sleep(1000);\r
+        throw;\r
+    }\r
+    return true;\r
+}\r
+\r
+void CMyApp::OnUnhandledException()\r
+{\r
+    // this shows how we may let some exception propagate uncaught\r
+    try\r
+    {\r
+        throw;\r
+    }\r
+    catch (std::exception& e)\r
+    {\r
+        PrintException(&e, "CMyApp::OnUnhandledException()");\r
+        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());\r
+        Sleep(1000);\r
+        throw;\r
+    }\r
+    catch (...)\r
+    {\r
+        PrintException(NULL, "CMyApp::OnUnhandledException()");\r
+        wxLogWarning("Unknown exception");\r
+        Sleep(1000);\r
+        throw;\r
+    }\r
+}\r
+\r
+void CMyApp::OnFatalException()\r
+{\r
+    wxMessageBox(_("Program has crashed and will terminate.  "), "Bitcoin", wxOK | wxICON_ERROR);\r
+}\r
diff --git a/ui.h b/ui.h
index a59e432..1fb6f26 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -4,24 +4,9 @@
 \r
 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)\r
 \r
-#if wxUSE_GUI\r
-static const bool fGUI=true;\r
-#else\r
-static const bool fGUI=false;\r
-#endif\r
 \r
-inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)\r
-{\r
-#if wxUSE_GUI\r
-    if (!fDaemon)\r
-        return wxMessageBox(message, caption, style, parent, x, y);\r
-#endif\r
-    printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());\r
-    fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());\r
-    return wxOK;\r
-}\r
-#define wxMessageBox  MyMessageBox\r
 \r
+extern wxLocale g_locale;\r
 \r
 \r
 \r
@@ -33,38 +18,23 @@ bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* pa
 void CalledSetStatusBar(const string& strText, int nField);\r
 void MainFrameRepaint();\r
 void CreateMainWindow();\r
+void SetStartOnSystemStartup(bool fAutoStart);\r
 \r
 \r
 \r
 \r
-\r
-#if !wxUSE_GUI\r
-inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)\r
-{\r
-    return MyMessageBox(message, caption, style, parent, x, y);\r
-}\r
-\r
-inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)\r
-{\r
-    return true;\r
-}\r
-\r
-inline void CalledSetStatusBar(const string& strText, int nField)\r
-{\r
-}\r
-\r
-inline void UIThreadCall(boost::function0<void> fn)\r
-{\r
-}\r
-\r
-inline void MainFrameRepaint()\r
+inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)\r
 {\r
+#ifdef GUI\r
+    if (!fDaemon)\r
+        return wxMessageBox(message, caption, style, parent, x, y);\r
+#endif\r
+    printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());\r
+    fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());\r
+    return wxOK;\r
 }\r
+#define wxMessageBox  MyMessageBox\r
 \r
-inline void CreateMainWindow()\r
-{\r
-}\r
-#else // wxUSE_GUI\r
 \r
 \r
 \r
@@ -334,11 +304,10 @@ public:
             m_textCtrl2->SetValue(strValue2);\r
             y += 46 + wxString(strMessage2).Freq('\n') * 14;\r
         }\r
-        if (!fWindows)\r
-        {\r
-            x *= 1.14;\r
-            y *= 1.14;\r
-        }\r
+#ifndef __WXMSW__\r
+        x *= 1.14;\r
+        y *= 1.14;\r
+#endif\r
         SetSize(x, y);\r
     }\r
 \r
@@ -375,5 +344,3 @@ public:
 \r
 DECLARE_EVENT_TABLE()\r
 };\r
-\r
-#endif // wxUSE_GUI\r
index 5d3728a..7cb6600 100644 (file)
--- a/util.cpp
+++ b/util.cpp
@@ -134,7 +134,7 @@ uint64 GetRand(uint64 nMax)
 inline int OutputDebugStringF(const char* pszFormat, ...)\r
 {\r
     int ret = 0;\r
-    if (fPrintToConsole || wxTheApp == NULL)\r
+    if (fPrintToConsole)\r
     {\r
         // print to console\r
         va_list arg_ptr;\r
@@ -441,6 +441,7 @@ void ParseParameters(int argc, char* argv[])
 \r
 const char* wxGetTranslation(const char* pszEnglish)\r
 {\r
+#ifdef GUI\r
     // Wrapper of wxGetTranslation returning the same const char* type as was passed in\r
     static CCriticalSection cs;\r
     CRITICAL_BLOCK(cs)\r
@@ -467,6 +468,9 @@ const char* wxGetTranslation(const char* pszEnglish)
         return pszCached;\r
     }\r
     return NULL;\r
+#else\r
+    return pszEnglish;\r
+#endif\r
 }\r
 \r
 \r
@@ -485,8 +489,6 @@ void FormatException(char* pszMessage, std::exception* pex, const char* pszThrea
     pszModule[0] = '\0';\r
     GetModuleFileNameA(NULL, pszModule, sizeof(pszModule));\r
 #else\r
-    // might not be thread safe, uses wxString\r
-    //const char* pszModule = wxStandardPaths::Get().GetExecutablePath().mb_str();\r
     const char* pszModule = "bitcoin";\r
 #endif\r
     if (pex)\r
@@ -510,8 +512,10 @@ void PrintException(std::exception* pex, const char* pszThread)
     FormatException(pszMessage, pex, pszThread);\r
     printf("\n\n************************\n%s\n", pszMessage);\r
     fprintf(stderr, "\n\n************************\n%s\n", pszMessage);\r
-    if (wxTheApp && !fDaemon && fGUI)\r
+#ifdef GUI\r
+    if (wxTheApp && !fDaemon)\r
         MyMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);\r
+#endif\r
     throw;\r
     //DebugBreak();\r
 }\r
@@ -574,10 +578,10 @@ string GetDefaultDataDir()
     string strHome = pszHome;\r
     if (strHome[strHome.size()-1] != '/')\r
         strHome += '/';\r
-#ifdef __WXOSX__\r
+#ifdef __WXMAC_OSX__\r
     // Mac\r
     strHome += "Library/Application Support/";\r
-    _mkdir(strHome.c_str());\r
+    filesystem::create_directory(strHome.c_str());\r
     return strHome + "Bitcoin";\r
 #else\r
     // Unix\r
@@ -596,7 +600,7 @@ void GetDataDir(char* pszDir)
         if (!fMkdirDone)\r
         {\r
             fMkdirDone = true;\r
-            _mkdir(pszDir);\r
+            filesystem::create_directory(pszDir);\r
         }\r
     }\r
     else\r
@@ -606,9 +610,8 @@ void GetDataDir(char* pszDir)
         static char pszCachedDir[MAX_PATH];\r
         if (pszCachedDir[0] == 0)\r
         {\r
-            //strlcpy(pszCachedDir, wxStandardPaths::Get().GetUserDataDir().c_str(), sizeof(pszCachedDir));\r
             strlcpy(pszCachedDir, GetDefaultDataDir().c_str(), sizeof(pszCachedDir));\r
-            _mkdir(pszCachedDir);\r
+            filesystem::create_directory(pszCachedDir);\r
         }\r
         strlcpy(pszDir, pszCachedDir, MAX_PATH);\r
     }\r
diff --git a/util.h b/util.h
index 49e3863..366c0e1 100644 (file)
--- a/util.h
+++ b/util.h
@@ -55,7 +55,6 @@ inline T& REF(const T& val)
 }\r
 \r
 #ifdef __WXMSW__\r
-static const bool fWindows = true;\r
 #define MSG_NOSIGNAL        0\r
 #define MSG_DONTWAIT        0\r
 #ifndef UINT64_MAX\r
@@ -70,7 +69,6 @@ static const bool fWindows = true;
 #define unlink              _unlink\r
 typedef int socklen_t;\r
 #else\r
-static const bool fWindows = false;\r
 #define WSAGetLastError()   errno\r
 #define WSAEWOULDBLOCK      EWOULDBLOCK\r
 #define WSAEMSGSIZE         EMSGSIZE\r
@@ -84,10 +82,12 @@ typedef u_int SOCKET;
 #define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d)\r
 #define strlwr(psz)         to_lower(psz)\r
 #define _strlwr(psz)        to_lower(psz)\r
-#define _mkdir(psz)         filesystem::create_directory(psz)\r
 #define MAX_PATH            1024\r
-#define Sleep(n)            wxMilliSleep(n)\r
 #define Beep(n1,n2)         (0)\r
+inline void Sleep(int64 n)\r
+{\r
+    boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(n));\r
+}\r
 #endif\r
 \r
 inline int myclosesocket(SOCKET& hSocket)\r
@@ -104,6 +104,13 @@ inline int myclosesocket(SOCKET& hSocket)
 }\r
 #define closesocket(s)      myclosesocket(s)\r
 \r
+#ifndef GUI\r
+inline const char* _(const char* psz)\r
+{\r
+    return psz;\r
+}\r
+#endif\r
+\r
 \r
 \r
 \r