forked from HMCL-dev/HMCL
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/refactor-hmclauncher' into prs
- Loading branch information
Showing
15 changed files
with
589 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: Build HMCLauncher (Using CMake and gcc) | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'HMCLauncher/**' | ||
- '.github/workflows/build-launcher(cmake-gcc).yml' | ||
pull_request: | ||
paths: | ||
- 'HMCLauncher/**' | ||
- '.github/workflows/build-launcher(cmake-gcc).yml' | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
defaults: | ||
run: | ||
shell: msys2 {0} | ||
steps: | ||
- name: 'Setup MSYS2' | ||
uses: msys2/setup-msys2@v2 | ||
with: | ||
msystem: mingw32 | ||
update: true | ||
install: >- | ||
mingw-w64-i686-toolchain | ||
mingw-w64-i686-ninja | ||
mingw-w64-i686-cmake | ||
git | ||
- name: 'Checkout' | ||
uses: actions/checkout@v4 | ||
- name: Build HMCLauncher | ||
run: | | ||
cmake -S ./HMCLauncher/HMCL -B ./HMCLauncher/HMCL/build -DCMAKE_BUILD_TYPE=Release | ||
cmake --build ./HMCLauncher/HMCL/build | ||
- name: Copy HMCLauncher to assets | ||
run: cp ./HMCLauncher/HMCL/build/HMCLauncher.exe ./HMCL/src/main/resources/assets/HMCLauncher.exe | ||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v4 | ||
with: | ||
distribution: 'zulu' | ||
java-version: '11' | ||
java-package: 'jdk+fx' | ||
- name: Build with Gradle | ||
run: ./gradlew makeExecutables --no-daemon | ||
env: | ||
MICROSOFT_AUTH_ID: ${{ secrets.MICROSOFT_AUTH_ID }} | ||
MICROSOFT_AUTH_SECRET: ${{ secrets.MICROSOFT_AUTH_SECRET }} | ||
CURSEFORGE_API_KEY: ${{ secrets.CURSEFORGE_API_KEY }} | ||
- name: Get short SHA | ||
uses: benjlevesque/[email protected] | ||
with: | ||
length: 7 | ||
- name: Copy HMCLauncher to libs | ||
run: cp ./HMCLauncher/HMCL/build/HMCLauncher.exe ./HMCL/build/libs/HMCLauncher.exe | ||
- name: Upload Artifacts | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: HMCLauncher-${{ env.SHA }} | ||
path: HMCL/build/libs/*.exe |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
cmake_minimum_required(VERSION 3.25) | ||
project(HMCLauncher) | ||
if(MSVC) | ||
add_compile_options(/utf-8 /D_UNICODE /W4) | ||
else() | ||
add_compile_options(-municode -Wall -Wextra -Wpedantic) | ||
endif() | ||
if(MSVC) | ||
add_link_options(/ENTRY:wWinMainCRTStartup) | ||
else() | ||
add_link_options(-municode) | ||
endif() | ||
OPTION(ENABLE_MINGW_STATIC_LINK_LIBSTDCXX "Link the C++ standard library statically to the executable file(mingw only)." ON) | ||
if(ENABLE_MINGW_STATIC_LINK_LIBSTDCXX AND MINGW) | ||
add_link_options(-static) | ||
endif() | ||
set(CMAKE_WIN32_EXECUTABLE ON) | ||
add_executable(HMCLauncher WIN32 HMCL.rc java.cpp main.cpp os.cpp install.cpp stdafx.cpp Version.cpp) | ||
target_link_libraries(HMCLauncher Version) | ||
target_link_libraries(HMCLauncher wininet) | ||
install(TARGETS HMCLauncher) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
#include "stdafx.h" | ||
#include "install.h" | ||
|
||
int InstallHMCLJRE(const std::wstring &home, const std::wstring &domain, | ||
const std::wstring &file) { | ||
WIN32_FIND_DATA ffd; | ||
std::wstring runtimeDirectory, jreDownloadedFile, jreDownloadedDirectory; | ||
|
||
runtimeDirectory = home + L"runtime"; | ||
jreDownloadedFile = home + L".hmclauncher-jre-"; | ||
jreDownloadedFile.append(std::to_wstring(rand())); | ||
jreDownloadedDirectory = jreDownloadedFile + L""; | ||
jreDownloadedFile.append(L".zip"); | ||
|
||
HANDLE hFind = INVALID_HANDLE_VALUE; | ||
|
||
int err = 0; | ||
|
||
err = DownloadHMCLJRE(jreDownloadedFile, domain, file); | ||
if (err != 0) { | ||
goto cleanup; | ||
} | ||
|
||
if (!CreateDirectory(jreDownloadedDirectory.c_str(), NULL)) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
UncompressHMCLJRE(jreDownloadedFile, jreDownloadedDirectory); | ||
|
||
hFind = FindFirstFile((jreDownloadedDirectory + L"\\*").c_str(), &ffd); | ||
if (hFind == INVALID_HANDLE_VALUE) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
{ | ||
std::wstring targetFile = std::wstring(); | ||
do { | ||
std::wstring fileName = std::wstring(ffd.cFileName); | ||
if (fileName.size() <= 2 && fileName[0] == L'.') { | ||
continue; | ||
} | ||
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { | ||
if (targetFile.size() != 0) { | ||
err = HMCL_ERR_INVALID_JRE_PACK; | ||
goto cleanup; | ||
} | ||
|
||
targetFile.append(fileName); | ||
} | ||
} while (FindNextFile(hFind, &ffd) != 0); | ||
err = GetLastError(); | ||
if (err != ERROR_NO_MORE_FILES) { | ||
goto cleanup; | ||
} | ||
err = 0; | ||
|
||
if (targetFile.size() == 0) { | ||
err = HMCL_ERR_INVALID_JRE_PACK; | ||
goto cleanup; | ||
} | ||
|
||
if (!MoveFile((jreDownloadedDirectory + L'\\' + targetFile).c_str(), runtimeDirectory.c_str())) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
} | ||
|
||
cleanup: | ||
if (hFind != INVALID_HANDLE_VALUE) { | ||
CloseHandle(hFind); | ||
} | ||
RemoveDirectory(jreDownloadedDirectory.c_str()); | ||
DeleteFile(jreDownloadedFile.c_str()); | ||
return err; | ||
} | ||
|
||
int DownloadHMCLJRE(std::wstring &jreDownloadedFile, const std::wstring &domain, | ||
const std::wstring &file) { | ||
int err = 0; | ||
HINTERNET hInternet = NULL, hConnection = NULL, hRequest = NULL; | ||
byte buffer[4096]; | ||
HANDLE fd = NULL; | ||
|
||
{ | ||
hInternet = InternetOpen(L"HMCLauncher", INTERNET_OPEN_TYPE_PRECONFIG, NULL, | ||
NULL, 0); | ||
if (hInternet == NULL) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
hConnection = | ||
InternetConnect(hInternet, domain.c_str(), INTERNET_DEFAULT_HTTPS_PORT, | ||
NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); | ||
if (hConnection == NULL) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
const wchar_t *ACCEPTS[] = {L"application/zip", NULL}; | ||
hRequest = HttpOpenRequest(hConnection, L"GET", file.c_str(), NULL, NULL, | ||
ACCEPTS, INTERNET_FLAG_SECURE, 0); | ||
if (hRequest == NULL) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0)) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
{ | ||
DWORD receivedCount, unused; | ||
|
||
fd = CreateFile(jreDownloadedFile.c_str(), GENERIC_WRITE, 0, NULL, | ||
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); | ||
if (fd == INVALID_HANDLE_VALUE) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
|
||
while (InternetReadFile(hRequest, buffer, 4096, &receivedCount) && | ||
receivedCount) { | ||
if (!WriteFile(fd, buffer, receivedCount, &unused, NULL)) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
} | ||
} | ||
} | ||
|
||
cleanup: | ||
if (hRequest != NULL) { | ||
InternetCloseHandle(hRequest); | ||
} | ||
if (hConnection != NULL) { | ||
InternetCloseHandle(hConnection); | ||
} | ||
if (hInternet != NULL) { | ||
InternetCloseHandle(hInternet); | ||
} | ||
if (fd != NULL) { | ||
CloseHandle(fd); | ||
} | ||
return err; | ||
} | ||
|
||
int UncompressHMCLJRE(std::wstring jreDownloadedFile, std::wstring jreDownloadedDirectory) { | ||
std::wstring command = L"tar.exe -xf \"" + jreDownloadedFile + L"\""; | ||
int err = 0; | ||
|
||
STARTUPINFO si; | ||
PROCESS_INFORMATION pi; | ||
|
||
si.cb = sizeof(si); | ||
ZeroMemory(&si, sizeof(si)); | ||
ZeroMemory(&pi, sizeof(pi)); | ||
if (!CreateProcess(NULL, &command[0], NULL, NULL, false, | ||
NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, NULL, jreDownloadedDirectory.c_str(), &si, | ||
&pi)) { | ||
return GetLastError(); | ||
} | ||
|
||
while (true) { | ||
DWORD exitCode; | ||
if (!GetExitCodeProcess(pi.hProcess, &exitCode)) { | ||
err = GetLastError(); | ||
goto cleanup; | ||
} | ||
if (exitCode != STILL_ACTIVE) { | ||
if (exitCode != 0) { | ||
err = exitCode; | ||
goto cleanup; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
cleanup: | ||
CloseHandle(si.hStdInput); | ||
CloseHandle(si.hStdOutput); | ||
CloseHandle(si.hStdError); | ||
CloseHandle(pi.hProcess); | ||
CloseHandle(pi.hThread); | ||
|
||
return err; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "stdafx.h" | ||
|
||
#define HMCL_ERR_INVALID_JRE_PACK -129 | ||
|
||
int InstallHMCLJRE(const std::wstring &home, const std::wstring &domain, | ||
const std::wstring &file); | ||
|
||
int DownloadHMCLJRE(std::wstring &target, const std::wstring &domain, | ||
const std::wstring &file); | ||
|
||
int UncompressHMCLJRE(std::wstring jreDownloadedFile, std::wstring jreDownloadedDirectory); |
Oops, something went wrong.