~cadence/crumpet

8e4de0faa7b2e2a676a143d35cd5e477e26443f3 — Cadence Ember 1 year, 2 months ago 84a1d21
Reset configuration in the case of corruption
1 files changed, 17 insertions(+), 4 deletions(-)

M crumpet.py
M crumpet.py => crumpet.py +17 -4
@@ 8,10 8,23 @@ import shutil

content_host = "https://cadence.moe"

db = shelve.open("crumpet_server_config", writeback=False)
db.setdefault("game_directory", None)
db.setdefault("customlevels_directory", None)
db.setdefault("is_installed", True)
db = None
def init_database():
	global db
	db = shelve.open("crumpet_server_config", writeback=False)
	db.setdefault("game_directory", None)
	db.setdefault("customlevels_directory", None)
	db.setdefault("is_installed", True)

try:
	init_database()
except:
	# database corruption error? HOW??? do I actually need to close the file like it told me
	# because I don't know how to close the file like it told me
	print("resetting server configuration due to database corruption")
	db.close()
	os.unlink("crumpet_server_config")
	init_database()

def hash_file(filename):
	h = hashlib.sha256()