Offer to restart game from VEH exception handler (#936)

This commit is contained in:
kizer 2022-07-27 04:14:48 +09:00 committed by GitHub
parent 98e421a227
commit 58ceb1dc87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 1279 additions and 616 deletions

View file

@ -520,3 +520,36 @@ void utils::wait_for_game_window() {
};
SendMessageW(game_window, WM_NULL, 0, 0);
}
std::wstring utils::escape_shell_arg(const std::wstring& arg) {
// https://docs.microsoft.com/en-us/archive/blogs/twistylittlepassagesallalike/everyone-quotes-command-line-arguments-the-wrong-way
std::wstring res;
if (!arg.empty() && arg.find_first_of(L" \t\n\v\"") == std::wstring::npos) {
res.append(arg);
} else {
res.push_back(L'"');
for (auto it = arg.begin(); ; ++it) {
size_t bsCount = 0;
while (it != arg.end() && *it == L'\\') {
++it;
++bsCount;
}
if (it == arg.end()) {
res.append(bsCount * 2, L'\\');
break;
} else if (*it == L'"') {
res.append(bsCount * 2 + 1, L'\\');
res.push_back(*it);
} else {
res.append(bsCount, L'\\');
res.push_back(*it);
}
}
res.push_back(L'"');
}
return res;
}