Skip to content

Commit 5468060

Browse files
authored
Merge pull request #64 from RXDCODX/main
Enhance solution secrecy checks in SolutionSecrecyService. Added supp…
2 parents 9779126 + 599bb9c commit 5468060

4 files changed

Lines changed: 59 additions & 4 deletions

File tree

VisualStudioDiscordRPC.Shared/Services/SolutionSecrecyService.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,18 @@ public void RemoveSecretSolution(string solutionPath)
8282

8383
public bool IsSolutionSecret(string solutionPath)
8484
{
85-
return _secretSolutions.Contains(solutionPath);
85+
if (string.IsNullOrEmpty(solutionPath))
86+
return false;
87+
88+
// Check for exact match first
89+
if (_secretSolutions.Contains(solutionPath))
90+
return true;
91+
92+
// Check for partial matches - if solution path starts with any of the secret paths
93+
return _secretSolutions.Any(secretPath => PathHelper.IsPathBaseOf(secretPath, solutionPath));
8694
}
8795

96+
8897
private void OnSolutionChanged(Solution solution)
8998
{
9099
_lastOpenedSolution = solution;
@@ -95,8 +104,8 @@ private void SyncRpcSecrecyStatus()
95104
{
96105
Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();
97106

98-
string fullSolutionName = _lastOpenedSolution.FullName;
99-
_discordRpcController.Secret = _secretSolutions.Contains(fullSolutionName);
107+
string fullSolutionName = _lastOpenedSolution?.FullName;
108+
_discordRpcController.Secret = IsSolutionSecret(fullSolutionName);
100109
}
101110

102111
private void SaveSecretSolutions()

VisualStudioDiscordRPC.Shared/Utils/PathHelper.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,19 @@ public static string GetApplicationDataPath()
3131
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
3232
AppDataFolderName);
3333
}
34+
35+
public static bool IsPathBaseOf(string basePath, string path)
36+
{
37+
try
38+
{
39+
var baseUri = new Uri(Path.GetFullPath(basePath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar) + Path.DirectorySeparatorChar);
40+
var pathUri = new Uri(Path.GetFullPath(path));
41+
return baseUri.IsBaseOf(pathUri);
42+
}
43+
catch
44+
{
45+
return false;
46+
}
47+
}
3448
}
3549
}

VisualStudioDiscordRPC.Shared/ViewModels/SettingsViewModel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using VisualStudioDiscordRPC.Shared.Nests;
1111
using VisualStudioDiscordRPC.Shared.Utils;
1212
using System.Windows.Input;
13+
using System.Windows.Forms;
1314

1415
namespace VisualStudioDiscordRPC.Shared.ViewModels
1516
{
@@ -266,6 +267,7 @@ public BaseButtonPlug SecondButtonPlug
266267
public RelayCommand ShowSecretSolutionsCommand { get; }
267268
public RelayCommand ShowPrivateRepositoriesCommand { get; }
268269
public RelayCommand ShowCustomTextPlugsEditorCommand { get; }
270+
public RelayCommand SelectSecretFolderCommand { get; }
269271

270272
public SettingsViewModel()
271273
{
@@ -287,6 +289,7 @@ public SettingsViewModel()
287289
ShowSecretSolutionsCommand = new RelayCommand(ShowSecretSolutionsEditor);
288290
ShowPrivateRepositoriesCommand = new RelayCommand(ShowPrivateRepositoriesEditor);
289291
ShowCustomTextPlugsEditorCommand = new RelayCommand(ShowCustomTextPlugsEditor);
292+
SelectSecretFolderCommand = new RelayCommand(SelectSecretFolder);
290293
}
291294

292295
private void ShowSecretSolutionsEditor(object parameter)
@@ -321,5 +324,24 @@ private void ShowCustomTextPlugsEditor(object parameter)
321324

322325
OnPropertyChanged(nameof(AvailableTextPlugs));
323326
}
327+
328+
private void SelectSecretFolder(object parameter)
329+
{
330+
using (var folderDialog = new System.Windows.Forms.FolderBrowserDialog())
331+
{
332+
folderDialog.Description = "Select folder to hide all solutions in it";
333+
folderDialog.ShowNewFolderButton = false;
334+
335+
if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
336+
{
337+
string selectedPath = folderDialog.SelectedPath;
338+
if (!string.IsNullOrEmpty(selectedPath))
339+
{
340+
_solutionSecrecyService.AddSecretSolution(selectedPath);
341+
OnPropertyChanged(nameof(SecretSolution));
342+
}
343+
}
344+
}
345+
}
324346
}
325347
}

VisualStudioDiscordRPC.Shared/Views/SettingsWindow.xaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@
6565
<Button
6666
Width="20"
6767
Height="20"
68-
Command="{Binding ShowSecretSolutionsCommand}">
68+
Margin="2,0,0,0"
69+
Command="{Binding ShowSecretSolutionsCommand}"
70+
ToolTip="Manage secret solutions list">
6971
<TextBlock Text="..."/>
7072
</Button>
73+
<Button
74+
Width="20"
75+
Height="20"
76+
Margin="2,0,0,0"
77+
Command="{Binding SelectSecretFolderCommand}"
78+
ToolTip="Select folder to hide all solutions in it">
79+
<TextBlock Text="📁"/>
80+
</Button>
7181
</StackPanel>
7282
<StackPanel
7383
HorizontalAlignment="Right"

0 commit comments

Comments
 (0)