|
25 | 25 |
|
26 | 26 | VERSION = "v2.3.5" |
27 | 27 |
|
28 | | -if getattr(sys, 'frozen', False): |
29 | | - # PyInstaller creates a temp folder and stores path in _MEIPASS |
30 | | - if hasattr(sys, '_MEIPASS'): |
31 | | - bundle_dir = sys._MEIPASS |
| 28 | + |
| 29 | +def get_user_data_path(filename): |
| 30 | + """Get the path for user data files """ |
| 31 | + if getattr(sys, 'frozen', False): |
| 32 | + # If running as PyInstaller exe, put user data files next to the executable |
| 33 | + return os.path.join(os.path.dirname(sys.executable), filename) |
32 | 34 | else: |
33 | | - bundle_dir = os.path.dirname(sys.executable) |
34 | | - os.chdir(bundle_dir) |
| 35 | + # If running as script, put files in current directory |
| 36 | + return os.path.join(os.path.abspath("."), filename) |
| 37 | + |
| 38 | + |
| 39 | +# if getattr(sys, 'frozen', False): |
| 40 | +# # PyInstaller creates a temp folder and stores path in _MEIPASS |
| 41 | +# if hasattr(sys, '_MEIPASS'): |
| 42 | +# bundle_dir = sys._MEIPASS |
| 43 | +# else: |
| 44 | +# bundle_dir = os.path.dirname(sys.executable) |
| 45 | +# os.chdir(bundle_dir) |
35 | 46 |
|
36 | | -log_file_path = "duce.log" |
| 47 | +log_file_path = get_user_data_path("duce.log") |
37 | 48 |
|
38 | 49 |
|
39 | 50 | logger.remove() |
@@ -781,8 +792,9 @@ def get_now_to_utc(self): |
781 | 792 | return datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ") |
782 | 793 |
|
783 | 794 | def load_settings(self): |
| 795 | + settings_file = get_user_data_path(f"duce-{self.interface}-settings.json") |
784 | 796 | try: |
785 | | - with open(f"duce-{self.interface}-settings.json") as f: |
| 797 | + with open(settings_file) as f: |
786 | 798 | self.settings = json.load(f) |
787 | 799 | except FileNotFoundError: |
788 | 800 | with open( |
@@ -815,7 +827,8 @@ def load_settings(self): |
815 | 827 | self.instructor_exclude = "\n".join(self.settings["instructor_exclude"]) |
816 | 828 |
|
817 | 829 | def save_settings(self): |
818 | | - with open(f"duce-{self.interface}-settings.json", "w") as f: |
| 830 | + settings_file = get_user_data_path(f"duce-{self.interface}-settings.json") |
| 831 | + with open(settings_file, "w") as f: |
819 | 832 | json.dump(self.settings, f, indent=4) |
820 | 833 |
|
821 | 834 | def compare_versions(self, version1, version2): |
|
0 commit comments