import _winreg
import os


def get_shared_cache_folder():
    """
    Look in the registry for the configured cache folder.
    If there is no entry, then we create one.
    :return:
    """
    _winreg.aReg = _winreg.ConnectRegistry(None, _winreg.HKEY_CURRENT_USER)
    try:
        key = _winreg.OpenKey(_winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
        path, _ = _winreg.QueryValueEx(key, "CACHEFOLDER")
    except OSError:
        return None
    return path


def set_shared_cache_folder(folder_path):
    if not os.path.isdir(folder_path):
        try:
            os.makedirs(folder_path)
        except OSError:
            raise ValueError("Could not create directory {}".format(folder_path))
    folder_path = os.path.normpath(folder_path) + os.sep

    key_eveonline = _winreg.CreateKey(_winreg.aReg, r"SOFTWARE\CCP\EVEONLINE")
    _winreg.SetValueEx(key_eveonline, "CACHEFOLDER", 0, _winreg.REG_SZ, folder_path)

    key_eveprobe = _winreg.CreateKey(_winreg.aReg, r"SOFTWARE\CCP\EVEPROBE")
    _winreg.SetValueEx(key_eveprobe, "CACHEFOLDER", 0, _winreg.REG_SZ, folder_path)


def get_index_path(hint):
    return hint

[((11, 19, 11, 75), '_winreg.ConnectRegistry', '_winreg.ConnectRegistry', ({(11, 43, 11, 47): 'None', (11, 49, 11, 74): '_winreg.HKEY_CURRENT_USER'}, {}), '(None, _winreg.HKEY_CURRENT_USER)', False, 'import _winreg\n'), ((28, 20, 28, 78), '_winreg.CreateKey', '_winreg.CreateKey', ({(28, 38, 28, 50): '_winreg.aReg', (28, 52, 28, 77): '"""SOFTWARE\\\\CCP\\\\EVEONLINE"""'}, {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEONLINE')", False, 'import _winreg\n'), ((29, 4, 29, 84), '_winreg.SetValueEx', '_winreg.SetValueEx', ({(29, 23, 29, 36): 'key_eveonline', (29, 38, 29, 51): '"""CACHEFOLDER"""', (29, 53, 29, 54): '(0)', (29, 56, 29, 70): '_winreg.REG_SZ', (29, 72, 29, 83): 'folder_path'}, {}), "(key_eveonline, 'CACHEFOLDER', 0, _winreg.REG_SZ, folder_path\n    )", False, 'import _winreg\n'), ((31, 19, 31, 76), '_winreg.CreateKey', '_winreg.CreateKey', ({(31, 37, 31, 49): '_winreg.aReg', (31, 51, 31, 75): '"""SOFTWARE\\\\CCP\\\\EVEPROBE"""'}, {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEPROBE')", False, 'import _winreg\n'), ((32, 4, 32, 83), '_winreg.SetValueEx', '_winreg.SetValueEx', ({(32, 23, 32, 35): 'key_eveprobe', (32, 37, 32, 50): '"""CACHEFOLDER"""', (32, 52, 32, 53): '(0)', (32, 55, 32, 69): '_winreg.REG_SZ', (32, 71, 32, 82): 'folder_path'}, {}), "(key_eveprobe, 'CACHEFOLDER', 0, _winreg.REG_SZ, folder_path)", False, 'import _winreg\n'), ((13, 14, 13, 70), '_winreg.OpenKey', '_winreg.OpenKey', ({(13, 30, 13, 42): '_winreg.aReg', (13, 44, 13, 69): '"""SOFTWARE\\\\CCP\\\\EVEONLINE"""'}, {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEONLINE')", False, 'import _winreg\n'), ((14, 18, 14, 58), '_winreg.QueryValueEx', '_winreg.QueryValueEx', ({(14, 39, 14, 42): 'key', (14, 44, 14, 57): '"""CACHEFOLDER"""'}, {}), "(key, 'CACHEFOLDER')", False, 'import _winreg\n'), ((21, 11, 21, 37), 'os.path.isdir', 'os.path.isdir', ({(21, 25, 21, 36): 'folder_path'}, {}), '(folder_path)', False, 'import os\n'), ((26, 18, 26, 47), 'os.path.normpath', 'os.path.normpath', ({(26, 35, 26, 46): 'folder_path'}, {}), '(folder_path)', False, 'import os\n'), ((23, 12, 23, 36), 'os.makedirs', 'os.makedirs', ({(23, 24, 23, 35): 'folder_path'}, {}), '(folder_path)', False, 'import os\n')]