diff --git a/.gitignore b/.gitignore index a7da806e..df50e32b 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ pylint.txt # Ignore Submodule data directory coriolis-data/ +FDevIDs/ \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index cd89b465..c65e62f1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "coriolis-data"] path = coriolis-data url = https://github.com/EDCD/coriolis-data.git -[submodule "FDevIDs"] - path = FDevIDs - url = https://github.com/EDCD/FDevIDs.git diff --git a/EDMC.py b/EDMC.py index 64488778..6b72c7d1 100755 --- a/EDMC.py +++ b/EDMC.py @@ -42,7 +42,7 @@ import stats from commodity import COMMODITY_DEFAULT from config import appcmdname, appversion, config from monitor import monitor -from update import EDMCVersion, Updater +from update import EDMCVersion, Updater, check_for_fdev_updates sys.path.append(config.internal_plugin_dir) # This import must be after the sys.path.append. @@ -497,6 +497,10 @@ def main(): # noqa: C901, CCR001 if __name__ == '__main__': - main() + try: + check_for_fdev_updates(silent=True) + main() + except KeyboardInterrupt: + logger.info("Ctrl+C Detected, Attempting Clean Shutdown") logger.debug('Exiting') sys.exit(EXIT_SUCCESS) diff --git a/EDMarketConnector.py b/EDMarketConnector.py index c11a9027..4932ea0d 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -2282,35 +2282,6 @@ sys.path: {sys.path}''' ) config.set('plugins_not_py3_last', int(time())) - def check_fdev_ids(): - """Display message about missing FDEVID files.""" - fdev_files = {'commodity.csv', 'rare_commodity.csv'} - for file in fdev_files: - fdevid_file = pathlib.Path(config.respath_path / 'FDevIDs' / file) - if fdevid_file.is_file(): - continue - # LANG: Popup-text about missing FDEVID Files - popup_text = tr.tl( - "FDevID Files not found! Some functionality regarding commodities " - r"may be disabled.\r\n\r\n Do you want to open the Wiki page on " - "how to set up submodules?" - ) - # 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') - - openwikipage = tk.messagebox.askquestion( - # LANG: Popup window title for missing FDEVID files - tr.tl('FDevIDs: Missing Commodity Files'), - popup_text - ) - if openwikipage == "yes": - webbrowser.open( - "https://github.com/EDCD/EDMarketConnector/wiki/Running-from-source" - "#obtain-a-copy-of-the-application-source" - ) - break - # UI Transparency ui_transparency = config.get_int('ui_transparency') if ui_transparency == 0: @@ -2323,8 +2294,6 @@ sys.path: {sys.path}''' root.after(1, messagebox_not_py3) # Show warning popup for killswitches matching current version root.after(2, show_killswitch_poppup, root) - # Check for FDEV IDs - root.after(3, check_fdev_ids) # Start the main event loop try: root.mainloop() diff --git a/FDevIDs b/FDevIDs deleted file mode 160000 index 9b3f4061..00000000 --- a/FDevIDs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9b3f40612017b43a8b826017e1e2befebd9074f2 diff --git a/L10n/en.template b/L10n/en.template index 2829b1bb..ae854134 100644 --- a/L10n/en.template +++ b/L10n/en.template @@ -216,12 +216,6 @@ /* EDMarketConnector.py: Popup-text about 'active' plugins without Python 3.x support; In files: EDMarketConnector.py:2253:2259; */ "One or more of your enabled plugins do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\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 do not yet have support for Python 3.x. Please see the list on the '{PLUGINS}' tab of '{FILE}' > '{SETTINGS}'. You should check if there is an updated version available, else alert the developer that they need to update the code for Python 3.x.\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 missing FDEVID Files; In files: EDMarketConnector.py:2329; */ -"FDevID Files not found! Some functionality regarding commodities may be disabled.\r\n\r\n Do you want to open the Wiki page on how to set up submodules?" = "FDevID Files not found! Some functionality regarding commodities may be disabled.\r\n\r\n Do you want to open the Wiki page on how to set up submodules?"; - -/* EDMarketConnector.py: Popup window title for missing FDEVID files; In files: EDMarketConnector.py:2340; */ -"FDevIDs: Missing Commodity Files" = "FDevIDs: Missing Commodity Files"; - /* EDMarketConnector.py: Settings > Plugins tab; prefs.py: Label on Settings > Plugins tab; In files: EDMarketConnector.py:2263; prefs.py:986; */ "Plugins" = "Plugins"; diff --git a/build.py b/build.py index 966799c4..2483a4e0 100644 --- a/build.py +++ b/build.py @@ -21,6 +21,7 @@ from config import ( _static_appversion, update_interval ) +from update import check_for_fdev_updates def iss_build(template_path: str, output_file: str) -> None: @@ -207,4 +208,5 @@ def build() -> None: if __name__ == "__main__": + check_for_fdev_updates() build() diff --git a/update.py b/update.py index 52983a5d..227e9995 100644 --- a/update.py +++ b/update.py @@ -7,6 +7,7 @@ See LICENSE file. """ from __future__ import annotations +import pathlib import sys import threading from traceback import print_exc @@ -25,6 +26,38 @@ if TYPE_CHECKING: logger = get_main_logger() +def check_for_fdev_updates(silent: bool = False) -> None: # noqa: CCR001 + """Check for and download FDEV ID file updates.""" + files_urls = [ + ('commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/commodity.csv'), + ('rare_commodity.csv', 'https://raw.githubusercontent.com/EDCD/FDevIDs/master/rare_commodity.csv') + ] + + for file, url in files_urls: + fdevid_file = pathlib.Path(config.respath_path / 'FDevIDs' / file) + fdevid_file.parent.mkdir(parents=True, exist_ok=True) + try: + with open(fdevid_file, newline='', encoding='utf-8') as f: + local_content = f.read() + except FileNotFoundError: + local_content = None + + response = requests.get(url) + if response.status_code != 200: + if not silent: + logger.error(f'Failed to download {file}! Unable to continue.') + continue + + if local_content == response.text: + if not silent: + logger.info(f'FDEV ID file {file} already up to date.') + else: + if not silent: + logger.info(f'FDEV ID file {file} not up to date. Downloading...') + with open(fdevid_file, 'w', newline='', encoding='utf-8') as csvfile: + csvfile.write(response.text) + + class EDMCVersion: """ Hold all the information about an EDMC version. @@ -135,6 +168,8 @@ class Updater: elif sys.platform == 'win32' and self.updater: self.updater.win_sparkle_check_update_with_ui() + check_for_fdev_updates() + def check_appcast(self) -> EDMCVersion | None: """ Manually (no Sparkle or WinSparkle) check the update_feed appcast file.