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

[((210, 266), '_winreg.ConnectRegistry', '_winreg.ConnectRegistry', (['None', '_winreg.HKEY_CURRENT_USER'], {}), '(None, _winreg.HKEY_CURRENT_USER)\n', (233, 266), False, 'import _winreg\n'), ((779, 838), '_winreg.CreateKey', '_winreg.CreateKey', (['_winreg.aReg', '"""SOFTWARE\\\\CCP\\\\EVEONLINE"""'], {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEONLINE')\n", (796, 838), False, 'import _winreg\n'), ((842, 927), '_winreg.SetValueEx', '_winreg.SetValueEx', (['key_eveonline', '"""CACHEFOLDER"""', '(0)', '_winreg.REG_SZ', 'folder_path'], {}), "(key_eveonline, 'CACHEFOLDER', 0, _winreg.REG_SZ, folder_path\n    )\n", (860, 927), False, 'import _winreg\n'), ((943, 1001), '_winreg.CreateKey', '_winreg.CreateKey', (['_winreg.aReg', '"""SOFTWARE\\\\CCP\\\\EVEPROBE"""'], {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEPROBE')\n", (960, 1001), False, 'import _winreg\n'), ((1005, 1084), '_winreg.SetValueEx', '_winreg.SetValueEx', (['key_eveprobe', '"""CACHEFOLDER"""', '(0)', '_winreg.REG_SZ', 'folder_path'], {}), "(key_eveprobe, 'CACHEFOLDER', 0, _winreg.REG_SZ, folder_path)\n", (1023, 1084), False, 'import _winreg\n'), ((290, 347), '_winreg.OpenKey', '_winreg.OpenKey', (['_winreg.aReg', '"""SOFTWARE\\\\CCP\\\\EVEONLINE"""'], {}), "(_winreg.aReg, 'SOFTWARE\\\\CCP\\\\EVEONLINE')\n", (305, 347), False, 'import _winreg\n'), ((365, 405), '_winreg.QueryValueEx', '_winreg.QueryValueEx', (['key', '"""CACHEFOLDER"""'], {}), "(key, 'CACHEFOLDER')\n", (385, 405), False, 'import _winreg\n'), ((517, 543), 'os.path.isdir', 'os.path.isdir', (['folder_path'], {}), '(folder_path)\n', (530, 543), False, 'import os\n'), ((719, 748), 'os.path.normpath', 'os.path.normpath', (['folder_path'], {}), '(folder_path)\n', (735, 748), False, 'import os\n'), ((570, 594), 'os.makedirs', 'os.makedirs', (['folder_path'], {}), '(folder_path)\n', (581, 594), False, 'import os\n')]