Research
Timechain
Search Donate
Sponsors
Cake Wallet, private Bitcoin and Monero walletSideShift.ai, no-signup crypto exchangeOrangeRock, non-custodial bitcoin spot and perps tradingBraiins Hashpower, buy and sell Bitcoin hashrateeCash.com
What changed

Bitcoin v0.2.6 → v0.2.7

13 files · +838 · −794 · c2430126d · 2010-02-25 · s_nakamoto

Release commit message: GUI-less build target bitcoind that links to wxBase and shouldn't need GTK, split init and shutdown from ui.cpp into init.cpp, support wxUSE_GUI=0 -- version 0.2.7

Previous diff: v0.2.5 → v0.2.6. Next: v0.2.7 → v0.2.8.

headers.h (modified)

1--- v0.2.6/headers.h2+++ v0.2.7/headers.h3@@ -21,9 +21,11 @@4 #include <wx/wx.h>5 #include <wx/clipbrd.h>6 #include <wx/snglinst.h>7-#include <wx/taskbar.h>8 #include <wx/stdpaths.h>9 #include <wx/utils.h>10+#if wxUSE_GUI11+#include <wx/taskbar.h>12+#endif13 #include <openssl/ecdsa.h>14 #include <openssl/evp.h>15 #include <openssl/rand.h>16@@ -100,8 +102,11 @@17 #include "irc.h"18 #include "main.h"19 #include "rpc.h"20+#if wxUSE_GUI21 #include "uibase.h"22+#endif23 #include "ui.h"24+#include "init.h"25 26 #include "xpm/addressbook16.xpm"27 #include "xpm/addressbook20.xpm"

init.cpp (added)

1--- /dev/null2+++ v0.2.7/init.cpp3@@ -1 +1,626 @@4-5+// Copyright (c) 2009-2010 Satoshi Nakamoto6+// Distributed under the MIT/X11 software license, see the accompanying7+// file license.txt or http://www.opensource.org/licenses/mit-license.php.8+9+#include "headers.h"10+11+12+13+14+void ExitTimeout(void* parg)15+{16+#ifdef __WXMSW__17+    Sleep(5000);18+    ExitProcess(0);19+#endif20+}21+22+void Shutdown(void* parg)23+{24+    static CCriticalSection cs_Shutdown;25+    static bool fTaken;26+    bool fFirstThread;27+    CRITICAL_BLOCK(cs_Shutdown)28+    {29+        fFirstThread = !fTaken;30+        fTaken = true;31+    }32+    static bool fExit;33+    if (fFirstThread)34+    {35+        fShutdown = true;36+        nTransactionsUpdated++;37+        DBFlush(false);38+        StopNode();39+        DBFlush(true);40+        CreateThread(ExitTimeout, NULL);41+        Sleep(50);42+        printf("Bitcoin exiting\n\n");43+        fExit = true;44+        exit(0);45+    }46+    else47+    {48+        while (!fExit)49+            Sleep(500);50+        Sleep(100);51+        ExitThread(0);52+    }53+}54+55+56+57+58+59+60+//////////////////////////////////////////////////////////////////////////////61+//62+// Startup folder63+//64+65+#ifdef __WXMSW__66+typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);67+68+string MyGetSpecialFolderPath(int nFolder, bool fCreate)69+{70+    char pszPath[MAX_PATH+100] = "";71+72+    // SHGetSpecialFolderPath is not usually available on NT 4.073+    HMODULE hShell32 = LoadLibraryA("shell32.dll");74+    if (hShell32)75+    {76+        PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =77+            (PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");78+        if (pSHGetSpecialFolderPath)79+            (*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);80+        FreeModule(hShell32);81+    }82+83+    // Backup option84+    if (pszPath[0] == '\0')85+    {86+        if (nFolder == CSIDL_STARTUP)87+        {88+            strcpy(pszPath, getenv("USERPROFILE"));89+            strcat(pszPath, "\\Start Menu\\Programs\\Startup");90+        }91+        else if (nFolder == CSIDL_APPDATA)92+        {93+            strcpy(pszPath, getenv("APPDATA"));94+        }95+    }96+97+    return pszPath;98+}99+100+string StartupShortcutPath()101+{102+    return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";103+}104+105+bool GetStartOnSystemStartup()106+{107+    return wxFileExists(StartupShortcutPath());108+}109+110+void SetStartOnSystemStartup(bool fAutoStart)111+{112+    // If the shortcut exists already, remove it for updating113+    remove(StartupShortcutPath().c_str());114+115+    if (fAutoStart)116+    {117+        CoInitialize(NULL);118+119+        // Get a pointer to the IShellLink interface.120+        IShellLink* psl = NULL;121+        HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,122+                                CLSCTX_INPROC_SERVER, IID_IShellLink,123+                                reinterpret_cast<void**>(&psl));124+125+        if (SUCCEEDED(hres))126+        {127+            // Get the current executable path128+            TCHAR pszExePath[MAX_PATH];129+            GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));130+131+            // Set the path to the shortcut target132+            psl->SetPath(pszExePath);133+            PathRemoveFileSpec(pszExePath);134+            psl->SetWorkingDirectory(pszExePath);135+            psl->SetShowCmd(SW_SHOWMINNOACTIVE);136+137+            // Query IShellLink for the IPersistFile interface for138+            // saving the shortcut in persistent storage.139+            IPersistFile* ppf = NULL;140+            hres = psl->QueryInterface(IID_IPersistFile,141+                                       reinterpret_cast<void**>(&ppf));142+            if (SUCCEEDED(hres))143+            {144+                WCHAR pwsz[MAX_PATH];145+                // Ensure that the string is ANSI.146+                MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);147+                // Save the link by calling IPersistFile::Save.148+                hres = ppf->Save(pwsz, TRUE);149+                ppf->Release();150+            }151+            psl->Release();152+        }153+        CoUninitialize();154+    }155+}156+#else157+bool GetStartOnSystemStartup() { return false; }158+void SetStartOnSystemStartup(bool fAutoStart) { }159+#endif160+161+162+163+164+165+166+167+//////////////////////////////////////////////////////////////////////////////168+//169+// CMyApp170+//171+172+// Define a new application173+class CMyApp: public wxApp174+{175+public:176+    wxLocale m_locale;177+178+    CMyApp(){};179+    ~CMyApp(){};180+    bool OnInit();181+    bool OnInit2();182+    int OnExit();183+184+    // Hook Initialize so we can start without GUI185+    virtual bool Initialize(int& argc, wxChar** argv);186+187+    // 2nd-level exception handling: we get all the exceptions occurring in any188+    // event handler here189+    virtual bool OnExceptionInMainLoop();190+191+    // 3rd, and final, level exception handling: whenever an unhandled192+    // exception is caught, this function is called193+    virtual void OnUnhandledException();194+195+    // and now for something different: this function is called in case of a196+    // crash (e.g. dereferencing null pointer, division by 0, ...)197+    virtual void OnFatalException();198+};199+200+IMPLEMENT_APP(CMyApp)201+202+bool CMyApp::Initialize(int& argc, wxChar** argv)203+{204+    if (argc > 1 && argv[1][0] != '-' && (!fWindows || argv[1][0] != '/') &&205+        wxString(argv[1]) != "start")206+    {207+        fCommandLine = true;208+    }209+    else if (!fGUI)210+    {211+        fDaemon = true;212+    }213+    else214+    {215+        // wxApp::Initialize will remove environment-specific parameters,216+        // so it's too early to call ParseParameters yet217+        for (int i = 1; i < argc; i++)218+        {219+            wxString str = argv[i];220+            #ifdef __WXMSW__221+            if (str.size() >= 1 && str[0] == '/')222+                str[0] = '-';223+            str = str.MakeLower();224+            #endif225+            // haven't decided which argument to use for this yet226+            if (str == "-daemon" || str == "-d" || str == "start")227+                fDaemon = true;228+        }229+    }230+231+    if (fDaemon)232+        fprintf(stdout, "bitcoin server starting\n");233+234+#ifdef __WXGTK__235+    if (fDaemon || fCommandLine)236+    {237+        // Call the original Initialize while suppressing error messages238+        // and ignoring failure.  If unable to initialize GTK, it fails239+        // near the end so hopefully the last few things don't matter.240+        {241+            wxLogNull logNo;242+            wxApp::Initialize(argc, argv);243+        }244+245+        if (fDaemon)246+        {247+            // Daemonize248+            pid_t pid = fork();249+            if (pid < 0)250+            {251+                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);252+                return false;253+            }254+            if (pid > 0)255+                pthread_exit((void*)0);256+        }257+258+        return true;259+    }260+#endif261+262+    return wxApp::Initialize(argc, argv);263+}264+265+bool CMyApp::OnInit()266+{267+    bool fRet = false;268+    try269+    {270+        fRet = OnInit2();271+    }272+    catch (std::exception& e) {273+        PrintException(&e, "OnInit()");274+    } catch (...) {275+        PrintException(NULL, "OnInit()");276+    }277+    if (!fRet)278+        Shutdown(NULL);279+    return fRet;280+}281+282+extern int g_isPainting;283+284+bool CMyApp::OnInit2()285+{286+#ifdef _MSC_VER287+    // Turn off microsoft heap dump noise288+    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);289+    _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));290+#endif291+#if defined(__WXMSW__) && defined(__WXDEBUG__) && wxUSE_GUI292+    // Disable malfunctioning wxWidgets debug assertion293+    g_isPainting = 10000;294+#endif295+#if wxUSE_GUI296+    wxImage::AddHandler(new wxPNGHandler);297+#endif298+#ifdef __WXMSW__299+    SetAppName("Bitcoin");300+#else301+    SetAppName("bitcoin");302+    umask(077);303+#endif304+#ifdef __WXMSW__305+#if wxUSE_UNICODE306+    // Hack to set wxConvLibc codepage to UTF-8 on Windows,307+    // may break if wxMBConv_win32 implementation in strconv.cpp changes.308+    class wxMBConv_win32 : public wxMBConv309+    {310+    public:311+        long m_CodePage;312+        size_t m_minMBCharWidth;313+    };314+    if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)315+        ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;316+#endif317+#endif318+319+    // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file320+    m_locale.Init(wxLANGUAGE_DEFAULT, 0);321+    m_locale.AddCatalogLookupPathPrefix("locale");322+    if (!fWindows)323+    {324+        m_locale.AddCatalogLookupPathPrefix("/usr/share/locale");325+        m_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");326+    }327+    m_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any328+    m_locale.AddCatalog("bitcoin");329+330+    //331+    // Parameters332+    //333+    if (fCommandLine)334+    {335+        int ret = CommandLineRPC(argc, argv);336+        exit(ret);337+    }338+339+    ParseParameters(argc, argv);340+    if (mapArgs.count("-?") || mapArgs.count("--help"))341+    {342+        wxString strUsage = string() +343+            _("Usage: bitcoin [options]") + "\t\t\t\t\t\t\n" +344+            _("Options:\n") +345+            "  -gen            \t\t  " + _("Generate coins\n") +346+            "  -gen=0          \t\t  " + _("Don't generate coins\n") +347+            "  -min            \t\t  " + _("Start minimized\n") +348+            "  -datadir=<dir>  \t  "   + _("Specify data directory\n") +349+            "  -proxy=<ip:port>\t  "   + _("Connect through socks4 proxy\n") +350+            "  -addnode=<ip>   \t  "   + _("Add a node to connect to\n") +351+            "  -connect=<ip>   \t  "   + _("Connect only to the specified node\n") +352+            "  -?              \t\t  " + _("This help message\n");353+354+        if (fWindows && fGUI)355+        {356+            // Remove spaces, the tabs make the columns line up in the message box357+            for (int i = 0; i < 50; i++)358+                strUsage.Replace(" \t", "\t");359+            wxMessageBox(strUsage, "Bitcoin", wxOK);360+        }361+        else362+        {363+            // Remove tabs364+            strUsage.Replace("\t", "");365+            fprintf(stderr, "%s", ((string)strUsage).c_str());366+        }367+        return false;368+    }369+370+    if (mapArgs.count("-datadir"))371+        strlcpy(pszSetDataDir, mapArgs["-datadir"].c_str(), sizeof(pszSetDataDir));372+373+    if (mapArgs.count("-debug"))374+        fDebug = true;375+376+    if (mapArgs.count("-printtodebugger"))377+        fPrintToDebugger = true;378+379+    if (!fDebug && !pszSetDataDir[0])380+        ShrinkDebugFile();381+    printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");382+    printf("Bitcoin version 0.%d.%d%s beta, OS version %s\n", VERSION/100, VERSION%100, pszSubVer, ((string)wxGetOsDescription()).c_str());383+    printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str());384+    printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str());385+386+    if (mapArgs.count("-loadblockindextest"))387+    {388+        CTxDB txdb("r");389+        txdb.LoadBlockIndex();390+        PrintBlockTree();391+        return false;392+    }393+394+    //395+    // Limit to single instance per user396+    // Required to protect the database files if we're going to keep deleting log.*397+    //398+#ifdef __WXMSW__399+    // todo: wxSingleInstanceChecker wasn't working on Linux, never deleted its lock file400+    //  maybe should go by whether successfully bind port 8333 instead401+    wxString strMutexName = wxString("bitcoin_running.") + getenv("HOMEPATH");402+    for (int i = 0; i < strMutexName.size(); i++)403+        if (!isalnum(strMutexName[i]))404+            strMutexName[i] = '.';405+    wxSingleInstanceChecker* psingleinstancechecker = new wxSingleInstanceChecker(strMutexName);406+    if (psingleinstancechecker->IsAnotherRunning())407+    {408+        printf("Existing instance found\n");409+        unsigned int nStart = GetTime();410+        loop411+        {412+            // TODO: find out how to do this in Linux, or replace with wxWidgets commands413+            // Show the previous instance and exit414+            HWND hwndPrev = FindWindowA("wxWindowClassNR", "Bitcoin");415+            if (hwndPrev)416+            {417+                if (IsIconic(hwndPrev))418+                    ShowWindow(hwndPrev, SW_RESTORE);419+                SetForegroundWindow(hwndPrev);420+                return false;421+            }422+423+            if (GetTime() > nStart + 60)424+                return false;425+426+            // Resume this instance if the other exits427+            delete psingleinstancechecker;428+            Sleep(1000);429+            psingleinstancechecker = new wxSingleInstanceChecker(strMutexName);430+            if (!psingleinstancechecker->IsAnotherRunning())431+                break;432+        }433+    }434+#endif435+436+    // Bind to the port early so we can tell if another instance is already running.437+    // This is a backup to wxSingleInstanceChecker, which doesn't work on Linux.438+    string strErrors;439+    if (!BindListenPort(strErrors))440+    {441+        wxMessageBox(strErrors, "Bitcoin");442+        return false;443+    }444+445+    //446+    // Load data files447+    //448+    bool fFirstRun;449+    strErrors = "";450+    int64 nStart;451+452+    printf("Loading addresses...\n");453+    nStart = GetTimeMillis();454+    if (!LoadAddresses())455+        strErrors += _("Error loading addr.dat      \n");456+    printf(" addresses   %15"PRI64d"ms\n", GetTimeMillis() - nStart);457+458+    printf("Loading block index...\n");459+    nStart = GetTimeMillis();460+    if (!LoadBlockIndex())461+        strErrors += _("Error loading blkindex.dat      \n");462+    printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);463+464+    printf("Loading wallet...\n");465+    nStart = GetTimeMillis();466+    if (!LoadWallet(fFirstRun))467+        strErrors += _("Error loading wallet.dat      \n");468+    printf(" wallet      %15"PRI64d"ms\n", GetTimeMillis() - nStart);469+470+    printf("Done loading\n");471+472+        //// debug print473+        printf("mapBlockIndex.size() = %d\n",   mapBlockIndex.size());474+        printf("nBestHeight = %d\n",            nBestHeight);475+        printf("mapKeys.size() = %d\n",         mapKeys.size());476+        printf("mapPubKeys.size() = %d\n",      mapPubKeys.size());477+        printf("mapWallet.size() = %d\n",       mapWallet.size());478+        printf("mapAddressBook.size() = %d\n",  mapAddressBook.size());479+480+    if (!strErrors.empty())481+    {482+        wxMessageBox(strErrors, "Bitcoin");483+        return false;484+    }485+486+    // Add wallet transactions that aren't already in a block to mapTransactions487+    ReacceptWalletTransactions();488+489+    //490+    // Parameters491+    //492+    if (mapArgs.count("-printblockindex") || mapArgs.count("-printblocktree"))493+    {494+        PrintBlockTree();495+        return false;496+    }497+498+    if (mapArgs.count("-printblock"))499+    {500+        string strMatch = mapArgs["-printblock"];501+        int nFound = 0;502+        for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)503+        {504+            uint256 hash = (*mi).first;505+            if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)506+            {507+                CBlockIndex* pindex = (*mi).second;508+                CBlock block;509+                block.ReadFromDisk(pindex);510+                block.BuildMerkleTree();511+                block.print();512+                printf("\n");513+                nFound++;514+            }515+        }516+        if (nFound == 0)517+            printf("No blocks matching %s were found\n", strMatch.c_str());518+        return false;519+    }520+521+    if (mapArgs.count("-gen"))522+    {523+        if (mapArgs["-gen"].empty())524+            fGenerateBitcoins = true;525+        else526+            fGenerateBitcoins = (atoi(mapArgs["-gen"].c_str()) != 0);527+    }528+529+    if (mapArgs.count("-proxy"))530+    {531+        fUseProxy = true;532+        addrProxy = CAddress(mapArgs["-proxy"]);533+        if (!addrProxy.IsValid())534+        {535+            wxMessageBox(_("Invalid -proxy address"), "Bitcoin");536+            return false;537+        }538+    }539+540+    if (mapArgs.count("-addnode"))541+    {542+        foreach(string strAddr, mapMultiArgs["-addnode"])543+        {544+            CAddress addr(strAddr, NODE_NETWORK);545+            addr.nTime = 0; // so it won't relay unless successfully connected546+            if (addr.IsValid())547+                AddAddress(addr);548+        }549+    }550+551+    //552+    // Create the main window and start the node553+    //554+    if (!fDaemon)555+        CreateMainWindow();556+557+    if (!CheckDiskSpace())558+        return false;559+560+    RandAddSeedPerfmon();561+562+    if (!CreateThread(StartNode, NULL))563+        wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin");564+565+    if (mapArgs.count("-server") || fDaemon)566+        CreateThread(ThreadRPCServer, NULL);567+568+    if (fFirstRun)569+        SetStartOnSystemStartup(true);570+571+    return true;572+}573+574+int CMyApp::OnExit()575+{576+    Shutdown(NULL);577+    return wxApp::OnExit();578+}579+580+bool CMyApp::OnExceptionInMainLoop()581+{582+    try583+    {584+        throw;585+    }586+    catch (std::exception& e)587+    {588+        PrintException(&e, "CMyApp::OnExceptionInMainLoop()");589+        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());590+        Sleep(1000);591+        throw;592+    }593+    catch (...)594+    {595+        PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");596+        wxLogWarning("Unknown exception");597+        Sleep(1000);598+        throw;599+    }600+    return true;601+}602+603+void CMyApp::OnUnhandledException()604+{605+    // this shows how we may let some exception propagate uncaught606+    try607+    {608+        throw;609+    }610+    catch (std::exception& e)611+    {612+        PrintException(&e, "CMyApp::OnUnhandledException()");613+        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());614+        Sleep(1000);615+        throw;616+    }617+    catch (...)618+    {619+        PrintException(NULL, "CMyApp::OnUnhandledException()");620+        wxLogWarning("Unknown exception");621+        Sleep(1000);622+        throw;623+    }624+}625+626+void CMyApp::OnFatalException()627+{628+    wxMessageBox(_("Program has crashed and will terminate.  "), "Bitcoin", wxOK | wxICON_ERROR);629+}630+

init.h (added)

1--- /dev/null2+++ v0.2.7/init.h3@@ -1 +1,8 @@4+// Copyright (c) 2009-2010 Satoshi Nakamoto5+// Distributed under the MIT/X11 software license, see the accompanying6+// file license.txt or http://www.opensource.org/licenses/mit-license.php.7 8+void Shutdown(void* parg);9+bool GetStartOnSystemStartup();10+void SetStartOnSystemStartup(bool fAutoStart);11+

main.cpp (modified)

1--- v0.2.6/main.cpp2+++ v0.2.7/main.cpp3@@ -55,6 +55,8 @@4 CAddress addrIncoming;5 int fLimitProcessors = false;6 int nLimitProcessors = 1;7+int fMinimizeToTray = true;8+int fMinimizeOnClose = true;9 10 11 12@@ -2990,7 +2992,7 @@13     if (nValue <= 0)14         return _("Invalid amount");15     if (nValue + nTransactionFee > GetBalance())16-        return _("You don't have enough money");17+        return _("Insufficient funds");18 19     // Parse bitcoin address20     CScript scriptPubKey;

main.h (modified)

1--- v0.2.6/main.h2+++ v0.2.7/main.h3@@ -45,6 +45,8 @@4 extern CAddress addrIncoming;5 extern int fLimitProcessors;6 extern int nLimitProcessors;7+extern int fMinimizeToTray;8+extern int fMinimizeOnClose;9 10 11 

makefile.mingw (modified)

1--- v0.2.6/makefile.mingw2+++ v0.2.7/makefile.mingw3@@ -18,70 +18,60 @@4  -L"/openssl/out" \5  -L"/wxwidgets/lib/gcc_lib"6 7+WXLIBS= \8+ -l wxmsw29ud_html -l wxmsw29ud_core -l wxmsw29ud_adv -l wxbase29ud -l wxtiffd -l wxjpegd -l wxpngd -l wxzlibd9+10 LIBS= \11  -l libboost_system-mgw34-mt-d -l libboost_filesystem-mgw34-mt-d \12  -l db_cxx \13  -l eay32 \14- -l wxmsw29ud_html -l wxmsw29ud_core -l wxmsw29ud_adv -l wxbase29ud -l wxtiffd -l wxjpegd -l wxpngd -l wxzlibd \15  -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 shlwapi16 17 WXDEFS=-DWIN32 -D__WXMSW__ -D_WINDOWS -DNOPCH18 DEBUGFLAGS=-g -D__WXDEBUG__19 CFLAGS=-mthreads -O0 -w -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)20-HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h21-22+HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \23+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h24 25 26 all: bitcoin.exe27 28 29-headers.h.gch: headers.h            $(HEADERS)30+headers.h.gch: headers.h $(HEADERS)31 	g++ -c $(CFLAGS) -o $@ $<32 33-obj/util.o: util.cpp                $(HEADERS)34+obj/%.o: %.cpp $(HEADERS) headers.h.gch35 	g++ -c $(CFLAGS) -o $@ $<36 37-obj/script.o: script.cpp            $(HEADERS)38-	g++ -c $(CFLAGS) -o $@ $<39-40-obj/db.o: db.cpp                    $(HEADERS)41-	g++ -c $(CFLAGS) -o $@ $<42-43-obj/net.o: net.cpp                  $(HEADERS)44-	g++ -c $(CFLAGS) -o $@ $<45-46-obj/main.o: main.cpp                $(HEADERS) sha.h47-	g++ -c $(CFLAGS) -o $@ $<48-49-obj/ui.o: ui.cpp                    $(HEADERS)50-	g++ -c $(CFLAGS) -o $@ $<51-52-obj/uibase.o: uibase.cpp            uibase.h53-	g++ -c $(CFLAGS) -o $@ $<54-55-obj/sha.o: sha.cpp                  sha.h56+obj/sha.o: sha.cpp sha.h57 	g++ -c $(CFLAGS) -O3 -o $@ $<58-59-obj/irc.o: irc.cpp                  $(HEADERS)60-	g++ -c $(CFLAGS) -o $@ $<61-62-obj/rpc.o: rpc.cpp                  $(HEADERS)63-	g++ -c $(CFLAGS) -o $@ $<64 65 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.bmp66 	windres $(WXDEFS) $(INCLUDEPATHS) -o $@ -i $<67 68+OBJS= \69+    obj/util.o \70+    obj/script.o \71+    obj/db.o \72+    obj/net.o \73+    obj/irc.o \74+    obj/main.o \75+    obj/rpc.o \76+    obj/init.o77+78+bitcoin.exe: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o obj/ui_res.o79+	g++ $(CFLAGS) -mwindows -Wl,--subsystem,windows -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)80 81 82-OBJS=obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o \83-        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/rpc.o \84-        obj/ui_res.o85+obj/nogui/%.o: %.cpp $(HEADERS)86+	g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<87 88-bitcoin.exe: headers.h.gch $(OBJS)89-	-kill /f bitcoin.exe90-	g++ $(CFLAGS) -mwindows -Wl,--subsystem,windows -o $@ $(LIBPATHS) $(OBJS) $(LIBS)91+bitcoind.exe: $(OBJS:obj/%=obj/nogui/%) obj/sha.o obj/ui_res.o92+	g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wxbase29ud $(LIBS)93+94 95 clean:96 	-del /Q obj\*97+	-del /Q obj\nogui\*98 	-del /Q headers.h.gch99 

makefile.unix (modified)

1--- v0.2.6/makefile.unix2+++ v0.2.7/makefile.unix3@@ -13,67 +13,62 @@4  -L"/usr/lib" \5  -L"/usr/local/lib"6 7+WXLIBS= \8+ -Wl,-Bstatic \9+   -l wx_gtk2ud-2.9 \10+ -Wl,-Bdynamic \11+   -l gtk-x11-2.0 -l SM12+13 LIBS= \14  -Wl,-Bstatic \15    -l boost_system-mt -l boost_filesystem-mt \16    -l db_cxx \17-   -l wx_gtk2ud-2.9 \18  -Wl,-Bdynamic \19    -l crypto \20-   -l gtk-x11-2.0 -l gthread-2.0 -l SM21+   -l gthread-2.022 23 WXDEFS=-D__WXGTK__ -DNOPCH24 DEBUGFLAGS=-g -D__WXDEBUG__25 CFLAGS=-O0 -Wno-invalid-offsetof -Wformat $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)26-HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h27-28+HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \29+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h30 31 32 all: bitcoin33 34 35-headers.h.gch: headers.h            $(HEADERS)36+headers.h.gch: headers.h $(HEADERS)37 	g++ -c $(CFLAGS) -o $@ $<38 39-obj/util.o: util.cpp                $(HEADERS)40+obj/%.o: %.cpp $(HEADERS) headers.h.gch41 	g++ -c $(CFLAGS) -o $@ $<42 43-obj/script.o: script.cpp            $(HEADERS)44-	g++ -c $(CFLAGS) -o $@ $<45-46-obj/db.o: db.cpp                    $(HEADERS)47-	g++ -c $(CFLAGS) -o $@ $<48-49-obj/net.o: net.cpp                  $(HEADERS)50-	g++ -c $(CFLAGS) -o $@ $<51-52-obj/main.o: main.cpp                $(HEADERS) sha.h53-	g++ -c $(CFLAGS) -o $@ $<54-55-obj/ui.o: ui.cpp                    $(HEADERS)56-	g++ -c $(CFLAGS) -o $@ $<57-58-obj/uibase.o: uibase.cpp            uibase.h59-	g++ -c $(CFLAGS) -o $@ $<60-61-obj/sha.o: sha.cpp                  sha.h62+obj/sha.o: sha.cpp sha.h63 	g++ -c $(CFLAGS) -O3 -o $@ $<64 65-obj/irc.o: irc.cpp                  $(HEADERS)66-	g++ -c $(CFLAGS) -o $@ $<67+OBJS= \68+    obj/util.o \69+    obj/script.o \70+    obj/db.o \71+    obj/net.o \72+    obj/irc.o \73+    obj/main.o \74+    obj/rpc.o \75+    obj/init.o76 77-obj/rpc.o: rpc.cpp                  $(HEADERS)78-	g++ -c $(CFLAGS) -o $@ $<79+bitcoin: $(OBJS) obj/ui.o obj/uibase.o obj/sha.o80+	g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(WXLIBS) $(LIBS)81 82 83+obj/nogui/%.o: %.cpp $(HEADERS)84+	g++ -c $(CFLAGS) -DwxUSE_GUI=0 -o $@ $<85 86-OBJS=obj/util.o obj/script.o obj/db.o obj/net.o obj/main.o \87-        obj/ui.o obj/uibase.o obj/sha.o obj/irc.o obj/rpc.o88+bitcoind: $(OBJS:obj/%=obj/nogui/%) obj/sha.o89+	g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ -l wx_baseud-2.9 $(LIBS)90 91-bitcoin: headers.h.gch $(OBJS)92-	g++ $(CFLAGS) -o $@ $(LIBPATHS) $(OBJS) $(LIBS)93 94 clean:95 	-rm obj/*96+	-rm obj/nogui/*97 	-rm headers.h.gch98 

makefile.vc (modified)

1--- v0.2.6/makefile.vc2+++ v0.2.7/makefile.vc3@@ -28,58 +28,81 @@4 WXDEFS=/DWIN32 /D__WXMSW__ /D_WINDOWS /DNOPCH5 DEBUGFLAGS=/Zi /Od /D__WXDEBUG__6 CFLAGS=/c /nologo /Ob0 /MDd /EHsc /GR /Zm300 $(DEBUGFLAGS) $(WXDEFS) $(INCLUDEPATHS)7-HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h8-9+HEADERS=headers.h strlcpy.h serialize.h uint256.h util.h key.h bignum.h base58.h \10+    script.h db.h net.h irc.h main.h rpc.h uibase.h ui.h init.h sha.h11 12 13 all: bitcoin.exe14 15 16-obj\util.obj: util.cpp        $(HEADERS)17-    cl $(CFLAGS) /Fo$@ %s18+.cpp{obj}.obj:19+	cl $(CFLAGS) /Fo$@ %s20 21-obj\script.obj: script.cpp    $(HEADERS)22-    cl $(CFLAGS) /Fo$@ %s23+obj\util.obj: $(HEADERS)24 25-obj\db.obj: db.cpp            $(HEADERS)26-    cl $(CFLAGS) /Fo$@ %s27+obj\script.obj: $(HEADERS)28 29-obj\net.obj: net.cpp          $(HEADERS)30-    cl $(CFLAGS) /Fo$@ %s31+obj\db.obj: $(HEADERS)32 33-obj\main.obj: main.cpp        $(HEADERS) sha.h34-    cl $(CFLAGS) /Fo$@ %s35+obj\net.obj: $(HEADERS)36 37-obj\ui.obj: ui.cpp            $(HEADERS)38-    cl $(CFLAGS) /Fo$@ %s39+obj\irc.obj: $(HEADERS)40 41-obj\uibase.obj: uibase.cpp    uibase.h42-    cl $(CFLAGS) /Fo$@ %s43+obj\main.obj: $(HEADERS)44 45-obj\sha.obj: sha.cpp          sha.h46-    cl $(CFLAGS) /O2 /Fo$@ %s47+obj\rpc.obj: $(HEADERS)48 49-obj\irc.obj:  irc.cpp         $(HEADERS)50-    cl $(CFLAGS) /Fo$@ %s51+obj\init.obj: $(HEADERS)52 53-obj\rpc.obj:  rpc.cpp         $(HEADERS)54-    cl $(CFLAGS) /Fo$@ %s55+obj\ui.obj: $(HEADERS)56+57+obj\uibase.obj: $(HEADERS)58+59+obj\sha.obj: sha.cpp sha.h60+	cl $(CFLAGS) /O2 /Fo$@ %s61 62 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.bmp63-    rc $(INCLUDEPATHS) $(WXDEFS) /Fo$@ %s64+	rc $(INCLUDEPATHS) $(WXDEFS) /Fo$@ %s65+66+OBJS= \67+    obj\util.obj \68+    obj\script.obj \69+    obj\db.obj \70+    obj\net.obj \71+    obj\irc.obj \72+    obj\main.obj \73+    obj\rpc.obj \74+    obj\init.obj75+76+bitcoin.exe: $(OBJS) obj\ui.obj obj\uibase.obj obj\sha.obj obj\ui.res77+	link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(LIBS)78 79 80+.cpp{obj\nogui}.obj:81+	cl $(CFLAGS) /DwxUSE_GUI=0 /Fo$@ %s82 83-OBJS=obj\util.obj obj\script.obj obj\db.obj obj\net.obj obj\main.obj \84-    obj\ui.obj obj\uibase.obj obj\sha.obj obj\irc.obj obj\rpc.obj \85-    obj\ui.res86+obj\nogui\util.obj: $(HEADERS)87 88-bitcoin.exe: $(OBJS)89-    -kill /f bitcoin.exe & sleep 190-    link /nologo /DEBUG /SUBSYSTEM:WINDOWS /OUT:$@ $(LIBPATHS) $** $(LIBS)91+obj\nogui\script.obj: $(HEADERS)92+93+obj\nogui\db.obj: $(HEADERS)94+95+obj\nogui\net.obj: $(HEADERS)96+97+obj\nogui\irc.obj: $(HEADERS)98+99+obj\nogui\main.obj: $(HEADERS)100+101+obj\nogui\rpc.obj: $(HEADERS)102+103+obj\nogui\init.obj: $(HEADERS)104+105+bitcoind.exe: $(OBJS:obj\=obj\nogui\) obj\sha.obj obj\ui.res106+	link /nologo /DEBUG /OUT:$@ $(LIBPATHS) $** $(LIBS)107+108 109 clean:110-    -del /Q obj\*111-    -del *.ilk112-    -del *.pdb113+	-del /Q obj\*114+	-del *.ilk115+	-del *.pdb116 

rpc.cpp (modified)

1--- v0.2.6/rpc.cpp2+++ v0.2.7/rpc.cpp3@@ -676,18 +676,18 @@4         string strResult = (result.type() == str_type ? result.get_str() : write_string(result, true));5         if (result.type() != null_type)6         {7-            if (fWindows)8+            if (fWindows && fGUI)9                 // Windows GUI apps can't print to command line,10-                // so for now settle for a message box yuck11-                wxMessageBox(strResult.c_str(), "Bitcoin", wxOK);12+                // so settle for a message box yuck13+                MyMessageBox(strResult.c_str(), "Bitcoin", wxOK);14             else15                 fprintf(stdout, "%s\n", strResult.c_str());16         }17         return 0;18     }19     catch (std::exception& e) {20-        if (fWindows)21-            wxMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK);22+        if (fWindows && fGUI)23+            MyMessageBox(strprintf("error: %s\n", e.what()).c_str(), "Bitcoin", wxOK);24         else25             fprintf(stderr, "error: %s\n", e.what());26     } catch (...) {

serialize.h (modified)

1--- v0.2.6/serialize.h2+++ v0.2.7/serialize.h3@@ -19,7 +19,7 @@4 class CDataStream;5 class CAutoFile;6 7-static const int VERSION = 206;8+static const int VERSION = 207;9 static const char* pszSubVer = ".0";10 11 

ui.cpp (modified)

1--- v0.2.6/ui.cpp2+++ v0.2.7/ui.cpp3@@ -7,36 +7,16 @@4 #include <crtdbg.h>5 #endif6 7-bool GetStartOnSystemStartup();8-void SetStartOnSystemStartup(bool fAutoStart);9-10 11 12 DEFINE_EVENT_TYPE(wxEVT_UITHREADCALL)13 14 CMainFrame* pframeMain = NULL;15 CMyTaskBarIcon* ptaskbaricon = NULL;16-extern int g_isPainting;17 bool fClosedToTray = false;18 19-// Settings20-int fMinimizeToTray = true;21-int fMinimizeOnClose = true;22-23-24-25-26-int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)27-{28-    if (fDaemon)29-    {30-        printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());31-        fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());32-        return wxOK;33-    }34-    return wxMessageBox(message, caption, style, parent, x, y);35-}36-#define wxMessageBox  MyMessageBox37+38+39 40 41 42@@ -47,47 +27,6 @@43 //44 // Util45 //46-47-void ExitTimeout(void* parg)48-{49-#ifdef __WXMSW__50-    Sleep(5000);51-    ExitProcess(0);52-#endif53-}54-55-void Shutdown(void* parg)56-{57-    static CCriticalSection cs_Shutdown;58-    static bool fTaken;59-    bool fFirstThread;60-    CRITICAL_BLOCK(cs_Shutdown)61-    {62-        fFirstThread = !fTaken;63-        fTaken = true;64-    }65-    static bool fExit;66-    if (fFirstThread)67-    {68-        fShutdown = true;69-        nTransactionsUpdated++;70-        DBFlush(false);71-        StopNode();72-        DBFlush(true);73-        CreateThread(ExitTimeout, NULL);74-        Sleep(50);75-        printf("Bitcoin exiting\n\n");76-        fExit = true;77-        exit(0);78-    }79-    else80-    {81-        while (!fExit)82-            Sleep(500);83-        Sleep(100);84-        ExitThread(0);85-    }86-}87 88 void HandleCtrlA(wxKeyEvent& event)89 {90@@ -312,7 +251,7 @@91     m_staticTextBalance->SetSize(140, 17);92     // resize to fit ubuntu's huge default font93     dResize = 1.22;94-    SetSize(dResize * GetSize().GetWidth(), 1.09 * GetSize().GetHeight());95+    SetSize(dResize * GetSize().GetWidth(), 1.15 * GetSize().GetHeight());96 #endif97     m_staticTextBalance->SetLabel(FormatMoney(GetBalance()) + "  ");98     m_listCtrl->SetFocus();99@@ -1630,7 +1569,6 @@100 101 102 103-104 //////////////////////////////////////////////////////////////////////////////105 //106 // CAboutDialog107@@ -2014,7 +1952,7 @@108     // Make sure we have enough money109     if (nPrice + nTransactionFee > GetBalance())110     {111-        Error(_("You don't have enough money"));112+        Error(_("Insufficient funds"));113         return;114     }115 116@@ -2081,7 +2019,7 @@117             return;118         if (nPrice + nTransactionFee > GetBalance())119         {120-            Error(_("You don't have enough money"));121+            Error(_("Insufficient funds"));122             return;123         }124         CKey key;125@@ -2562,609 +2500,28 @@126 127 128 129-//////////////////////////////////////////////////////////////////////////////130-//131-// CMyApp132-//133-134-// Define a new application135-class CMyApp: public wxApp136-{137-public:138-    wxLocale m_locale;139-140-    CMyApp(){};141-    ~CMyApp(){};142-    bool OnInit();143-    bool OnInit2();144-    int OnExit();145-146-    // Hook Initialize so we can start without GUI147-    virtual bool Initialize(int& argc, wxChar** argv);148-149-    // 2nd-level exception handling: we get all the exceptions occurring in any150-    // event handler here151-    virtual bool OnExceptionInMainLoop();152-153-    // 3rd, and final, level exception handling: whenever an unhandled154-    // exception is caught, this function is called155-    virtual void OnUnhandledException();156-157-    // and now for something different: this function is called in case of a158-    // crash (e.g. dereferencing null pointer, division by 0, ...)159-    virtual void OnFatalException();160-};161-162-IMPLEMENT_APP(CMyApp)163-164-bool CMyApp::Initialize(int& argc, wxChar** argv)165-{166-    if (argc > 1 && argv[1][0] != '-' && (!fWindows || argv[1][0] != '/') &&167-        wxString(argv[1]) != "start")168-    {169-        fCommandLine = true;170-    }171-    else172-    {173-        // wxApp::Initialize will remove environment-specific parameters,174-        // so it's too early to call ParseParameters yet175-        for (int i = 1; i < argc; i++)176-        {177-            wxString str = argv[i];178-            #ifdef __WXMSW__179-            if (str.size() >= 1 && str[0] == '/')180-                str[0] = '-';181-            str = str.MakeLower();182-            #endif183-            // haven't decided which argument to use for this yet184-            if (str == "-daemon" || str == "-d" || str == "start")185-                fDaemon = true;186-        }187-    }188-189-#ifdef __WXGTK__190-    if (fDaemon || fCommandLine)191-    {192-        // Call the original Initialize while suppressing error messages193-        // and ignoring failure.  If unable to initialize GTK, it fails194-        // near the end so hopefully the last few things don't matter.195-        {196-            wxLogNull logNo;197-            wxApp::Initialize(argc, argv);198-        }199-200-        if (fDaemon)201-        {202-            fprintf(stdout, "bitcoin server starting\n");203-204-            // Daemonize205-            pid_t pid = fork();206-            if (pid < 0)207-            {208-                fprintf(stderr, "Error: fork() returned %d errno %d\n", pid, errno);209-                return false;210-            }211-            if (pid > 0)212-                pthread_exit((void*)0);213-        }214-215-        return true;216-    }217-#endif218-219-    return wxApp::Initialize(argc, argv);220-}221-222-bool CMyApp::OnInit()223-{224-    bool fRet = false;225-    try226-    {227-        fRet = OnInit2();228-    }229-    catch (std::exception& e) {230-        PrintException(&e, "OnInit()");231-    } catch (...) {232-        PrintException(NULL, "OnInit()");233-    }234-    if (!fRet)235-        Shutdown(NULL);236-    return fRet;237-}238-239-bool CMyApp::OnInit2()240-{241-#ifdef _MSC_VER242-    // Turn off microsoft heap dump noise243-    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);244-    _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0));245-#endif246-#if defined(__WXMSW__) && defined(__WXDEBUG__)247-    // Disable malfunctioning wxWidgets debug assertion248-    g_isPainting = 10000;249-#endif250-    wxImage::AddHandler(new wxPNGHandler);251-#ifdef __WXMSW__252-    SetAppName("Bitcoin");253-#else254-    SetAppName("bitcoin");255-    umask(077);256-#endif257-#ifdef __WXMSW__258-#if wxUSE_UNICODE259-    // Hack to set wxConvLibc codepage to UTF-8 on Windows,260-    // may break if wxMBConv_win32 implementation in strconv.cpp changes.261-    class wxMBConv_win32 : public wxMBConv262-    {263-    public:264-        long m_CodePage;265-        size_t m_minMBCharWidth;266-    };267-    if (((wxMBConv_win32*)&wxConvLibc)->m_CodePage == CP_ACP)268-        ((wxMBConv_win32*)&wxConvLibc)->m_CodePage = CP_UTF8;269-#endif270-#endif271-272-    // Load locale/<lang>/LC_MESSAGES/bitcoin.mo language file273-    m_locale.Init(wxLANGUAGE_DEFAULT, 0);274-    m_locale.AddCatalogLookupPathPrefix("locale");275-    if (!fWindows)276-    {277-        m_locale.AddCatalogLookupPathPrefix("/usr/share/locale");278-        m_locale.AddCatalogLookupPathPrefix("/usr/local/share/locale");279-    }280-    m_locale.AddCatalog("wxstd"); // wxWidgets standard translations, if any281-    m_locale.AddCatalog("bitcoin");282-283-    //284-    // Parameters285-    //286-    if (fCommandLine)287-    {288-        int ret = CommandLineRPC(argc, argv);289-        exit(ret);290-    }291-292-    ParseParameters(argc, argv);293-    if (mapArgs.count("-?") || mapArgs.count("--help"))294-    {295-        wxString strUsage = string() +296-            _("Usage: bitcoin [options]") + "\t\t\t\t\t\t\n" +297-            _("Options:\n") +298-            "  -gen            \t\t  " + _("Generate coins\n") +299-            "  -gen=0          \t\t  " + _("Don't generate coins\n") +300-            "  -min            \t\t  " + _("Start minimized\n") +301-            "  -datadir=<dir>  \t  "   + _("Specify data directory\n") +302-            "  -proxy=<ip:port>\t  "   + _("Connect through socks4 proxy\n") +303-            "  -addnode=<ip>   \t  "   + _("Add a node to connect to\n") +304-            "  -connect=<ip>   \t  "   + _("Connect only to the specified node\n") +305-            "  -?              \t\t  " + _("This help message\n");306-307-        if (fWindows)308-        {309-            // Remove spaces, the tabs make the columns line up in the message box310-            for (int i = 0; i < 50; i++)311-                strUsage.Replace(" \t", "\t");312-            wxMessageBox(strUsage, "Bitcoin", wxOK);313-        }314-        else315-        {316-            // Remove tabs317-            strUsage.Replace("\t", "");318-            fprintf(stderr, "%s", ((string)strUsage).c_str());319-        }320-        return false;321-    }322-323-    if (mapArgs.count("-datadir"))324-        strlcpy(pszSetDataDir, mapArgs["-datadir"].c_str(), sizeof(pszSetDataDir));325-326-    if (mapArgs.count("-debug"))327-        fDebug = true;328-329-    if (mapArgs.count("-printtodebugger"))330-        fPrintToDebugger = true;331-332-    if (!fDebug && !pszSetDataDir[0])333-        ShrinkDebugFile();334-    printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");335-    printf("Bitcoin version 0.%d.%d%s beta, OS version %s\n", VERSION/100, VERSION%100, pszSubVer, ((string)wxGetOsDescription()).c_str());336-    printf("System default language is %d %s\n", m_locale.GetSystemLanguage(), ((string)m_locale.GetSysName()).c_str());337-    printf("Language file %s (%s)\n", (string("locale/") + (string)m_locale.GetCanonicalName() + "/LC_MESSAGES/bitcoin.mo").c_str(), ((string)m_locale.GetLocale()).c_str());338-339-    if (mapArgs.count("-loadblockindextest"))340-    {341-        CTxDB txdb("r");342-        txdb.LoadBlockIndex();343-        PrintBlockTree();344-        return false;345-    }346-347-    //348-    // Limit to single instance per user349-    // Required to protect the database files if we're going to keep deleting log.*350-    //351-#ifdef __WXMSW__352-    // todo: wxSingleInstanceChecker wasn't working on Linux, never deleted its lock file353-    //  maybe should go by whether successfully bind port 8333 instead354-    wxString strMutexName = wxString("bitcoin_running.") + getenv("HOMEPATH");355-    for (int i = 0; i < strMutexName.size(); i++)356-        if (!isalnum(strMutexName[i]))357-            strMutexName[i] = '.';358-    wxSingleInstanceChecker* psingleinstancechecker = new wxSingleInstanceChecker(strMutexName);359-    if (psingleinstancechecker->IsAnotherRunning())360-    {361-        printf("Existing instance found\n");362-        unsigned int nStart = GetTime();363-        loop364-        {365-            // TODO: find out how to do this in Linux, or replace with wxWidgets commands366-            // Show the previous instance and exit367-            HWND hwndPrev = FindWindowA("wxWindowClassNR", "Bitcoin");368-            if (hwndPrev)369-            {370-                if (IsIconic(hwndPrev))371-                    ShowWindow(hwndPrev, SW_RESTORE);372-                SetForegroundWindow(hwndPrev);373-                return false;374-            }375-376-            if (GetTime() > nStart + 60)377-                return false;378-379-            // Resume this instance if the other exits380-            delete psingleinstancechecker;381-            Sleep(1000);382-            psingleinstancechecker = new wxSingleInstanceChecker(strMutexName);383-            if (!psingleinstancechecker->IsAnotherRunning())384-                break;385-        }386-    }387-#endif388-389-    // Bind to the port early so we can tell if another instance is already running.390-    // This is a backup to wxSingleInstanceChecker, which doesn't work on Linux.391-    string strErrors;392-    if (!BindListenPort(strErrors))393-    {394-        wxMessageBox(strErrors, "Bitcoin");395-        return false;396-    }397-398-    //399-    // Load data files400-    //401-    bool fFirstRun;402-    strErrors = "";403-    int64 nStart;404-405-    printf("Loading addresses...\n");406-    nStart = GetTimeMillis();407-    if (!LoadAddresses())408-        strErrors += _("Error loading addr.dat      \n");409-    printf(" addresses   %15"PRI64d"ms\n", GetTimeMillis() - nStart);410-411-    printf("Loading block index...\n");412-    nStart = GetTimeMillis();413-    if (!LoadBlockIndex())414-        strErrors += _("Error loading blkindex.dat      \n");415-    printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart);416-417-    printf("Loading wallet...\n");418-    nStart = GetTimeMillis();419-    if (!LoadWallet(fFirstRun))420-        strErrors += _("Error loading wallet.dat      \n");421-    printf(" wallet      %15"PRI64d"ms\n", GetTimeMillis() - nStart);422-423-    printf("Done loading\n");424-425-        //// debug print426-        printf("mapBlockIndex.size() = %d\n",   mapBlockIndex.size());427-        printf("nBestHeight = %d\n",            nBestHeight);428-        printf("mapKeys.size() = %d\n",         mapKeys.size());429-        printf("mapPubKeys.size() = %d\n",      mapPubKeys.size());430-        printf("mapWallet.size() = %d\n",       mapWallet.size());431-        printf("mapAddressBook.size() = %d\n",  mapAddressBook.size());432-433-    if (!strErrors.empty())434-    {435-        wxMessageBox(strErrors, "Bitcoin");436-        return false;437-    }438-439-    // Add wallet transactions that aren't already in a block to mapTransactions440-    ReacceptWalletTransactions();441-442-    //443-    // Parameters444-    //445-    if (mapArgs.count("-printblockindex") || mapArgs.count("-printblocktree"))446-    {447-        PrintBlockTree();448-        return false;449-    }450-451-    if (mapArgs.count("-printblock"))452-    {453-        string strMatch = mapArgs["-printblock"];454-        int nFound = 0;455-        for (map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi)456-        {457-            uint256 hash = (*mi).first;458-            if (strncmp(hash.ToString().c_str(), strMatch.c_str(), strMatch.size()) == 0)459-            {460-                CBlockIndex* pindex = (*mi).second;461-                CBlock block;462-                block.ReadFromDisk(pindex);463-                block.BuildMerkleTree();464-                block.print();465-                printf("\n");466-                nFound++;467-            }468-        }469-        if (nFound == 0)470-            printf("No blocks matching %s were found\n", strMatch.c_str());471-        return false;472-    }473-474-    if (mapArgs.count("-gen"))475-    {476-        if (mapArgs["-gen"].empty())477-            fGenerateBitcoins = true;478-        else479-            fGenerateBitcoins = (atoi(mapArgs["-gen"].c_str()) != 0);480-    }481-482-    if (mapArgs.count("-proxy"))483-    {484-        fUseProxy = true;485-        addrProxy = CAddress(mapArgs["-proxy"]);486-        if (!addrProxy.IsValid())487-        {488-            wxMessageBox(_("Invalid -proxy address"), "Bitcoin");489-            return false;490-        }491-    }492-493-    if (mapArgs.count("-addnode"))494-    {495-        foreach(string strAddr, mapMultiArgs["-addnode"])496-        {497-            CAddress addr(strAddr, NODE_NETWORK);498-            addr.nTime = 0; // so it won't relay unless successfully connected499-            if (addr.IsValid())500-                AddAddress(addr);501-        }502-    }503-504-    //505-    // Create the main frame window506-    //507-    if (!fDaemon)508-    {509-        pframeMain = new CMainFrame(NULL);510-        if (mapArgs.count("-min"))511-            pframeMain->Iconize(true);512-        pframeMain->Show(true);  // have to show first to get taskbar button to hide513-        if (fMinimizeToTray && pframeMain->IsIconized())514-            fClosedToTray = true;515-        pframeMain->Show(!fClosedToTray);516-        ptaskbaricon->Show(fMinimizeToTray || fClosedToTray);517-518-        CreateThread(ThreadDelayedRepaint, NULL);519-    }520-521-    if (!CheckDiskSpace())522-        return false;523-524-    RandAddSeedPerfmon();525-526-    if (!CreateThread(StartNode, NULL))527-        wxMessageBox("Error: CreateThread(StartNode) failed", "Bitcoin");528-529-    if (mapArgs.count("-server") || fDaemon)530-        CreateThread(ThreadRPCServer, NULL);531-532-    if (fFirstRun)533-        SetStartOnSystemStartup(true);534-535-536-    //537-    // Tests538-    //539-#ifdef __WXMSW__540-    if (argc >= 2 && stricmp(argv[1], "-send") == 0)541-#else542-    if (argc >= 2 && strcmp(argv[1], "-send") == 0)543-#endif544-    {545-        int64 nValue = 1;546-        if (argc >= 3)547-            ParseMoney(argv[2], nValue);548-549-        string strAddress;550-        if (argc >= 4)551-            strAddress = argv[3];552-        CAddress addr(strAddress);553-554-        CWalletTx wtx;555-        wtx.mapValue["to"] = strAddress;556-        wtx.mapValue["from"] = addrLocalHost.ToString();557-        wtx.mapValue["message"] = "command line send";558-559-        // Send to IP address560-        CSendingDialog* pdialog = new CSendingDialog(pframeMain, addr, nValue, wtx);561-        if (!pdialog->ShowModal())562-            return false;563-    }564-565-    return true;566-}567-568-int CMyApp::OnExit()569-{570-    Shutdown(NULL);571-    return wxApp::OnExit();572-}573-574-bool CMyApp::OnExceptionInMainLoop()575-{576-    try577-    {578-        throw;579-    }580-    catch (std::exception& e)581-    {582-        PrintException(&e, "CMyApp::OnExceptionInMainLoop()");583-        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());584-        Sleep(1000);585-        throw;586-    }587-    catch (...)588-    {589-        PrintException(NULL, "CMyApp::OnExceptionInMainLoop()");590-        wxLogWarning("Unknown exception");591-        Sleep(1000);592-        throw;593-    }594-    return true;595-}596-597-void CMyApp::OnUnhandledException()598-{599-    // this shows how we may let some exception propagate uncaught600-    try601-    {602-        throw;603-    }604-    catch (std::exception& e)605-    {606-        PrintException(&e, "CMyApp::OnUnhandledException()");607-        wxLogWarning("Exception %s %s", typeid(e).name(), e.what());608-        Sleep(1000);609-        throw;610-    }611-    catch (...)612-    {613-        PrintException(NULL, "CMyApp::OnUnhandledException()");614-        wxLogWarning("Unknown exception");615-        Sleep(1000);616-        throw;617-    }618-}619-620-void CMyApp::OnFatalException()621-{622-    wxMessageBox(_("Program has crashed and will terminate.  "), "Bitcoin", wxOK | wxICON_ERROR);623-}624-625-626-627-628-629-#ifdef __WXMSW__630-typedef WINSHELLAPI BOOL (WINAPI *PSHGETSPECIALFOLDERPATHA)(HWND hwndOwner, LPSTR lpszPath, int nFolder, BOOL fCreate);631-632-string MyGetSpecialFolderPath(int nFolder, bool fCreate)633-{634-    char pszPath[MAX_PATH+100] = "";635-636-    // SHGetSpecialFolderPath is not usually available on NT 4.0637-    HMODULE hShell32 = LoadLibraryA("shell32.dll");638-    if (hShell32)639-    {640-        PSHGETSPECIALFOLDERPATHA pSHGetSpecialFolderPath =641-            (PSHGETSPECIALFOLDERPATHA)GetProcAddress(hShell32, "SHGetSpecialFolderPathA");642-        if (pSHGetSpecialFolderPath)643-            (*pSHGetSpecialFolderPath)(NULL, pszPath, nFolder, fCreate);644-        FreeModule(hShell32);645-    }646-647-    // Backup option648-    if (pszPath[0] == '\0')649-    {650-        if (nFolder == CSIDL_STARTUP)651-        {652-            strcpy(pszPath, getenv("USERPROFILE"));653-            strcat(pszPath, "\\Start Menu\\Programs\\Startup");654-        }655-        else if (nFolder == CSIDL_APPDATA)656-        {657-            strcpy(pszPath, getenv("APPDATA"));658-        }659-    }660-661-    return pszPath;662-}663-664-string StartupShortcutPath()665-{666-    return MyGetSpecialFolderPath(CSIDL_STARTUP, true) + "\\Bitcoin.lnk";667-}668-669-bool GetStartOnSystemStartup()670-{671-    return wxFileExists(StartupShortcutPath());672-}673-674-void SetStartOnSystemStartup(bool fAutoStart)675-{676-    // If the shortcut exists already, remove it for updating677-    remove(StartupShortcutPath().c_str());678-679-    if (fAutoStart)680-    {681-        CoInitialize(NULL);682-683-        // Get a pointer to the IShellLink interface.684-        IShellLink* psl = NULL;685-        HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL,686-                                CLSCTX_INPROC_SERVER, IID_IShellLink,687-                                reinterpret_cast<void**>(&psl));688-689-        if (SUCCEEDED(hres))690-        {691-            // Get the current executable path692-            TCHAR pszExePath[MAX_PATH];693-            GetModuleFileName(NULL, pszExePath, sizeof(pszExePath));694-695-            // Set the path to the shortcut target696-            psl->SetPath(pszExePath);697-            PathRemoveFileSpec(pszExePath);698-            psl->SetWorkingDirectory(pszExePath);699-            psl->SetShowCmd(SW_SHOWMINNOACTIVE);700-701-            // Query IShellLink for the IPersistFile interface for702-            // saving the shortcut in persistent storage.703-            IPersistFile* ppf = NULL;704-            hres = psl->QueryInterface(IID_IPersistFile,705-                                       reinterpret_cast<void**>(&ppf));706-            if (SUCCEEDED(hres))707-            {708-                WCHAR pwsz[MAX_PATH];709-                // Ensure that the string is ANSI.710-                MultiByteToWideChar(CP_ACP, 0, StartupShortcutPath().c_str(), -1, pwsz, MAX_PATH);711-                // Save the link by calling IPersistFile::Save.712-                hres = ppf->Save(pwsz, TRUE);713-                ppf->Release();714-            }715-            psl->Release();716-        }717-        CoUninitialize();718-    }719-}720-#else721-bool GetStartOnSystemStartup() { return false; }722-void SetStartOnSystemStartup(bool fAutoStart) { }723-#endif724-725-726-727-728-729-730-731-732-733-734-735+736+737+738+void CreateMainWindow()739+{740+    pframeMain = new CMainFrame(NULL);741+    if (mapArgs.count("-min"))742+        pframeMain->Iconize(true);743+    pframeMain->Show(true);  // have to show first to get taskbar button to hide744+    if (fMinimizeToTray && pframeMain->IsIconized())745+        fClosedToTray = true;746+    pframeMain->Show(!fClosedToTray);747+    ptaskbaricon->Show(fMinimizeToTray || fClosedToTray);748+    CreateThread(ThreadDelayedRepaint, NULL);749+}750+751+752+753+754+755+756+757+758+759+

ui.h (modified)

1--- v0.2.6/ui.h2+++ v0.2.7/ui.h3@@ -4,23 +4,58 @@4 5 DECLARE_EVENT_TYPE(wxEVT_UITHREADCALL, -1)6 7-8-extern map<string, string> mapArgs;9-10-// Settings11-extern int fMinimizeToTray;12-extern int fMinimizeOnClose;13+#if wxUSE_GUI14+static const bool fGUI=true;15+#else16+static const bool fGUI=false;17+#endif18+19+inline int MyMessageBox(const wxString& message, const wxString& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1)20+{21+#if wxUSE_GUI22+    if (!fDaemon)23+        return wxMessageBox(message, caption, style, parent, x, y);24+#endif25+    printf("wxMessageBox %s: %s\n", string(caption).c_str(), string(message).c_str());26+    fprintf(stderr, "%s: %s\n", string(caption).c_str(), string(message).c_str());27+    return wxOK;28+}29+#define wxMessageBox  MyMessageBox30+31 32 33 34 void HandleCtrlA(wxKeyEvent& event);35 string FormatTxStatus(const CWalletTx& wtx);36 void UIThreadCall(boost::function0<void>);37-void MainFrameRepaint();38-void Shutdown(void* parg);39 int ThreadSafeMessageBox(const string& message, const string& caption="Message", int style=wxOK, wxWindow* parent=NULL, int x=-1, int y=-1);40 bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent);41-42+void MainFrameRepaint();43+void CreateMainWindow();44+45+46+47+48+49+#if !wxUSE_GUI50+inline int ThreadSafeMessageBox(const string& message, const string& caption, int style, wxWindow* parent, int x, int y)51+{52+    return MyMessageBox(message, caption, style, parent, x, y);53+}54+55+inline bool ThreadSafeAskFee(int64 nFeeRequired, const string& strCaption, wxWindow* parent)56+{57+    return true;58+}59+60+inline void MainFrameRepaint()61+{62+}63+64+inline void CreateMainWindow()65+{66+}67+#else // wxUSE_GUI68 69 70 71@@ -332,3 +367,5 @@72 DECLARE_EVENT_TABLE()73 };74 75+#endif // wxUSE_GUI76+

util.cpp (modified)

1--- v0.2.6/util.cpp2+++ v0.2.7/util.cpp3@@ -459,6 +459,7 @@4         mapCache[pszEnglish] = pszCached;5         return pszCached;6     }7+    return NULL;8 }9 10 11@@ -502,8 +503,8 @@12     FormatException(pszMessage, pex, pszThread);13     printf("\n\n************************\n%s\n", pszMessage);14     fprintf(stderr, "\n\n************************\n%s\n", pszMessage);15-    if (wxTheApp && !fDaemon)16-        wxMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);17+    if (wxTheApp && !fDaemon && fGUI)18+        MyMessageBox(pszMessage, "Error", wxOK | wxICON_ERROR);19     throw;20     //DebugBreak();21 }
0:000:00