cwoac / TTS-Manager

Import/Export Mods from Tabletop Simulator
MIT License
24 stars 10 forks source link

Use of os.path doesn't show custom my documents locations #38

Open Goldendawn69 opened 3 years ago

Goldendawn69 commented 3 years ago

Hi,

It would appear that os.path.expanduser doesn't find the directories you are looking for when that default directory has been changed. For me, I have moved that using windows Location to H drive.

When you try to set up the TTS Install location, it gives the error: 2021-07-19 12:43:17,041 - ERROR - TTS Dir missing: C:\Users\OEM\Documents\My Games\Tabletop Simulator\Saves

This is also noticed here: https://stackoverflow.com/questions/6227590/finding-the-users-my-documents-path

So for example I would think you need to find where the My Documents is located first. This is an example I took from : https://stackoverflow.com/questions/3858851/python-get-windows-special-folders-for-currently-logged-in-user

Should you wish to do it without the win32 extensions, you can use ctypes to call SHGetFolderPath:

>>> import ctypes.wintypes
>>> CSIDL_PERSONAL= 5       # My Documents
>>> SHGFP_TYPE_CURRENT= 0   # Want current, not default value

>>> buf= ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
>>> ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, buf)
0
>>> buf.value
'H:\\My Documents'

I have run this myself and proved it worked - though not sure how to add this into code to be honest.

I am assuming it is in the filesystem.py that this would need to be identified first. Before the line:

  if platform.system() == 'Windows':
    basepath = os.path.join(os.path.expanduser("~"),"Documents","My Games","Tabletop Simulator")

I made the following changes to my code download, but for some reason I cannot Push the changes for you to view in GIT, and review and decide to merge into your base code :(

At start of Filesystem.py

if platform.system() == 'Windows':
   import ctypes.wintypes
def standard_basepath():
  if platform.system() == 'Windows':
    CSIDL_PERSONAL = 5
    SHGFP_TYPE_CURRENT= 0 
    buf = ctypes.create_unicode_buffer(ctypes.wintypes.MAX_PATH)
    ctypes.windll.shell32.SHGetFolderPathW(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, buf)
    basepath = os.path.join(buf.value,"My Games","Tabletop Simulator")
    #basepath = os.path.join(os.path.expanduser("~"),"Documents","My Games","Tabletop Simulator")