Merge pull request #167 from fsb4000/Выравнивание
[novacoin.git] / src / init.cpp
index 296369d..22d345f 100644 (file)
@@ -86,6 +86,7 @@ void Shutdown(void* parg)
     if (fFirstThread)
     {
         fShutdown = true;
+        fRequestShutdown = true;
         nTransactionsUpdated++;
 //        CTxDB().Close();
         bitdb.Flush(false);
@@ -273,7 +274,7 @@ std::string HelpMessage()
         "  -detachdb              " + _("Detach block and address databases. Increases shutdown time (default: 0)") + "\n" +
 
 #ifdef DB_LOG_IN_MEMORY
-        "  -memorylog              " + _("Use in-memory logging for block index database (default: 1)") + "\n" +
+        "  -memorylog             " + _("Use in-memory logging for block index database (default: 1)") + "\n" +
 #endif
 
         "  -paytxfee=<amt>        " + _("Fee per KB to add to transactions you send") + "\n" +
@@ -766,12 +767,36 @@ bool AppInit2()
         return false;
     }
 
-    uiInterface.InitMessage(_("Loading block index..."));
+
     printf("Loading block index...\n");
-    nStart = GetTimeMillis();
-    if (!LoadBlockIndex())
-        return InitError(_("Error loading blkindex.dat"));
+    bool fLoaded = false;
+    while (!fLoaded) {
+        std::string strLoadError;
+        uiInterface.InitMessage(_("Loading block index..."));
+
+        nStart = GetTimeMillis();
+        do {
+            try {
+                UnloadBlockIndex();
+
+                if (!LoadBlockIndex()) {
+                    strLoadError = _("Error loading block database");
+                    break;
+                }
+            } catch(std::exception &e) {
+                (void)e;
+                strLoadError = _("Error opening block database");
+                break;
+            }
+
+            fLoaded = true;
+        } while(false);
 
+        if (!fLoaded) {
+            // TODO: suggest reindex here
+            return InitError(strLoadError);
+        }
+    }
 
     // as LoadBlockIndex can take several minutes, it's possible the user
     // requested to kill bitcoin-qt during the last operation. If so, exit.