← Back to team overview

zim-wiki team mailing list archive

Re: Win32: configuration path

 

On Mon, Oct 29, 2012 at 8:42 PM, Jaap Karssenberg wrote:
>> So that if user has config files as in zim 0.57 config folders, above
>> snippet will make it compatible to potentially new config folder
>> scheme?
>
> Yes, that is the idea.

That sounds great :)


>>> Probably the CACHE variable should go to a folder for temporary data.
>>> Not %TMP% because we want it available longer, but it can be flushed
>>> when space is needed on the system.
>>
>> I don't know about existence of other temporary folder except %TMP% and %TEMP%
>
> Isn't there a folder that is also used for things like temporary
> internet files ?

Sure, and by just looking in there I see Gimp also uses it for caching (gegl)

With SPL folder can be located by reading the registry (on any Windows version):

========================================
>>> import _winreg as wreg
>>> wreg_key = wreg.OpenKey(wreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders')
>>> wreg.QueryValueEx(wreg_key, "Cache")
(u'%USERPROFILE%\\Local Settings\\Temporary Internet Files', 2)
========================================

And:

========================================
>>> import os
>>> wreg.QueryValueEx(wreg_key, "Cache")[0].replace(u'%USERPROFILE%', os.environ['USERPROFILE'])
u'C:\\Documents and Settings\\klo\\Local Settings\\Temporary Internet Files'
>>>wreg.CloseKey(wreg_key)
========================================


So, considering previous talk, something like this should be sensible
for Windows users:

========================================
if os.name == 'nt':
	import _winreg as wreg
	XDG_DATA_HOME = Dir(
		get_environ('XDG_DATA_HOME', os.environ['APPDATA'] + '//zim//data'))

	XDG_DATA_DIRS = Dir(
			get_environ('XDG_DATA_HOME', '~/.local/share/'))

	XDG_CONFIG_HOME = Dir(
		get_environ('XDG_CONFIG_HOME', os.environ['APPDATA'] + '//zim//config'))

	XDG_CONFIG_DIRS = Dir(
			get_environ('XDG_CONFIG_HOME', '~/.config/'))

	try:
		wreg_key = wreg.OpenKey(wreg.HKEY_CURRENT_USER,
r'Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell
Folders')
		cache_dir = str(wreg.QueryValueEx(wreg_key,
"Cache")[0].replace(u'%USERPROFILE%', os.environ['USERPROFILE']))
		wreg.CloseKey(wreg_key)
	except:
		cache_dir = os.environ['TEMP']

	XDG_CACHE_HOME = Dir(
		get_environ('XDG_CACHE_HOME', cache_dir + '//zim'))
========================================


Follow ups

References