Skip to content

Commit

Permalink
Merge pull request #50 from macarooni-man/dev
Browse files Browse the repository at this point in the history
v2.1.1
  • Loading branch information
macarooni-man authored May 1, 2024
2 parents 1e83a47 + cc13837 commit 9fc40be
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 62 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/compiler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fetch-depth: 1

- name: Install Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'

Expand All @@ -28,7 +28,7 @@ jobs:
powershell -noprofile -executionpolicy bypass -file .\build-tools\build-windows.ps1
- name: Upload Executable
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: auto-mcs-windows
path: build-tools/dist/
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:
done
- name: Upload Binary
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: auto-mcs-macos
path: build-tools/dist/auto-mcs.dmg
Expand Down Expand Up @@ -107,7 +107,7 @@ jobs:
fluxbox > /dev/null 2>&1 &
- name: Install Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.9'

Expand Down Expand Up @@ -147,7 +147,7 @@ jobs:
# uses: lhotari/action-upterm@v1

- name: Upload Binary
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: auto-mcs-linux
path: build-tools/dist/
Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
chmod +x dist/auto-mcs
- name: Upload Binary
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: auto-mcs-linux-arm64
path: build-tools/dist/
Expand Down
7 changes: 3 additions & 4 deletions build-tools/reqs-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ bs4==0.0.1
certifi>=2023.7.22
charset-normalizer==2.1.1
cloudscraper>=1.2.71
dnspython==2.2.1
dnspython==2.6.1
docutils==0.19
idna>=2.5
idna==3.7
ipaddress==1.0.23
Kivy==2.1.0
Kivy-Garden==0.1.5
munch==3.0.0
NBT==1.5.1
Pillow==10.2.0
Pillow==10.3.0
plyer>=2.1.0
psutil==5.9.2
Pygments==2.16.1
Expand All @@ -27,5 +27,4 @@ six==1.16.0
soupsieve==2.3.2.post1
urllib3==1.26.18
PyYAML>=6.0.1
googletrans==3.1.0a0
json_repair==0.10.1
7 changes: 3 additions & 4 deletions build-tools/reqs-macos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ bs4==0.0.1
certifi>=2023.7.22
charset-normalizer==2.1.1
cloudscraper>=1.2.71
dnspython==2.2.1
dnspython==2.6.1
docutils==0.19
idna>=2.5
idna==3.7
ipaddress==1.0.23
Kivy==2.1.0
Kivy-Garden==0.1.5
munch==3.0.0
NBT==1.5.1
Pillow==10.2.0
Pillow==10.3.0
plyer>=2.1.0
psutil==5.9.2
Pygments==2.16.1
Expand All @@ -29,5 +29,4 @@ urllib3==1.26.18
tkmacosx>=1.0.5
pyobjus>=1.2.3
PyYAML>=6.0.1
googletrans==3.1.0a0
json_repair==0.10.1
7 changes: 3 additions & 4 deletions build-tools/reqs-windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ beautifulsoup4==4.11.1
certifi>=2023.7.22
charset-normalizer==2.1.1
cloudscraper>=1.2.71
dnspython==2.2.1
dnspython==2.6.1
docutils==0.19
future==0.18.3
idna>=2.5
idna==3.7
ipaddress==1.0.23
Kivy==2.0.0
kivy-deps.angle==0.3.2
Expand All @@ -17,7 +17,7 @@ Kivy-Garden==0.1.5
munch==3.0.0
NBT==1.5.1
pefile==2022.5.30
Pillow==10.2.0
Pillow==10.3.0
plyer>=2.1.0
psutil==5.9.2
Pygments==2.16.1
Expand All @@ -34,5 +34,4 @@ six==1.16.0
soupsieve==2.3.2.post1
urllib3==1.26.18
PyYAML>=6.0.1
googletrans==3.1.0a0
json_repair==0.10.1
11 changes: 7 additions & 4 deletions source/amseditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3673,10 +3673,13 @@ def edit_script(script_path: str, data: dict, *args):
from ctypes import windll, c_int64

# Calculate screen width and disable DPI scaling if bigger than a certain resolution
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
try:
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
except:
print('Error: failed to set DPI context')

default_font_size = 14
font_size = 13
Expand Down
85 changes: 53 additions & 32 deletions source/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# ---------------------------------------------- Global Variables ------------------------------------------------------

app_version = "2.1"
app_version = "2.1.1"
ams_version = "1.2"
app_title = "auto-mcs"
dev_version = False
Expand Down Expand Up @@ -2093,32 +2093,38 @@ def iter_name(new_name):

# Verify portable java is available in '.auto-mcs\Tools', if not install it
modern_pct = 0
lts_pct = 0
legacy_pct = 0
def java_check(progress_func=None):
global java_executable, modern_pct, legacy_pct
global java_executable, modern_pct, lts_pct, legacy_pct
max_retries = 3
retries = 0
modern_version = 21

java_url = {
'windows': {
"modern": "https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.zip",
"modern": f"https://download.oracle.com/java/{modern_version}/latest/jdk-{modern_version}_windows-x64_bin.zip",
"lts": f"https://download.oracle.com/java/17/latest/jdk-17_windows-x64_bin.zip",
"legacy": "https://javadl.oracle.com/webapps/download/GetFile/1.8.0_331-b09/165374ff4ea84ef0bbd821706e29b123/windows-i586/jre-8u331-windows-x64.tar.gz"
},
'linux': {
"modern": "https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz",
"modern": f"https://download.oracle.com/java/{modern_version}/latest/jdk-{modern_version}_linux-x64_bin.tar.gz",
"lts": f"https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz",
"legacy": "https://javadl.oracle.com/webapps/download/GetFile/1.8.0_331-b09/165374ff4ea84ef0bbd821706e29b123/linux-i586/jre-8u331-linux-x64.tar.gz"
},
'linux-arm64': {
"modern": "https://download.oracle.com/java/17/latest/jdk-17_linux-aarch64_bin.tar.gz",
"modern": f"https://download.oracle.com/java/{modern_version}/latest/jdk-{modern_version}_linux-aarch64_bin.tar.gz",
"lts": f"https://download.oracle.com/java/17/latest/jdk-17_linux-aarch64_bin.tar.gz",
"legacy": "https://javadl.oracle.com/webapps/download/GetFile/1.8.0_281-b09/89d678f2be164786b292527658ca1605/linux-i586/jdk-8u281-linux-aarch64.tar.gz"
},
'macos': {
"modern": "https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.tar.gz",
"modern": f"https://download.oracle.com/java/{modern_version}/latest/jdk-{modern_version}_macos-x64_bin.tar.gz",
"lts": f"https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.tar.gz",
"legacy": "https://javadl.oracle.com/webapps/download/GetFile/1.8.0_331-b09/165374ff4ea84ef0bbd821706e29b123/unix-i586/jre-8u331-macosx-x64.tar.gz"
}
}

while not java_executable['modern'] or not java_executable['legacy']:
while not (java_executable['modern'] and java_executable['lts'] and java_executable['legacy']):

# Delete downloads folder
safe_delete(downDir)
Expand All @@ -2135,34 +2141,40 @@ def java_check(progress_func=None):
# Gather paths to Java installed internally
if os_name == 'macos':
modern_path = os.path.join(applicationFolder, 'Tools', 'java', 'modern', 'Contents', 'Home', 'bin', 'java')
lts_path = os.path.join(applicationFolder, 'Tools', 'java', 'lts', 'Contents', 'Home', 'bin', 'java')
legacy_path = os.path.join(applicationFolder, 'Tools', 'java', 'legacy', 'Contents', 'Home', 'bin', 'java')
jar_path = os.path.join(applicationFolder, 'Tools', 'java', 'modern', 'Contents', 'Home', 'bin', 'jar')

else:
modern_path = os.path.join(applicationFolder, 'Tools', 'java', 'modern', 'bin', 'java.exe' if os_name == "windows" else 'java')
lts_path = os.path.join(applicationFolder, 'Tools', 'java', 'lts', 'bin', 'java.exe' if os_name == "windows" else 'java')
legacy_path = os.path.join(applicationFolder, 'Tools', 'java', 'legacy', 'bin', 'java.exe' if os_name == "windows" else 'java')
jar_path = os.path.join(applicationFolder, 'Tools', 'java', 'modern', 'bin', 'jar.exe' if os_name == "windows" else 'jar')


if (run_proc(f'"{os.path.abspath(modern_path)}" --version') == 0) and (run_proc(f'"{os.path.abspath(legacy_path)}" -version') == 0):
if (run_proc(f'"{os.path.abspath(modern_path)}" --version') == 0) and (run_proc(f'"{os.path.abspath(lts_path)}" --version') == 0) and (run_proc(f'"{os.path.abspath(legacy_path)}" -version') == 0):

java_executable = {
"modern": str(os.path.abspath(modern_path)),
"legacy": str(os.path.abspath(legacy_path)),
"jar": str(os.path.abspath(jar_path))
}
# Check for appropriate modern version
if run_proc(f'"{os.path.abspath(modern_path)}" --version', return_text=True).startswith(f'java {modern_version}.'):

if debug:
print('\nValid Java installations detected\n')
java_executable = {
"modern": str(os.path.abspath(modern_path)),
"lts": str(os.path.abspath(lts_path)),
"legacy": str(os.path.abspath(legacy_path)),
"jar": str(os.path.abspath(jar_path))
}

if progress_func:
progress_func(100)
if debug:
print('\nValid Java installations detected\n')

return True
if progress_func:
progress_func(100)

return True


# If valid java installs are not detected, install them to '.auto-mcs\Tools'
if not java_executable['modern'] or not java_executable['legacy']:
if not (java_executable['modern'] and java_executable['lts'] and java_executable['legacy']):

if debug:
print('\nJava is not detected, installing...\n')
Expand All @@ -2171,18 +2183,20 @@ def java_check(progress_func=None):
folder_check(downDir)

modern_filename = f'modern-java.{os.path.basename(java_url[os_name]["modern"]).split(".", 1)[1]}'
lts_filename = f'lts-java.{os.path.basename(java_url[os_name]["lts"]).split(".", 1)[1]}'
legacy_filename = f'legacy-java.{os.path.basename(java_url[os_name]["legacy"]).split(".", 1)[1]}'

# Use timer and combined function to get total percentage of both installs
modern_pct = 0
lts_pct = 0
legacy_pct = 0

def avg_total(*args):
global modern_pct, legacy_pct
while True:
progress_func(round((modern_pct + legacy_pct) / 2))
progress_func(round((modern_pct + lts_pct + legacy_pct) / 3))
time.sleep(0.2)
if (modern_pct >= 100 and legacy_pct >= 100):
if (modern_pct >= 100 and lts_pct >= 100 and legacy_pct >= 100):
break

if progress_func:
Expand All @@ -2201,37 +2215,43 @@ def avg_total(*args):
with ThreadPoolExecutor(max_workers=2) as pool:

def hook1(a, b, c):
global modern_pct, legacy_pct
global modern_pct
modern_pct = round(100 * a * b / c)

def hook2(a, b, c):
global modern_pct, legacy_pct
global lts_pct
lts_pct = round(100 * a * b / c)

def hook3(a, b, c):
global legacy_pct
legacy_pct = round(100 * a * b / c)

pool.map(
download_url,
[java_url[os_download]['modern'], java_url[os_download]['legacy']],
[modern_filename, legacy_filename],
[downDir, downDir],
[hook1 if progress_func else None, hook2 if progress_func else None]
[java_url[os_download]['modern'], java_url[os_download]['lts'], java_url[os_download]['legacy']],
[modern_filename, lts_filename, legacy_filename],
[downDir, downDir, downDir],
[hook1 if progress_func else None, hook2 if progress_func else None, hook3 if progress_func else None]
)

if progress_func:
timer.cancel()

# Install java by extracting the files to their respective folder
modern_path = os.path.join(javaDir, 'modern')
lts_path = os.path.join(javaDir, 'lts')
legacy_path = os.path.join(javaDir, 'legacy')

safe_delete(modern_path)
safe_delete(lts_path)
safe_delete(legacy_path)

with ThreadPoolExecutor(max_workers=2) as pool:
pool.map(
extract_archive,
[os.path.join(downDir, modern_filename), os.path.join(downDir, legacy_filename)],
[modern_path, legacy_path],
[True, True]
[os.path.join(downDir, modern_filename), os.path.join(downDir, lts_filename), os.path.join(downDir, legacy_filename)],
[modern_path, lts_path, legacy_path],
[True, True, True]
)

retries += 1
Expand Down Expand Up @@ -3976,7 +3996,7 @@ def generate_run_script(properties, temp_server=False, custom_flags=None, no_fla
if properties['type'] != 'forge':

# Make sure this works non-spigot versions
java = java_executable["legacy"] if version_check(properties['version'], '<','1.17') else java_executable['modern']
java = java_executable["legacy"] if version_check(properties['version'], '<','1.17') else java_executable['lts'] if version_check(properties['version'], '<','1.20.5') else java_executable['modern']

# On bukkit derivatives, install geysermc, floodgate, and viaversion if version >= 1.13.2 (add -DPaper.ignoreJavaVersion=true if paper < 1.16.5)
script = f'"{java}" -Xmx{ram}G -Xms{int(round(ram/2))}G{start_flags} -Dlog4j2.formatMsgNoLookups=true'
Expand All @@ -3996,9 +4016,10 @@ def generate_run_script(properties, temp_server=False, custom_flags=None, no_fla

# Modern
if version_check(properties['version'], ">=", "1.17"):
java = java_executable["lts"] if version_check(properties['version'], '<', '1.20.5') else java_executable['modern']
version_list = [os.path.basename(file) for file in glob(os.path.join("libraries", "net", "minecraftforge", "forge", f"1.{math.floor(float(properties['version'].replace('1.', '', 1)))}*"))]
arg_file = f"libraries/net/minecraftforge/forge/{version_list[-1]}/{'win_args.txt' if os_name == 'windows' else 'unix_args.txt'}"
script = f'"{java_executable["modern"]}" -Xmx{ram}G -Xms{int(round(ram/2))}G {start_flags} -Dlog4j2.formatMsgNoLookups=true @{arg_file} nogui'
script = f'"{java}" -Xmx{ram}G -Xms{int(round(ram/2))}G {start_flags} -Dlog4j2.formatMsgNoLookups=true @{arg_file} nogui'

# 1.6 to 1.16
elif version_check(properties['version'], ">=", "1.6") and version_check(properties['version'], "<", "1.17"):
Expand Down
11 changes: 7 additions & 4 deletions source/logviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,13 @@ def open_log(server_name: str, path: str, data: dict, *args):
from ctypes import windll, c_int64

# Calculate screen width and disable DPI scaling if bigger than a certain resolution
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
try:
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
except:
print('Error: failed to set DPI context')



Expand Down
11 changes: 7 additions & 4 deletions source/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ def mainLoop():
from ctypes import windll, c_int64

# Calculate screen width and disable DPI scaling if bigger than a certain resolution
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
try:
width = windll.user32.GetSystemMetrics(0)
scale = windll.shcore.GetScaleFactorForDevice(0) / 100
if (width * scale) < 2000:
windll.user32.SetProcessDpiAwarenessContext(c_int64(-4))
except:
print('Error: failed to set DPI context')


# Cleanup temp files and generate splash text
Expand Down

0 comments on commit 9fc40be

Please sign in to comment.