new build_info.py; correctly set GPODDER_HOME on windows

This commit is contained in:
Eric Le Lay 2018-05-02 14:39:47 +02:00
parent b6d020cc56
commit 5a0a1c04b6
5 changed files with 190 additions and 70 deletions

View File

@ -34,6 +34,8 @@ import platform
import gettext
import locale
from gpodder.build_info import BUILD_TYPE
# Check if real hard dependencies are available
try:
import podcastparser
@ -168,10 +170,22 @@ def set_home(new_home):
def fixup_home(old_home):
if ui.osx:
new_home = os.path.expanduser(os.path.join('~', 'Library',
'Application Support', 'gPodder'))
if ui.osx or ui.win32:
if ui.osx:
new_home = os.path.expanduser(os.path.join('~', 'Library',
'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
try:
from gpodder.utilwin32ctypes import get_documents_folder
new_home = os.path.join(get_documents_folder(), "gPodder")
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

18
src/gpodder/build_info.py Normal file
View File

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Christoph Reiter
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
"""This file gets edited at build time to add build specific data"""
BUILD_TYPE = u"default"
"""Either 'windows', 'windows-portable', 'osx' or 'default'"""
BUILD_INFO = u""
"""Additional build info like git revision etc"""
BUILD_VERSION = 0
"""1.2.3 with a BUILD_VERSION of 1 results in 1.2.3.1"""

View File

@ -1,54 +1,143 @@
# -*- coding: utf-8 -*-
#
# gPodder - A media aggregator and podcast client
# Copyright (c) 2005-2018 The gPodder Team
# Copyright (c) 2018 Eric Le Lay
#
# gPodder is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import ctypes
from ctypes import c_ulonglong
from ctypes.wintypes import (BOOL, DWORD, LPCWSTR, PULARGE_INTEGER)
from win32ctypes.core.ctypes._common import byreference
from win32ctypes.core.ctypes._util import check_zero, function_factory
# Use a local copy of the kernel32 dll.
kernel32 = ctypes.WinDLL('kernel32')
_BaseGetDiskFreeSpaceEx = function_factory(
kernel32.GetDiskFreeSpaceExW,
[LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER],
BOOL, check_zero)
_BaseGetFileAttributes = function_factory(
kernel32.GetFileAttributesW,
[LPCWSTR],
DWORD)
def GetDiskFreeSpaceEx(lpDirectoryName):
lp_dirname = LPCWSTR(lpDirectoryName)
lpFreeBytesAvailable = c_ulonglong(0)
lpTotalNumberOfBytes = c_ulonglong(0)
lpTotalNumberOfFreeBytes = c_ulonglong(0)
_BaseGetDiskFreeSpaceEx(lp_dirname, byreference(lpFreeBytesAvailable), byreference(lpTotalNumberOfBytes), byreference(lpTotalNumberOfFreeBytes))
freeBytesAvailable = lpFreeBytesAvailable.value
totalNumberOfBytes = lpTotalNumberOfBytes.value
totalNumberOfFreeBytes = lpTotalNumberOfFreeBytes.value
return (freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes)
def GetFileAttributes(lpFileName):
lp_filename = LPCWSTR(lpFileName)
return _BaseGetFileAttributes(lp_filename)
# -*- coding: utf-8 -*-
#
# gPodder - A media aggregator and podcast client
# Copyright (c) 2005-2018 The gPodder Team
# Copyright (c) 2018 Eric Le Lay
#
# gPodder is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import ctypes
from ctypes import c_ulonglong, HRESULT, Structure
from ctypes.wintypes import (BOOL, BYTE, DWORD, HANDLE, LPCWSTR, MAX_PATH, PULARGE_INTEGER, WORD)
from uuid import UUID
from win32ctypes.core.ctypes._common import byreference
from win32ctypes.core.ctypes._util import check_zero, function_factory
# Use a local copy of dlls.
kernel32 = ctypes.WinDLL('kernel32')
shell32 = ctypes.WinDLL('shell32')
ole32 = ctypes.WinDLL('ole32')
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa373931%28v=vs.85%29.aspx
class GUID(ctypes.Structure):
_fields_ = [
("Data1", DWORD),
("Data2", WORD),
("Data3", WORD),
("Data4", BYTE * 8),
]
def __init__(self, uuidstr=None):
uuid = UUID(uuidstr)
Structure.__init__(self)
self.Data1, self.Data2, self.Data3, self.Data4[0], self.Data4[1], rest = uuid.fields
for i in range(2, 8):
self.Data4[i] = rest>>(8-i-1)*8 & 0xff
REFKNOWNFOLDERID = ctypes.POINTER(GUID)
S_OK = HRESULT(0).value
CoTaskMemFree = function_factory(
ole32.CoTaskMemFree,
[ctypes.c_void_p],
None)
_BaseGetDiskFreeSpaceEx = function_factory(
kernel32.GetDiskFreeSpaceExW,
[LPCWSTR, PULARGE_INTEGER, PULARGE_INTEGER, PULARGE_INTEGER],
BOOL, check_zero)
_BaseGetFileAttributes = function_factory(
kernel32.GetFileAttributesW,
[LPCWSTR],
DWORD)
_BaseSHGetKnownFolderPath = function_factory(
shell32.SHGetKnownFolderPath,
[REFKNOWNFOLDERID, DWORD, HANDLE, ctypes.POINTER(ctypes.c_wchar_p)],
HRESULT)
def GetDiskFreeSpaceEx(lpDirectoryName):
lp_dirname = LPCWSTR(lpDirectoryName)
lpFreeBytesAvailable = c_ulonglong(0)
lpTotalNumberOfBytes = c_ulonglong(0)
lpTotalNumberOfFreeBytes = c_ulonglong(0)
_BaseGetDiskFreeSpaceEx(lp_dirname, byreference(lpFreeBytesAvailable), byreference(lpTotalNumberOfBytes), byreference(lpTotalNumberOfFreeBytes))
freeBytesAvailable = lpFreeBytesAvailable.value
totalNumberOfBytes = lpTotalNumberOfBytes.value
totalNumberOfFreeBytes = lpTotalNumberOfFreeBytes.value
return (freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes)
def GetFileAttributes(lpFileName):
lp_filename = LPCWSTR(lpFileName)
return _BaseGetFileAttributes(lp_filename)
def SHGetKnownFolderPath(rfid, dwFlags):
out_buf = ctypes.c_wchar_p()
try:
ret = _BaseSHGetKnownFolderPath(byreference(rfid), dwFlags, None, byreference(out_buf))
except WindowsError:
return None
if ret != S_OK:
return None
res = out_buf.value
CoTaskMemFree(out_buf)
return res
# https://msdn.microsoft.com/en-us/library/dd378447(v=vs.85).aspx
class KNOWN_FOLDER_FLAG:
KF_FLAG_DEFAULT = 0x00000000
KF_FLAG_SIMPLE_IDLIST = 0x00000100
KF_FLAG_NOT_PARENT_RELATIVE = 0x00000200
KF_FLAG_DEFAULT_PATH = 0x00000400
KF_FLAG_INIT = 0x00000800
KF_FLAG_NO_ALIAS = 0x00001000
KF_FLAG_DONT_UNEXPAND = 0x00002000
KF_FLAG_DONT_VERIFY = 0x00004000
KF_FLAG_CREATE = 0x00008000
KF_FLAG_NO_PACKAGE_REDIRECTION = 0x00010000
KF_FLAG_NO_APPCONTAINER_REDIRECTION = 0x00010000
KF_FLAG_FORCE_PACKAGE_REDIRECTION = 0x00020000
KF_FLAG_FORCE_APPCONTAINER_REDIRECTION = 0x00020000
KF_FLAG_RETURN_FILTER_REDIRECTION_TARGET = 0x00040000
KF_FLAG_FORCE_APP_DATA_REDIRECTION = 0x00080000
KF_FLAG_ALIAS_ONLY = 0x80000000
# https://msdn.microsoft.com/en-us/library/dd378457(v=vs.85).aspx
class KNOWNFOLDERID:
FOLDERID_Documents = GUID("{FDD39AD0-238F-46AF-ADB4-6C85480369C7}")
def get_documents_folder():
flags = KNOWN_FOLDER_FLAG.KF_FLAG_DEFAULT | \
KNOWN_FOLDER_FLAG.KF_FLAG_DONT_UNEXPAND | \
KNOWN_FOLDER_FLAG.KF_FLAG_CREATE | \
KNOWN_FOLDER_FLAG.KF_FLAG_DONT_VERIFY
return SHGetKnownFolderPath(KNOWNFOLDERID.FOLDERID_Documents, flags)

View File

@ -208,6 +208,7 @@ function cleanup_after {
rm -Rf "${MINGW_ROOT}"/share/doc
rm -Rf "${MINGW_ROOT}"/share/man
rm -Rf "${MINGW_ROOT}"/share/info
# FIXME: don't we need it for icons?
rm -Rf "${MINGW_ROOT}"/share/mime
rm -Rf "${MINGW_ROOT}"/share/gettext
rm -Rf "${MINGW_ROOT}"/share/libtool
@ -291,12 +292,11 @@ function cleanup_after {
}
function build_installer {
# TODO: this is nice way to embed version info in the program
BUILDPY=$(echo "${MINGW_ROOT}"/lib/python3.*/site-packages/gpodder)/build_info.py
# cp "${REPO_CLONE}"/gpodder/build_info.py "$BUILDPY"
# echo 'BUILD_TYPE = u"windows"' >> "$BUILDPY"
# echo "BUILD_VERSION = $BUILD_VERSION" >> "$BUILDPY"
# (cd "$REPO_CLONE" && echo "BUILD_INFO = u\"$(git rev-parse --short HEAD)\"" >> "$BUILDPY")
cp "${REPO_CLONE}"/src/gpodder/build_info.py "$BUILDPY"
echo 'BUILD_TYPE = u"windows"' >> "$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 .)
rm -f "$BUILDPY"
@ -308,11 +308,10 @@ function build_installer {
function build_portable_installer {
BUILDPY=$(echo "${MINGW_ROOT}"/lib/python3.*/site-packages/gpodder)/build_info.py
# TODO: this is nice way to embed version info in the program
# cp "${REPO_CLONE}"/gpodder/build_info.py "$BUILDPY"
# echo 'BUILD_TYPE = u"windows"' >> "$BUILDPY"
# echo "BUILD_VERSION = $BUILD_VERSION" >> "$BUILDPY"
# (cd "$REPO_CLONE" && echo "BUILD_INFO = u\"$(git rev-parse --short HEAD)\"" >> "$BUILDPY")
cp "${REPO_CLONE}"/src/gpodder/build_info.py "$BUILDPY"
echo 'BUILD_TYPE = u"windows"' >> "$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 .)
rm -f "$BUILDPY"

View File

@ -1,2 +1,2 @@
[Settings]
gtk-font-name = Segoe UI 10
[Settings]
gtk-font-name = Segoe UI 10