[stylecop] program plugin/unit test first pass (#5908)

* initial pass

* multiple whitespace fixes
This commit is contained in:
Clint Rutkas
2020-08-12 11:46:11 -07:00
committed by GitHub
parent 8888739867
commit 95e82ca359
36 changed files with 351 additions and 273 deletions

View File

@@ -46,5 +46,19 @@
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>
<!--<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>-->
</Project> </Project>

View File

@@ -1,8 +1,12 @@
using Castle.Core.Internal; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Castle.Core.Internal;
using Microsoft.Plugin.Program.Programs; using Microsoft.Plugin.Program.Programs;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using System.Collections.Generic;
namespace Microsoft.Plugin.Program.UnitTests.Programs namespace Microsoft.Plugin.Program.UnitTests.Programs
{ {

View File

@@ -1,15 +1,15 @@
using Moq; // Copyright (c) Microsoft Corporation
using NUnit.Framework; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure; using Wox.Infrastructure;
using Wox.Plugin; using Wox.Plugin;
using Microsoft.Plugin.Program;
using System.IO.Packaging;
using Windows.ApplicationModel;
using System;
namespace Microsoft.Plugin.Program.UnitTests.Programs namespace Microsoft.Plugin.Program.UnitTests.Programs
{ {
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program; using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
@@ -23,7 +23,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "notepad.exe", ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe", FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk", LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program notepad_users = new Win32Program static Win32Program notepad_users = new Win32Program
@@ -32,7 +32,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "notepad.exe", ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe", FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program azure_command_prompt = new Win32Program static Win32Program azure_command_prompt = new Win32Program
@@ -41,7 +41,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe", ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe", FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program visual_studio_command_prompt = new Win32Program static Win32Program visual_studio_command_prompt = new Win32Program
@@ -50,7 +50,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe", ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe", FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program command_prompt = new Win32Program static Win32Program command_prompt = new Win32Program
@@ -59,7 +59,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe", ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe", FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk", LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program file_explorer = new Win32Program static Win32Program file_explorer = new Win32Program
@@ -68,7 +68,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "File Explorer.lnk", ExecutableName = "File Explorer.lnk",
FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk", FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 2 AppType = 2,
}; };
static Win32Program wordpad = new Win32Program static Win32Program wordpad = new Win32Program
@@ -77,7 +77,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "wordpad.exe", ExecutableName = "wordpad.exe",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe", FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program wordpad_duplicate = new Win32Program static Win32Program wordpad_duplicate = new Win32Program
@@ -86,7 +86,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "WORDPAD.EXE", ExecutableName = "WORDPAD.EXE",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe", FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 2 AppType = 2,
}; };
static Win32Program twitter_pwa = new Win32Program static Win32Program twitter_pwa = new Win32Program
@@ -95,7 +95,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe", FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk", LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi", Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi",
AppType = 0 AppType = 0,
}; };
static Win32Program pinned_webpage = new Win32Program static Win32Program pinned_webpage = new Win32Program
@@ -104,7 +104,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk", LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd", Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd",
AppType = 0 AppType = 0,
}; };
static Win32Program edge_named_pinned_webpage = new Win32Program static Win32Program edge_named_pinned_webpage = new Win32Program
@@ -113,7 +113,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk", LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd", Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd",
AppType = 0 AppType = 0,
}; };
static Win32Program msedge = new Win32Program static Win32Program msedge = new Win32Program
@@ -122,7 +122,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "msedge.exe", ExecutableName = "msedge.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program chrome = new Win32Program static Win32Program chrome = new Win32Program
@@ -131,7 +131,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "chrome.exe", ExecutableName = "chrome.exe",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe", FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program dummy_proxy_app = new Win32Program static Win32Program dummy_proxy_app = new Win32Program
@@ -140,7 +140,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "test_proxy.exe", ExecutableName = "test_proxy.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\test_proxy.exe", FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\test_proxy.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk", LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk",
AppType = 2 AppType = 2,
}; };
static Win32Program cmd_run_command = new Win32Program static Win32Program cmd_run_command = new Win32Program
@@ -149,7 +149,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe", ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe", FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 3 // Run command AppType = 3, // Run command
}; };
static Win32Program cmder_run_command = new Win32Program static Win32Program cmder_run_command = new Win32Program
@@ -159,7 +159,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "Cmder.exe", ExecutableName = "Cmder.exe",
FullPath = "c:\\tools\\cmder\\cmder.exe", FullPath = "c:\\tools\\cmder\\cmder.exe",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 3 // Run command AppType = 3, // Run command
}; };
static Win32Program dummy_internetShortcut_app = new Win32Program static Win32Program dummy_internetShortcut_app = new Win32Program
@@ -169,7 +169,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "steam://rungameid/1258080", FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam", ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 1 AppType = 1,
}; };
static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program
@@ -179,7 +179,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "steam://rungameid/1258080", FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\Desktop", ParentDirectory = "C:\\Users\\temp\\Desktop",
LnkResolvedPath = null, LnkResolvedPath = null,
AppType = 1 AppType = 1,
}; };
[Test] [Test]

View File

@@ -1,12 +1,9 @@
using Microsoft.Plugin.Program.Storage; // Copyright (c) Microsoft Corporation
using Moq; // The Microsoft Corporation licenses this file to you under the MIT license.
using NUnit.Framework; // See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.Media.Capture; using NUnit.Framework;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage namespace Microsoft.Plugin.Program.UnitTests.Storage
@@ -18,51 +15,51 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
[Test] [Test]
public void ContainsShouldReturnTrueWhenListIsInitializedWithItem() public void ContainsShouldReturnTrueWhenListIsInitializedWithItem()
{ {
//Arrange // Arrange
var itemName = "originalItem1"; var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName }; IRepository<string> repository = new ListRepository<string>() { itemName };
//Act // Act
var result = repository.Contains(itemName); var result = repository.Contains(itemName);
//Assert // Assert
Assert.IsTrue(result); Assert.IsTrue(result);
} }
[Test] [Test]
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd() public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{ {
//Arrange // Arrange
IRepository<string> repository = new ListRepository<string>(); IRepository<string> repository = new ListRepository<string>();
//Act // Act
var itemName = "newItem"; var itemName = "newItem";
repository.Add(itemName); repository.Add(itemName);
var result = repository.Contains(itemName); var result = repository.Contains(itemName);
//Assert // Assert
Assert.IsTrue(result); Assert.IsTrue(result);
} }
[Test] [Test]
public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove() public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove()
{ {
//Arrange // Arrange
var itemName = "originalItem1"; var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName }; IRepository<string> repository = new ListRepository<string>() { itemName };
//Act // Act
repository.Remove(itemName); repository.Remove(itemName);
var result = repository.Contains(itemName); var result = repository.Contains(itemName);
//Assert // Assert
Assert.IsFalse(result); Assert.IsFalse(result);
} }
[Test] [Test]
public async Task AddShouldNotThrowWhenBeingIterated() public async Task AddShouldNotThrowWhenBeingIterated()
{ {
//Arrange // Arrange
ListRepository<string> repository = new ListRepository<string>(); ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000; var numItems = 1000;
for (var i = 0; i < numItems; ++i) for (var i = 0; i < numItems; ++i)
@@ -70,7 +67,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}"); repository.Add($"OriginalItem_{i}");
} }
//Act - Begin iterating on one thread // Act - Begin iterating on one thread
var iterationTask = Task.Run(() => var iterationTask = Task.Run(() =>
{ {
var remainingIterations = 10000; var remainingIterations = 10000;
@@ -78,7 +75,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{ {
foreach (var item in repository) foreach (var item in repository)
{ {
//keep iterating // keep iterating
} }
--remainingIterations; --remainingIterations;
@@ -86,7 +83,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}); });
//Act - Insert on another thread // Act - Insert on another thread
var addTask = Task.Run(() => var addTask = Task.Run(() =>
{ {
for (var i = 0; i < numItems; ++i) for (var i = 0; i < numItems; ++i)
@@ -95,14 +92,14 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
} }
}); });
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating // Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false); await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
} }
[Test] [Test]
public async Task RemoveShouldNotThrowWhenBeingIterated() public async Task RemoveShouldNotThrowWhenBeingIterated()
{ {
//Arrange // Arrange
ListRepository<string> repository = new ListRepository<string>(); ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000; var numItems = 1000;
for (var i = 0; i < numItems; ++i) for (var i = 0; i < numItems; ++i)
@@ -110,7 +107,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}"); repository.Add($"OriginalItem_{i}");
} }
//Act - Begin iterating on one thread // Act - Begin iterating on one thread
var iterationTask = Task.Run(() => var iterationTask = Task.Run(() =>
{ {
var remainingIterations = 10000; var remainingIterations = 10000;
@@ -118,7 +115,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{ {
foreach (var item in repository) foreach (var item in repository)
{ {
//keep iterating // keep iterating
} }
--remainingIterations; --remainingIterations;
@@ -126,7 +123,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
}); });
//Act - Remove on another thread // Act - Remove on another thread
var addTask = Task.Run(() => var addTask = Task.Run(() =>
{ {
for (var i = 0; i < numItems; ++i) for (var i = 0; i < numItems; ++i)
@@ -135,7 +132,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
} }
}); });
//Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating // Assert that this does not throw. Collections that aren't syncronized will throw an invalidoperatioexception if the list is modified while enumerating
await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false); await Task.WhenAll(new Task[] { iterationTask, addTask }).ConfigureAwait(false);
} }
} }

View File

@@ -1,6 +1,6 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Program.UnitTests.Storage namespace Microsoft.Plugin.Program.UnitTests.Storage
{ {

View File

@@ -1,15 +1,18 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Moq; using System.Diagnostics;
using NUnit.Framework; using System.IO;
using System.Linq; using System.Linq;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Microsoft.Plugin.Program.Programs; using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage; using Microsoft.Plugin.Program.Storage;
using System.IO; using Moq;
using NUnit.Framework;
using Wox.Infrastructure.FileSystemHelper; using Wox.Infrastructure.FileSystemHelper;
using System.Diagnostics; using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage namespace Microsoft.Plugin.Program.UnitTests.Storage
{ {
@@ -47,7 +50,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name, Name = name,
ExecutableName = exename, ExecutableName = exename,
FullPath = fullPath, FullPath = fullPath,
Description = description1 Description = description1,
}; };
Win32Program item2 = new Win32Program Win32Program item2 = new Win32Program
@@ -55,7 +58,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name, Name = name,
ExecutableName = exename, ExecutableName = exename,
FullPath = fullPath, FullPath = fullPath,
Description = description2 Description = description2,
}; };
// Act // Act
@@ -357,7 +360,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
ExecutableName = "path.exe", ExecutableName = "path.exe",
ParentDirectory = "directory", ParentDirectory = "directory",
FullPath = "directory\\path.exe", FullPath = "directory\\path.exe",
LnkResolvedPath = "directory\\path.lnk" // This must be equal for lnk applications LnkResolvedPath = "directory\\path.lnk", // This must be equal for lnk applications
}; };
_win32ProgramRepository.Add(item); _win32ProgramRepository.Add(item);

View File

@@ -1,9 +1,13 @@
using System.Windows; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Linq;
using System.Windows;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Plugin.Program.Views; using Microsoft.Plugin.Program.Views;
using System.Linq;
using Wox.Plugin; using Wox.Plugin;
using System;
namespace Microsoft.Plugin.Program namespace Microsoft.Plugin.Program
{ {
@@ -60,7 +64,7 @@ namespace Microsoft.Plugin.Program
var source = new ProgramSource var source = new ProgramSource
{ {
Location = Directory.Text, Location = Directory.Text,
UniqueIdentifier = Directory.Text UniqueIdentifier = Directory.Text,
}; };
_settings.ProgramSources.Insert(0, source); _settings.ProgramSources.Insert(0, source);

View File

@@ -1,58 +0,0 @@
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Wox.Infrastructure.Logger;
using Microsoft.Plugin.Program.Programs;
namespace Microsoft.Plugin.Program
{
//internal static class FileChangeWatcher
//{
// private static readonly List<string> WatchedPath = new List<string>();
// // todo remove previous watcher events
// public static void AddAll(List<UnregisteredPrograms> sources, string[] suffixes)
// {
// foreach (var s in sources)
// {
// if (Directory.Exists(s.Location))
// {
// AddWatch(s.Location, suffixes);
// }
// }
// }
// public static void AddWatch(string path, string[] programSuffixes, bool includingSubDirectory = true)
// {
// if (WatchedPath.Contains(path)) return;
// if (!Directory.Exists(path))
// {
// Log.Warn($"|FileChangeWatcher|{path} doesn't exist");
// return;
// }
// WatchedPath.Add(path);
// foreach (string fileType in programSuffixes)
// {
// FileSystemWatcher watcher = new FileSystemWatcher
// {
// Path = path,
// IncludeSubdirectories = includingSubDirectory,
// Filter = $"*.{fileType}",
// EnableRaisingEvents = true
// };
// watcher.Changed += FileChanged;
// watcher.Created += FileChanged;
// watcher.Deleted += FileChanged;
// watcher.Renamed += FileChanged;
// }
// }
// private static void FileChanged(object source, FileSystemEventArgs e)
// {
// Task.Run(() =>
// {
// Main.IndexPrograms();
// });
// }
//}
}

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization; using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Markup; using System.Windows.Markup;

View File

@@ -1,11 +1,15 @@
using NLog; // Copyright (c) Microsoft Corporation
using NLog.Config; // The Microsoft Corporation licenses this file to you under the MIT license.
using NLog.Targets; // See the LICENSE file in the project root for more information.
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Security; using System.Security;
using NLog;
using NLog.Config;
using NLog.Targets;
using Wox.Infrastructure; using Wox.Infrastructure;
namespace Microsoft.Plugin.Program.Logger namespace Microsoft.Plugin.Program.Logger
@@ -138,4 +142,4 @@ namespace Microsoft.Plugin.Program.Logger
return false; return false;
} }
} }
} }

View File

@@ -1,20 +1,19 @@
using Microsoft.PowerToys.Settings.UI.Lib; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers; using Microsoft.Plugin.Program.Programs;
using System.Windows.Controls; using Microsoft.Plugin.Program.Storage;
using Microsoft.PowerToys.Settings.UI.Lib;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
using Wox.Plugin; using Wox.Plugin;
using Microsoft.Plugin.Program.Views;
using Stopwatch = Wox.Infrastructure.Stopwatch; using Stopwatch = Wox.Infrastructure.Stopwatch;
using Windows.ApplicationModel;
using Microsoft.Plugin.Program.Storage;
using Microsoft.Plugin.Program.Programs;
namespace Microsoft.Plugin.Program namespace Microsoft.Plugin.Program
{ {
@@ -61,7 +60,6 @@ namespace Microsoft.Plugin.Program
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms); Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
}); });
Task.WaitAll(a, b); Task.WaitAll(a, b);
_settings.LastIndexTime = DateTime.Today; _settings.LastIndexTime = DateTime.Today;
@@ -202,4 +200,4 @@ namespace Microsoft.Plugin.Program
} }
} }
} }
} }

View File

@@ -137,6 +137,20 @@
<_Parameter1>Microsoft.Plugin.Program.UnitTests</_Parameter1> <_Parameter1>Microsoft.Plugin.Program.UnitTests</_Parameter1>
</AssemblyAttribute> </AssemblyAttribute>
</ItemGroup> </ItemGroup>
<!--<ItemGroup>
<Compile Include="..\..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers">
<Version>1.1.118</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>-->
</Project> </Project>

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -7,8 +11,11 @@ namespace Microsoft.Plugin.Program
public class ProgramPluginSettings public class ProgramPluginSettings
{ {
public DateTime LastIndexTime { get; set; } public DateTime LastIndexTime { get; set; }
public List<ProgramSource> ProgramSources { get;} = new List<ProgramSource>(); public List<ProgramSource> ProgramSources { get;} = new List<ProgramSource>();
public List<DisabledProgramSource> DisabledProgramSources { get;} = new List<DisabledProgramSource>(); public List<DisabledProgramSource> DisabledProgramSources { get;} = new List<DisabledProgramSource>();
public List<string> ProgramSuffixes { get; } = new List<string>(){ "bat", "appref-ms", "exe", "lnk", "url" }; public List<string> ProgramSuffixes { get; } = new List<string>(){ "bat", "appref-ms", "exe", "lnk", "url" };
public bool EnableStartMenuSource { get; set; } = true; public bool EnableStartMenuSource { get; set; } = true;
@@ -22,8 +29,7 @@ namespace Microsoft.Plugin.Program
public double MinScoreThreshold { get; set; } = 0.75; public double MinScoreThreshold { get; set; } = 0.75;
internal const char SuffixSeparator = ';'; internal const char SuffixSeparator = ';';
} }
/// <summary> /// <summary>
@@ -39,8 +45,11 @@ namespace Microsoft.Plugin.Program
private string name; private string name;
public string Location { get; set; } public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; } public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true; public bool Enabled { get; set; } = true;
public string UniqueIdentifier { get; set; } public string UniqueIdentifier { get; set; }
} }

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Windows; using System.Windows;
using Wox.Plugin; using Wox.Plugin;

View File

@@ -1,8 +1,10 @@
using System; // Copyright (c) Microsoft Corporation
using System.Diagnostics; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
{ {
@@ -21,7 +23,9 @@ namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
public interface IApplicationActivationManager public interface IApplicationActivationManager
{ {
IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId); IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId); IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr /*IShellItemArray* */ itemArray, [In] String verb, [Out] out UInt32 processId);
IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId); IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr /* IShellItemArray* */itemArray, [Out] out UInt32 processId);
} }

View File

@@ -1,9 +1,11 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using Windows.Storage;
using static Microsoft.Plugin.Program.Programs.UWP; using static Microsoft.Plugin.Program.Programs.UWP;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
@@ -52,6 +54,7 @@ namespace Microsoft.Plugin.Program.Programs
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap0_2(); // skip 2 methods void _VtblGap0_2(); // skip 2 methods
IAppxManifestReader CreateManifestReader(IStream inputStream); IAppxManifestReader CreateManifestReader(IStream inputStream);
} }
@@ -60,10 +63,12 @@ namespace Microsoft.Plugin.Program.Programs
{ {
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap0_1(); // skip 1 method void _VtblGap0_1(); // skip 1 method
IAppxManifestProperties GetProperties(); IAppxManifestProperties GetProperties();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")] [System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap1_5(); // skip 5 methods void _VtblGap1_5(); // skip 5 methods
IAppxManifestApplicationsEnumerator GetApplications(); IAppxManifestApplicationsEnumerator GetApplications();
} }
@@ -71,7 +76,9 @@ namespace Microsoft.Plugin.Program.Programs
public interface IAppxManifestApplicationsEnumerator public interface IAppxManifestApplicationsEnumerator
{ {
IAppxManifestApplication GetCurrent(); IAppxManifestApplication GetCurrent();
bool GetHasCurrent(); bool GetHasCurrent();
bool MoveNext(); bool MoveNext();
} }
@@ -90,6 +97,7 @@ namespace Microsoft.Plugin.Program.Programs
{ {
[PreserveSig] [PreserveSig]
Hresult GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value); Hresult GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value);
[PreserveSig] [PreserveSig]
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value); Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
} }

View File

@@ -1,6 +1,6 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {

View File

@@ -1,6 +1,7 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.Foundation; using Windows.Foundation;
@@ -9,7 +10,9 @@ namespace Microsoft.Plugin.Program.Programs
internal interface IPackageCatalog internal interface IPackageCatalog
{ {
event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling; event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling;
event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling; event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling;
event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating; event TypedEventHandler<PackageCatalog, PackageUpdatingEventArgs> PackageUpdating;
} }
} }

View File

@@ -1,6 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {

View File

@@ -1,4 +1,8 @@
using System.Collections.Generic; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using Wox.Plugin; using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
@@ -6,10 +10,15 @@ namespace Microsoft.Plugin.Program.Programs
public interface IProgram public interface IProgram
{ {
List<ContextMenuResult> ContextMenus(IPublicAPI api); List<ContextMenuResult> ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api); Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; } string UniqueIdentifier { get; set; }
string Name { get; } string Name { get; }
string Description { get; set; } string Description { get; set; }
string Location { get; } string Location { get; }
} }
} }

View File

@@ -1,14 +1,17 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
public interface IShellLinkHelper public interface IShellLinkHelper
{ {
string RetrieveTargetPath(string path); string RetrieveTargetPath(string path);
string description { get; set; } string description { get; set; }
string Arguments { get; set; } string Arguments { get; set; }
bool hasArguments { get; set; } bool hasArguments { get; set; }
} }

View File

@@ -1,6 +1,7 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.Foundation; using Windows.Foundation;
@@ -52,7 +53,6 @@ namespace Microsoft.Plugin.Program.Programs
} }
} }
// //
// Summary: // Summary:
// Indicates that an app package is updating. // Indicates that an app package is updating.

View File

@@ -1,6 +1,10 @@
using Microsoft.Plugin.Program.Logger; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.IO; using System.IO;
using Microsoft.Plugin.Program.Logger;
using Package = Windows.ApplicationModel.Package; using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs

View File

@@ -1,9 +1,10 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
using System.IO.Packaging;
using System.Security.Principal; using System.Security.Principal;
using Windows.Management.Deployment; using Windows.Management.Deployment;
using Windows.ApplicationModel;
using Package = Windows.ApplicationModel.Package; using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs

View File

@@ -1,11 +1,12 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
using System.Text; // See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.IO;
using Accessibility;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using System.Security.Policy; using System.Text;
using Accessibility;
using Microsoft.Plugin.Program.Logger; using Microsoft.Plugin.Program.Logger;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
@@ -17,7 +18,7 @@ namespace Microsoft.Plugin.Program.Programs
{ {
SLGP_SHORTPATH = 0x1, SLGP_SHORTPATH = 0x1,
SLGP_UNCPRIORITY = 0x2, SLGP_UNCPRIORITY = 0x2,
SLGP_RAWPATH = 0x4 SLGP_RAWPATH = 0x4,
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -48,10 +49,9 @@ namespace Microsoft.Plugin.Program.Programs
SLR_NOSEARCH = 0x10, SLR_NOSEARCH = 0x10,
SLR_NOTRACK = 0x20, SLR_NOTRACK = 0x20,
SLR_NOLINKINFO = 0x40, SLR_NOLINKINFO = 0x40,
SLR_INVOKE_MSI = 0x80 SLR_INVOKE_MSI = 0x80,
} }
// Reference : http://www.pinvoke.net/default.aspx/Interfaces.IShellLinkW // Reference : http://www.pinvoke.net/default.aspx/Interfaces.IShellLinkW
/// The IShellLink interface allows Shell links to be created, modified, and resolved /// The IShellLink interface allows Shell links to be created, modified, and resolved
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F9-0000-0000-C000-000000000046")] [ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214F9-0000-0000-C000-000000000046")]
@@ -106,6 +106,7 @@ namespace Microsoft.Plugin.Program.Programs
// Contains the arguments to the app // Contains the arguments to the app
public string Arguments { get; set; } = String.Empty; public string Arguments { get; set; } = String.Empty;
public bool hasArguments { get; set; } = false; public bool hasArguments { get; set; } = false;
// Retrieve the target path using Shell Link // Retrieve the target path using Shell Link
@@ -154,4 +155,4 @@ namespace Microsoft.Plugin.Program.Programs
return target; return target;
} }
} }
} }

View File

@@ -1,19 +1,17 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Xml.Linq;
using Windows.ApplicationModel;
using Windows.Management.Deployment;
using Microsoft.Plugin.Program.Logger;
using Rect = System.Windows.Rect;
using System.Windows.Controls;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using Wox.Infrastructure.Logger; using System.Xml.Linq;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32; using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
@@ -21,8 +19,11 @@ namespace Microsoft.Plugin.Program.Programs
public partial class UWP public partial class UWP
{ {
public string Name { get; } public string Name { get; }
public string FullName { get; } public string FullName { get; }
public string FamilyName { get; } public string FamilyName { get; }
public string Location { get; set; } public string Location { get; set; }
public IList<UWPApplication> Apps { get; private set; } public IList<UWPApplication> Apps { get; private set; }
@@ -86,9 +87,7 @@ namespace Microsoft.Plugin.Program.Programs
Apps = new List<UWPApplication>().ToArray(); Apps = new List<UWPApplication>().ToArray();
} }
} }
/// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx /// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
private static string[] XmlNamespaces(string path) private static string[] XmlNamespaces(string path)
{ {
@@ -195,7 +194,6 @@ namespace Microsoft.Plugin.Program.Programs
return false; return false;
} }
return valid; return valid;
}); });
@@ -229,7 +227,7 @@ namespace Microsoft.Plugin.Program.Programs
Windows10, Windows10,
Windows81, Windows81,
Windows8, Windows8,
Unknown Unknown,
} }
[Flags] [Flags]
@@ -244,6 +242,5 @@ namespace Microsoft.Plugin.Program.Programs
Ok = 0x0, Ok = 0x0,
} }
} }
} }

View File

@@ -1,25 +1,28 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Wox.Infrastructure; using System.Windows.Input;
using Microsoft.Plugin.Program.Logger;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Wox.Plugin; using Microsoft.Plugin.Program.Logger;
using System.Windows.Input; using Microsoft.Plugin.Program.Win32;
using Wox.Plugin.SharedCommands; using Wox.Infrastructure;
using System.Reflection;
using Wox.Infrastructure.Image; using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger; using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Wox.Plugin.SharedCommands;
using static Microsoft.Plugin.Program.Programs.UWP; using static Microsoft.Plugin.Program.Programs.UWP;
using System.Runtime.InteropServices.ComTypes;
using System.Globalization;
using Microsoft.Plugin.Program.Win32;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
@@ -28,20 +31,29 @@ namespace Microsoft.Plugin.Program.Programs
public class UWPApplication : IProgram public class UWPApplication : IProgram
{ {
public string AppListEntry { get; set; } public string AppListEntry { get; set; }
public string UniqueIdentifier { get; set; } public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; } public string DisplayName { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string UserModelId { get; set; } public string UserModelId { get; set; }
public string BackgroundColor { get; set; } public string BackgroundColor { get; set; }
public string EntryPoint { get; set; } public string EntryPoint { get; set; }
public string Name => DisplayName; public string Name => DisplayName;
public string Location => Package.Location; public string Location => Package.Location;
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool CanRunElevated { get; set; } public bool CanRunElevated { get; set; }
public string LogoPath { get; set; } public string LogoPath { get; set; }
public UWP Package { get; set; } public UWP Package { get; set; }
private string logoUri; private string logoUri;
@@ -84,14 +96,13 @@ namespace Microsoft.Plugin.Program.Programs
{ {
Launch(api); Launch(api);
return true; return true;
} },
}; };
// To set the title to always be the displayname of the packaged application // To set the title to always be the displayname of the packaged application
result.Title = DisplayName; result.Title = DisplayName;
result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData; result.TitleHighlightData = StringMatcher.FuzzySearch(query, Name).MatchData;
var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title); var toolTipTitle = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_name"), result.Title);
var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location); var toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText); result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
@@ -130,7 +141,7 @@ namespace Microsoft.Plugin.Program.Programs
Process.Start(info); Process.Start(info);
return true; return true;
} },
} }
); );
} }
@@ -148,7 +159,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location)); Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));
return true; return true;
} },
}); });
contextMenus.Add(new ContextMenuResult contextMenus.Add(new ContextMenuResult
@@ -171,7 +182,7 @@ namespace Microsoft.Plugin.Program.Programs
Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e); Log.Exception($"|Microsoft.Plugin.Program.UWP.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false; return false;
} }
} },
}); });
return contextMenus; return contextMenus;
@@ -318,7 +329,6 @@ namespace Microsoft.Plugin.Program.Programs
} }
} }
internal string LogoUriFromManifest(IAppxManifestApplication app) internal string LogoUriFromManifest(IAppxManifestApplication app)
{ {
var logoKeyFromVersion = new Dictionary<PackageVersion, string> var logoKeyFromVersion = new Dictionary<PackageVersion, string>
@@ -382,7 +392,7 @@ namespace Microsoft.Plugin.Program.Programs
// scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables, // scale factors on win10: https://docs.microsoft.com/en-us/windows/uwp/controls-and-patterns/tiles-and-notifications-app-assets#asset-size-tables,
{ PackageVersion.Windows10, new List<int> { 100, 125, 150, 200, 400 } }, { PackageVersion.Windows10, new List<int> { 100, 125, 150, 200, 400 } },
{ PackageVersion.Windows81, new List<int> { 100, 120, 140, 160, 180 } }, { PackageVersion.Windows81, new List<int> { 100, 120, 140, 160, 180 } },
{ PackageVersion.Windows8, new List<int> { 100 } } { PackageVersion.Windows8, new List<int> { 100 } },
}; };
if (scaleFactors.ContainsKey(Package.Version)) if (scaleFactors.ContainsKey(Package.Version))
@@ -451,7 +461,6 @@ namespace Microsoft.Plugin.Program.Programs
return logo; return logo;
} }
private BitmapImage ImageFromPath(string path) private BitmapImage ImageFromPath(string path)
{ {
if (File.Exists(path)) if (File.Exists(path))
@@ -483,4 +492,4 @@ namespace Microsoft.Plugin.Program.Programs
} }
} }
} }

View File

@@ -1,22 +1,25 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Reflection;
using System.Security; using System.Security;
using System.Text; using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Win32; using Microsoft.Win32;
using Wox.Infrastructure; using Wox.Infrastructure;
using Microsoft.Plugin.Program.Logger;
using Wox.Plugin;
using System.Windows.Input;
using System.Reflection;
using System.Text.RegularExpressions;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.FileSystemHelper; using Wox.Infrastructure.FileSystemHelper;
using System.Globalization; using Wox.Infrastructure.Logger;
using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs namespace Microsoft.Plugin.Program.Programs
{ {
@@ -25,22 +28,38 @@ namespace Microsoft.Plugin.Program.Programs
public class Win32Program : IProgram public class Win32Program : IProgram
{ {
public string Name { get; set; } public string Name { get; set; }
public string UniqueIdentifier { get; set; } public string UniqueIdentifier { get; set; }
public string IcoPath { get; set; } public string IcoPath { get; set; }
public string FullPath { get; set; } public string FullPath { get; set; }
public string LnkResolvedPath { get; set; } public string LnkResolvedPath { get; set; }
public string ParentDirectory { get; set; } public string ParentDirectory { get; set; }
public string ExecutableName { get; set; } public string ExecutableName { get; set; }
public string Description { get; set; } = String.Empty; public string Description { get; set; } = String.Empty;
public bool Valid { get; set; } public bool Valid { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool hasArguments { get; set; } = false; public bool hasArguments { get; set; } = false;
public string Arguments { get; set; } = String.Empty; public string Arguments { get; set; } = String.Empty;
public string Location => ParentDirectory; public string Location => ParentDirectory;
public uint AppType { get; set; } public uint AppType { get; set; }
// Wrappers for File Operations // Wrappers for File Operations
public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set;} = new FileVersionInfoWrapper(); public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set;} = new FileVersionInfoWrapper();
public static IFileWrapper FileWrapper { get; set; } = new FileWrapper(); public static IFileWrapper FileWrapper { get; set; } = new FileWrapper();
public static IShellLinkHelper Helper { get; set; } = new ShellLinkHelper(); public static IShellLinkHelper Helper { get; set; } = new ShellLinkHelper();
private const string ShortcutExtension = "lnk"; private const string ShortcutExtension = "lnk";
@@ -56,7 +75,7 @@ namespace Microsoft.Plugin.Program.Programs
WEB_APPLICATION = 0, WEB_APPLICATION = 0,
INTERNET_SHORTCUT_APPLICATION = 1, INTERNET_SHORTCUT_APPLICATION = 1,
WIN32_APPLICATION = 2, WIN32_APPLICATION = 2,
RUN_COMMAND = 3 RUN_COMMAND = 3,
} }
// Function to calculate the score of a result // Function to calculate the score of a result
@@ -197,7 +216,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, info); Main.StartProcess(Process.Start, info);
return true; return true;
} },
}; };
// To set the title for the result to always be the name of the application // To set the title for the result to always be the name of the application
@@ -244,7 +263,7 @@ namespace Microsoft.Plugin.Program.Programs
Task.Run(() => Main.StartProcess(Process.Start, info)); Task.Run(() => Main.StartProcess(Process.Start, info));
return true; return true;
} },
}); });
} }
@@ -261,7 +280,7 @@ namespace Microsoft.Plugin.Program.Programs
{ {
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory)); Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true; return true;
} },
}); });
contextMenus.Add( contextMenus.Add(
@@ -285,14 +304,12 @@ namespace Microsoft.Plugin.Program.Programs
Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e); Log.Exception($"|Microsoft.Plugin.Program.Win32.ContextMenu| Failed to open {Name} in console, {e.Message}", e);
return false; return false;
} }
} },
}); });
return contextMenus; return contextMenus;
} }
public override string ToString() public override string ToString()
{ {
return ExecutableName; return ExecutableName;
@@ -313,7 +330,7 @@ namespace Microsoft.Plugin.Program.Programs
Description = string.Empty, Description = string.Empty,
Valid = true, Valid = true,
Enabled = true, Enabled = true,
AppType = (uint)ApplicationTypes.WIN32_APPLICATION AppType = (uint)ApplicationTypes.WIN32_APPLICATION,
}; };
return p; return p;
} }
@@ -378,7 +395,7 @@ namespace Microsoft.Plugin.Program.Programs
ParentDirectory = Directory.GetParent(path).FullName, ParentDirectory = Directory.GetParent(path).FullName,
Valid = true, Valid = true,
Enabled = true, Enabled = true,
AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION,
}; };
return p; return p;
} }
@@ -602,8 +619,7 @@ namespace Microsoft.Plugin.Program.Programs
select CreateWin32Program(p); select CreateWin32Program(p);
return programs1.Concat(programs2).Concat(programs3); return programs1.Concat(programs2).Concat(programs3);
} }
// Function to obtain the list of applications, the locations of which have been added to the env variable PATH // Function to obtain the list of applications, the locations of which have been added to the env variable PATH
private static ParallelQuery<Win32Program> PathEnvironmentPrograms(IList<string> suffixes) private static ParallelQuery<Win32Program> PathEnvironmentPrograms(IList<string> suffixes)
{ {

View File

@@ -1,11 +1,15 @@
using Windows.ApplicationModel; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.Plugin.Program.Storage namespace Microsoft.Plugin.Program.Storage
{ {
internal interface IProgramRepository internal interface IProgramRepository
{ {
void IndexPrograms(); void IndexPrograms();
void Load(); void Load();
void Save(); void Save();
} }
} }

View File

@@ -1,10 +1,12 @@
using Microsoft.Plugin.Program.Logger; // Copyright (c) Microsoft Corporation
using Microsoft.Plugin.Program.Programs; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using Microsoft.Plugin.Program.Logger;
using System.Threading.Tasks; using Microsoft.Plugin.Program.Programs;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
@@ -19,6 +21,7 @@ namespace Microsoft.Plugin.Program.Storage
private IStorage<IList<UWPApplication>> _storage; private IStorage<IList<UWPApplication>> _storage;
private IPackageCatalog _packageCatalog; private IPackageCatalog _packageCatalog;
public PackageRepository(IPackageCatalog packageCatalog, IStorage<IList<UWPApplication>> storage) public PackageRepository(IPackageCatalog packageCatalog, IStorage<IList<UWPApplication>> storage)
{ {
_storage = storage ?? throw new ArgumentNullException(nameof(storage), "StorageRepository requires an initialized storage interface"); _storage = storage ?? throw new ArgumentNullException(nameof(storage), "StorageRepository requires an initialized storage interface");

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Wox.Infrastructure.Storage; using Wox.Infrastructure.Storage;
@@ -25,7 +29,7 @@ namespace Microsoft.Plugin.Program.Storage
{ {
Environment.GetFolderPath(Environment.SpecialFolder.Programs), Environment.GetFolderPath(Environment.SpecialFolder.Programs),
Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms), Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms),
Environment.GetFolderPath(Environment.SpecialFolder.Desktop) Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
}; };
return paths; return paths;
} }

View File

@@ -1,16 +1,18 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using Microsoft.Plugin.Program.Programs;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using System.IO;
using System.Linq;
using System.Globalization; using System.Globalization;
using System.IO;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
namespace Microsoft.Plugin.Program.Storage namespace Microsoft.Plugin.Program.Storage
{ {
using Win32Program = Programs.Win32Program;
internal class Win32ProgramRepository : ListRepository<Programs.Win32Program>, IProgramRepository internal class Win32ProgramRepository : ListRepository<Programs.Win32Program>, IProgramRepository
{ {
private IStorage<IList<Programs.Win32Program>> _storage; private IStorage<IList<Programs.Win32Program>> _storage;
@@ -92,8 +94,7 @@ namespace Microsoft.Plugin.Program.Storage
{ {
Log.Info($"|Win32ProgramRepository|OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}| {ex.Message}"); Log.Info($"|Win32ProgramRepository|OnAppRenamed-{extension}Program|{oldPath}|Unable to create program from {oldPath}| {ex.Message}");
} }
// To remove the old app which has been renamed and to add the new application. // To remove the old app which has been renamed and to add the new application.
if (oldApp != null) if (oldApp != null)
{ {

View File

@@ -1,4 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Globalization; using System.Globalization;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Markup; using System.Windows.Markup;

View File

@@ -1,8 +1,10 @@
using System; // Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Microsoft.Plugin.Program.Views.Commands namespace Microsoft.Plugin.Program.Views.Commands
{ {
internal static class ProgramSettingDisplay internal static class ProgramSettingDisplay
@@ -18,7 +20,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Enabled = x.Enabled, Enabled = x.Enabled,
Location = x.Location, Location = x.Location,
Name = x.Name, Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier UniqueIdentifier = x.UniqueIdentifier,
} }
)); ));
@@ -37,7 +39,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Enabled = x.Enabled, Enabled = x.Enabled,
Location = x.Location, Location = x.Location,
Name = x.Name, Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier UniqueIdentifier = x.UniqueIdentifier,
} }
)); ));
@@ -92,7 +94,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Name = x.Name, Name = x.Name,
Location = x.Location, Location = x.Location,
UniqueIdentifier = x.UniqueIdentifier, UniqueIdentifier = x.UniqueIdentifier,
Enabled = false Enabled = false,
} }
)); ));
} }

View File

@@ -1,16 +1,19 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input; using System.Windows.Input;
using Microsoft.Plugin.Program.Views.Commands; using Microsoft.Plugin.Program.Views.Commands;
using Microsoft.Plugin.Program.Programs;
using System.ComponentModel;
using System.Windows.Data;
using Wox.Plugin; using Wox.Plugin;
using System.Globalization;
namespace Microsoft.Plugin.Program.Views namespace Microsoft.Plugin.Program.Views
{ {
@@ -136,7 +139,7 @@ namespace Microsoft.Plugin.Program.Views
var source = new ProgramSource var source = new ProgramSource
{ {
Location = directory, Location = directory,
UniqueIdentifier = directory UniqueIdentifier = directory,
}; };
directoriesToAdd.Add(source); directoriesToAdd.Add(source);
@@ -304,4 +307,4 @@ namespace Microsoft.Plugin.Program.Views
} }
} }
} }
} }

View File

@@ -1,5 +1,8 @@
using System; // Copyright (c) Microsoft Corporation
using System.Collections.Generic; // The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes; using System.Runtime.InteropServices.ComTypes;
using System.Text; using System.Text;