|
20 | 20 | from CommonClient import ClientCommandProcessor, CommonContext, logger, server_loop, gui_enabled, get_base_parser |
21 | 21 | from MultiServer import mark_raw |
22 | 22 | from NetUtils import ClientStatus, NetworkItem, JSONtoTextParser, JSONMessagePart |
23 | | -from Utils import async_start, get_file_safe_name, is_windows, Version, format_SI_prefix, get_text_between |
| 23 | +from Utils import async_start, get_file_safe_name, is_windows, Version, format_SI_prefix, get_text_between, user_path |
24 | 24 | from .FactorioSettings import FactorioSettings |
25 | 25 | from settings import get_settings |
26 | 26 |
|
@@ -599,18 +599,27 @@ def launch(*new_args: str): |
599 | 599 | else: |
600 | 600 | raise FileNotFoundError(f"Path {executable} is not an executable file.") |
601 | 601 |
|
602 | | - config_directory = args.config if args.config \ |
603 | | - else os.path.join(getattr(settings, "write_directory", None), "config") |
604 | | - |
605 | | - if not os.path.exists(config_directory): |
606 | | - logger.info(f"Could not find {config_directory} for config. Attempting to create it.") |
607 | | - os.makedirs(config_directory, exist_ok=True) |
608 | | - |
609 | | - config_file = os.path.join(config_directory, "apconfig.ini") |
610 | | - if not os.path.exists(config_file): |
611 | | - logger.info(f"Could not find {config_file} for config file. Attempting to create it.") |
612 | | - with open(config_file, 'w') as f: |
613 | | - f.write(f"[path]\nread-data=__PATH__system-read-data__\nwrite-data={getattr(settings, "write_directory", None)}") |
| 602 | + if args.config: |
| 603 | + config_file = args.config |
| 604 | + if not os.path.exists(config_file): |
| 605 | + raise FileNotFoundError(f"Could not find factorio config file: {config_file}.") |
| 606 | + else: |
| 607 | + config_file = os.path.join(getattr(settings, "config_file", None)) |
| 608 | + |
| 609 | + if not os.path.exists(config_file): |
| 610 | + if config_file != user_path("factorio_mods", "config", "apconfig.ini"): |
| 611 | + raise FileNotFoundError(f"Could not find factorio config file: {config_file}.") |
| 612 | + write_directory = user_path("factorio_mods") |
| 613 | + config_directory = os.path.join(write_directory, "config") |
| 614 | + if not os.path.exists(config_directory): |
| 615 | + logger.info(f"Could not find {config_directory} for config. Attempting to create it.") |
| 616 | + os.makedirs(config_directory, exist_ok=True) |
| 617 | + |
| 618 | + config_file = os.path.join(config_directory, "apconfig.ini") |
| 619 | + if not os.path.exists(config_file): |
| 620 | + logger.info(f"Could not find {config_file} for config file. Attempting to create it.") |
| 621 | + with open(config_file, 'w') as f: |
| 622 | + f.write(f"[path]\nread-data=__PATH__system-read-data__\nwrite-data={write_directory}") |
614 | 623 |
|
615 | 624 | mod_directory = args.mod_directory if args.mod_directory \ |
616 | 625 | else getattr(settings, "mod_directory", None) |
|
0 commit comments