Skip to content

Commit 6a110fa

Browse files
committed
Fix Windows folder issue
1 parent 4b97488 commit 6a110fa

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
## Changes compared to v2.1.0.5702_dev
4646

47-
- pending
47+
- EmuGUI now utilises the Win32 API on Windows. This is to fix an issue where EmuGUI is not able to determine the Documents folder properly.
4848

4949
## Known issues
5050

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
import os
22
import sqlite3
33
from pathlib import Path
4+
from win32com.shell import shell, shellcon
45

56
def setupWindowsBackend():
67
connection = None
78

89
try:
9-
connection = sqlite3.connect(f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\virtual_machines.sqlite")
10+
connection = sqlite3.connect(f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\virtual_machines.sqlite")
1011
print("Connection established.")
1112

1213
except sqlite3.Error as e:
1314
print(f"The SQLite module encountered an error: {e}. Trying to create the file.")
1415

1516
try:
1617
windowsCreEmuGUIFolder()
17-
file = open(f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\virtual_machines.sqlite", "w+")
18+
file = open(f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\virtual_machines.sqlite", "w+")
1819
file.close()
1920

2021
except:
2122
print("EmuGUI wasn't able to create the file.")
2223

2324
try:
24-
connection = sqlite3.connect(f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\virtual_machines.sqlite")
25+
connection = sqlite3.connect(f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\virtual_machines.sqlite")
2526
print("Connection established.")
2627

2728
except sqlite3.Error as e:
@@ -30,30 +31,30 @@ def setupWindowsBackend():
3031
return connection
3132

3233
def windowsTempVmStarterFile():
33-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\vmstart.txt"
34+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\vmstart.txt"
3435
return fileName
3536

3637
def windowsLanguageFile():
37-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\lang.txt"
38+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\lang.txt"
3839
return fileName
3940

4041
def windowsUpdateFile():
41-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\update.txt"
42+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\update.txt"
4243
return fileName
4344

4445
def windowsExportFile():
45-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\vmdef.txt"
46+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\vmdef.txt"
4647
return fileName
4748

4849
def windowsErrorFile():
49-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\error.txt"
50+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\error.txt"
5051

5152
return fileName
5253

5354
def windowsLogFile(logID):
54-
fileName = f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI\\log-{logID}.txt"
55+
fileName = f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI\\log-{logID}.txt"
5556

5657
return fileName
5758

5859
def windowsCreEmuGUIFolder():
59-
Path(f"{os.environ['USERPROFILE']}\\Documents\\EmuGUI").mkdir(parents=True, exist_ok=True)
60+
Path(f"{shell.SHGetFolderPath(0,shellcon.CSIDL_PERSONAL, None, 0)}\\EmuGUI").mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)