Skip to content

Commit a3f8d78

Browse files
MuyuanMSCopilot
andcommitted
Address review: quote template path and use full explorer.exe path
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c275343 commit a3f8d78

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) Microsoft Corporation
2+
// The Microsoft Corporation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Reflection;
9+
10+
using Microsoft.PowerToys.Settings.UI.ViewModels;
11+
using Microsoft.VisualStudio.TestTools.UnitTesting;
12+
13+
namespace ViewModelTests
14+
{
15+
[TestClass]
16+
public class NewPlus
17+
{
18+
[TestMethod]
19+
public void CreateExplorerProcessStartInfoShouldQuoteTemplatePathAndUseFullExplorerPath()
20+
{
21+
// Arrange
22+
const string templatePath = @"C:\Users\Test User\Documents\My Templates";
23+
var createExplorerProcessStartInfoMethod = typeof(NewPlusViewModel).GetMethod("CreateExplorerProcessStartInfo", BindingFlags.NonPublic | BindingFlags.Static);
24+
25+
// Act
26+
var processStartInfo = (ProcessStartInfo)createExplorerProcessStartInfoMethod.Invoke(null, new object[] { templatePath });
27+
28+
// Assert
29+
Assert.IsNotNull(processStartInfo);
30+
Assert.AreEqual(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"), processStartInfo.FileName);
31+
Assert.AreEqual($"\"{templatePath}\"", processStartInfo.Arguments);
32+
}
33+
}
34+
}

src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ public static void CopyTemplateExamples(string templateLocation)
330330
}
331331
}
332332

333+
private static readonly string ExplorerExePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe");
334+
333335
private bool _isNewPlusEnabled;
334336
private string _templateLocation;
335337
private bool _hideFileExtension;
@@ -356,14 +358,23 @@ private void OpenNewTemplateFolder()
356358
{
357359
CopyTemplateExamples(_templateLocation);
358360

359-
Process.Start("explorer.exe", _templateLocation);
361+
Process.Start(CreateExplorerProcessStartInfo(_templateLocation));
360362
}
361363
catch (Exception ex)
362364
{
363365
Logger.LogError("Failed to show NewPlus template folder.", ex);
364366
}
365367
}
366368

369+
private static ProcessStartInfo CreateExplorerProcessStartInfo(string templateLocation)
370+
{
371+
return new ProcessStartInfo
372+
{
373+
FileName = ExplorerExePath,
374+
Arguments = $"\"{templateLocation}\"",
375+
};
376+
}
377+
367378
private async void PickNewTemplateFolder()
368379
{
369380
var newPath = await PickFolderDialog();

0 commit comments

Comments
 (0)