Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Installer script that automatically installs WSA with Google Play and root as well as all prerequisites #98

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c8c9cf4
Update README.md
khanhtranngoccva Oct 31, 2021
e93cc28
One-click script wrapper for root + Google Play
khanhtranngoccva Oct 31, 2021
5798d87
One-click precompiled executable file
khanhtranngoccva Oct 31, 2021
d20b58a
Merge branch 'main' of https://github.com/khanhtranngoccva/WSAGAScript
khanhtranngoccva Oct 31, 2021
e6f1205
Update README.md
khanhtranngoccva Oct 31, 2021
94fbbfa
Merge branch 'WSA-Community:main' into main
khanhtranngoccva Nov 1, 2021
2a09970
Improved rollback and updatability
khanhtranngoccva Nov 1, 2021
a194d7e
Improved rollback and updatability
khanhtranngoccva Nov 1, 2021
2d4579d
Minor fixes
khanhtranngoccva Nov 1, 2021
ccad8d1
Minor fixes
khanhtranngoccva Nov 1, 2021
d0abeb0
Uninstaller script
khanhtranngoccva Nov 1, 2021
12cc3a3
Rename for easier use
khanhtranngoccva Nov 1, 2021
5468e24
rename kernel to match newest commit
khanhtranngoccva Nov 1, 2021
74d4b47
Script now checks for CPU architecture
khanhtranngoccva Nov 1, 2021
f4fc633
Minor fixes
khanhtranngoccva Nov 1, 2021
fa51fbb
Merge branch 'WSA-Community:main' into main
khanhtranngoccva Nov 1, 2021
0cc941b
Minor fixes for kernel
khanhtranngoccva Nov 1, 2021
163fc5d
Retries download if it fails for no reason
khanhtranngoccva Nov 1, 2021
943cf1c
Retries download if it fails for no reason
khanhtranngoccva Nov 1, 2021
de2efd4
Retries download if it fails for no reason
khanhtranngoccva Nov 1, 2021
f8e40bd
fixes kernel folder
khanhtranngoccva Nov 1, 2021
8697e2e
fixes kernel folder
khanhtranngoccva Nov 2, 2021
5e8add2
Fixes weird uninstall behavior that deletes the main installation fol…
khanhtranngoccva Nov 3, 2021
37d347d
Fixes stdout checking of uninstall script
khanhtranngoccva Nov 3, 2021
75e04f4
Merge branch 'WSA-Community:main' into main
khanhtranngoccva Nov 26, 2021
bba8be8
Captcha bypass
khanhtranngoccva Mar 26, 2022
73faa19
Merge remote-tracking branch 'origin/main'
khanhtranngoccva Mar 26, 2022
3a9da7c
Merge branch 'WSA-Community:main' into main
khanhtranngoccva May 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improved rollback and updatability
khanhtranngoccva committed Nov 1, 2021
commit 2a099706aa18658ea798df6a290a6b187c08e3d1
10 changes: 1 addition & 9 deletions functions.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@
import time
import shutil
import tkinter
import traceback
from tkinter import filedialog
from tkinter.font import Font
import ctypes
import sys
@@ -12,12 +10,6 @@
from speed_downloader import speed_download


def request_file_name(**kwargs):
root = tkinter.Tk()
root.withdraw()
return tkinter.filedialog.askopenfilename(**kwargs)


def download_url(url, root=".", filename=None):
"""Download a file from a url and place it in root.
Args:
@@ -198,4 +190,4 @@ def remove(path):
if os.path.isfile(path) or os.path.islink(path):
os.remove(path) # remove the file
elif os.path.isdir(path):
shutil.rmtree(path) # remove dir and all contains
shutil.rmtree(path) # remove dir and all contains
95 changes: 69 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
@@ -7,16 +7,40 @@
import fnmatch
from speed_downloader import speed_download
from xml.dom import minidom
from packaging import version
import subprocess

# URL to download WSA Script from GitHub
wsagascript_url = "https://github.com/ADeltaX/WSAGAScript/archive/refs/heads/main.zip"

# URL to download GApps from SourceForge. Hardcoded :(
gapps_url = "https://nchc.dl.sourceforge.net/project/opengapps/x86_64/20211021/open_gapps-x86_64-11.0-pico-20211021.zip"

# directories for system images
gapps_dir = "./TEMP/WSAGAScript-main/#GAPPS"
images_dir = "./TEMP/WSAGAScript-main/#IMAGES"

# instead of installing in a temporary folder, move everything to install_loc before installing
install_loc = "C:/Program Files/WSA_Advanced/"

# preinstalled version initialization
existing_install_version = None


def cleanup():
cur_dir = os.path.dirname(__file__)
os.chdir(cur_dir)
remove("./TEMP/wsa")
remove("./TEMP/wsa_main")
remove("./TEMP/WSAGAScript-main")
remove("./TEMP/wsa.zip")
remove("./TEMP/WSAGAScript.zip")
if os.path.exists("./TEMP"):
for f in os.listdir("./TEMP"):
if fnmatch.fnmatch(f, "*.part*"):
remove(os.path.join("./TEMP", f))


if __name__ == "__main__":
try:
# gets admin and modifies registry for developer mode, tries to enable WSL,
@@ -25,7 +49,8 @@

get_admin_permission()
executable_dir = os.path.dirname(__file__)

# if the script executes in the shell with the location C:\,
# it will affect the folder C:\TEMP (which is NOT good)
print(f"EXECUTABLE DIRECTORY: {executable_dir}")
os.chdir(executable_dir)
print(f'WSL install status: {is_linux_enabled("debian")}')
@@ -34,34 +59,37 @@
' /t REG_DWORD'
' /f /v "AllowDevelopmentWithoutDevLicense" /d "1"').read()


def cleanup():
remove("./TEMP/wsa")
remove("./TEMP/wsa_main")
remove("./TEMP/WSAGAScript-main")
remove("./TEMP/wsa.zip")
remove("./TEMP/WSAGAScript.zip")
for f in os.listdir("./TEMP"):
if fnmatch.fnmatch(f, "*.part*"):
remove(os.path.join("./TEMP", f))


cleanup()

# creates WSA directories
# downloads the newest version of WSA. Otherwise asks for a MSIX archive if the link happens to not be found
# Checks for updates and downloads the newest version of WSA.
os.makedirs("./TEMP/wsa", exist_ok=True)
os.makedirs("./TEMP/wsa_main", exist_ok=True)
wsa_archive_url = get_wsa_linkstore_id()
if not wsa_archive_url:
wsa_archive_dir = request_file_name(title="Select Windows Subsystem for Android MSIXBUNDLE archive",
initialdir=".",
filetypes=(('MSIX bundle files', '*.msixbundle'),))
if not wsa_archive_dir:
exit()
print(f"ARCHIVE LOCATION: {wsa_archive_dir}")
shutil.unpack_archive(wsa_archive_dir, "./TEMP/wsa", "zip")
os.makedirs(install_loc, exist_ok=True)
wsa_entry_result = get_wsa_entry()
if not wsa_entry_result:
wsa_archive_version = None
input("No matching Windows Subsystem for Android package was found. Press ENTER to exit.")
exit()
else:
wsa_archive_url, wsa_archive_name = wsa_entry_result
wsa_archive_version = version.parse(wsa_archive_name.split("_")[1])
if not wsa_archive_version:
raise Exception("Sanity check failed. WSA archive version not found.")
try:
existing_install_version = max(map(version.parse, os.listdir(install_loc)))
if not existing_install_version:
# makes sure the version is not empty. Empty directories may cause unintentional deletions.
raise Exception("Sanity check failed. WSA existing version not found.")
print(f"Existing installation version: {existing_install_version}")
print(f'Latest version: {wsa_archive_version}')
if wsa_archive_version <= existing_install_version:
input("Windows Subsystem for Android is up-to-date. Press ENTER to exit.")
exit()
else:
print("Updating WSA...")
except ValueError:
print("New installation detected.")
speed_download(wsa_archive_url, "./TEMP", "wsa.zip")
shutil.unpack_archive("./TEMP/wsa.zip", "./TEMP/wsa", "zip")

@@ -127,15 +155,30 @@ def cleanup():
with open("./TEMP/wsa_main/AppxManifest.xml", "w", encoding="utf-8") as file:
file.write(manifest_data.toxml())

print(os.popen("powershell.exe Add-AppxPackage -Register .\\TEMP\\wsa_main\\AppXManifest.xml").read())
new_install_location = os.path.realpath(os.path.join("C:/Program Files/WSA_Advanced", str(wsa_archive_version)))
print(f'Installing to {new_install_location}')
os.makedirs(new_install_location, exist_ok=True)

for file in os.listdir("./TEMP/wsa_main"):
shutil.move(os.path.join("./TEMP/wsa_main", file), new_install_location)

# cleans up
print()
print("Cleaning up temporary files.")
cleanup()
input("WSA with GApps and root access installed. Press Enter to exit.")
install_process = subprocess.run(f"powershell.exe Add-AppxPackage -Registe '{new_install_location}\\AppXManifest.xml'")

if not install_process.returncode:
if existing_install_version:
print(f"Deleting version {existing_install_version}.")
remove(os.path.join("C:/Program Files/WSA_Advanced", str(existing_install_version)))
input("WSA with GApps and root access installed. Press ENTER to exit.")
else:
remove(new_install_location)
input("Package install failure. Installation has been rolled back. Press ENTER to exit.")
except Exception as e:
cleanup()
print(traceback.format_exc())
input("Install failure. An exception occured. Installation has been rolled back. Press ENTER to exit.")
with open("error.log", "w") as file:
print(e, file=file)
print(traceback.format_exc(), file=file)
12 changes: 8 additions & 4 deletions wsa_online_link_generator.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,9 @@
import fnmatch


def get_wsa_linkstore_id():
def get_wsa_entry():
"""Returns a tuple containing the Windows Subsystem for Android link and its file name (used to check for
updates) """
store_id = "9p3395vx91nr"
api_url = "https://store.rg-adguard.net/api/GetFiles"
data = {
@@ -19,6 +21,8 @@ def get_wsa_linkstore_id():
soup = BeautifulSoup(r.text, "html.parser")
for link in soup.select("tr a"):
if fnmatch.fnmatch(link.string.casefold(), "*windowssubsystemforandroid*.msixbundle"):
return link['href']
else:
return False
return link['href'], link.string


if __name__ == '__main__':
print(get_wsa_entry())