From fbc268be74317b450c7a3e240a92a3db8571917d Mon Sep 17 00:00:00 2001 From: Eric Le Lay Date: Sun, 6 May 2018 18:17:23 +0200 Subject: [PATCH] win: get GPODDER_HOME from registry --- src/gpodder/__init__.py | 26 ++++++++++++++++++-------- src/gpodder/utilwin32ctypes.py | 16 ++++++++++++++++ tools/win_installer/_base.sh | 11 ++++++----- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gpodder/__init__.py b/src/gpodder/__init__.py index 16b9755d..93b383b5 100644 --- a/src/gpodder/__init__.py +++ b/src/gpodder/__init__.py @@ -176,16 +176,26 @@ def fixup_home(old_home): 'Application Support', 'gPodder')) elif BUILD_TYPE == 'windows-portable': new_home = os.path.normpath(os.path.join(os.path.dirname(sys.executable), "..", "..", "config")) - else: # ui.win32, not portable buildq - # XXX: use registy key like in old launcher? - # HKEY_CURRENT_USER\\Software\\gpodder.org\\gPodder" - # https://github.com/gpodder/gpodder/blob/old/gtk2/tools/win32-launcher/folderselector.c + old_home = new_home # force to config directory + print("D: windows-portable build; forcing home to config directory %s" % new_home) + else: # ui.win32, not portable build + from gpodder.utilwin32ctypes import get_documents_folder, get_reg_current_user_string_value try: - from gpodder.utilwin32ctypes import get_documents_folder - new_home = os.path.join(get_documents_folder(), "gPodder") + # from old launcher, see + # https://github.com/gpodder/gpodder/blob/old/gtk2/tools/win32-launcher/folderselector.c + new_home = get_reg_current_user_string_value("Software\\gpodder.org\\gPodder", "GPODDER_HOME") + print("D: windows build; registry home = %s" % new_home) except Exception as e: - print("E: can't get user's Documents folder: %s" % e) - new_home = old_home + print("E: can't get GPODDER_HOME from registry: %s" % e) + new_home = None + if new_home is None: + try: + new_home = os.path.join(get_documents_folder(), "gPodder") + print("D: windows build; documents home = %s" % new_home) + except Exception as e: + print("E: can't get user's Documents folder: %s" % e) + new_home = old_home + # Users who do not have the old home directory, or who have it but also # have the new home directory (to cater to situations where the user # might for some reason or the other have a ~/gPodder/ directory) get diff --git a/src/gpodder/utilwin32ctypes.py b/src/gpodder/utilwin32ctypes.py index db220c12..ca34a0d4 100644 --- a/src/gpodder/utilwin32ctypes.py +++ b/src/gpodder/utilwin32ctypes.py @@ -141,3 +141,19 @@ def get_documents_folder(): KNOWN_FOLDER_FLAG.KF_FLAG_CREATE | \ KNOWN_FOLDER_FLAG.KF_FLAG_DONT_VERIFY return SHGetKnownFolderPath(KNOWNFOLDERID.FOLDERID_Documents, flags) + + +def get_reg_current_user_string_value(subkey, value_name): + import winreg + try: + my_key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, subkey) + except FileNotFoundError: + return None + try: + value, type_ = winreg.QueryValueEx(my_key, value_name) + if type_ == winreg.REG_SZ: + return value + else: + raise WindowsError("Unexpected type for value %s in registry: %i" % (valueName, type_)) + except FileNotFoundError: + return None diff --git a/tools/win_installer/_base.sh b/tools/win_installer/_base.sh index 186a7f44..097a23fa 100644 --- a/tools/win_installer/_base.sh +++ b/tools/win_installer/_base.sh @@ -122,10 +122,6 @@ function install_gpodder { (cd "${REPO_CLONE}" && PYTHON="${BUILD_ROOT}"/"${MINGW}"/bin/python3.exe mingw32-make install-win) - # Create launchers - python3 "${MISC}"/create-launcher.py \ - "${GPO_VERSION}" "${MINGW_ROOT}"/bin - GPO_VERSION=$(MSYSTEM= build_python -c \ "import gpodder; import sys; sys.stdout.write(gpodder.__version__)") GPO_VERSION_DESC="$GPO_VERSION" @@ -135,6 +131,11 @@ function install_gpodder { local GIT_HASH=$(git rev-parse --short HEAD) GPO_VERSION_DESC="$GPO_VERSION-rev$GIT_REV-$GIT_HASH" fi + + # Create launchers + python3 "${MISC}"/create-launcher.py \ + "${GPO_VERSION}" "${MINGW_ROOT}"/bin + # install fake dbus rsync -arv --delete "${REPO_CLONE}"/tools/fake-dbus-module/dbus "${BUILD_ROOT}"/"${MINGW}"/lib/python3.6/site-packages/ @@ -309,7 +310,7 @@ function build_installer { function build_portable_installer { BUILDPY=$(echo "${MINGW_ROOT}"/lib/python3.*/site-packages/gpodder)/build_info.py cp "${REPO_CLONE}"/src/gpodder/build_info.py "$BUILDPY" - echo 'BUILD_TYPE = u"windows"' >> "$BUILDPY" + echo 'BUILD_TYPE = u"windows-portable"' >> "$BUILDPY" echo "BUILD_VERSION = $BUILD_VERSION" >> "$BUILDPY" (cd "$REPO_CLONE" && echo "BUILD_INFO = u\"$(git rev-parse --short HEAD)\"" >> "$BUILDPY") (cd $(dirname "$BUILDPY") && build_compileall -d "" -q -f -l .)