Skip to content

Commit

Permalink
Merge pull request #2154 from HullSeals/enhancement/2077/ensure_valid…
Browse files Browse the repository at this point in the history
…_providers

[#2077] Ensure Providers Are Valid
  • Loading branch information
C1701D authored Feb 8, 2024
2 parents 610d197 + c45a476 commit 2b54439
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
48 changes: 48 additions & 0 deletions EDMarketConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@ def open_window(systray: 'SysTrayIcon') -> None:
self.w.bind_all('<<CompanionAuthEvent>>', self.auth) # cAPI auth
self.w.bind_all('<<Quit>>', self.onexit) # Updater

# Check for Valid Providers
validate_providers()

# Start a protocol handler to handle cAPI registration. Requires main loop to be running.
self.w.after_idle(lambda: protocol.protocolhandler.start(self.w))

Expand Down Expand Up @@ -2115,6 +2118,51 @@ def show_killswitch_poppup(root=None):
ok_button.grid(columnspan=2, sticky=tk.EW)


def validate_providers():
"""Check if Config has an invalid provider set, and reset to default if we do."""
reset_providers = {}
station_provider: str = config.get_str("station_provider")
if station_provider not in plug.provides('station_url'):
logger.error("Station Provider Not Valid. Setting to Default.")
config.set('station_provider', 'EDSM')
reset_providers["Station"] = (station_provider, "EDSM")

shipyard_provider: str = config.get_str("shipyard_provider")
if shipyard_provider not in plug.provides('shipyard_url'):
logger.error("Shipyard Provider Not Valid. Setting to Default.")
config.set('shipyard_provider', 'EDSY')
reset_providers["Shipyard"] = (shipyard_provider, "EDSY")

system_provider: str = config.get_str("system_provider")
if system_provider not in plug.provides('system_url'):
logger.error("System Provider Not Valid. Setting to Default.")
config.set('system_provider', 'EDSM')
reset_providers["System"] = (system_provider, "EDSM")

if not reset_providers:
return

# LANG: Popup-text about Reset Providers
popup_text = _(r'One or more of your URL Providers were invalid, and have been reset:\r\n\r\n')
for provider in reset_providers:
# LANG: Text About What Provider Was Reset
popup_text += _(r'{PROVIDER} was set to {OLDPROV}, and has been reset to {NEWPROV}\r\n')
popup_text = popup_text.format(
PROVIDER=provider,
OLDPROV=reset_providers[provider][0],
NEWPROV=reset_providers[provider][1]
)
# And now we do need these to be actual \r\n
popup_text = popup_text.replace('\\n', '\n')
popup_text = popup_text.replace('\\r', '\r')

tk.messagebox.showinfo(
# LANG: Popup window title for Reset Providers
_('EDMC: Default Providers Reset'),
popup_text
)


# Run the app
if __name__ == "__main__": # noqa: C901
logger.info(f'Startup v{appversion()} : Running on Python v{sys.version}')
Expand Down
9 changes: 9 additions & 0 deletions L10n/en.template
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,15 @@
/* EDMarketConnector.py: Popup-text about 'broken' plugins that failed to load; In files: EDMarketConnector.py:2266; */
"One or more of your enabled plugins failed to load. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. This could be caused by a wrong folder structure. The load.py file should be located under plugins/PLUGIN_NAME/load.py.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name." = "One or more of your enabled plugins failed to load. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. This could be caused by a wrong folder structure. The load.py file should be located under plugins/PLUGIN_NAME/load.py.\r\n\r\nYou can disable a plugin by renaming its folder to have '{DISABLED}' on the end of the name.";

/* EDMarketConnector.py: Popup-text about Reset Providers; In files: EDMarketConnector.py:2146; */
"One or more of your URL Providers were invalid, and have been reset:\r\n\r\n" = "One or more of your URL Providers were invalid, and have been reset:\r\n\r\n";

/* EDMarketConnector.py: Text About What Provider Was Reset; In files: EDMarketConnector.py:2148; */
"{PROVIDER} was set to {OLDPROV}, and has been reset to {NEWPROV}\r\n" = "{PROVIDER} was set to {OLDPROV}, and has been reset to {NEWPROV}\r\n";

/* EDMarketConnector.py: Popup window title for Reset Providers; In files: EDMarketConnector.py:2161; */
"EDMC: Default Providers Reset" = "EDMC: Default Providers Reset";

/* journal_lock.py: Title text on popup when Journal directory already locked; In files: journal_lock.py:208; */
"Journal directory already locked" = "Journal directory already locked";

Expand Down

0 comments on commit 2b54439

Please sign in to comment.