Extract and execute the script 'java-download.ps1'

This commit is contained in:
Glavo
2022-02-07 21:22:35 +08:00
committed by Yuhui Huang
parent aafe7f44e7
commit a1f8ff7463
3 changed files with 83 additions and 9 deletions

View File

@@ -123,4 +123,42 @@ void MyPathAddBackslash(std::wstring &filePath) {
if (filePath.back() != L'\\') {
filePath += L'\\';
}
}
LSTATUS MyGetTempPath(std::wstring &out) {
out = std::wstring();
out.resize(MAX_PATH);
DWORD res = GetTempPath(MAX_PATH, &out[0]);
if (res == 0) {
return GetLastError();
}
out.resize(res);
return ERROR_SUCCESS;
}
LSTATUS MyGetTempFileName(const std::wstring &pathName, const std::wstring &prefixString, std::wstring &out) {
out = std::wstring();
out.resize(MAX_PATH);
if (GetTempFileName(pathName.c_str(), prefixString.c_str(), 0, &out[0]) == 0) {
out.resize(0);
return GetLastError();
}
out.resize(wcslen(&out[0]));
return ERROR_SUCCESS;
}
void MyAppendPathToCommandLine(std::wstring &commandLine, const std::wstring &path) {
commandLine += L'"';
for (WCHAR ch : path) {
if (ch == L'\\') {
commandLine += L"\\\\";
} else if (ch == L'"') {
commandLine += L"\\\"";
} else {
commandLine += ch;
}
}
commandLine += L'"';
}