From 19fc7ba100cb959b947fbbaf5ba62a2272b256bf Mon Sep 17 00:00:00 2001 From: Peter Henniger <3252681+hennigerpeter@users.noreply.github.com> Date: Tue, 2 Sep 2025 20:42:33 +0200 Subject: [PATCH] added mists of pandaria configuration --- README.md | 118 +++++++++++----------- main.py | 284 +++++++++++++++++++++++++++------------------------- version.txt | 1 + 3 files changed, 205 insertions(+), 198 deletions(-) create mode 100644 version.txt diff --git a/README.md b/README.md index 9d2ceea..da50562 100644 --- a/README.md +++ b/README.md @@ -1,60 +1,58 @@ -# WoW Sim Sod/WotLK/Cataclysm Auto-Updater - -This script is designed to automatically update the World of Warcraft Simulator (WoW Sim) for Season of Discovery (Classic Era), Wrath of the Lich King (WotLK) or Cataclysm. It checks for the latest release of the simulator from a specified GitHub repository, downloads it if it is newer than the current version, and then unzips and runs the simulator. - -## Features - -- Checks for the latest release version from the GitHub repository. -- Downloads the latest release if it is not already present or if there is a new version. -- Unzips the downloaded file. -- Automatically terminates the running WoW Sim process before updating. -- Starts the WoW Sim application. - -## Requirements - -Before running this script, ensure you have Python 3.x installed on your system. Additionally, you will need the dependencies listed in the `requirements.txt` file. - -## Installation - -1. Clone this repository or download the script to your local machine. -2. Install the required Python libraries by running: -``` -pip install -r requirements.txt -``` - - -The script will: - -1. Fetch the latest release information from the GitHub repository. -2. Compare the latest release version with the local version (if present). -3. Download the new release if necessary. -4. Unzip the downloaded file. -5. Run the WoW Sim application. - -## Configuration - -The script uses the following default configuration: - -- GitHub API URL for WoW Sim WotLK releases: `https://api.github.com/repos/wowsims/wotlk/releases/latest` -- Release file name pattern: `wowsimwotlk-windows.exe.zip` -- Executable file name: `wowsimwotlk-windows.exe` - -If you need to update these values, modify the respective variables in the script. - -## Contributing - -Contributions to this project are welcome. Please fork the repository and submit a pull request with your improvements. - -## License - -[MIT License](LICENSE) - - -## Acknowledgments - -- Thanks to the maintainers of the WoW Sim project for providing the community with useful tools. - ---- - -For more information, questions, or feedback, please open an issue in this repository. - +# WoW Sim Sod/WotLK/Cataclysm/MoP Auto-Updater + +This script is designed to automatically update the World of Warcraft Simulator (WoW Sim) for Season of Discovery (Classic Era), Wrath of the Lich King (WotLK), Cataclysm and Mists of Pandaria (MoP). It checks for the latest release of the simulator from a specified GitHub repository, downloads it if it is newer than the current version, and then unzips and runs the simulator. + +## Features + +- Checks for the latest release version from the GitHub repository. +- Downloads the latest release if it is not already present or if there is a new version. +- Unzips the downloaded file. +- Automatically terminates the running WoW Sim process before updating. +- Starts the WoW Sim application. + +## Requirements + +Before running this script, ensure you have Python 3.x installed on your system. Additionally, you will need the dependencies listed in the `requirements.txt` file. + +## Installation + +1. Clone this repository or download the script to your local machine. +2. Install the required Python libraries by running: + +``` +pip install -r requirements.txt +``` + +The script will: + +1. Fetch the latest release information from the GitHub repository. +2. Compare the latest release version with the local version (if present). +3. Download the new release if necessary. +4. Unzip the downloaded file. +5. Run the WoW Sim application. + +## Configuration + +The script uses the following default configuration: + +- GitHub API URL for WoW Sim WotLK releases: `https://api.github.com/repos/wowsims/wotlk/releases/latest` +- Release file name pattern: `wowsimwotlk-windows.exe.zip` +- Executable file name: `wowsimwotlk-windows.exe` + +If you need to update these values, modify the respective variables in the script. + +## Contributing + +Contributions to this project are welcome. Please fork the repository and submit a pull request with your improvements. + +## License + +[MIT License](LICENSE) + +## Acknowledgments + +- Thanks to the maintainers of the WoW Sim project for providing the community with useful tools. + +--- + +For more information, questions, or feedback, please open an issue in this repository. diff --git a/main.py b/main.py index 0e41b10..672a78a 100644 --- a/main.py +++ b/main.py @@ -1,138 +1,146 @@ -import requests -import os -import zipfile -import psutil -import logging - -logging.basicConfig( - level=logging.INFO, - format='%(asctime)s %(levelname)s %(message)s', - datefmt='%d-%m-%y %H:%M:%S', - filename='sim_downloader.log', - filemode='w' -) - -# Cataclysm -cata_api_repo_url = 'https://api.github.com/repos/wowsims/cata/releases/latest' -cata_release_file_name = 'wowsimcata-windows.exe.zip' -cata_file_name = 'wowsimcata-windows.exe' - -# Wrath of the Lich King -wotlk_api_repo_url = 'https://api.github.com/repos/wowsims/wotlk/releases/latest' -wotlk_release_file_name = 'wowsimwotlk-windows.exe.zip' -wotlk_file_name = 'wowsimwotlk-windows.exe' - -# Season of Discovery -sod_api_repo_url = 'https://api.github.com/repos/wowsims/sod/releases/latest' -sod_release_file_name = 'wowsimsod-windows.exe.zip' -sod_file_name = 'wowsimsod-windows.exe' - - -def file_exists(file_path): - # check if given file exists - return os.path.exists(file_path) - - -def fetch_release_info(repo_url): - # Fetches the release information from the given GitHub repository URL. - response = requests.get(repo_url) - if response.status_code == 200: - return response.json() - else: - print(f"Failed to fetch latest release. Status Code: {response.status_code}") - logging.critical(f"Failed to fetch latest release. Status Code: {response.status_code}") - return None - - -def get_download_url(release_info, file_name): - # Gets the download URL for the specified file from the release information. - for asset in release_info['assets']: - if asset['name'].lower() == file_name.lower(): - return asset['browser_download_url'] - return None - - -def download_file(url, file_name, file_version): - # Downloads the file from the given URL and writes it to disk. - response = requests.get(url) - if response.status_code == 200: - with open(file_name, 'wb') as file: - file.write(response.content) - with open('version.txt', 'w') as version: - version.write(file_version) - return True - else: - print(f"Failed to download the file. Status Code: {response.status_code}") - logging.error(f"Failed to download the file. Status Code: {response.status_code}") - return False - - -def unzip_file(file): - if file_exists(file): - with zipfile.ZipFile(file, 'r') as zip_ref: - zip_ref.extractall() - zip_ref.close() - - -def run_sim(file): - if file_exists(file): - os.startfile(file) - - -def download_sim(api_repo_url, release_file_name, file_name): - # Fetch the latest release information from the GitHub repository. - release_info = fetch_release_info(api_repo_url) - - if release_info: - # Extract the release tag/version number from the release information. - release_tag = release_info['tag_name'] - # Get the download URL for the specified file from the release information. - download_url = get_download_url(release_info, release_file_name) - - if download_url: - version_number = None - if file_exists('version.txt'): - with open('version.txt') as version: - version_number = version.read() - - if version_number != release_tag: - for proc in psutil.process_iter(): - # check whether the process name matches - if proc.name() == file_name: - proc.kill() - print(f"Downloading latest {release_file_name} from Github. {release_tag}") - logging.info(f"Downloading latest {release_file_name} from Github. {release_tag}") - # Download the file and update the local version number. - if download_file(download_url, release_file_name, release_tag): - print("Download complete.") - logging.info("Download complete.") - # Unzip downloaded file - unzip_file(release_file_name) - else: - print("Failed to download the file.") - logging.error("Failed to download the file.") - else: - print(f"You already have the latest version {version_number}.") - logging.warning(f"You already have the latest version {version_number}.") - else: - print("Download URL not found.") - logging.critical(f"Download URL {download_url} not found.") - - -def cataclysm(): - download_sim(cata_api_repo_url, cata_release_file_name, cata_file_name) - run_sim(cata_file_name) - - -def wrath_of_the_lich_king(): - download_sim(wotlk_api_repo_url, wotlk_release_file_name, wotlk_file_name) - run_sim(wotlk_file_name) - - -def season_of_discovery(): - download_sim(sod_api_repo_url, sod_release_file_name, sod_file_name) - run_sim(sod_file_name) - - -if __name__ == "__main__": - cataclysm() +import requests +import os +import zipfile +import psutil +import logging + +logging.basicConfig( + level=logging.INFO, + format='%(asctime)s %(levelname)s %(message)s', + datefmt='%d-%m-%y %H:%M:%S', + filename='sim_downloader.log', + filemode='w' +) + +# Mists of Pandaria +mop_api_repo_url = 'https://api.github.com/repos/wowsims/mop/releases/latest' +mop_release_file_name = 'wowsimmop-windows.exe.zip' +mop_file_name = 'wowsimmop-windows.exe' + +# Cataclysm +cata_api_repo_url = 'https://api.github.com/repos/wowsims/cata/releases/latest' +cata_release_file_name = 'wowsimcata-windows.exe.zip' +cata_file_name = 'wowsimcata-windows.exe' + +# Wrath of the Lich King +wotlk_api_repo_url = 'https://api.github.com/repos/wowsims/wotlk/releases/latest' +wotlk_release_file_name = 'wowsimwotlk-windows.exe.zip' +wotlk_file_name = 'wowsimwotlk-windows.exe' + +# Season of Discovery +sod_api_repo_url = 'https://api.github.com/repos/wowsims/sod/releases/latest' +sod_release_file_name = 'wowsimsod-windows.exe.zip' +sod_file_name = 'wowsimsod-windows.exe' + + +def file_exists(file_path): + # check if given file exists + return os.path.exists(file_path) + + +def fetch_release_info(repo_url): + # Fetches the release information from the given GitHub repository URL. + response = requests.get(repo_url) + if response.status_code == 200: + return response.json() + else: + print(f"Failed to fetch latest release. Status Code: {response.status_code}") + logging.critical(f"Failed to fetch latest release. Status Code: {response.status_code}") + return None + + +def get_download_url(release_info, file_name): + # Gets the download URL for the specified file from the release information. + for asset in release_info['assets']: + if asset['name'].lower() == file_name.lower(): + return asset['browser_download_url'] + return None + + +def download_file(url, file_name, file_version): + # Downloads the file from the given URL and writes it to disk. + response = requests.get(url) + if response.status_code == 200: + with open(file_name, 'wb') as file: + file.write(response.content) + with open('version.txt', 'w') as version: + version.write(file_version) + return True + else: + print(f"Failed to download the file. Status Code: {response.status_code}") + logging.error(f"Failed to download the file. Status Code: {response.status_code}") + return False + + +def unzip_file(file): + if file_exists(file): + with zipfile.ZipFile(file, 'r') as zip_ref: + zip_ref.extractall() + zip_ref.close() + + +def run_sim(file): + if file_exists(file): + os.startfile(file) + + +def download_sim(api_repo_url, release_file_name, file_name): + # Fetch the latest release information from the GitHub repository. + release_info = fetch_release_info(api_repo_url) + + if release_info: + # Extract the release tag/version number from the release information. + release_tag = release_info['tag_name'] + # Get the download URL for the specified file from the release information. + download_url = get_download_url(release_info, release_file_name) + + if download_url: + version_number = None + if file_exists('version.txt'): + with open('version.txt') as version: + version_number = version.read() + + if version_number != release_tag: + for proc in psutil.process_iter(): + # check whether the process name matches + if proc.name() == file_name: + proc.kill() + print(f"Downloading latest {release_file_name} from Github. {release_tag}") + logging.info(f"Downloading latest {release_file_name} from Github. {release_tag}") + # Download the file and update the local version number. + if download_file(download_url, release_file_name, release_tag): + print("Download complete.") + logging.info("Download complete.") + # Unzip downloaded file + unzip_file(release_file_name) + else: + print("Failed to download the file.") + logging.error("Failed to download the file.") + else: + print(f"You already have the latest version {version_number}.") + logging.warning(f"You already have the latest version {version_number}.") + else: + print("Download URL not found.") + logging.critical(f"Download URL {download_url} not found.") + +def mists_of_pandaria(): + download_sim(mop_api_repo_url, mop_release_file_name, mop_file_name) + run_sim(mop_file_name) + +def cataclysm(): + download_sim(cata_api_repo_url, cata_release_file_name, cata_file_name) + run_sim(cata_file_name) + + +def wrath_of_the_lich_king(): + download_sim(wotlk_api_repo_url, wotlk_release_file_name, wotlk_file_name) + run_sim(wotlk_file_name) + + +def season_of_discovery(): + download_sim(sod_api_repo_url, sod_release_file_name, sod_file_name) + run_sim(sod_file_name) + + +if __name__ == "__main__": + mists_of_pandaria() diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..01ae75c --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +v0.0.66 \ No newline at end of file