-
Notifications
You must be signed in to change notification settings - Fork 7.8k
[Workspaces]Fix for steam games capture&launch: capture and correctly launch steam games. #38380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
991c18b
Workspaces fix: capture steam games.
vanzue e189a59
minor fix
vanzue 22de8b2
Launch steam apps by url appmodeluserid instead of directly exe call.
vanzue 5f8f87a
fix copilot comment
vanzue 7fb545b
fix
vanzue b74f2b7
remove unnecessary string
vanzue a9e4375
expect words
vanzue ae0d325
Merge branch 'main' into dev/vanzue
vanzue 7f79fad
white list words
vanzue 769e433
Order of alphabet
vanzue 884ab94
exclude thin frame if it's not a steam game.
vanzue 1f0186c
fix build
vanzue 9e8e3c9
fix regression
vanzue 1852d98
adjust comment
vanzue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -273,4 +273,4 @@ mengyuanchen | |
| testhost | ||
|
|
||
| #Tools | ||
| OIP | ||
| OIP | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
src/modules/Workspaces/WorkspacesLib/SteamGameHelper.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| #include "pch.h" | ||
| #include "SteamHelper.h" | ||
| #include <fstream> | ||
| #include <sstream> | ||
| #include <unordered_map> | ||
| #include <filesystem> | ||
| #include <regex> | ||
| #include <string> | ||
|
|
||
| namespace Utils | ||
| { | ||
|
|
||
| static std::wstring Utf8ToWide(const std::string& utf8) | ||
| { | ||
| if (utf8.empty()) | ||
| return L""; | ||
|
|
||
| int size = MultiByteToWideChar(CP_UTF8, 0, utf8.data(), static_cast<int>(utf8.size()), nullptr, 0); | ||
| if (size <= 0) | ||
| return L""; | ||
|
|
||
| std::wstring wide(size, L'\0'); | ||
| MultiByteToWideChar(CP_UTF8, 0, utf8.data(), static_cast<int>(utf8.size()), wide.data(), size); | ||
| return wide; | ||
| } | ||
|
|
||
| namespace Steam | ||
| { | ||
| using namespace std; | ||
| namespace fs = std::filesystem; | ||
|
|
||
| static std::optional<std::wstring> GetSteamExePathFromRegistry() | ||
| { | ||
| static std::optional<std::wstring> cachedPath; | ||
| if (cachedPath.has_value()) | ||
| { | ||
| return cachedPath; | ||
| } | ||
|
|
||
| const std::vector<HKEY> roots = { HKEY_CLASSES_ROOT, HKEY_LOCAL_MACHINE, HKEY_USERS }; | ||
| const std::vector<std::wstring> subKeys = { | ||
| L"steam\\shell\\open\\command", | ||
| L"Software\\Classes\\steam\\shell\\open\\command", | ||
| }; | ||
|
|
||
| for (HKEY root : roots) | ||
| { | ||
| for (const auto& subKey : subKeys) | ||
| { | ||
| HKEY hKey; | ||
| if (RegOpenKeyExW(root, subKey.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS) | ||
| { | ||
| wchar_t value[512]; | ||
| DWORD size = sizeof(value); | ||
| DWORD type = 0; | ||
|
|
||
| if (RegQueryValueExW(hKey, nullptr, nullptr, &type, reinterpret_cast<LPBYTE>(value), &size) == ERROR_SUCCESS && | ||
| (type == REG_SZ || type == REG_EXPAND_SZ)) | ||
| { | ||
| std::wregex exeRegex(LR"delim("([^"]+steam\.exe)")delim"); | ||
| std::wcmatch match; | ||
| if (std::regex_search(value, match, exeRegex) && match.size() > 1) | ||
| { | ||
| RegCloseKey(hKey); | ||
| cachedPath = match[1].str(); | ||
| return cachedPath; | ||
| } | ||
| } | ||
|
|
||
| RegCloseKey(hKey); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| cachedPath = std::nullopt; | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| static fs::path GetSteamBasePath() | ||
| { | ||
| auto steamFolderOpt = GetSteamExePathFromRegistry(); | ||
| if (!steamFolderOpt) | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| return fs::path(*steamFolderOpt).parent_path() / L"steamapps"; | ||
| } | ||
|
|
||
| static fs::path GetAcfFilePath(const std::wstring& gameId) | ||
| { | ||
| auto steamFolderOpt = GetSteamExePathFromRegistry(); | ||
| if (!steamFolderOpt) | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| return GetSteamBasePath() / (L"appmanifest_" + gameId + L".acf"); | ||
| } | ||
|
|
||
| static fs::path GetGameInstallPath(const std::wstring& gameFolderName) | ||
| { | ||
| auto steamFolderOpt = GetSteamExePathFromRegistry(); | ||
| if (!steamFolderOpt) | ||
| { | ||
| return {}; | ||
| } | ||
|
|
||
| return GetSteamBasePath() / L"common" / gameFolderName; | ||
| } | ||
|
|
||
| static unordered_map<wstring, wstring> ParseAcfFile(const fs::path& acfPath) | ||
| { | ||
| unordered_map<wstring, wstring> result; | ||
|
|
||
| ifstream file(acfPath); | ||
| if (!file.is_open()) | ||
| return result; | ||
|
|
||
| string line; | ||
| while (getline(file, line)) | ||
| { | ||
| smatch matches; | ||
| static const regex pattern(R"delim("([^"]+)"\s+"([^"]+)")delim"); | ||
|
|
||
| if (regex_search(line, matches, pattern) && matches.size() == 3) | ||
| { | ||
| wstring key = Utf8ToWide(matches[1].str()); | ||
| wstring value = Utf8ToWide(matches[2].str()); | ||
| result[key] = value; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| std::unique_ptr<Steam::SteamGame> GetSteamGameInfoFromAcfFile(const std::wstring& gameId) | ||
| { | ||
| fs::path acfPath = Steam::GetAcfFilePath(gameId); | ||
|
|
||
| if (!fs::exists(acfPath)) | ||
| return nullptr; | ||
|
|
||
| auto kv = ParseAcfFile(acfPath); | ||
| if (kv.empty() || kv.find(L"installdir") == kv.end()) | ||
| return nullptr; | ||
|
|
||
| fs::path gamePath = Steam::GetGameInstallPath(kv[L"installdir"]); | ||
| if (!fs::exists(gamePath)) | ||
| return nullptr; | ||
|
|
||
| auto game = std::make_unique<Steam::SteamGame>(); | ||
| game->gameId = gameId; | ||
| game->gameInstallationPath = gamePath.wstring(); | ||
| return game; | ||
| } | ||
|
|
||
| std::wstring GetGameIdFromUrlProtocolPath(const std::wstring& urlPath) | ||
| { | ||
| const std::wstring steamGamePrefix = L"steam://rungameid/"; | ||
|
|
||
| if (urlPath.rfind(steamGamePrefix, 0) == 0) | ||
| { | ||
| return urlPath.substr(steamGamePrefix.length()); | ||
| } | ||
|
|
||
| return L""; | ||
| } | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #pragma once | ||
|
|
||
| #include "pch.h" | ||
|
|
||
| namespace Utils | ||
| { | ||
| namespace NonLocalizable | ||
| { | ||
| const std::wstring AcfFileNameTemplate = L"appmanifest_<gameid>.acfs"; | ||
| } | ||
|
|
||
| namespace Steam | ||
| { | ||
| struct SteamGame | ||
| { | ||
| std::wstring gameId; | ||
| std::wstring gameInstallationPath; | ||
| }; | ||
|
|
||
| std::unique_ptr<SteamGame> GetSteamGameInfoFromAcfFile(const std::wstring& gameId); | ||
|
|
||
| std::wstring GetGameIdFromUrlProtocolPath(const std::wstring& urlPath); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.