try catch getting music folder from reg registry

This commit is contained in:
RemixDev 2021-12-21 15:13:27 +01:00
parent 8be934fb42
commit 6a6ec400db
No known key found for this signature in database
GPG Key ID: B33962B465BDB51C
1 changed files with 13 additions and 10 deletions

View File

@ -52,16 +52,19 @@ def getMusicFolder():
musicdata = Path(os.path.expandvars(musicdata)) musicdata = Path(os.path.expandvars(musicdata))
musicdata = checkPath(musicdata) musicdata = checkPath(musicdata)
if os.name == 'nt' and musicdata == "": if os.name == 'nt' and musicdata == "":
musicKeys = ['My Music', '{4BD8D571-6D19-48D3-BE97-422220080E43}'] try:
regData = os.popen(r'reg.exe query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"').read().split('\r\n') musicKeys = ['My Music', '{4BD8D571-6D19-48D3-BE97-422220080E43}']
for i, line in enumerate(regData): regData = os.popen(r'reg.exe query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"').read().split('\r\n')
if line == "": continue for i, line in enumerate(regData):
if i == 1: continue if line == "": continue
line = line.split(' ') if i == 1: continue
if line[1] in musicKeys: line = line.split(' ')
musicdata = Path(line[3]) if line[1] in musicKeys:
break musicdata = Path(line[3])
musicdata = checkPath(musicdata) break
musicdata = checkPath(musicdata)
except Exception:
musicdata = ""
if musicdata == "": if musicdata == "":
musicdata = homedata / 'Music' musicdata = homedata / 'Music'
musicdata = checkPath(musicdata) musicdata = checkPath(musicdata)