initial commit
This commit is contained in:
		
							parent
							
								
									e2258e270c
								
							
						
					
					
						commit
						03d4c53525
					
				
							
								
								
									
										53
									
								
								dynamic_launcher.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								dynamic_launcher.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,53 @@
 | 
				
			|||||||
 | 
					import os
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					import requests
 | 
				
			||||||
 | 
					import importlib.util
 | 
				
			||||||
 | 
					import zipfile
 | 
				
			||||||
 | 
					import shutil
 | 
				
			||||||
 | 
					import json
 | 
				
			||||||
 | 
					from datetime import datetime
 | 
				
			||||||
 | 
					import configparser
 | 
				
			||||||
 | 
					from PyQt5 import QtWidgets, QtGui
 | 
				
			||||||
 | 
					from PyQt5.QtWidgets import (
 | 
				
			||||||
 | 
					    QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout,
 | 
				
			||||||
 | 
					    QLabel, QLineEdit, QPushButton, QCheckBox, QComboBox, QDialog,
 | 
				
			||||||
 | 
					    QMessageBox, QFileDialog
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					from PyQt5.QtGui import QFont
 | 
				
			||||||
 | 
					from PyQt5.QtCore import Qt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Define repository details
 | 
				
			||||||
 | 
					file_url = 'https://git.rolfsvaag.no/frarol96/ERSCMU/raw/branch/main/ERSCMU.py'
 | 
				
			||||||
 | 
					cache_dir = os.path.join(os.getenv('APPDATA'), 'ERSC Mod Updater')
 | 
				
			||||||
 | 
					cache_file = os.path.join(cache_dir, 'ERSCMU.py')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Ensure cache directory exists
 | 
				
			||||||
 | 
					if not os.path.exists(cache_dir):
 | 
				
			||||||
 | 
					    os.makedirs(cache_dir)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Function to fetch the latest file
 | 
				
			||||||
 | 
					def fetch_latest_file(url, cache_path):
 | 
				
			||||||
 | 
					    try:
 | 
				
			||||||
 | 
					        print("Fetching latest version of the script...")
 | 
				
			||||||
 | 
					        response = requests.get(url)
 | 
				
			||||||
 | 
					        response.raise_for_status()
 | 
				
			||||||
 | 
					        with open(cache_path, 'wb') as f:
 | 
				
			||||||
 | 
					            f.write(response.content)
 | 
				
			||||||
 | 
					        print("Latest version fetched and cached.")
 | 
				
			||||||
 | 
					    except requests.RequestException as e:
 | 
				
			||||||
 | 
					        print(f"Failed to fetch the latest version. Using cached version if available.\nError: {e}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Fetch the latest version of the file or use the cached version
 | 
				
			||||||
 | 
					fetch_latest_file(file_url, cache_file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Ensure the cached file exists
 | 
				
			||||||
 | 
					if not os.path.exists(cache_file):
 | 
				
			||||||
 | 
					    print("No cached version available. Exiting.")
 | 
				
			||||||
 | 
					    sys.exit(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Prepare the global context with necessary imports
 | 
				
			||||||
 | 
					global_context = globals().copy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Import and run the cached script
 | 
				
			||||||
 | 
					with open(cache_file, 'r') as file:
 | 
				
			||||||
 | 
					    exec(file.read(), global_context)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user