1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-09 03:42:16 +03:00

config.py: More import clean & misc.

This commit is contained in:
Athanasius 2020-10-08 15:58:52 +01:00
parent b2629286b4
commit c3150dae76

View File

@ -31,12 +31,15 @@ update_interval = 8*60*60
if platform == 'darwin': if platform == 'darwin':
from Foundation import NSBundle, NSUserDefaults, NSSearchPathForDirectoriesInDomains, NSApplicationSupportDirectory, NSDocumentDirectory, NSLibraryDirectory, NSUserDomainMask from Foundation import (
NSApplicationSupportDirectory, NSBundle, NSDocumentDirectory, NSSearchPathForDirectoriesInDomains,
NSUserDefaults, NSUserDomainMask
)
elif platform == 'win32': elif platform == 'win32':
import ctypes import ctypes
from ctypes.wintypes import *
import uuid import uuid
from ctypes.wintypes import DWORD, HANDLE, LONG, HKEY, LPCWSTR, LPCVOID
FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}') FOLDERID_Documents = uuid.UUID('{FDD39AD0-238F-46AF-ADB4-6C85480369C7}')
FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}') FOLDERID_LocalAppData = uuid.UUID('{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}')
@ -60,7 +63,9 @@ elif platform == 'win32':
RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW RegCreateKeyEx = ctypes.windll.advapi32.RegCreateKeyExW
RegCreateKeyEx.restype = LONG RegCreateKeyEx.restype = LONG
RegCreateKeyEx.argtypes = [HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD)] RegCreateKeyEx.argtypes = [
HKEY, LPCWSTR, DWORD, LPCVOID, DWORD, DWORD, LPCVOID, ctypes.POINTER(HKEY), ctypes.POINTER(DWORD)
]
RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW RegOpenKeyEx = ctypes.windll.advapi32.RegOpenKeyExW
RegOpenKeyEx.restype = LONG RegOpenKeyEx.restype = LONG
@ -90,7 +95,8 @@ elif platform == 'win32':
RegDeleteValue.restype = LONG RegDeleteValue.restype = LONG
RegDeleteValue.argtypes = [HKEY, LPCWSTR] RegDeleteValue.argtypes = [HKEY, LPCWSTR]
def KnownFolderPath(guid): def known_folder_path(guid):
"""Look up a Windows GUID to actual folder path name."""
buf = ctypes.c_wchar_p() buf = ctypes.c_wchar_p()
if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)): if SHGetKnownFolderPath(ctypes.create_string_buffer(guid.bytes_le), 0, 0, ctypes.byref(buf)):
return None return None
@ -98,13 +104,13 @@ elif platform == 'win32':
CoTaskMemFree(buf) # and free original CoTaskMemFree(buf) # and free original
return retval return retval
elif platform == 'linux':
elif platform=='linux':
import codecs import codecs
from configparser import RawConfigParser from configparser import RawConfigParser
class Config(object): class Config(object):
"""Object that holds all configuration data."""
OUT_MKT_EDDN = 1 OUT_MKT_EDDN = 1
# OUT_MKT_BPC = 2 # No longer supported # OUT_MKT_BPC = 2 # No longer supported
@ -122,7 +128,7 @@ class Config(object):
OUT_SYS_EDDN = 2048 OUT_SYS_EDDN = 2048
OUT_SYS_DELAY = 4096 OUT_SYS_DELAY = 4096
if platform=='darwin': if platform == 'darwin':
def __init__(self): def __init__(self):
self.__in_shutdown = False # Is the application currently shutting down ? self.__in_shutdown = False # Is the application currently shutting down ?
@ -220,7 +226,7 @@ class Config(object):
self.__in_shutdown = False # Is the application currently shutting down ? self.__in_shutdown = False # Is the application currently shutting down ?
self.__auth_force_localserver = False # Should we use localhost for auth callback ? self.__auth_force_localserver = False # Should we use localhost for auth callback ?
self.app_dir = join(KnownFolderPath(FOLDERID_LocalAppData), appname) self.app_dir = join(known_folder_path(FOLDERID_LocalAppData), appname)
if not isdir(self.app_dir): if not isdir(self.app_dir):
mkdir(self.app_dir) mkdir(self.app_dir)
@ -231,9 +237,9 @@ class Config(object):
self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable or __file__), u'plugins') self.internal_plugin_dir = join(dirname(getattr(sys, 'frozen', False) and sys.executable or __file__), u'plugins')
# expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207 # expanduser in Python 2 on Windows doesn't handle non-ASCII - http://bugs.python.org/issue13207
self.home = KnownFolderPath(FOLDERID_Profile) or u'\\' self.home = known_folder_path(FOLDERID_Profile) or u'\\'
journaldir = KnownFolderPath(FOLDERID_SavedGames) journaldir = known_folder_path(FOLDERID_SavedGames)
self.default_journal_dir = journaldir and join(journaldir, 'Frontier Developments', 'Elite Dangerous') or None self.default_journal_dir = journaldir and join(journaldir, 'Frontier Developments', 'Elite Dangerous') or None
self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__) self.respath = dirname(getattr(sys, 'frozen', False) and sys.executable or __file__)
@ -260,7 +266,7 @@ class Config(object):
RegCloseKey(sparklekey) RegCloseKey(sparklekey)
if not self.get('outdir') or not isdir(self.get('outdir')): if not self.get('outdir') or not isdir(self.get('outdir')):
self.set('outdir', KnownFolderPath(FOLDERID_Documents) or self.home) self.set('outdir', known_folder_path(FOLDERID_Documents) or self.home)
def get(self, key): def get(self, key):
typ = DWORD() typ = DWORD()