11import os
22import sqlite3
33from pathlib import Path
4+ from win32com .shell import shell , shellcon
45
56def 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
3233def 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
3637def 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
4041def 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
4445def 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
4849def 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
5354def 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
5859def 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