diff --git a/.github/workflows/build-launcher.yml b/.github/workflows/build-launcher.yml deleted file mode 100644 index d0598ff3e..000000000 --- a/.github/workflows/build-launcher.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Build HMCLauncher - -on: - push: - paths: - - 'HMCLauncher/**' - - '.github/workflows/build-launcher.yml' - pull_request: - paths: - - 'HMCLauncher/**' - - '.github/workflows/build-launcher.yml' - -jobs: - build: - runs-on: windows-latest - steps: - - uses: actions/checkout@v4 - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v2 - with: - msbuild-architecture: x86 - - name: Build HMCLauncher - run: msbuild /p:Configuration=Release /t:Rebuild /verbosity:detailed .\HMCLauncher\ - - name: Copy HMCLauncher to assets - run: Copy-Item .\HMCLauncher\Release\HMCLauncher.exe -Destination .\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 - run: echo "SHORT_SHA=$("${{ github.sha }}".SubString(0, 7))" >> $env:GITHUB_ENV - - name: Copy HMCLauncher to libs - run: Copy-Item .\HMCLauncher\Release\HMCLauncher.exe -Destination .\HMCL\build\libs\HMCLauncher.exe - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: HMCLauncher-${{ env.SHORT_SHA }} - path: HMCL/build/libs/*.exe diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index acc107f82..2a2217ec3 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,6 @@ on: pull_request: paths-ignore: - '**.md' - - 'HMCLauncher/**' jobs: build: diff --git a/.gitignore b/.gitignore index ebf00fe4c..010c85963 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,6 @@ minecraft-exported-crash-info* .nb-gradle *.exe -!/HMCL/src/main/resources/assets/HMCLauncher.exe # macos .DS_Store diff --git a/HMCL/build.gradle.kts b/HMCL/build.gradle.kts index e1928bed2..f84199231 100644 --- a/HMCL/build.gradle.kts +++ b/HMCL/build.gradle.kts @@ -33,12 +33,18 @@ val microsoftAuthId = System.getenv("MICROSOFT_AUTH_ID") ?: "" val microsoftAuthSecret = System.getenv("MICROSOFT_AUTH_SECRET") ?: "" val curseForgeApiKey = System.getenv("CURSEFORGE_API_KEY") ?: "" +val launcherExe = System.getenv("HMCL_LAUNCHER_EXE") + version = "$versionRoot.$buildNumber" dependencies { implementation(project(":HMCLCore")) implementation("libs:JFoenix") implementation("com.twelvemonkeys.imageio:imageio-webp:3.12.0") + + if (launcherExe == null) { + implementation("org.glavo.hmcl:HMCLauncher:3.6.0.1") + } } fun digest(algorithm: String, bytes: ByteArray): ByteArray = MessageDigest.getInstance(algorithm).digest(bytes) @@ -154,23 +160,18 @@ tasks.getByName("sha } } + if (launcherExe != null) { + into("assets") { + from(file(launcherExe)) + } + } + doLast { attachSignature(jarPath) createChecksum(jarPath) } } -fun createExecutable(suffix: String, header: String) { - val output = File(jarPath.parentFile, jarPath.nameWithoutExtension + '.' + suffix) - - output.outputStream().use { - it.write(File(project.projectDir, header).readBytes()) - it.write(jarPath.readBytes()) - } - - createChecksum(output) -} - tasks.processResources { into("META-INF/versions/11") { from(sourceSets["java11"].output) @@ -179,10 +180,30 @@ tasks.processResources { } val makeExecutables = tasks.create("makeExecutables") { + val extensions = listOf("exe", "sh") + dependsOn(tasks.jar) + + inputs.file(jarPath) + outputs.files(extensions.map { File(jarPath.parentFile, jarPath.nameWithoutExtension + '.' + it) }) + doLast { - createExecutable("exe", "src/main/resources/assets/HMCLauncher.exe") - createExecutable("sh", "src/main/resources/assets/HMCLauncher.sh") + val jarContent = jarPath.readBytes() + + ZipFile(jarPath).use { zipFile -> + for (extension in extensions) { + val output = File(jarPath.parentFile, jarPath.nameWithoutExtension + '.' + extension) + val entry = zipFile.getEntry("assets/HMCLauncher.$extension") + ?: throw GradleException("HMCLauncher.$extension not found") + + output.outputStream().use { outputStream -> + zipFile.getInputStream(entry).use { it.copyTo(outputStream) } + outputStream.write(jarContent) + } + + createChecksum(output) + } + } } } @@ -256,8 +277,10 @@ tasks.create("run") { val hmclJavaHome = System.getenv("HMCL_JAVA_HOME") if (hmclJavaHome != null) { - this.executable(file(hmclJavaHome).resolve("bin") - .resolve(if (System.getProperty("os.name").lowercase().startsWith("windows")) "java.exe" else "java")) + this.executable( + file(hmclJavaHome).resolve("bin") + .resolve(if (System.getProperty("os.name").lowercase().startsWith("windows")) "java.exe" else "java") + ) } doFirst { diff --git a/HMCL/src/main/resources/assets/HMCLauncher.exe b/HMCL/src/main/resources/assets/HMCLauncher.exe deleted file mode 100644 index 12ccc5216..000000000 Binary files a/HMCL/src/main/resources/assets/HMCLauncher.exe and /dev/null differ diff --git a/HMCLauncher/.clang-format b/HMCLauncher/.clang-format deleted file mode 100644 index 3d71f04b4..000000000 --- a/HMCLauncher/.clang-format +++ /dev/null @@ -1,4 +0,0 @@ -# Use the Google style in this project. -BasedOnStyle: Google - -SortIncludes: false \ No newline at end of file diff --git a/HMCLauncher/.gitignore b/HMCLauncher/.gitignore deleted file mode 100644 index 3b5cac370..000000000 --- a/HMCLauncher/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -Debug -Release -.vs -*.APS -cmake-build-*/ diff --git a/HMCLauncher/CMakeLists.txt b/HMCLauncher/CMakeLists.txt deleted file mode 100644 index 1edf65cf6..000000000 --- a/HMCLauncher/CMakeLists.txt +++ /dev/null @@ -1,18 +0,0 @@ -cmake_minimum_required(VERSION 3.25) -project(HMCLauncher) -if(MSVC) - add_definitions(-DUNICODE -D_UNICODE) - add_compile_options(/utf-8 /W4) - add_link_options(/ENTRY:wWinMainCRTStartup) -else() - add_compile_options(-municode -Wall -Wextra -Wpedantic) - 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/HMCL.rc HMCL/java.cpp HMCL/main.cpp HMCL/os.cpp HMCL/stdafx.cpp HMCL/Version.cpp) -target_link_libraries(HMCLauncher Version) -install(TARGETS HMCLauncher) \ No newline at end of file diff --git a/HMCLauncher/HMCL/HMCL.ico b/HMCLauncher/HMCL/HMCL.ico deleted file mode 100644 index d27303714..000000000 Binary files a/HMCLauncher/HMCL/HMCL.ico and /dev/null differ diff --git a/HMCLauncher/HMCL/HMCL.rc b/HMCLauncher/HMCL/HMCL.rc deleted file mode 100644 index ecc8c147c..000000000 --- a/HMCLauncher/HMCL/HMCL.rc +++ /dev/null @@ -1,143 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#ifndef APSTUDIO_INVOKED -#include "targetver.h" -#endif -#define APSTUDIO_HIDDEN_SYMBOLS -#include "windows.h" -#undef APSTUDIO_HIDDEN_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// 中文(简体,中国) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS) -LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_HMCL ICON "HMCL.ico" - - -///////////////////////////////////////////////////////////////////////////// -// -// Accelerator -// - -IDC_HMCL ACCELERATORS -BEGIN - "?", IDM_ABOUT, ASCII, ALT - "/", IDM_ABOUT, ASCII, ALT -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#ifndef APSTUDIO_INVOKED\r\n" - "#include ""targetver.h""\r\n" - "#endif\r\n" - "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" - "#include ""windows.h""\r\n" - "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -VS_VERSION_INFO VERSIONINFO - FILEVERSION 3,5,0,0 - PRODUCTVERSION 3,5,0,0 - FILEFLAGSMASK 0x3fL -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x40004L - FILETYPE 0x1L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "080404b0" - BEGIN - VALUE "CompanyName", "huanghongxun" - VALUE "FileDescription", "Hello Minecraft! Launcher For Windows" - VALUE "FileVersion", "3.5.0.0" - VALUE "InternalName", "HMCL.exe" - VALUE "LegalCopyright", "Copyright (C) 2021 huangyuhui" - VALUE "OriginalFilename", "HMCL.exe" - VALUE "ProductName", "Hello Minecraft! Launcher" - VALUE "ProductVersion", "3.5.0.0" - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x804, 1200 - END -END - - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE -BEGIN - IDS_APP_TITLE "HMCL" - IDC_HMCL "HMCL" -END - -#endif // 中文(简体,中国) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/HMCLauncher/HMCL/HMCL.vcxproj b/HMCLauncher/HMCL/HMCL.vcxproj deleted file mode 100644 index fe4858207..000000000 --- a/HMCLauncher/HMCL/HMCL.vcxproj +++ /dev/null @@ -1,192 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 15.0 - {672B1019-E741-4C0D-A986-627E2ACE157B} - Win32Proj - HMCL - 10.0 - HMCLauncher - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - true - - - true - - - false - - - false - - - - Use - Level3 - Disabled - true - WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - /utf-8 %(AdditionalOptions) - - - Windows - true - version.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - Use - Level3 - Disabled - true - _DEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - /utf-8 %(AdditionalOptions) - - - Windows - true - - - - - Use - Level3 - MinSpace - true - false - true - WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS - false - MultiThreaded - Disabled - Size - /utf-8 %(AdditionalOptions) - - - Windows - true - true - true - version.lib;%(AdditionalDependencies) - - - - - Use - Level3 - MinSpace - true - false - true - NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - false - Disabled - Size - /utf-8 %(AdditionalOptions) - - - Windows - true - true - true - - - - - - - - - - - - - - - - - - Create - Create - Create - Create - - - - - - - - - - - - - \ No newline at end of file diff --git a/HMCLauncher/HMCL/HMCL.vcxproj.filters b/HMCLauncher/HMCL/HMCL.vcxproj.filters deleted file mode 100644 index fea247b7a..000000000 --- a/HMCLauncher/HMCL/HMCL.vcxproj.filters +++ /dev/null @@ -1,70 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - 头文件 - - - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - 源文件 - - - - - 资源文件 - - - - - 资源文件 - - - \ No newline at end of file diff --git a/HMCLauncher/HMCL/HMCL.vcxproj.user b/HMCLauncher/HMCL/HMCL.vcxproj.user deleted file mode 100644 index be2507870..000000000 --- a/HMCLauncher/HMCL/HMCL.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/HMCLauncher/HMCL/Version.cpp b/HMCLauncher/HMCL/Version.cpp deleted file mode 100644 index ed91397dd..000000000 --- a/HMCLauncher/HMCL/Version.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "stdafx.h" -#include "version.h" - -Version::Version(const std::wstring &rawString) { - int idx = 0; - ver[0] = ver[1] = ver[2] = ver[3] = 0; - for (auto &i : rawString) { - if (idx >= 4) break; - if (i == '.') - ++idx; - else if (i == '_') - ++idx; - else if (isdigit(i)) - ver[idx] = ver[idx] * 10 + (i - L'0'); - } -} diff --git a/HMCLauncher/HMCL/Version.h b/HMCLauncher/HMCL/Version.h deleted file mode 100644 index 523690402..000000000 --- a/HMCLauncher/HMCL/Version.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -class Version { - public: - int ver[4]; - - Version(const std::wstring &rawString); - - template - Version(std::initializer_list ver_list) { - int i = 0; - for (const auto &data : ver_list) { - if (i >= 4) break; - ver[i++] = data; - } - } - - bool operator<(const Version &other) const { - for (int i = 0; i < 4; ++i) - if (ver[i] != other.ver[i]) return ver[i] < other.ver[i]; - return false; - } - - bool operator<=(const Version &other) const { - for (int i = 0; i < 4; ++i) - if (ver[i] != other.ver[i]) return ver[i] < other.ver[i]; - return true; - } -}; diff --git a/HMCLauncher/HMCL/java.cpp b/HMCLauncher/HMCL/java.cpp deleted file mode 100644 index 067c12fb2..000000000 --- a/HMCLauncher/HMCL/java.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "stdafx.h" -#include "java.h" -#include "os.h" -#include "version.h" - -const Version JAVA_8(L"1.8"), JAVA_11(L"11"); - -const LPCWSTR JDK_NEW = L"SOFTWARE\\JavaSoft\\JDK"; -const LPCWSTR JRE_NEW = L"SOFTWARE\\JavaSoft\\JRE"; -const LPCWSTR JDK_OLD = L"SOFTWARE\\JavaSoft\\Java Development Kit"; -const LPCWSTR JRE_OLD = L"SOFTWARE\\JavaSoft\\Java Runtime Environment"; - -bool oldJavaFound = false; - -bool FindJavaByRegistryKey(HKEY rootKey, LPCWSTR subKey, std::wstring& path) { - WCHAR javaVer[MAX_KEY_LENGTH]; // buffer for subkey name, special for - // JavaVersion - DWORD cbName; // size of name string - DWORD cSubKeys = 0; // number of subkeys - DWORD cbMaxSubKey; // longest subkey size - DWORD cValues; // number of values for key - DWORD cchMaxValue; // longest value name - DWORD cbMaxValueData; // longest value data - LSTATUS result; - - HKEY hKey; - if (ERROR_SUCCESS != - (result = - RegOpenKeyEx(rootKey, subKey, 0, KEY_WOW64_64KEY | KEY_READ, &hKey))) - return false; - - RegQueryInfoKey(hKey, // key handle - NULL, // buffer for class name - NULL, // size of class string - NULL, // reserved - &cSubKeys, // number of subkeys - &cbMaxSubKey, // longest subkey size - NULL, // longest class string - &cValues, // number of values for this key - &cchMaxValue, // longest value name - &cbMaxValueData, // longest value data - NULL, // security descriptor - NULL); // last write time - - if (!cSubKeys) return false; - - bool flag = false; - for (DWORD i = 0; i < cSubKeys; ++i) { - cbName = MAX_KEY_LENGTH; - if (ERROR_SUCCESS != (result = RegEnumKeyEx(hKey, i, javaVer, &cbName, NULL, - NULL, NULL, NULL))) - continue; - - HKEY javaKey; - if (ERROR_SUCCESS != RegOpenKeyEx(hKey, javaVer, 0, KEY_READ, &javaKey)) - continue; - - if (ERROR_SUCCESS == MyRegQueryValue(javaKey, L"JavaHome", REG_SZ, path)) { - if (Version(javaVer) < JAVA_8) - oldJavaFound = true; - else - flag = true; - } - - if (flag) break; - } - - RegCloseKey(hKey); - - return flag; -} - -bool FindJavaInRegistry(std::wstring& path) { - return FindJavaByRegistryKey(HKEY_LOCAL_MACHINE, JDK_NEW, path) || - FindJavaByRegistryKey(HKEY_LOCAL_MACHINE, JRE_NEW, path) || - FindJavaByRegistryKey(HKEY_LOCAL_MACHINE, JDK_OLD, path) || - FindJavaByRegistryKey(HKEY_LOCAL_MACHINE, JRE_OLD, path); -} - -bool FindJava(std::wstring& path) { - return ERROR_SUCCESS == MyGetEnvironmentVariable(L"HMCL_JAVA_HOME", path) || - ERROR_SUCCESS == MyGetEnvironmentVariable(L"JAVA_HOME", path) || - FindJavaInRegistry(path); -} diff --git a/HMCLauncher/HMCL/java.h b/HMCLauncher/HMCL/java.h deleted file mode 100644 index eb0a289f9..000000000 --- a/HMCLauncher/HMCL/java.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include -#include - -// Find Java installation in system registry -bool FindJavaInRegistry(std::wstring &path); - -// Find Java Installation in registry and environment variable -bool FindJava(std::wstring &path); diff --git a/HMCLauncher/HMCL/lang.h b/HMCLauncher/HMCL/lang.h deleted file mode 100644 index b6207594e..000000000 --- a/HMCLauncher/HMCL/lang.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#define ERROR_TITLE L"Java not found" - -#define ERROR_TITLE_ZH L"未找到 Java" - -#define ERROR_PROMPT L"The Java runtime environment is required to run HMCL and Minecraft,\n"\ - L"Click 'OK' to start downloading java.\n"\ - L"Please restart HMCL after installing Java." - -#define ERROR_PROMPT_ZH L"运行 HMCL 以及 Minecraft 需要 Java 运行时环境,点击“确定”开始下载。\n"\ - L"请在安装 Java 完成后重新启动 HMCL。" diff --git a/HMCLauncher/HMCL/main.cpp b/HMCLauncher/HMCL/main.cpp deleted file mode 100644 index ba2055891..000000000 --- a/HMCLauncher/HMCL/main.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include "stdafx.h" -#include "main.h" -#include "os.h" -#include "java.h" -#include "lang.h" -#include - -Version J8(TEXT("8")); - -extern "C" { -__declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001; -__declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001; -} - -LPCWSTR VENDOR_DIRS[] = { - L"Java", L"Microsoft", L"BellSoft", L"Zulu", L"Eclipse Foundation", L"AdoptOpenJDK", L"Semeru" -}; - -void RawLaunchJVM(const std::wstring &javaPath, const std::wstring &workdir, - const std::wstring &jarPath, const std::wstring &jvmOptions) { - if (MyCreateProcess(L"\"" + javaPath + L"\" " + jvmOptions + L" -jar \"" + jarPath + L"\"", workdir)) - exit(EXIT_SUCCESS); -} - -void LaunchJVM(const std::wstring &javaPath, const std::wstring &workdir, - const std::wstring &jarPath, const std::wstring &jvmOptions) { - Version javaVersion(L""); - if (!MyGetFileVersionInfo(javaPath, javaVersion)) return; - - if (J8 <= javaVersion) { - RawLaunchJVM(javaPath, workdir, jarPath, jvmOptions); - } -} - -void FindJavaInDirAndLaunchJVM(const std::wstring &baseDir, const std::wstring &workdir, - const std::wstring &jarPath, const std::wstring &jvmOptions) { - std::wstring pattern = baseDir + L"*"; - - WIN32_FIND_DATA data; - HANDLE hFind = FindFirstFile(pattern.c_str(), &data); // Search all subdirectory - - if (hFind != INVALID_HANDLE_VALUE) { - do { - std::wstring javaw = baseDir + data.cFileName + std::wstring(L"\\bin\\javaw.exe"); - if (FindFirstFileExists(javaw.c_str(), 0)) { - LaunchJVM(javaw, workdir, jarPath, jvmOptions); - } - } while (FindNextFile(hFind, &data)); - FindClose(hFind); - } -} - -void OpenHelpPage() { - ShellExecute(0, 0, L"https://docs.hmcl.net/help.html", 0, 0, SW_SHOW); -} - -int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, - LPWSTR lpCmdLine, int nCmdShow) { - std::wstring path, exeName, jvmOptions; - - // Since Jar file is appended to this executable, we should first get the - // location of JAR file. - if (ERROR_SUCCESS != MyGetModuleFileName(NULL, exeName)) return 1; - - std::wstring workdir; - size_t last_slash = exeName.find_last_of(L"/\\"); - if (last_slash != std::wstring::npos && last_slash + 1 < exeName.size()) { - workdir = exeName.substr(0, last_slash); - exeName = exeName.substr(last_slash + 1); - } - - if (ERROR_SUCCESS != MyGetEnvironmentVariable(L"HMCL_JAVA_OPTS", jvmOptions)) { - jvmOptions = L"-XX:MinHeapFreeRatio=5 -XX:MaxHeapFreeRatio=15"; // Default Options - } - - bool useChinese = GetUserDefaultUILanguage() == 2052; // zh-CN - - MyArchitecture architecture = MyGetArchitecture(); - - // First try the Java packaged together. - bool isX64 = architecture == MyArchitecture::X86_64; - bool isARM64 = architecture == MyArchitecture::ARM64; - - if (isARM64) { - RawLaunchJVM(L"jre-arm64\\bin\\javaw.exe", workdir, exeName, jvmOptions); - } - if (isX64) { - RawLaunchJVM(L"jre-x64\\bin\\javaw.exe", workdir, exeName, jvmOptions); - } - RawLaunchJVM(L"jre-x86\\bin\\javaw.exe", workdir, exeName, jvmOptions); - - if (FindJava(path)) LaunchJVM(path + L"\\bin\\javaw.exe", workdir, exeName, jvmOptions); - - std::wstring programFiles; - - // Or we try to search Java in C:\Program Files - if (!SUCCEEDED(MySHGetFolderPath(CSIDL_PROGRAM_FILES, programFiles))) programFiles = L"C:\\Program Files\\"; - for (LPCWSTR vendorDir : VENDOR_DIRS) { - std::wstring dir = programFiles; - MyPathAppend(dir, vendorDir); - MyPathAddBackslash(dir); - - FindJavaInDirAndLaunchJVM(dir, workdir, exeName, jvmOptions); - } - - // Consider C:\Program Files (x86) - if (!SUCCEEDED(MySHGetFolderPath(CSIDL_PROGRAM_FILESX86, programFiles))) programFiles = L"C:\\Program Files (x86)\\"; - for (LPCWSTR vendorDir : VENDOR_DIRS) { - std::wstring dir = programFiles; - MyPathAppend(dir, vendorDir); - MyPathAddBackslash(dir); - - FindJavaInDirAndLaunchJVM(dir, workdir, exeName, jvmOptions); - } - - // Try java in PATH - RawLaunchJVM(L"javaw", workdir, exeName, jvmOptions); - - std::wstring hmclJavaDir; - { - std::wstring buffer; - if (SUCCEEDED(MySHGetFolderPath(CSIDL_APPDATA, buffer)) || SUCCEEDED(MySHGetFolderPath(CSIDL_PROFILE, buffer))) { - MyPathAppend(buffer, L".hmcl"); - MyPathAppend(buffer, L"java"); - if (isARM64) { - MyPathAppend(buffer, L"windows-arm64"); - } else if (isX64) { - MyPathAppend(buffer, L"windows-x86_64"); - } else { - MyPathAppend(buffer, L"windows-x86"); - } - MyPathAddBackslash(buffer); - hmclJavaDir = buffer; - } - } - - if (!hmclJavaDir.empty()) { - FindJavaInDirAndLaunchJVM(hmclJavaDir, workdir, exeName, jvmOptions); - } - - LPCWSTR downloadLink; - - if (isARM64) { - downloadLink = L"https://docs.hmcl.net/downloads/windows/arm64.html"; - } else if (isX64) { - downloadLink = L"https://docs.hmcl.net/downloads/windows/x86_64.html"; - } else { - downloadLink = L"https://docs.hmcl.net/downloads/windows/x86.html"; - } - - if (IDOK == MessageBox(NULL, useChinese ? ERROR_PROMPT_ZH : ERROR_PROMPT, useChinese ? ERROR_TITLE_ZH : ERROR_TITLE, MB_ICONWARNING | MB_OKCANCEL)) { - ShellExecute(0, 0, downloadLink, 0, 0, SW_SHOW); - } - return 1; -} diff --git a/HMCLauncher/HMCL/main.h b/HMCLauncher/HMCL/main.h deleted file mode 100644 index d00d47e78..000000000 --- a/HMCLauncher/HMCL/main.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#include "resource.h" diff --git a/HMCLauncher/HMCL/os.cpp b/HMCLauncher/HMCL/os.cpp deleted file mode 100644 index b10718586..000000000 --- a/HMCLauncher/HMCL/os.cpp +++ /dev/null @@ -1,203 +0,0 @@ -#include "stdafx.h" -#include "os.h" - -typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS2) (HANDLE, PUSHORT, PUSHORT); - -MyArchitecture MyGetArchitecture() { - LPFN_ISWOW64PROCESS2 fnIsWow64Process2 = (LPFN_ISWOW64PROCESS2)GetProcAddress( - GetModuleHandle(L"Kernel32.dll"), "IsWow64Process2"); - if (NULL != fnIsWow64Process2) { - USHORT uProcessMachine = 0; - USHORT uNativeMachine = 0; - if (fnIsWow64Process2(GetCurrentProcess(), &uProcessMachine, &uNativeMachine)) { - if (uNativeMachine == 0xAA64) { - return MyArchitecture::ARM64; - } - - if (uNativeMachine == 0x8664) { - return MyArchitecture::X86_64; - } - - return MyArchitecture::X86; - } - } - - SYSTEM_INFO systemInfo; - GetNativeSystemInfo(&systemInfo); - - if (systemInfo.wProcessorArchitecture == 12) { // PROCESSOR_ARCHITECTURE_ARM64 - return MyArchitecture::ARM64; - } - - if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { - return MyArchitecture::X86_64; - } - - return MyArchitecture::X86; -} - -LSTATUS MyRegQueryValue(HKEY hKey, LPCWSTR subKey, DWORD dwType, - std::wstring &out) { - DWORD dwSize = 0; - LSTATUS ret = RegQueryValueEx(hKey, subKey, 0, &dwType, NULL, &dwSize); - if (ret != ERROR_SUCCESS) return ret; - WCHAR *buffer = new WCHAR[dwSize]; - ret = RegQueryValueEx(hKey, subKey, 0, &dwType, (LPBYTE)buffer, &dwSize); - if (ret != ERROR_SUCCESS) return ret; - out = buffer; - delete[] buffer; - return ERROR_SUCCESS; -} - -LSTATUS MyGetModuleFileName(HMODULE hModule, std::wstring &out) { - DWORD res, size = MAX_PATH; - out = std::wstring(); - out.resize(size); - while ((res = GetModuleFileName(hModule, &out[0], size)) == size) { - out.resize(size += MAX_PATH); - } - if (res == 0) - return GetLastError(); - else { - out.resize(size - MAX_PATH + res); - return ERROR_SUCCESS; - } -} - -LSTATUS MyGetEnvironmentVariable(LPCWSTR name, std::wstring &out) { - DWORD res, size = MAX_PATH; - out = std::wstring(); - out.resize(size); - while ((res = GetEnvironmentVariable(name, &out[0], size)) == size) { - out.resize(size += MAX_PATH); - } - if (res == 0) - return GetLastError(); - else { - out.resize(size - MAX_PATH + res); - return ERROR_SUCCESS; - } -} - -bool MyCreateProcess(const std::wstring &command, const std::wstring &workdir) { - std::wstring writable_command = command; - STARTUPINFO si; - PROCESS_INFORMATION pi; - si.cb = sizeof(si); - ZeroMemory(&si, sizeof(si)); - ZeroMemory(&pi, sizeof(pi)); - - if (workdir.empty()) { - return CreateProcess(NULL, &writable_command[0], NULL, NULL, false, - NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi); - } else { - return CreateProcess(NULL, &writable_command[0], NULL, NULL, false, - NORMAL_PRIORITY_CLASS, NULL, workdir.c_str(), &si, - &pi); - } -} - -bool FindFirstFileExists(LPCWSTR lpPath, DWORD dwFilter) { - WIN32_FIND_DATA fd; - HANDLE hFind = FindFirstFile(lpPath, &fd); - bool bFilter = (false == dwFilter) ? true : fd.dwFileAttributes & dwFilter; - bool ret = ((hFind != INVALID_HANDLE_VALUE) && bFilter) ? true : false; - FindClose(hFind); - return ret; -} - -bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version) { - DWORD verHandle = 0; - UINT size = 0; - LPBYTE lpBuffer = NULL; - VS_FIXEDFILEINFO *pFileInfo; - DWORD dwSize = GetFileVersionInfoSize(filePath.c_str(), NULL); - - if (!dwSize) return false; - - LPBYTE data = new BYTE[dwSize]; - if (!GetFileVersionInfo(filePath.c_str(), 0, dwSize, data)) { - delete[] data; - return false; - } - - if (!VerQueryValue(data, TEXT("\\"), (LPVOID *)&pFileInfo, &size)) { - delete[] data; - return false; - } - - version = Version{(pFileInfo->dwFileVersionMS >> 16) & 0xFFFF, - (pFileInfo->dwFileVersionMS >> 0) & 0xFFFF, - (pFileInfo->dwFileVersionLS >> 16) & 0xFFFF, - (pFileInfo->dwFileVersionLS >> 0) & 0xFFFF}; - return true; -} - -HRESULT MySHGetFolderPath(int csidl, std::wstring &out) { - out = std::wstring(); - out.resize(MAX_PATH); - - HRESULT res = SHGetFolderPath(NULL, csidl, NULL, 0, &out[0]); - if (SUCCEEDED(res)) { - out.resize(wcslen(&out[0])); - } else { - out.resize(0); - } - return res; -} - -void MyPathAppend(std::wstring &filePath, const std::wstring &more) { - if (filePath.back() != L'\\') { - filePath += L'\\'; - } - - filePath += more; -} - -void MyPathAddBackslash(std::wstring &filePath) { - if (filePath.back() != L'\\') { - filePath += L'\\'; - } -} - -LSTATUS MyGetTempFile(const std::wstring &prefixString, const std::wstring &ext, std::wstring &out) { - out.resize(MAX_PATH); - DWORD res = GetTempPath(MAX_PATH, &out[0]); - if (res == 0) { - return GetLastError(); - } - - out.resize(res); - - GUID guid; - CoCreateGuid(&guid); - - WCHAR buffer[MAX_PATH]; - int n = StringFromGUID2(guid, buffer, MAX_PATH); - if (n == 0) { - return CO_E_PATHTOOLONG; - } - - MyPathAddBackslash(out); - out += prefixString; - out += buffer; - out += L'.'; - out += ext; - - return ERROR_SUCCESS; -} - -void MyAppendPathToCommandLine(std::wstring &commandLine, const std::wstring &path) { - commandLine += L'"'; - for (size_t i = 0; i < path.size(); i++) { - WCHAR ch = path[i]; - if (ch == L'\\' && (i + 1 == path.size() || path[i + 1] == L'"')) { - commandLine += L"\\\\"; - } else if (ch == L'"') { - commandLine += L"\\\""; - } else { - commandLine += ch; - } - } - commandLine += L'"'; -} \ No newline at end of file diff --git a/HMCLauncher/HMCL/os.h b/HMCLauncher/HMCL/os.h deleted file mode 100644 index e44743a9f..000000000 --- a/HMCLauncher/HMCL/os.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include "Version.h" - -const int MAX_KEY_LENGTH = 255; -const int MAX_VALUE_NAME = 16383; - -enum MyArchitecture { - X86, - X86_64, - ARM64 -}; - -MyArchitecture MyGetArchitecture(); - -// Query registry value of class root hKey, key path subKey, stores result in -// parameter out. -LSTATUS MyRegQueryValue(HKEY hKey, LPCWSTR subKey, DWORD dwType, - std::wstring &out); - -// Get module file name, stores result in parameter out. -LSTATUS MyGetModuleFileName(HMODULE hModule, std::wstring &out); - -// Get environment variable by name, C++ style, stores the value in parameter -// out. -LSTATUS MyGetEnvironmentVariable(LPCWSTR name, std::wstring &out); - -// Create process by invoking CreateProcess, only pass command. -bool MyCreateProcess(const std::wstring &command, const std::wstring &workdir); - -// Check if file lpPath exists. -bool FindFirstFileExists(LPCWSTR lpPath, DWORD dwFilter); - -bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version); - -HRESULT MySHGetFolderPath(int csidl, std::wstring &out); - -void MyPathAppend(std::wstring &filePath, const std::wstring &more); - -void MyPathAddBackslash(std::wstring &filePath); - -LSTATUS MyGetTempFile(const std::wstring &prefixString, const std::wstring &ext, std::wstring &out); - -void MyAppendPathToCommandLine(std::wstring &commandLine, const std::wstring &path); \ No newline at end of file diff --git a/HMCLauncher/HMCL/resource.h b/HMCLauncher/HMCL/resource.h deleted file mode 100644 index 37674e53f..000000000 --- a/HMCLauncher/HMCL/resource.h +++ /dev/null @@ -1,25 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ 生成的包含文件。 -// 供 HMCL.rc 使用 -// -#define IDC_MYICON 2 -#define IDD_HMCL_DIALOG 102 -#define IDS_APP_TITLE 103 -#define IDM_ABOUT 104 -#define IDI_HMCL 107 -#define IDC_HMCL 109 -#define IDR_MAINFRAME 128 -#define ID_SCRIPT_DOWNLOAD_JAVA 160 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 129 -#define _APS_NEXT_COMMAND_VALUE 32771 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 110 -#endif -#endif diff --git a/HMCLauncher/HMCL/stdafx.cpp b/HMCLauncher/HMCL/stdafx.cpp deleted file mode 100644 index 88cf932c2..000000000 --- a/HMCLauncher/HMCL/stdafx.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// stdafx.cpp : 只包括标准包含文件的源文件 -// HMCL.pch 将作为预编译标头 -// stdafx.obj 将包含预编译类型信息 - -#include "stdafx.h" - -// TODO: 在 STDAFX.H 中引用任何所需的附加头文件, -//而不是在此文件中引用 diff --git a/HMCLauncher/HMCL/stdafx.h b/HMCLauncher/HMCL/stdafx.h deleted file mode 100644 index b7aace52a..000000000 --- a/HMCLauncher/HMCL/stdafx.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "targetver.h" - -#include -#include -#include diff --git a/HMCLauncher/HMCL/targetver.h b/HMCLauncher/HMCL/targetver.h deleted file mode 100644 index e1306e323..000000000 --- a/HMCLauncher/HMCL/targetver.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -// Windows 7 - -#define WINVER 0x0601 -#define _WIN32_WINNT 0x0601 - -#include diff --git a/HMCLauncher/HMCLauncher.sln b/HMCLauncher/HMCLauncher.sln deleted file mode 100644 index 792b39bb9..000000000 --- a/HMCLauncher/HMCLauncher.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27428.2005 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HMCL", "HMCL\HMCL.vcxproj", "{672B1019-E741-4C0D-A986-627E2ACE157B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x86 = Debug|x86 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {672B1019-E741-4C0D-A986-627E2ACE157B}.Debug|x86.ActiveCfg = Debug|Win32 - {672B1019-E741-4C0D-A986-627E2ACE157B}.Debug|x86.Build.0 = Debug|Win32 - {672B1019-E741-4C0D-A986-627E2ACE157B}.Release|x86.ActiveCfg = Release|Win32 - {672B1019-E741-4C0D-A986-627E2ACE157B}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {FE40055B-673D-42F5-8AE4-6DF2C87EB659} - EndGlobalSection -EndGlobal