Skip to content

Commit

Permalink
Loads of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazzzny committed Apr 1, 2023
1 parent b241c4a commit bd0a27d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 25 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/build-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
release:
types: [published]

permissions:
contents: read
Expand Down Expand Up @@ -42,9 +44,15 @@ jobs:
pyinstaller Discord\ Legacy\ Patcher.py --onefile --add-data "files/asar:files"
python3 ./support/patchbinary.py
codesign --force --deep -s - ./dist/Discord\ Legacy\ Patcher
- name: Upload a Build Artifact
- name: Upload Binary to Actions
uses: actions/upload-artifact@v3.1.2
with:
name: Discord Legacy Patcher
path: ./dist/Discord\ Legacy\ Patcher

- name: Upload Binary to Release
if: github.event_name == 'release'
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./dist/Discord\ Legacy\ Patcher
tag: ${{ github.ref }}
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Changelog

## Discord Legacy Patcher 1.2
- Partial rewrite
- Copy just the Discord application instead of the entire disk image
- Improve error handling
- Implement GitHub releases

## Discord Legacy Patcher 1.1
- Create PyInstaller binary
- Embed Asar binary
- Enable 10.9 support

## Discord Legacy Patcher 1.0
- Initial release
77 changes: 54 additions & 23 deletions Discord Legacy Patcher.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import sys, os, tempfile, requests, subprocess, shutil
version = "1.1"
version = "1.2"
localrun = False
origdir = os.getcwd()

def clear():
print("\033c", end='')

discordpackages = {
1:["macOS 10.12","0.0.273"],
2:["OS X 10.11","0.0.273"],
3:["OS X 10.10","0.0.262"],
4:["OS X 10.9","0.0.255"]
"macOS 10.12" : "0.0.273",
"OS X 10.11" : "0.0.273",
"OS X 10.10" : "0.0.262",
"OS X 10.9" : "0.0.255",
}

def preflight():
Expand Down Expand Up @@ -54,7 +54,7 @@ def copyfiles():
subprocess.call(["/usr/bin/hdiutil","attach","./Discord.dmg","-nobrowse","-noverify","-quiet"])
print("Copying files")
try:
shutil.copytree("/Volumes/Discord/","./Discord/",symlinks=True) #will try to copy the entire applications folder if set to false
shutil.copytree("/Volumes/Discord/Discord.app/","./Discord/Discord.app/",symlinks=True) #will try to copy the entire applications folder if set to false
except:
print("Could not mount disk image/copy files. Please restart your machine.")
sys.exit()
Expand All @@ -67,9 +67,29 @@ def downloaddiscord(build):
print(f"Downloading Discord {build} from \n{url}\nThis may take a while.")
response = requests.get(url, stream=True)
with open("Discord.dmg", 'wb') as f:
total_size = int(response.headers.get('content-length', 0))
progress = 0
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
progress += len(chunk)
percent_done = int(progress / total_size * 100)
print(f"Download progress: {percent_done}%", end='\r')

def downloadlatestdiscord():
print("====================================================")
url = f"https://discord.com/api/download?platform=osx"
print(f"Downloading Discord (Latest) from \n{url}\nThis may take a while.")
response = requests.get(url, stream=True)
with open("Discord.dmg", 'wb') as f:
total_size = int(response.headers.get('content-length', 0))
progress = 0
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
progress += len(chunk)
percent_done = int(progress / total_size * 100)
print(f"Download progress: {percent_done}%", end='\r')

def extractasar():
global localrun
Expand Down Expand Up @@ -99,6 +119,7 @@ def patchupdater():
file.write(filedata)

def fixminver(): #0.0.255 needs to have it's minimum version adjusted to support 10.9
print("Patching LSMinimumSystemVersion")
with open('./Discord/Discord.app/Contents/Info.plist','r') as file:
filedata = file.read()
filedata = filedata.replace("10.10","10.9")
Expand Down Expand Up @@ -129,18 +150,23 @@ def cleartemp():
os.remove("Discord_RW.dmg")
def preparepackage(version):
clear()
mktemp()
if version != 1 and version != 6: #1 is latest, 6 is custom
selectedmacOSBuild = list(discordpackages.keys())[version-2]
selectedclient = discordpackages[selectedmacOSBuild]

print("====================================================")
if version != 5:
print(f"Preparing to download Discord {discordpackages[version][1]} for {discordpackages[version][0]}")
else:

if version == 1:
print("Preparing to download Discord (Latest) for 10.13+")
downloadlatestdiscord()
elif version == 6:
downloaddiscord(input("\nPlease enter the build you wish to download: "))
print(f"Preparing to download Discord")
print("====================================================")

mktemp()
if version != 5:
downloaddiscord(discordpackages[version][1])
else:
downloaddiscord(input("Please enter the build you wish to download: "))
print(f"Preparing to download Discord {selectedclient} for {selectedmacOSBuild}")
downloaddiscord(selectedclient)
print("====================================================")
clear()
print("====================================================")
print(f"Patching Discord")
Expand All @@ -149,7 +175,7 @@ def preparepackage(version):
extractasar()
patchupdater()
packasar()
if version == 4:
if selectedclient == "0.0.255":
fixminver()
makerwdmg()
movetodownloads()
Expand All @@ -173,15 +199,20 @@ def mainmenu():
"""
,end="")
preflight()
for i,v in discordpackages.items():
print(f"{i}. {v[0]} (Client {v[1]})")
print("5. Other")
print("6. Exit")
choice = int(input("Choose an Option: "))
if choice == 6:
print("1. Latest Client (Disables Discord Updates, macOS 10.13+)")
for ind, (ver,build) in enumerate(discordpackages.items()):
print(f"{ind+2}. {ver} (Client {build})")
print("6. Other Client")
print("7. Exit")
try:
choice = int(input("Choose an Option: "))
except:
input("Invalid option! Press enter to continue")
return
if choice == 7:
sys.exit()
else:
preparepackage(choice)

while True:
mainmenu()

0 comments on commit bd0a27d

Please sign in to comment.