Replace 'PathAppend' with 'MyPathAppend'

This commit is contained in:
Glavo 2022-02-07 14:46:19 +08:00 committed by Yuhui Huang
parent 8909224a13
commit aafe7f44e7
3 changed files with 49 additions and 11 deletions

View File

@ -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);
}
}
}
}

View File

@ -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'\\';
}
}

View File

@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <windows.h>
#include <shlobj.h>
#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);
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);