fix licence file loading

This commit is contained in:
Andrew Ward
2025-03-22 10:19:16 +00:00
parent 469826056c
commit ed9e89f6c9
2 changed files with 34 additions and 15 deletions

View File

@@ -485,22 +485,41 @@ Please also make sure you read the Terms of use and licence statement before usi
ttk.Button(instruction_window, text="Close", command=instruction_window.destroy).pack(pady=(10, 0)) ttk.Button(instruction_window, text="Close", command=instruction_window.destroy).pack(pady=(10, 0))
def show_terms_of_use(self): def show_terms_of_use(self):
# Get the path to the LICENSE.md file using the resource_path method # Try multiple approaches to find the LICENSE.md file
license_path = self.resource_path("LICENSE.md") license_content = None
possible_paths = [
"LICENSE.md", # Direct path when running as script
self.resource_path("LICENSE.md"), # Using resource_path helper
self.resource_path("assets/LICENSE.md"), # Check in assets folder
Path("assets") / "LICENSE.md" # Alternative assets path
]
# Attempt to read the content of the LICENSE.md file # Try each path until we find the file
try: for path in possible_paths:
# Open the file with 'r' (read mode) and specify 'utf-8' encoding try:
with open(license_path, "r", encoding="utf-8") as file: with open(path, "r", encoding="utf-8") as file:
license_content = file.read() license_content = file.read()
except FileNotFoundError: break
license_content = "License file not found. Please ensure the LICENSE.md file exists in the application directory." except (FileNotFoundError, PermissionError, UnicodeDecodeError):
except PermissionError: continue
license_content = "Permission denied. Please ensure the script has read access to LICENSE.md."
except UnicodeDecodeError as e: # If we couldn't find the file in the filesystem, provide a fallback
license_content = f"Error reading license file due to encoding issue: {e}" if license_content is None:
except Exception as e: license_content = """
license_content = f"An unexpected error occurred while reading the license file: {e}" Scorchsoft Text to Mic License
This application is provided for personal and commercial use, subject to the following conditions:
1. You may use this application for personal or commercial purposes.
2. You may not redistribute, sell, or include this application as part of another product without explicit permission.
3. This application uses the OpenAI API, and you are responsible for any charges incurred through your API key.
4. The developer assumes no liability for any misuse or charges incurred through use of this application.
For the complete license text, please visit:
https://www.scorchsoft.com/text-to-mic-license
Copyright © Scorchsoft.com
"""
# Create a new window to display the terms of use # Create a new window to display the terms of use
instruction_window = tk.Toplevel(self) instruction_window = tk.Toplevel(self)