-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsaving_system.py
More file actions
54 lines (44 loc) · 1.76 KB
/
saving_system.py
File metadata and controls
54 lines (44 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from cryptography.fernet import Fernet
from datetime import datetime as dt
from sys import platform
import asyncio
import os
"""
This script creates the folders necessary to hold save files and the encryption key
for save files in a cross-platform way.
"""
game_path = os.getcwd()
saves_path = os.path.join(game_path, "saves")
if platform == "win32":
game_appdata_path = os.path.join(os.environ.get("APPDATA"), "The Amazing Text Adventure")
key_path = os.path.join(game_appdata_path, "key.agkey")
if "The Amazing Text Adventure" not in os.listdir(os.environ.get("APPDATA")):
try:
os.mkdir(game_appdata_path)
except Exception as e:
print("Could not create AppData folder!\nException: " + str(e))
else:
game_appdata_path = os.path.join(os.getcwd(), "AppData")
key_path = os.path.join(game_appdata_path, "key.agkey")
if "AppData" not in os.listdir(game_path):
try:
os.mkdir(game_appdata_path)
except Exception as e:
print("Could not create AppData folder!\nException: " + str(e))
if "saves" not in os.listdir(game_path):
os.mkdir(saves_path)
# if "The Amazing Text Adventure" not in os.listdir(documents_folder):
# os.mkdir(game_path)
# os.mkdir(saves_path)
if "key.agkey" not in os.listdir(game_appdata_path):
with open(key_path, "wb") as skey:
key = Fernet.generate_key()
skey.write(key)
with open(key_path, "rb") as skey:
key = skey.read()
fernet_key = Fernet(key)
def string_to_binary(string):
return bin(int.from_bytes(string.encode(), "big"))
def binary_to_string(string):
int_string = int(string, 2)
return int_string.to_bytes((int_string.bit_length() + 7) // 8, "big").decode()