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

Renamed various config values to be backwards compatible

This commit is contained in:
A_D 2021-01-11 15:55:50 +02:00 committed by Athanasius
parent f38b2aa95e
commit 051245cf90
14 changed files with 90 additions and 90 deletions

View File

@ -41,7 +41,7 @@ from config import appcmdname, appversion, config
from monitor import monitor from monitor import monitor
from update import EDMCVersion, Updater from update import EDMCVersion, Updater
sys.path.append(config.internal_plugin_dir_str) sys.path.append(config.internal_plugin_dir)
# This import must be after the sys.path.append. # This import must be after the sys.path.append.
# The sys.path.append has to be after `import sys` and `from config import config` # The sys.path.append has to be after `import sys` and `from config import config`
# isort: off # isort: off
@ -189,9 +189,9 @@ sys.path: {sys.path}'''
# Get state from latest Journal file # Get state from latest Journal file
logger.debug('Getting state from latest journal file') logger.debug('Getting state from latest journal file')
try: try:
logdir = config.get_str('journaldir', default=config.default_journal_dir_str) logdir = config.get_str('journaldir', default=config.default_journal_dir)
if not logdir: if not logdir:
logdir = config.default_journal_dir_str logdir = config.default_journal_dir
logger.debug(f'logdir = "{logdir}"') logger.debug(f'logdir = "{logdir}"')
logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)), logfiles = sorted((x for x in os.listdir(logdir) if JOURNAL_RE.search(x)),

View File

@ -422,8 +422,8 @@ class EDMCContextFilter(logging.Filter):
:return: The munged module_name. :return: The munged module_name.
""" """
file_name = pathlib.Path(frame_info.filename).expanduser() file_name = pathlib.Path(frame_info.filename).expanduser()
plugin_dir = pathlib.Path(config.plugin_dir).expanduser() plugin_dir = pathlib.Path(config.plugin_dir_path).expanduser()
internal_plugin_dir = pathlib.Path(config.internal_plugin_dir).expanduser() internal_plugin_dir = pathlib.Path(config.internal_plugin_dir_path).expanduser()
# Find the first parent called 'plugins' # Find the first parent called 'plugins'
plugin_top = file_name plugin_top = file_name
while plugin_top and plugin_top.name != '': while plugin_top and plugin_top.name != '':

View File

@ -415,7 +415,7 @@ class AppWindow(object):
else: else:
self.w.tk.call('wm', 'iconphoto', self.w, '-default', self.w.tk.call('wm', 'iconphoto', self.w, '-default',
tk.PhotoImage(file=join(config.respath, 'EDMarketConnector.png'))) tk.PhotoImage(file=join(config.respath_path, 'EDMarketConnector.png')))
# TODO: Export to files and merge from them in future ? # TODO: Export to files and merge from them in future ?
self.theme_icon = tk.PhotoImage( self.theme_icon = tk.PhotoImage(
@ -1145,7 +1145,7 @@ class AppWindow(object):
# Avoid file length limits if possible # Avoid file length limits if possible
provider = config.get_str('shipyard_provider', default='EDSY') provider = config.get_str('shipyard_provider', default='EDSY')
target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta) target = plug.invoke(provider, 'EDSY', 'shipyard_url', monitor.ship(), monitor.is_beta)
file_name = join(config.app_dir, "last_shipyard.html") file_name = join(config.app_dir_path, "last_shipyard.html")
with open(file_name, 'w') as f: with open(file_name, 'w') as f:
print(SHIPYARD_HTML_TEMPLATE.format( print(SHIPYARD_HTML_TEMPLATE.format(

View File

@ -660,7 +660,7 @@ def fixup(data: CAPIData) -> CAPIData: # noqa: C901, CCR001 # Can't be usefully
if not commodity_map: if not commodity_map:
# Lazily populate # Lazily populate
for f in ('commodity.csv', 'rare_commodity.csv'): for f in ('commodity.csv', 'rare_commodity.csv'):
with open(join(config.respath, f), 'r') as csvfile: with open(join(config.respath_path, f), 'r') as csvfile:
reader = csv.DictReader(csvfile) reader = csv.DictReader(csvfile)
for row in reader: for row in reader:

View File

@ -107,19 +107,19 @@ class AbstractConfig(abc.ABC):
OUT_SYS_EDDN = 2048 OUT_SYS_EDDN = 2048
OUT_SYS_DELAY = 4096 OUT_SYS_DELAY = 4096
app_dir: pathlib.Path app_dir_path: pathlib.Path
plugin_dir: pathlib.Path plugin_dir_path: pathlib.Path
internal_plugin_dir: pathlib.Path internal_plugin_dir_path: pathlib.Path
respath: pathlib.Path respath_path: pathlib.Path
home: pathlib.Path home_path: pathlib.Path
default_journal_dir: pathlib.Path default_journal_dir_path: pathlib.Path
identifier: str identifier: str
__in_shutdown = False # Is the application currently shutting down ? __in_shutdown = False # Is the application currently shutting down ?
def __init__(self) -> None: def __init__(self) -> None:
self.home = pathlib.Path.home() self.home_path = pathlib.Path.home()
def set_shutdown(self): def set_shutdown(self):
self.__in_shutdown = True self.__in_shutdown = True
@ -129,34 +129,34 @@ class AbstractConfig(abc.ABC):
return self.__in_shutdown return self.__in_shutdown
@property @property
def app_dir_str(self) -> str: def app_dir(self) -> str:
"""Return a string version of app_dir.""" """Return a string version of app_dir."""
return str(self.app_dir) return str(self.app_dir_path)
@property @property
def plugin_dir_str(self) -> str: def plugin_dir(self) -> str:
"""Return a string version of plugin_dir.""" """Return a string version of plugin_dir."""
return str(self.plugin_dir) return str(self.plugin_dir_path)
@property @property
def internal_plugin_dir_str(self) -> str: def internal_plugin_dir(self) -> str:
"""Return a string version of internal_plugin_dir.""" """Return a string version of internal_plugin_dir."""
return str(self.internal_plugin_dir) return str(self.internal_plugin_dir_path)
@property @property
def respath_str(self) -> str: def respath(self) -> str:
"""Return a string version of respath.""" """Return a string version of respath."""
return str(self.respath) return str(self.respath_path)
@property @property
def home_str(self) -> str: def home(self) -> str:
"""Return a string version of home.""" """Return a string version of home."""
return str(self.home) return str(self.home_path)
@property @property
def default_journal_dir_str(self) -> str: def default_journal_dir(self) -> str:
"""Return a string version of default_journal_dir.""" """Return a string version of default_journal_dir."""
return str(self.default_journal_dir) return str(self.default_journal_dir_path)
@staticmethod @staticmethod
def _suppress_call( def _suppress_call(
@ -308,27 +308,27 @@ class WinConfig(AbstractConfig):
"""Implementation of AbstractConfig for windows.""" """Implementation of AbstractConfig for windows."""
def __init__(self, do_winsparkle=True) -> None: def __init__(self, do_winsparkle=True) -> None:
self.app_dir = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname self.app_dir_path = pathlib.Path(str(known_folder_path(FOLDERID_LocalAppData))) / appname
self.app_dir.mkdir(exist_ok=True) self.app_dir_path.mkdir(exist_ok=True)
self.plugin_dir = self.app_dir / 'plugins' self.plugin_dir_path = self.app_dir_path / 'plugins'
self.plugin_dir.mkdir(exist_ok=True) self.plugin_dir_path.mkdir(exist_ok=True)
if getattr(sys, 'frozen', False): if getattr(sys, 'frozen', False):
self.respath = pathlib.Path(sys.executable).parent self.respath_path = pathlib.Path(sys.executable).parent
self.internal_plugin_dir = self.respath / 'plugins' self.internal_plugin_dir_path = self.respath_path / 'plugins'
else: else:
self.respath = pathlib.Path(__file__).parent self.respath_path = pathlib.Path(__file__).parent
self.internal_plugin_dir = self.respath / 'plugins' self.internal_plugin_dir_path = self.respath_path / 'plugins'
self.home = pathlib.Path.home() self.home_path = pathlib.Path.home()
journal_dir_str = known_folder_path(FOLDERID_SavedGames) journal_dir_str = known_folder_path(FOLDERID_SavedGames)
journaldir = pathlib.Path(journal_dir_str) if journal_dir_str is not None else None journaldir = pathlib.Path(journal_dir_str) if journal_dir_str is not None else None
self.default_journal_dir = None self.default_journal_dir_path = None
if journaldir is not None: if journaldir is not None:
self.default_journal_dir = journaldir / 'Frontier Developments' / 'Elite Dangerous' self.default_journal_dir_path = journaldir / 'Frontier Developments' / 'Elite Dangerous'
create_key_defaults = functools.partial( create_key_defaults = functools.partial(
winreg.CreateKeyEx, winreg.CreateKeyEx,
@ -350,7 +350,7 @@ class WinConfig(AbstractConfig):
self.identifier = applongname self.identifier = applongname
if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir(): if (outdir_str := self.get_str('outdir')) is None or not pathlib.Path(outdir_str).is_dir():
docs = known_folder_path(FOLDERID_Documents) docs = known_folder_path(FOLDERID_Documents)
self.set('outdir', docs if docs is not None else str(self.home)) self.set('outdir', docs if docs is not None else str(self.home_path))
def __setup_winsparkle(self): def __setup_winsparkle(self):
create_key_defaults = functools.partial( create_key_defaults = functools.partial(
@ -535,29 +535,29 @@ class MacConfig(AbstractConfig):
)[0] )[0]
) )
self.app_dir = support_path / appname self.app_dir_path = support_path / appname
self.app_dir.mkdir(exist_ok=True) self.app_dir_path.mkdir(exist_ok=True)
self.plugin_dir = self.app_dir / 'plugins' self.plugin_dir_path = self.app_dir_path / 'plugins'
self.plugin_dir.mkdir(exist_ok=True) self.plugin_dir_path.mkdir(exist_ok=True)
# Bundle IDs identify a singled app though out a system # Bundle IDs identify a singled app though out a system
if getattr(sys, 'frozen', False): if getattr(sys, 'frozen', False):
exe_dir = pathlib.Path(sys.executable).parent exe_dir = pathlib.Path(sys.executable).parent
self.internal_plugin_dir = exe_dir.parent / 'Library' / 'plugins' self.internal_plugin_dir_path = exe_dir.parent / 'Library' / 'plugins'
self.respath = exe_dir.parent / 'Resources' self.respath_path = exe_dir.parent / 'Resources'
self.identifier = NSBundle.mainBundle().bundleIdentifier() self.identifier = NSBundle.mainBundle().bundleIdentifier()
else: else:
file_dir = pathlib.Path(__file__).parent file_dir = pathlib.Path(__file__).parent
self.internal_plugin_dir = file_dir / 'plugins' self.internal_plugin_dir_path = file_dir / 'plugins'
self.respath = file_dir self.respath_path = file_dir
self.identifier = f'uk.org.marginal.{appname.lower()}' self.identifier = f'uk.org.marginal.{appname.lower()}'
NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier NSBundle.mainBundle().infoDictionary()['CFBundleIdentifier'] = self.identifier
self.default_journal_dir = support_path / 'Frontier Developments' / 'Elite Dangerous' self.default_journal_dir_path = support_path / 'Frontier Developments' / 'Elite Dangerous'
self._defaults = NSUserDefaults.standardUserDefaults() self._defaults = NSUserDefaults.standardUserDefaults()
self._settings: Dict[str, Union[int, str, list]] = dict( self._settings: Dict[str, Union[int, str, list]] = dict(
self._defaults.persistentDomainForName_(self.identifier) or {} self._defaults.persistentDomainForName_(self.identifier) or {}
@ -682,16 +682,16 @@ class LinuxConfig(AbstractConfig):
super().__init__() super().__init__()
# http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html # http://standards.freedesktop.org/basedir-spec/latest/ar01s03.html
xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser() xdg_data_home = pathlib.Path(os.getenv('XDG_DATA_HOME', default='~/.local/share')).expanduser()
self.app_dir = xdg_data_home / appname self.app_dir_path = xdg_data_home / appname
self.app_dir.mkdir(exist_ok=True, parents=True) self.app_dir_path.mkdir(exist_ok=True, parents=True)
self.plugin_dir = self.app_dir / 'plugins' self.plugin_dir_path = self.app_dir_path / 'plugins'
self.plugin_dir.mkdir(exist_ok=True) self.plugin_dir_path.mkdir(exist_ok=True)
self.respath = pathlib.Path(__file__).parent self.respath_path = pathlib.Path(__file__).parent
self.internal_plugin_dir = self.respath / 'plugins' self.internal_plugin_dir_path = self.respath_path / 'plugins'
self.default_journal_dir = None self.default_journal_dir_path = None
self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused? self.identifier = f'uk.org.marginal.{appname.lower()}' # TODO: Unused?
config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser() config_home = pathlib.Path(os.getenv('XDG_CONFIG_HOME', default='~/.config')).expanduser()
@ -711,7 +711,7 @@ class LinuxConfig(AbstractConfig):
self.config.add_section(self.SECTION) self.config.add_section(self.SECTION)
if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir(): if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir():
self.set('outdir', str(self.home)) self.set('outdir', str(self.home_path))
def __escape(self, s: str) -> str: def __escape(self, s: str) -> str:
""" """

View File

@ -41,9 +41,9 @@ class Dashboard(FileSystemEventHandler):
self.root = root self.root = root
self.session_start = started self.session_start = started
logdir = config.get_str('journaldir', default=config.default_journal_dir_str) logdir = config.get_str('journaldir', default=config.default_journal_dir)
if logdir == '': if logdir == '':
logdir = config.default_journal_dir_str logdir = config.default_journal_dir
if not logdir or not isdir(logdir): if not logdir or not isdir(logdir):
logger.info(f"No logdir, or it isn't a directory: {logdir=}") logger.info(f"No logdir, or it isn't a directory: {logdir=}")

View File

@ -48,7 +48,7 @@ slot_map = {
# Ship masses # Ship masses
# TODO: prefer something other than pickle for this storage (dev readability, security) # TODO: prefer something other than pickle for this storage (dev readability, security)
ships = pickle.load(open(join(config.respath, 'ships.p'), 'rb')) ships = pickle.load(open(join(config.respath_path, 'ships.p'), 'rb'))
# Export ship loadout in E:D Shipyard plain text format # Export ship loadout in E:D Shipyard plain text format

View File

@ -42,8 +42,8 @@ if platform == 'darwin':
self.tkProcessKeyEvent_old = None self.tkProcessKeyEvent_old = None
self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_good.wav'), False) self.snd_good = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_good.wav'), False)
self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath, 'snd_bad.wav'), False) self.snd_bad = NSSound.alloc().initWithContentsOfFile_byReference_(join(config.respath_path, 'snd_bad.wav'), False)
def register(self, root, keycode, modifiers): def register(self, root, keycode, modifiers):
self.root = root self.root = root
@ -291,8 +291,8 @@ elif platform == 'win32':
def __init__(self): def __init__(self):
self.root = None self.root = None
self.thread = None self.thread = None
self.snd_good = open(join(config.respath, 'snd_good.wav'), 'rb').read() self.snd_good = open(join(config.respath_path, 'snd_good.wav'), 'rb').read()
self.snd_bad = open(join(config.respath, 'snd_bad.wav'), 'rb').read() self.snd_bad = open(join(config.respath_path, 'snd_bad.wav'), 'rb').read()
atexit.register(self.unregister) atexit.register(self.unregister)
def register(self, root, keycode, modifiers): def register(self, root, keycode, modifiers):

View File

@ -113,8 +113,8 @@ class _Translations:
return return
self.translations = {None: self.contents(cast(str, lang))} self.translations = {None: self.contents(cast(str, lang))}
for plugin in os.listdir(config.plugin_dir): for plugin in os.listdir(config.plugin_dir_path):
plugin_path = join(config.plugin_dir, plugin, LOCALISATION_DIR) plugin_path = join(config.plugin_dir_path, plugin, LOCALISATION_DIR)
if isdir(plugin_path): if isdir(plugin_path):
try: try:
self.translations[plugin] = self.contents(cast(str, lang), str(plugin_path)) self.translations[plugin] = self.contents(cast(str, lang), str(plugin_path))
@ -160,7 +160,7 @@ class _Translations:
""" """
if context: if context:
# TODO: There is probably a better way to go about this now. # TODO: There is probably a better way to go about this now.
context = context[len(config.plugin_dir_str)+1:].split(os.sep)[0] context = context[len(config.plugin_dir)+1:].split(os.sep)[0]
if self.translations[None] and context not in self.translations: if self.translations[None] and context not in self.translations:
logger.debug(f'No translations for {context!r}') logger.debug(f'No translations for {context!r}')

View File

@ -132,7 +132,7 @@ class EDLogs(FileSystemEventHandler): # type: ignore # See below
journal_dir = config.get_str('journaldir') journal_dir = config.get_str('journaldir')
if journal_dir == '' or journal_dir is None: if journal_dir == '' or journal_dir is None:
journal_dir = config.default_journal_dir_str journal_dir = config.default_journal_dir
# TODO(A_D): this is ignored for type checking due to all the different types config.get returns # TODO(A_D): this is ignored for type checking due to all the different types config.get returns
# When that is refactored, remove the magic comment # When that is refactored, remove the magic comment

View File

@ -350,7 +350,7 @@ def lookup(module, ship_map, entitled=False):
# Lazily populate # Lazily populate
if not moduledata: if not moduledata:
moduledata.update(pickle.load(open(join(config.respath, 'modules.p'), 'rb'))) moduledata.update(pickle.load(open(join(config.respath_path, 'modules.p'), 'rb')))
# if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout # if not module.get('category'): raise AssertionError('%s: Missing category' % module['id']) # only present post 1.3, and not present in ship loadout
if not module.get('name'): raise AssertionError('%s: Missing name' % module['id']) if not module.get('name'): raise AssertionError('%s: Missing name' % module['id'])

16
plug.py
View File

@ -173,10 +173,10 @@ def load_plugins(master):
last_error['root'] = master last_error['root'] = master
internal = [] internal = []
for name in sorted(os.listdir(config.internal_plugin_dir)): for name in sorted(os.listdir(config.internal_plugin_dir_path)):
if name.endswith('.py') and not name[0] in ['.', '_']: if name.endswith('.py') and not name[0] in ['.', '_']:
try: try:
plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir, name), logger) plugin = Plugin(name[:-3], os.path.join(config.internal_plugin_dir_path, name), logger)
plugin.folder = None # Suppress listing in Plugins prefs tab plugin.folder = None # Suppress listing in Plugins prefs tab
internal.append(plugin) internal.append(plugin)
except Exception as e: except Exception as e:
@ -184,13 +184,13 @@ def load_plugins(master):
PLUGINS.extend(sorted(internal, key=lambda p: operator.attrgetter('name')(p).lower())) PLUGINS.extend(sorted(internal, key=lambda p: operator.attrgetter('name')(p).lower()))
# Add plugin folder to load path so packages can be loaded from plugin folder # Add plugin folder to load path so packages can be loaded from plugin folder
sys.path.append(config.plugin_dir_str) sys.path.append(config.plugin_dir)
found = [] found = []
# Load any plugins that are also packages first # Load any plugins that are also packages first
for name in sorted(os.listdir(config.plugin_dir), for name in sorted(os.listdir(config.plugin_dir_path),
key = lambda n: (not os.path.isfile(os.path.join(config.plugin_dir, n, '__init__.py')), n.lower())): key = lambda n: (not os.path.isfile(os.path.join(config.plugin_dir_path, n, '__init__.py')), n.lower())):
if not os.path.isdir(os.path.join(config.plugin_dir, name)) or name[0] in ['.', '_']: if not os.path.isdir(os.path.join(config.plugin_dir_path, name)) or name[0] in ['.', '_']:
pass pass
elif name.endswith('.disabled'): elif name.endswith('.disabled'):
name, discard = name.rsplit('.', 1) name, discard = name.rsplit('.', 1)
@ -198,14 +198,14 @@ def load_plugins(master):
else: else:
try: try:
# Add plugin's folder to load path in case plugin has internal package dependencies # Add plugin's folder to load path in case plugin has internal package dependencies
sys.path.append(os.path.join(config.plugin_dir, name)) sys.path.append(os.path.join(config.plugin_dir_path, name))
# Create a logger for this 'found' plugin. Must be before the # Create a logger for this 'found' plugin. Must be before the
# load.py is loaded. # load.py is loaded.
import EDMCLogging import EDMCLogging
plugin_logger = EDMCLogging.get_plugin_logger(name) plugin_logger = EDMCLogging.get_plugin_logger(name)
found.append(Plugin(name, os.path.join(config.plugin_dir, name, 'load.py'), plugin_logger)) found.append(Plugin(name, os.path.join(config.plugin_dir_path, name, 'load.py'), plugin_logger))
except Exception as e: except Exception as e:
logger.exception(f'Failure loading found Plugin "{name}"') logger.exception(f'Failure loading found Plugin "{name}"')
pass pass

View File

@ -745,7 +745,7 @@ def journal_entry( # noqa: C901
journaldir = config.get_str('journaldir') journaldir = config.get_str('journaldir')
if journaldir is None or journaldir == '': if journaldir is None or journaldir == '':
journaldir = config.default_journal_dir_str journaldir = config.default_journal_dir
path = pathlib.Path(journaldir) / f'{entry["event"]}.json' path = pathlib.Path(journaldir) / f'{entry["event"]}.json'

View File

@ -408,7 +408,7 @@ class PreferencesDialog(tk.Toplevel):
row = AutoInc(start=1) row = AutoInc(start=1)
self.logdir = tk.StringVar() self.logdir = tk.StringVar()
default = config.default_journal_dir_str if config.default_journal_dir is not None else '' default = config.default_journal_dir if config.default_journal_dir_path is not None else ''
logdir = config.get_str('journaldir') logdir = config.get_str('journaldir')
if logdir is None or logdir == '': if logdir is None or logdir == '':
logdir = default logdir = default
@ -431,7 +431,7 @@ class PreferencesDialog(tk.Toplevel):
) )
self.logbutton.grid(column=3, padx=self.PADX, pady=self.PADY, sticky=tk.EW, row=row.get()) self.logbutton.grid(column=3, padx=self.PADX, pady=self.PADY, sticky=tk.EW, row=row.get())
if config.default_journal_dir: if config.default_journal_dir_path:
# Appearance theme and language setting # Appearance theme and language setting
nb.Button( nb.Button(
config_frame, config_frame,
@ -800,7 +800,7 @@ class PreferencesDialog(tk.Toplevel):
plugins_frame = nb.Frame(notebook) plugins_frame = nb.Frame(notebook)
plugins_frame.columnconfigure(0, weight=1) plugins_frame.columnconfigure(0, weight=1)
plugdir = tk.StringVar() plugdir = tk.StringVar()
plugdir.set(config.plugin_dir_str) plugdir.set(config.plugin_dir)
row = AutoInc(1) row = AutoInc(1)
# Section heading in settings # Section heading in settings
@ -949,7 +949,7 @@ class PreferencesDialog(tk.Toplevel):
browseInfo.lpszTitle = title browseInfo.lpszTitle = title
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI
browseInfo.lpfn = BrowseCallbackProc(browsecallback) browseInfo.lpfn = BrowseCallbackProc(browsecallback)
browseInfo.lParam = pathvar.get().startswith('~') and join(config.home, browseInfo.lParam = pathvar.get().startswith('~') and join(config.home_path,
pathvar.get()[2:]) or pathvar.get() pathvar.get()[2:]) or pathvar.get()
ctypes.windll.ole32.CoInitialize(None) ctypes.windll.ole32.CoInitialize(None)
pidl = ctypes.windll.shell32.SHBrowseForFolderW(ctypes.byref(browseInfo)) pidl = ctypes.windll.shell32.SHBrowseForFolderW(ctypes.byref(browseInfo))
@ -985,7 +985,7 @@ class PreferencesDialog(tk.Toplevel):
entryfield['state'] = tk.NORMAL # must be writable to update entryfield['state'] = tk.NORMAL # must be writable to update
entryfield.delete(0, tk.END) entryfield.delete(0, tk.END)
if platform == 'win32': if platform == 'win32':
start = len(config.home_str.split('\\')) if pathvar.get().lower().startswith(config.home_str.lower()) else 0 start = len(config.home.split('\\')) if pathvar.get().lower().startswith(config.home.lower()) else 0
display = [] display = []
components = normpath(pathvar.get()).split('\\') components = normpath(pathvar.get()).split('\\')
buf = ctypes.create_unicode_buffer(MAX_PATH) buf = ctypes.create_unicode_buffer(MAX_PATH)
@ -1006,9 +1006,9 @@ class PreferencesDialog(tk.Toplevel):
# None if path doesn't exist # None if path doesn't exist
elif platform == 'darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()): elif platform == 'darwin' and NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get()):
if pathvar.get().startswith(config.home_str): if pathvar.get().startswith(config.home):
display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[ display = ['~'] + NSFileManager.defaultManager().componentsToDisplayForPath_(pathvar.get())[
len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home_str)): len(NSFileManager.defaultManager().componentsToDisplayForPath_(config.home)):
] ]
else: else:
@ -1016,8 +1016,8 @@ class PreferencesDialog(tk.Toplevel):
entryfield.insert(0, '/'.join(display)) entryfield.insert(0, '/'.join(display))
else: else:
if pathvar.get().startswith(config.home_str): if pathvar.get().startswith(config.home):
entryfield.insert(0, '~' + pathvar.get()[len(config.home_str):]) entryfield.insert(0, '~' + pathvar.get()[len(config.home):])
else: else:
entryfield.insert(0, pathvar.get()) entryfield.insert(0, pathvar.get())
@ -1026,8 +1026,8 @@ class PreferencesDialog(tk.Toplevel):
def logdir_reset(self) -> None: def logdir_reset(self) -> None:
"""Reset the log dir to the default.""" """Reset the log dir to the default."""
if config.default_journal_dir: if config.default_journal_dir_path:
self.logdir.set(config.default_journal_dir_str) self.logdir.set(config.default_journal_dir)
self.outvarchanged() self.outvarchanged()
@ -1134,11 +1134,11 @@ class PreferencesDialog(tk.Toplevel):
config.set( config.set(
'outdir', 'outdir',
join(config.home, self.outdir.get()[2:]) if self.outdir.get().startswith('~') else self.outdir.get() join(config.home_path, self.outdir.get()[2:]) if self.outdir.get().startswith('~') else self.outdir.get()
) )
logdir = self.logdir.get() logdir = self.logdir.get()
if config.default_journal_dir and logdir.lower() == config.default_journal_dir_str.lower(): if config.default_journal_dir_path and logdir.lower() == config.default_journal_dir.lower():
config.set('journaldir', '') # default location config.set('journaldir', '') # default location
else: else: