Skip to content

Commit 732d828

Browse files
committed
Add SelectSecretFolderCommand to SettingsViewModel and implement folder selection for hiding solutions. Refactor SolutionSecrecyService to use PathHelper for path matching.
1 parent eb5d49c commit 732d828

4 files changed

Lines changed: 48 additions & 45 deletions

File tree

VisualStudioDiscordRPC.Shared/Services/SolutionSecrecyService.cs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -90,52 +90,9 @@ public bool IsSolutionSecret(string solutionPath)
9090
return true;
9191

9292
// Check for partial matches - if solution path starts with any of the secret paths
93-
foreach (string secretPath in _secretSolutions)
94-
{
95-
if (IsPathMatch(solutionPath, secretPath))
96-
return true;
97-
}
98-
99-
return false;
93+
return _secretSolutions.Any(secretPath => PathHelper.IsPathBaseOf(secretPath, solutionPath));
10094
}
10195

102-
/// <summary>
103-
/// Checks if solution path matches secret path (exact or partial match)
104-
/// </summary>
105-
/// <param name="solutionPath">Full path to the solution</param>
106-
/// <param name="secretPath">Secret path (can be partial)</param>
107-
/// <returns>true if solution should be hidden</returns>
108-
private bool IsPathMatch(string solutionPath, string secretPath)
109-
{
110-
if (string.IsNullOrEmpty(secretPath))
111-
return false;
112-
113-
try
114-
{
115-
// Normalize paths for correct comparison
116-
string normalizedSecretPath = Path.GetFullPath(secretPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
117-
string normalizedSolutionPath = Path.GetFullPath(solutionPath);
118-
119-
// Check if solution path starts with secret path
120-
if (normalizedSolutionPath.StartsWith(normalizedSecretPath, System.StringComparison.OrdinalIgnoreCase))
121-
{
122-
// Additional check: next character must be path separator or end of string
123-
if (normalizedSolutionPath.Length == normalizedSecretPath.Length ||
124-
normalizedSolutionPath[normalizedSecretPath.Length] == Path.DirectorySeparatorChar ||
125-
normalizedSolutionPath[normalizedSecretPath.Length] == Path.AltDirectorySeparatorChar)
126-
{
127-
return true;
128-
}
129-
}
130-
}
131-
catch
132-
{
133-
// In case of path errors, return false
134-
return false;
135-
}
136-
137-
return false;
138-
}
13996

14097
private void OnSolutionChanged(Solution solution)
14198
{

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)