From b297b8728075d9633569dd548ae74226d59f57b3 Mon Sep 17 00:00:00 2001 From: Luke Horwell Date: Sun, 2 Jun 2024 16:18:17 +0100 Subject: [PATCH] CI: Build executable for Windows/Linux with cx_Freeze https://pypi.org/project/cx-Freeze/ --- .github/workflows/build.yml | 81 +++++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 6 +-- .gitignore | 1 + README.md | 59 ++++++++++++++++++--------- assets/github.url | 5 +++ requirements.txt | 4 +- setup.py | 19 +++++++++ 7 files changed, 150 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 assets/github.url create mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..07d7c68 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,81 @@ +name: Build + +on: [push, pull_request] + +jobs: + windows_x64: + name: Windows x64 + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + architecture: 'x64' + + - name: Cache Dependencies + uses: actions/cache@v4 + with: + path: venv + key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }} + + - name: Install Dependencies + run: | + python -m venv venv + .\venv\Scripts\activate + pip install -r requirements.txt + + - name: Build + run: | + .\venv\Scripts\activate + python setup.py build + copy version.txt dist\ + copy assets\github.url "dist\View on GitHub.url" + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: "build-windows-x64" + path: "dist" + + + linux_x64: + name: Linux x64 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + architecture: 'x64' + + - name: Cache Dependencies + uses: actions/cache@v4 + with: + path: venv + key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }} + + - name: Install Dependencies + run: | + python -m venv venv + source venv/bin/activate + pip install -r requirements.txt + + - name: Build + run: | + source venv/bin/activate + python setup.py build + cp version.txt dist/ + echo "https://github.com/lah7/sims2-4k-ui-patch" > "dist/View on GitHub.txt" + + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: "build-linux-x64" + path: "dist" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65b761c..aebb5a3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,13 +16,11 @@ jobs: python-version: '3.12' architecture: 'x64' - - name: Cache Python Environment - uses: actions/cache@v3 + - name: Cache Dependencies + uses: actions/cache@v4 with: path: venv key: ${{ runner.os }}-venv-${{ hashFiles('**/requirements.txt') }} - restore-keys: | - ${{ runner.os }}-venv - name: Install Dependencies run: | diff --git a/.gitignore b/.gitignore index e6305bf..7cba802 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ __pycache__ /tests/files/ui.package +/build/ diff --git a/README.md b/README.md index 39c1d46..2b09c71 100644 --- a/README.md +++ b/README.md @@ -45,31 +45,39 @@ The program automatically checks this repository for an update, to ensure you ha ### Windows -1. Download the latest version from the [Releases] page. +1. Download the latest `windows-x64` asset from the [Releases] page. 2. Extract the contents and run `sims2-4k-ui-patcher.exe`. * You'll need to run as administrator to modify the game files. * If you don't want to do that, change the permissions of your EA GAMES directory, usually at `C:\Program Files (x86)\EA GAMES`. 3. Click "Patch"! +To run the program, you may need to install [Microsoft Visual C++ Redistributable (x64)](https://aka.ms/vs/17/release/vc_redist.x64.exe). -### Linux/macOS (Wine/Proton) -[The Sims 2 is playable under Wine!] For the best patching performance, -run this patch program natively under Python. +### Linux -1. Download the [latest ZIP of this repository](https://github.com/lah7/sims2-4k-ui-patch/archive/refs/heads/master.zip). +For users who play The Sims 2 under the Wine/Proton compatibility layer. [It works well with DXVK!](https://github.com/lah7/sims2-wine-patches/blob/master/README-D9VK.md) -2. Extract the contents and run: - - python -m venv venv - source venv/bin/activate - pip install -r requirements.txt - python sims2-4k-ui-patcher.py +1. Download the latest `linux-x64` asset from the [Releases] page. +2. Extract the contents and run `./sims2-4k-ui-patcher`. + * You may need to mark it as executable first (e.g. right click -> Properties -> Permissions tab). +3. Find your "EA GAMES" directory, e.g. a wine prefix at `~/.wine/drive_c/Program Files (x86)/EA GAMES`. +4. Click "Patch"! Ironically, the patcher interface (built with TK) may not scale well on a 4K display. + +### macOS + +We don't have a pre-built binary for macOS, but you can run the Python script directly. See [Development](#development) for instructions. + +This patch program will work fine if you play the game under a Wine compatibility layer. + +If you purchased the [The Sims™ 2: Super Collection](https://apps.apple.com/us/app/the-sims-2-super-collection/id883782620?mt=12), +we don't know whether files are exposed in a way that is compatible with this program. Please let us know! + + [Releases]: https://github.com/lah7/sims2-4k-ui-patch/releases/latest -[The Sims 2 is playable under Wine!]: https://github.com/lah7/sims-2-wine-patches ## Compatibility @@ -84,26 +92,37 @@ this program. Using such mods may result in mixed UI scaling. However, any existing UI modifications that were made in the game's installation folder (like `TSData/Res/UI/ui.package`) are compatible with this program. -**On a Mac?** We don't know whether [The Sims™ 2: Super Collection](https://apps.apple.com/us/app/the-sims-2-super-collection/id883782620?mt=12) -is compatible with this program. Please let us know! - ## Development This project is written in Python. To start hacking, clone this repository - and set up a [virtual environment](https://docs.python.org/3/library/venv.html#creating-virtual-environments) - to install [requirements.txt](requirements.txt). +and set up a [virtual environment](https://docs.python.org/3/library/venv.html#creating-virtual-environments) +to install [requirements.txt](requirements.txt). -For Windows, [install Python], and run: +For Windows, [install Python 3](https://www.python.org/downloads/windows/), and run: python -m venv venv venv\Scripts\activate + pip install --upgrade pip pip install -r requirements.txt python sims2_4k_ui_patcher.py -For macOS/Linux instructions, [see above](#linuxmacos-wineproton). +For Linux, your distribution likely already has Python 3 installed: + + python3 -m venv venv + source venv/bin/activate + pip install --upgrade pip + pip install -r requirements.txt + python3 sims2-4k-ui-patcher.py + +For macOS, [install Python 3](https://www.python.org/downloads/macos/), and run: + + python3 -m venv venv + source venv/bin/activate + pip install --upgrade pip + pip install -r requirements.txt + python3 sims2-4k-ui-patcher.py -[install Python]: https://www.python.org/downloads/windows/ ### Tests diff --git a/assets/github.url b/assets/github.url new file mode 100644 index 0000000..32cf7af --- /dev/null +++ b/assets/github.url @@ -0,0 +1,5 @@ +[{000214A0-0000-0000-C000-000000000046}] +Prop3=19,11 +[InternetShortcut] +IDList= +URL=https://github.com/lah7/sims2-4k-ui-patch diff --git a/requirements.txt b/requirements.txt index 78d0a62..93460ae 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Pillow -pyinstaller requests + +# Build only +cx_Freeze diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..c75f71c --- /dev/null +++ b/setup.py @@ -0,0 +1,19 @@ +from cx_Freeze import Executable, setup + +build_exe_options = { + "build_exe": "dist", + "excludes": ["unittest"], + "include_files": [ + ("assets/banner.png", "assets/banner.png"), + ("assets/icon.ico", "assets/icon.ico"), + ], + "optimize": "2", +} + +setup( + name="sims2_4k_ui_patcher", + version="0.1.0", + description="4K UI Patcher for The Sims 2", + options={"build_exe": build_exe_options}, + executables=[Executable("sims2_4k_ui_patcher.py", base="gui", icon="assets/icon")], +)