-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSteamService.cs
More file actions
156 lines (133 loc) · 6.31 KB
/
SteamService.cs
File metadata and controls
156 lines (133 loc) · 6.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using Microsoft.Win32;
using Playnite.SDK;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace GameSnapPlugin
{
public class SteamScreenshot
{
public string FilePath { get; set; } = "";
public string AppId { get; set; } = "";
public string SteamUserId { get; set; } = "";
}
public class SteamService
{
private readonly IPlayniteAPI _playniteApi;
private readonly GameSnapLogger _logger;
// Cache AppID → Game name (built from Playnite library)
private Dictionary<string, string> _appIdToName = new Dictionary<string, string>();
public SteamService(IPlayniteAPI playniteApi, GameSnapLogger logger)
{
_playniteApi = playniteApi;
_logger = logger;
RebuildCache();
}
// ──────────────────────────────────────────────
// Detecta o caminho do Steam via registro
// ──────────────────────────────────────────────
public static string? DetectSteamPath()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam")
?? Registry.LocalMachine.OpenSubKey(@"Software\Valve\Steam")
?? Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Valve\Steam");
return key?.GetValue("SteamPath") as string;
}
catch
{
return null;
}
}
// ──────────────────────────────────────────────
// Retorna todas as pastas de screenshots do Steam
// ──────────────────────────────────────────────
public List<string> GetScreenshotFolders(string steamPath)
{
var folders = new List<string>();
var userdataPath = Path.Combine(steamPath, "userdata");
if (!Directory.Exists(userdataPath)) return folders;
foreach (var userDir in Directory.GetDirectories(userdataPath))
{
var remotePath = Path.Combine(userDir, "760", "remote");
if (!Directory.Exists(remotePath)) continue;
foreach (var appDir in Directory.GetDirectories(remotePath))
{
var ssPath = Path.Combine(appDir, "screenshots");
if (Directory.Exists(ssPath))
folders.Add(ssPath);
}
}
return folders;
}
// ──────────────────────────────────────────────
// Lê screenshots prontas para mover
// ──────────────────────────────────────────────
public List<SteamScreenshot> GetPendingScreenshots(string steamPath)
{
var result = new List<SteamScreenshot>();
var userdataPath = Path.Combine(steamPath, "userdata");
if (!Directory.Exists(userdataPath)) return result;
foreach (var userDir in Directory.GetDirectories(userdataPath))
{
var userId = Path.GetFileName(userDir);
var remotePath = Path.Combine(userDir, "760", "remote");
if (!Directory.Exists(remotePath)) continue;
foreach (var appDir in Directory.GetDirectories(remotePath))
{
var appId = Path.GetFileName(appDir);
var ssPath = Path.Combine(appDir, "screenshots");
if (!Directory.Exists(ssPath)) continue;
foreach (var file in Directory.GetFiles(ssPath))
{
var ext = Path.GetExtension(file).ToLowerInvariant();
if (ext != ".jpg" && ext != ".png") continue;
result.Add(new SteamScreenshot
{
FilePath = file,
AppId = appId,
SteamUserId = userId
});
}
}
}
return result;
}
// ──────────────────────────────────────────────
// Resolve o nome do jogo a partir do AppID
// ──────────────────────────────────────────────
public string? ResolveGameName(string appId)
{
if (_appIdToName.TryGetValue(appId, out var name))
return name;
return null;
}
// ──────────────────────────────────────────────
// Reconstrói o cache AppID → Nome do jogo
// usando a biblioteca do Playnite
// ──────────────────────────────────────────────
public void RebuildCache()
{
_appIdToName.Clear();
try
{
foreach (var game in _playniteApi.Database.Games)
{
if (game.PluginId == Guid.Parse("CB91DFC9-B977-43BF-8E70-55F46E410FAB") // Steam plugin GUID
&& !string.IsNullOrEmpty(game.GameId))
{
if (!_appIdToName.ContainsKey(game.GameId))
_appIdToName[game.GameId] = game.Name;
}
}
_logger.Info($"Steam cache: {_appIdToName.Count} games mapped.");
}
catch (Exception ex)
{
_logger.Error($"Steam cache build failed: {ex.Message}");
}
}
}
}