From 86ce3de50dd2eadf5dd79501506729e561438cf3 Mon Sep 17 00:00:00 2001
From: DivineOmega
Date: Thu, 27 Jun 2013 10:42:03 +0100
Subject: [PATCH] Refactored config file (keys.dat) mangement to use
helper_config.py and not specify filename throughout code
---
src/api_client.py | 2 +-
src/bitmessagemain.py | 8 +--
src/bitmessageqt/__init__.py | 65 +++++++++------------
src/bitmessageqt/newaddressdialog.py | 2 +-
src/class_addressGenerator.py | 7 +--
src/class_singleWorker.py | 18 +++---
src/class_sqlThread.py | 13 ++---
src/helper_bootstrap.py | 3 +-
src/{helper_startup.py => helper_config.py} | 25 ++++++--
src/shared.py | 3 +-
10 files changed, 71 insertions(+), 75 deletions(-)
rename src/{helper_startup.py => helper_config.py} (87%)
diff --git a/src/api_client.py b/src/api_client.py
index e07258d5..ceaae293 100644
--- a/src/api_client.py
+++ b/src/api_client.py
@@ -35,7 +35,7 @@ print 'Uncomment these next four lines to create new deterministic addresses.'
#print jsonDeterministicAddresses
#print json.loads(jsonDeterministicAddresses)
-#print 'Uncomment this next line to print the first deterministic address that would be generated with the given passphrase. This will Not add it to the Bitmessage interface or the keys.dat file.'
+#print 'Uncomment this next line to print the first deterministic address that would be generated with the given passphrase. This will Not add it to the Bitmessage interface or the '+helper_config.getFileName()+' file.'
#print api.getDeterministicAddress('asdfasdfqwser'.encode('base64'),3,1)
#print 'Uncomment this line to subscribe to an address. (You must use your own address, this one is invalid).'
diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py
index c4c2b6db..f7f67aaa 100644
--- a/src/bitmessagemain.py
+++ b/src/bitmessagemain.py
@@ -26,7 +26,7 @@ from class_singleListener import *
from class_addressGenerator import *
# Helper Functions
-import helper_startup
+import helper_config
import helper_bootstrap
def connectToStream(streamNumber):
@@ -496,7 +496,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
fromAddressEnabled = shared.config.getboolean(
fromAddress, 'enabled')
except:
- return 'API Error 0013: Could not find your fromAddress in the keys.dat file.'
+ return 'API Error 0013: Could not find your fromAddress in the '+helper_config.getFileName()+' file.'
if not fromAddressEnabled:
return 'API Error 0014: Your fromAddress is disabled. Cannot send.'
@@ -560,7 +560,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
fromAddressEnabled = shared.config.getboolean(
fromAddress, 'enabled')
except:
- return 'API Error 0013: could not find your fromAddress in the keys.dat file.'
+ return 'API Error 0013: could not find your fromAddress in the '+helper_config.getFileName()+' file.'
ackdata = OpenSSL.rand(32)
toAddress = '[Broadcast subscribers]'
ripe = ''
@@ -706,7 +706,7 @@ if __name__ == "__main__":
signal.signal(signal.SIGINT, helper_generic.signal_handler)
# signal.signal(signal.SIGINT, signal.SIG_DFL)
- helper_startup.loadConfig()
+ helper_config.loadConfig()
helper_bootstrap.knownNodes()
helper_bootstrap.dns()
diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py
index ce477836..99f717fc 100644
--- a/src/bitmessageqt/__init__.py
+++ b/src/bitmessageqt/__init__.py
@@ -29,6 +29,7 @@ import os
from pyelliptic.openssl import OpenSSL
import pickle
import platform
+import helper_config
try:
from PyQt4 import QtCore, QtGui
@@ -72,11 +73,10 @@ class MyForm(QtGui.QMainWindow):
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
shared.config.remove_section(addressInKeysFile)
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig();
# Configure Bitmessage to start on startup (or remove the
- # configuration) based on the setting in the keys.dat file
+ # configuration) based on the setting in the config file
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
RUN_PATH = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
@@ -924,23 +924,19 @@ class MyForm(QtGui.QMainWindow):
def click_actionManageKeys(self):
if 'darwin' in sys.platform or 'linux' in sys.platform:
if shared.appdata == '':
- # reply = QtGui.QMessageBox.information(self, 'keys.dat?','You
- # may manage your keys by editing the keys.dat file stored in
- # the same directory as this program. It is important that you
- # back up this file.', QMessageBox.Ok)
- reply = QtGui.QMessageBox.information(self, 'keys.dat?', _translate(
- "MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file."), QMessageBox.Ok)
+ reply = QtGui.QMessageBox.information(self, helper_config.getFileName()+'?', _translate(
+ "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in the same directory as this program. It is important that you back up this file."), QMessageBox.Ok)
else:
- QtGui.QMessageBox.information(self, 'keys.dat?', _translate(
- "MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file.").arg(shared.appdata), QMessageBox.Ok)
+ QtGui.QMessageBox.information(self, helper_config.getFileName()+'?', _translate(
+ "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in\n %1 \nIt is important that you back up this file.").arg(shared.appdata), QMessageBox.Ok)
elif sys.platform == 'win32' or sys.platform == 'win64':
if shared.appdata == '':
- reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate(
- "MainWindow", "You may manage your keys by editing the keys.dat file stored in the same directory as this program. It is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
+ reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open "+helper_config.getFileName()+"?"), _translate(
+ "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in the same directory as this program. It is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)"), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
else:
- reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open keys.dat?"), _translate(
- "MainWindow", "You may manage your keys by editing the keys.dat file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(shared.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
+ reply = QtGui.QMessageBox.question(self, _translate("MainWindow", "Open "+helper_config.getFileName()+"?"), _translate(
+ "MainWindow", "You may manage your keys by editing the "+helper_config.getFileName()+" file stored in\n %1 \nIt is important that you back up this file. Would you like to open the file now? (Be sure to close Bitmessage before making any changes.)").arg(shared.appdata), QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.openKeysFile()
@@ -974,9 +970,9 @@ class MyForm(QtGui.QMainWindow):
def openKeysFile(self):
if 'linux' in sys.platform:
- subprocess.call(["xdg-open", shared.appdata + 'keys.dat'])
+ subprocess.call(["xdg-open", helper_config.getFilepath()])
else:
- os.startfile(shared.appdata + 'keys.dat')
+ os.startfile(helper_config.getFilepath())
def changeEvent(self, event):
if event.type() == QtCore.QEvent.WindowStateChange:
@@ -1783,8 +1779,7 @@ class MyForm(QtGui.QMainWindow):
# shared.config.set('bitmessagesettings', 'maxcores',
# str(self.settingsDialogInstance.ui.comboBoxMaxCores.currentText()))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
if 'win32' in sys.platform or 'win64' in sys.platform:
# Auto-startup for Windows
@@ -1802,19 +1797,18 @@ class MyForm(QtGui.QMainWindow):
pass
if shared.appdata != '' and self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we are NOT using portable mode now but the user selected that we should...
- # Write the keys.dat file to disk in the new location
+ # Write the config file to disk in the new location
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('movemessagstoprog')
shared.sqlLock.release()
- with open('keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# Write the knownnodes.dat file to disk in the new location
shared.knownNodesLock.acquire()
output = open('knownnodes.dat', 'wb')
pickle.dump(shared.knownNodes, output)
output.close()
shared.knownNodesLock.release()
- os.remove(shared.appdata + 'keys.dat')
+ os.remove(shared.appdata + helper_config.getFileName())
os.remove(shared.appdata + 'knownnodes.dat')
shared.appdata = ''
@@ -1825,23 +1819,21 @@ class MyForm(QtGui.QMainWindow):
shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('movemessagstoappdata')
shared.sqlLock.release()
- # Write the keys.dat file to disk in the new location
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ # Write the config file to disk in the new location
+ helper_config.saveConfig()
# Write the knownnodes.dat file to disk in the new location
shared.knownNodesLock.acquire()
output = open(shared.appdata + 'knownnodes.dat', 'wb')
pickle.dump(shared.knownNodes, output)
output.close()
shared.knownNodesLock.release()
- os.remove('keys.dat')
+ os.remove(helper_config.getFileName())
os.remove('knownnodes.dat')
def click_radioButtonBlacklist(self):
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white':
shared.config.set('bitmessagesettings', 'blackwhitelist', 'black')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# self.ui.tableWidgetBlacklist.clearContents()
self.ui.tableWidgetBlacklist.setRowCount(0)
self.loadBlackWhiteList()
@@ -1850,8 +1842,7 @@ class MyForm(QtGui.QMainWindow):
def click_radioButtonWhitelist(self):
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'black':
shared.config.set('bitmessagesettings', 'blackwhitelist', 'white')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# self.ui.tableWidgetBlacklist.clearContents()
self.ui.tableWidgetBlacklist.setRowCount(0)
self.loadBlackWhiteList()
@@ -1931,8 +1922,7 @@ class MyForm(QtGui.QMainWindow):
shared.config.set(str(addressAtCurrentRow), 'mailinglistname', str(
self.dialog.ui.lineEditMailingListName.text().toUtf8()))
self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
self.rerenderInboxToLabels()
def click_NewAddressDialog(self):
@@ -2442,8 +2432,7 @@ class MyForm(QtGui.QMainWindow):
addressAtCurrentRow = str(
self.ui.tableWidgetYourIdentities.item(currentRow, 1).text())
shared.config.set(addressAtCurrentRow, 'enabled', 'true')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
self.ui.tableWidgetYourIdentities.item(
currentRow, 0).setTextColor(QtGui.QColor(0, 0, 0))
self.ui.tableWidgetYourIdentities.item(
@@ -2467,8 +2456,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 2).setTextColor(QtGui.QColor(128, 128, 128))
if shared.safeConfigGetBoolean(addressAtCurrentRow, 'mailinglist'):
self.ui.tableWidgetYourIdentities.item(currentRow, 1).setTextColor(QtGui.QColor(137, 04, 177))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
shared.reloadMyAddressHashes()
def on_action_YourIdentitiesClipboard(self):
@@ -2561,8 +2549,7 @@ class MyForm(QtGui.QMainWindow):
currentRow, 1).text()
shared.config.set(str(addressAtCurrentRow), 'label', str(
self.ui.tableWidgetYourIdentities.item(currentRow, 0).text().toUtf8()))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
self.rerenderComboBoxSendFrom()
# self.rerenderInboxFromLabels()
self.rerenderInboxToLabels()
diff --git a/src/bitmessageqt/newaddressdialog.py b/src/bitmessageqt/newaddressdialog.py
index f9bf9203..474a0af3 100644
--- a/src/bitmessageqt/newaddressdialog.py
+++ b/src/bitmessageqt/newaddressdialog.py
@@ -173,7 +173,7 @@ class Ui_NewAddressDialog(object):
NewAddressDialog.setWindowTitle(_translate("NewAddressDialog", "Create new Address", None))
self.label.setText(_translate("NewAddressDialog", "Here you may generate as many addresses as you like. Indeed, creating and abandoning addresses is encouraged. You may generate addresses by using either random numbers or by using a passphrase. If you use a passphrase, the address is called a \"deterministic\" address.\n"
"The \'Random Number\' option is selected by default but deterministic addresses have several pros and cons:", None))
- self.label_5.setText(_translate("NewAddressDialog", "
Pros:
You can recreate your addresses on any computer from memory.
You need-not worry about backing up your keys.dat file as long as you can remember your passphrase.
Cons:
You must remember (or write down) your passphrase if you expect to be able to recreate your keys if they are lost.
You must remember the address version number and the stream number along with your passphrase.
If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you.
", None))
+ self.label_5.setText(_translate("NewAddressDialog", "Pros:
You can recreate your addresses on any computer from memory.
You need-not worry about backing up your private keys as long as you can remember your passphrase.
Cons:
You must remember (or write down) your passphrase if you expect to be able to recreate your keys if they are lost.
You must remember the address version number and the stream number along with your passphrase.
If you choose a weak passphrase and someone on the Internet can brute-force it, they can read your messages and send messages as you.
", None))
self.radioButtonRandomAddress.setText(_translate("NewAddressDialog", "Use a random number generator to make an address", None))
self.radioButtonDeterministicAddress.setText(_translate("NewAddressDialog", "Use a passphrase to make addresses", None))
self.checkBoxEighteenByteRipe.setText(_translate("NewAddressDialog", "Spend several minutes of extra computing time to make the address(es) 1 or 2 characters shorter", None))
diff --git a/src/class_addressGenerator.py b/src/class_addressGenerator.py
index 08c7773e..323d17e1 100644
--- a/src/class_addressGenerator.py
+++ b/src/class_addressGenerator.py
@@ -9,6 +9,7 @@ import highlevelcrypto
from addresses import *
from pyelliptic import arithmetic
import tr
+import helper_config
class addressGenerator(threading.Thread):
@@ -114,8 +115,7 @@ class addressGenerator(threading.Thread):
address, 'privSigningKey', privSigningKeyWIF)
shared.config.set(
address, 'privEncryptionKey', privEncryptionKeyWIF)
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# It may be the case that this address is being generated
# as a result of a call to the API. Let us put the result
@@ -226,8 +226,7 @@ class addressGenerator(threading.Thread):
address, 'privSigningKey', privSigningKeyWIF)
shared.config.set(
address, 'privEncryptionKey', privEncryptionKeyWIF)
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
shared.UISignalQueue.put(('writeNewAddressToTable', (
label, address, str(streamNumber))))
diff --git a/src/class_singleWorker.py b/src/class_singleWorker.py
index 13cceb9e..9e0f073b 100644
--- a/src/class_singleWorker.py
+++ b/src/class_singleWorker.py
@@ -125,7 +125,7 @@ class singleWorker(threading.Thread):
except Exception as err:
shared.printLock.acquire()
sys.stderr.write(
- 'Error within doPOWForMyV2Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err)
+ 'Error within doPOWForMyV2Pubkey. Could not read the keys from the '+helper_config.getFileName()+' file for a requested address. %s\n' % err)
shared.printLock.release()
return
@@ -170,8 +170,7 @@ class singleWorker(threading.Thread):
shared.UISignalQueue.put(('updateStatusBar', ''))
shared.config.set(
myAddress, 'lastpubkeysendtime', str(int(time.time())))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
def doPOWForMyV3Pubkey(self, hash): # This function also broadcasts out the pubkey message once it is done with the POW
myAddress = shared.myAddressesByHash[hash]
@@ -192,7 +191,7 @@ class singleWorker(threading.Thread):
except Exception as err:
shared.printLock.acquire()
sys.stderr.write(
- 'Error within doPOWForMyV3Pubkey. Could not read the keys from the keys.dat file for a requested address. %s\n' % err)
+ 'Error within doPOWForMyV3Pubkey. Could not read the keys from the '+helper_config.getFileName()+' file for a requested address. %s\n' % err)
shared.printLock.release()
return
@@ -246,8 +245,7 @@ class singleWorker(threading.Thread):
shared.UISignalQueue.put(('updateStatusBar', ''))
shared.config.set(
myAddress, 'lastpubkeysendtime', str(int(time.time())))
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
def sendBroadcast(self):
shared.sqlLock.acquire()
@@ -271,7 +269,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey')
except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
- ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
+ ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -345,7 +343,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey')
except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
- ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
+ ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -639,7 +637,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey')
except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
- ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
+ ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue
privSigningKeyHex = shared.decodeWalletImportFormat(
@@ -685,7 +683,7 @@ class singleWorker(threading.Thread):
fromaddress, 'privencryptionkey')
except:
shared.UISignalQueue.put(('updateSentItemStatusByAckdata', (
- ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the keys.dat file."))))
+ ackdata, tr.translateText("MainWindow", "Error! Could not find sender address (your address) in the "+helper_config.getFileName()+" file."))))
continue
privSigningKeyHex = shared.decodeWalletImportFormat(
diff --git a/src/class_sqlThread.py b/src/class_sqlThread.py
index ebe6a7ff..67904d71 100644
--- a/src/class_sqlThread.py
+++ b/src/class_sqlThread.py
@@ -5,6 +5,7 @@ import time
import shutil # used for moving the messages.dat file
import sys
import os
+import helper_config
# This thread exists because SQLITE3 is so un-threadsafe that we must
# submit queries to it and it puts results back in a different queue. They
@@ -82,8 +83,7 @@ class sqlThread(threading.Thread):
shared.config.set('bitmessagesettings', 'sockspassword', '')
shared.config.set('bitmessagesettings', 'keysencrypted', 'false')
shared.config.set('bitmessagesettings', 'messagesencrypted', 'false')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# People running earlier versions of PyBitmessage do not have the
# usedpersonally field in their pubkeys table. Let's add it.
@@ -94,8 +94,7 @@ class sqlThread(threading.Thread):
self.conn.commit()
shared.config.set('bitmessagesettings', 'settingsversion', '3')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# People running earlier versions of PyBitmessage do not have the
# encodingtype field in their inbox and sent tables or the read field
@@ -115,8 +114,7 @@ class sqlThread(threading.Thread):
self.conn.commit()
shared.config.set('bitmessagesettings', 'settingsversion', '4')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
if shared.config.getint('bitmessagesettings', 'settingsversion') == 4:
shared.config.set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(
@@ -131,8 +129,7 @@ class sqlThread(threading.Thread):
shared.config.set(
'bitmessagesettings', 'maxacceptablepayloadlengthextrabytes', '0')
shared.config.set('bitmessagesettings', 'settingsversion', '6')
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+ helper_config.saveConfig()
# From now on, let us keep a 'version' embedded in the messages.dat
# file so that when we make changes to the database, the database
diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py
index 296dda6b..b9cc1893 100644
--- a/src/helper_bootstrap.py
+++ b/src/helper_bootstrap.py
@@ -3,6 +3,7 @@ import socket
import defaultKnownNodes
import pickle
import time
+import helper_config
def knownNodes():
try:
@@ -17,7 +18,7 @@ def knownNodes():
shared.knownNodes = pickle.load(pickleFile)
pickleFile.close()
if shared.config.getint('bitmessagesettings', 'settingsversion') > 6:
- print 'Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.'
+ print 'Bitmessage cannot read future versions of the keys file ('+helper_config.getFileName()+'). Run the newer version of Bitmessage.'
raise SystemExit
diff --git a/src/helper_startup.py b/src/helper_config.py
similarity index 87%
rename from src/helper_startup.py
rename to src/helper_config.py
index e6590b0e..08878209 100644
--- a/src/helper_startup.py
+++ b/src/helper_config.py
@@ -4,21 +4,28 @@ import sys
import os
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder.
+filename = 'keys.dat'
+
+def getFileName():
+ return filename
+
+def getFilePath():
+ return shared.appdata + filename
def loadConfig():
- # First try to load the config file (the keys.dat file) from the program
+ # First try to load the config file (as defiend in 'filename') from the program
# directory
- shared.config.read('keys.dat')
+ shared.config.read(getFilePath())
try:
shared.config.get('bitmessagesettings', 'settingsversion')
print 'Loading config files from same directory as program'
shared.appdata = ''
except:
- # Could not load the keys.dat file in the program directory. Perhaps it
+ # Could not load the config file in the program directory. Perhaps it
# is in the appdata directory.
shared.appdata = shared.lookupAppdataFolder()
shared.config = ConfigParser.SafeConfigParser()
- shared.config.read(shared.appdata + 'keys.dat')
+ shared.config.read(getFilePath())
try:
shared.config.get('bitmessagesettings', 'settingsversion')
print 'Loading existing config files from', shared.appdata
@@ -74,5 +81,11 @@ def loadConfig():
print 'Creating new config files in', shared.appdata
if not os.path.exists(shared.appdata):
os.makedirs(shared.appdata)
- with open(shared.appdata + 'keys.dat', 'wb') as configfile:
- shared.config.write(configfile)
+
+ saveConfig();
+
+
+def saveConfig():
+
+ with open(getFilePath(), 'wb') as configfile:
+ shared.config.write(configfile)
\ No newline at end of file
diff --git a/src/shared.py b/src/shared.py
index 4b3ef73b..feddaf56 100644
--- a/src/shared.py
+++ b/src/shared.py
@@ -21,6 +21,7 @@ import socket
import random
import highlevelcrypto
import shared
+import helper_config
config = ConfigParser.SafeConfigParser()
myECCryptorObjects = {}
@@ -201,7 +202,7 @@ def decodeWalletImportFormat(WIFstring):
def reloadMyAddressHashes():
printLock.acquire()
- print 'reloading keys from keys.dat file'
+ print 'reloading keys from '+helper_config.getFileName()+' file'
printLock.release()
myECCryptorObjects.clear()
myAddressesByHash.clear()