From aafe7f44e772444551baa41c47027c86976eb15d Mon Sep 17 00:00:00 2001 From: Glavo Date: Mon, 7 Feb 2022 14:46:19 +0800 Subject: [PATCH] Replace 'PathAppend' with 'MyPathAppend' --- HMCLauncher/HMCL/main.cpp | 24 ++++++++++++++---------- HMCLauncher/HMCL/os.cpp | 27 +++++++++++++++++++++++++++ HMCLauncher/HMCL/os.h | 9 ++++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/HMCLauncher/HMCL/main.cpp b/HMCLauncher/HMCL/main.cpp index a01a7f010..9f8368cb6 100644 --- a/HMCLauncher/HMCL/main.cpp +++ b/HMCLauncher/HMCL/main.cpp @@ -88,18 +88,17 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, std::wstring hmclJavaDir; { - WCHAR buffer[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, buffer)) - || SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, 0, buffer))) { - PathAppend(buffer, L".hmcl"); - PathAppend(buffer, L"java"); + std::wstring buffer; + if (SUCCEEDED(MySHGetFolderPath(CSIDL_APPDATA, buffer)) || SUCCEEDED(MySHGetFolderPath(CSIDL_PROFILE, buffer))) { + MyPathAppend(buffer, L".hmcl"); + MyPathAppend(buffer, L"java"); if (isX64) { - PathAppend(buffer, L"windows-x86_64"); + MyPathAppend(buffer, L"windows-x86_64"); } else { - PathAppend(buffer, L"windows-x86"); + MyPathAppend(buffer, L"windows-x86"); } - PathAddBackslash(buffer); - hmclJavaDir = std::wstring(buffer); + MyPathAddBackslash(buffer); + hmclJavaDir = buffer; } } @@ -122,7 +121,12 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, // Try downloading Java on Windows 7 or later if (VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask)) { - // TODO + HRSRC scriptFileResource = FindResource(NULL, MAKEINTRESOURCE(ID_SCRIPT_DOWNLOAD_JAVA), RT_RCDATA); + if (scriptFileResource) { + HGLOBAL scriptHandle = LoadResource(NULL, scriptFileResource); + DWORD dataSize = SizeofResource(NULL, scriptFileResource); + void *data = LockResource(scriptHandle); + } } } } diff --git a/HMCLauncher/HMCL/os.cpp b/HMCLauncher/HMCL/os.cpp index 27c36da28..4dc3c21cd 100644 --- a/HMCLauncher/HMCL/os.cpp +++ b/HMCLauncher/HMCL/os.cpp @@ -97,3 +97,30 @@ bool MyGetFileVersionInfo(const std::wstring &filePath, Version &version) { (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_APPDATA, 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'\\'; + } +} \ No newline at end of file diff --git a/HMCLauncher/HMCL/os.h b/HMCLauncher/HMCL/os.h index 129cae201..9af58f528 100644 --- a/HMCLauncher/HMCL/os.h +++ b/HMCLauncher/HMCL/os.h @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include "Version.h" const int MAX_KEY_LENGTH = 255; @@ -24,4 +25,10 @@ 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); \ No newline at end of file +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); \ No newline at end of file