-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
66 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,46 @@ | ||
using GameFinder.RegistryUtils; | ||
using GameFinder.StoreHandlers.Steam; | ||
using GameFinder.StoreHandlers.Steam.Models.ValueTypes; | ||
using NexusMods.Paths; | ||
|
||
namespace TweaksLauncher.Utility; | ||
|
||
internal static class SteamTools | ||
{ | ||
private static readonly SteamHandler handler = new(FileSystem.Shared, WindowsRegistry.Shared); | ||
|
||
public static string? GetPathFromShortcut(string shortcutPath) | ||
{ | ||
if (!shortcutPath.EndsWith(".url", StringComparison.OrdinalIgnoreCase)) | ||
return null; | ||
|
||
string contents; | ||
try | ||
{ | ||
contents = File.ReadAllText(shortcutPath); | ||
} | ||
catch | ||
{ | ||
return null; | ||
} | ||
|
||
var pattern = "URL=steam://rungameid/"; | ||
var startIdx = contents.IndexOf(pattern); | ||
if (startIdx == -1) | ||
return null; | ||
|
||
startIdx += pattern.Length; | ||
|
||
var endIdx = contents.IndexOf('\r', startIdx); | ||
if (endIdx == -1) | ||
return null; | ||
|
||
var length = endIdx - startIdx; | ||
|
||
if (!uint.TryParse(contents.AsSpan(startIdx, length), out var appId)) | ||
return null; | ||
|
||
var game = handler.FindOneGameById(AppId.From(appId), out _); | ||
return game?.Path.GetFullPath(); | ||
} | ||
} |
This file contains 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