[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>
</None>
</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>

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 Moq;
using NUnit.Framework;
using System.Collections.Generic;
namespace Microsoft.Plugin.Program.UnitTests.Programs
{

View File

@@ -1,15 +1,15 @@
using Moq;
using NUnit.Framework;
// 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.Linq;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure;
using Wox.Plugin;
using Microsoft.Plugin.Program;
using System.IO.Packaging;
using Windows.ApplicationModel;
using System;
namespace Microsoft.Plugin.Program.UnitTests.Programs
{
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
@@ -23,7 +23,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
AppType = 2,
};
static Win32Program notepad_users = new Win32Program
@@ -32,7 +32,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
AppType = 2,
};
static Win32Program azure_command_prompt = new Win32Program
@@ -41,7 +41,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "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",
AppType = 2
AppType = 2,
};
static Win32Program visual_studio_command_prompt = new Win32Program
@@ -50,7 +50,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "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",
AppType = 2
AppType = 2,
};
static Win32Program command_prompt = new Win32Program
@@ -59,7 +59,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
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
@@ -68,7 +68,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "File Explorer.lnk",
FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk",
LnkResolvedPath = null,
AppType = 2
AppType = 2,
};
static Win32Program wordpad = new Win32Program
@@ -77,7 +77,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "wordpad.exe",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
AppType = 2
AppType = 2,
};
static Win32Program wordpad_duplicate = new Win32Program
@@ -86,7 +86,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "WORDPAD.EXE",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = null,
AppType = 2
AppType = 2,
};
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",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi",
AppType = 0
AppType = 0,
};
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",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd",
AppType = 0
AppType = 0,
};
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",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd",
AppType = 0
AppType = 0,
};
static Win32Program msedge = new Win32Program
@@ -122,7 +122,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "msedge.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
AppType = 2
AppType = 2,
};
static Win32Program chrome = new Win32Program
@@ -131,7 +131,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "chrome.exe",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
AppType = 2
AppType = 2,
};
static Win32Program dummy_proxy_app = new Win32Program
@@ -140,7 +140,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "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",
AppType = 2
AppType = 2,
};
static Win32Program cmd_run_command = new Win32Program
@@ -149,7 +149,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = null,
AppType = 3 // Run command
AppType = 3, // Run command
};
static Win32Program cmder_run_command = new Win32Program
@@ -159,7 +159,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
ExecutableName = "Cmder.exe",
FullPath = "c:\\tools\\cmder\\cmder.exe",
LnkResolvedPath = null,
AppType = 3 // Run command
AppType = 3, // Run command
};
static Win32Program dummy_internetShortcut_app = new Win32Program
@@ -169,7 +169,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
LnkResolvedPath = null,
AppType = 1
AppType = 1,
};
static Win32Program dummy_internetShortcut_app_duplicate = new Win32Program
@@ -179,7 +179,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Programs
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\Desktop",
LnkResolvedPath = null,
AppType = 1
AppType = 1,
};
[Test]

View File

@@ -1,12 +1,9 @@
using Microsoft.Plugin.Program.Storage;
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// 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.Threading.Tasks;
using Windows.Media.Capture;
using NUnit.Framework;
using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
@@ -18,51 +15,51 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
[Test]
public void ContainsShouldReturnTrueWhenListIsInitializedWithItem()
{
//Arrange
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
//Act
// Act
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsTrue(result);
}
[Test]
public void ContainsShouldReturnTrueWhenListIsUpdatedWithAdd()
{
//Arrange
// Arrange
IRepository<string> repository = new ListRepository<string>();
//Act
// Act
var itemName = "newItem";
repository.Add(itemName);
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsTrue(result);
}
[Test]
public void ContainsShouldReturnFalseWhenListIsUpdatedWithRemove()
{
//Arrange
// Arrange
var itemName = "originalItem1";
IRepository<string> repository = new ListRepository<string>() { itemName };
//Act
// Act
repository.Remove(itemName);
var result = repository.Contains(itemName);
//Assert
// Assert
Assert.IsFalse(result);
}
[Test]
public async Task AddShouldNotThrowWhenBeingIterated()
{
//Arrange
// Arrange
ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000;
for (var i = 0; i < numItems; ++i)
@@ -70,7 +67,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}");
}
//Act - Begin iterating on one thread
// Act - Begin iterating on one thread
var iterationTask = Task.Run(() =>
{
var remainingIterations = 10000;
@@ -78,7 +75,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
foreach (var item in repository)
{
//keep iterating
// keep iterating
}
--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(() =>
{
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);
}
[Test]
public async Task RemoveShouldNotThrowWhenBeingIterated()
{
//Arrange
// Arrange
ListRepository<string> repository = new ListRepository<string>();
var numItems = 1000;
for (var i = 0; i < numItems; ++i)
@@ -110,7 +107,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
repository.Add($"OriginalItem_{i}");
}
//Act - Begin iterating on one thread
// Act - Begin iterating on one thread
var iterationTask = Task.Run(() =>
{
var remainingIterations = 10000;
@@ -118,7 +115,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
{
foreach (var item in repository)
{
//keep iterating
// keep iterating
}
--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(() =>
{
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);
}
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.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 Moq;
using NUnit.Framework;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage;
using System.IO;
using Moq;
using NUnit.Framework;
using Wox.Infrastructure.FileSystemHelper;
using System.Diagnostics;
using Wox.Infrastructure.Storage;
namespace Microsoft.Plugin.Program.UnitTests.Storage
{
@@ -47,7 +50,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name,
ExecutableName = exename,
FullPath = fullPath,
Description = description1
Description = description1,
};
Win32Program item2 = new Win32Program
@@ -55,7 +58,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
Name = name,
ExecutableName = exename,
FullPath = fullPath,
Description = description2
Description = description2,
};
// Act
@@ -357,7 +360,7 @@ namespace Microsoft.Plugin.Program.UnitTests.Storage
ExecutableName = "path.exe",
ParentDirectory = "directory",
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);

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 Microsoft.Plugin.Program.Views;
using System.Linq;
using Wox.Plugin;
using System;
namespace Microsoft.Plugin.Program
{
@@ -60,7 +64,7 @@ namespace Microsoft.Plugin.Program
var source = new ProgramSource
{
Location = Directory.Text,
UniqueIdentifier = Directory.Text
UniqueIdentifier = Directory.Text,
};
_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.Windows.Data;
using System.Windows.Markup;

View File

@@ -1,11 +1,15 @@
using NLog;
using NLog.Config;
using NLog.Targets;
// 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.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Security;
using NLog;
using NLog.Config;
using NLog.Targets;
using Wox.Infrastructure;
namespace Microsoft.Plugin.Program.Logger

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.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Controls;
using Microsoft.Plugin.Program.Programs;
using Microsoft.Plugin.Program.Storage;
using Microsoft.PowerToys.Settings.UI.Lib;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using Wox.Plugin;
using Microsoft.Plugin.Program.Views;
using Stopwatch = Wox.Infrastructure.Stopwatch;
using Windows.ApplicationModel;
using Microsoft.Plugin.Program.Storage;
using Microsoft.Plugin.Program.Programs;
namespace Microsoft.Plugin.Program
{
@@ -61,7 +60,6 @@ namespace Microsoft.Plugin.Program
Stopwatch.Normal("|Microsoft.Plugin.Program.Main|Win32Program index cost", _packageRepository.IndexPrograms);
});
Task.WaitAll(a, b);
_settings.LastIndexTime = DateTime.Today;

View File

@@ -138,5 +138,19 @@
</AssemblyAttribute>
</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>

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.IO;
@@ -7,8 +11,11 @@ namespace Microsoft.Plugin.Program
public class ProgramPluginSettings
{
public DateTime LastIndexTime { get; set; }
public List<ProgramSource> ProgramSources { get;} = new List<ProgramSource>();
public List<DisabledProgramSource> DisabledProgramSources { get;} = new List<DisabledProgramSource>();
public List<string> ProgramSuffixes { get; } = new List<string>(){ "bat", "appref-ms", "exe", "lnk", "url" };
public bool EnableStartMenuSource { get; set; } = true;
@@ -23,7 +30,6 @@ namespace Microsoft.Plugin.Program
internal const char SuffixSeparator = ';';
}
/// <summary>
@@ -39,8 +45,11 @@ namespace Microsoft.Plugin.Program
private string name;
public string Location { get; set; }
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
public bool Enabled { get; set; } = true;
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 Wox.Plugin;

View File

@@ -1,8 +1,10 @@
using System;
using System.Diagnostics;
// 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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
{
@@ -21,7 +23,9 @@ namespace Microsoft.Plugin.Program.Programs.ApplicationActivationHelper
public interface IApplicationActivationManager
{
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 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.Text;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Windows.Storage;
using static Microsoft.Plugin.Program.Programs.UWP;
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")]
void _VtblGap0_2(); // skip 2 methods
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")]
void _VtblGap0_1(); // skip 1 method
IAppxManifestProperties GetProperties();
[System.Diagnostics.CodeAnalysis.SuppressMessage("Naming", "CA1707:Identifiers should not contain underscores", Justification = "Implements COM Interface")]
void _VtblGap1_5(); // skip 5 methods
IAppxManifestApplicationsEnumerator GetApplications();
}
@@ -71,7 +76,9 @@ namespace Microsoft.Plugin.Program.Programs
public interface IAppxManifestApplicationsEnumerator
{
IAppxManifestApplication GetCurrent();
bool GetHasCurrent();
bool MoveNext();
}
@@ -90,6 +97,7 @@ namespace Microsoft.Plugin.Program.Programs
{
[PreserveSig]
Hresult GetBoolValue([MarshalAs(UnmanagedType.LPWStr)] string name, out bool value);
[PreserveSig]
Hresult GetStringValue([MarshalAs(UnmanagedType.LPWStr)] string name, [MarshalAs(UnmanagedType.LPWStr)] out string value);
}

View File

@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.Programs
{

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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 Windows.ApplicationModel;
using Windows.Foundation;
@@ -9,7 +10,9 @@ namespace Microsoft.Plugin.Program.Programs
internal interface IPackageCatalog
{
event TypedEventHandler<PackageCatalog, PackageInstallingEventArgs> PackageInstalling;
event TypedEventHandler<PackageCatalog, PackageUninstallingEventArgs> PackageUninstalling;
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.Text;
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;
namespace Microsoft.Plugin.Program.Programs
@@ -6,10 +10,15 @@ namespace Microsoft.Plugin.Program.Programs
public interface IProgram
{
List<ContextMenuResult> ContextMenus(IPublicAPI api);
Result Result(string query, IPublicAPI api);
string UniqueIdentifier { get; set; }
string Name { get; }
string Description { get; set; }
string Location { get; }
}
}

View File

@@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.Programs
{
public interface IShellLinkHelper
{
string RetrieveTargetPath(string path);
string description { get; set; }
string Arguments { get; set; }
bool hasArguments { get; set; }
}

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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 Windows.ApplicationModel;
using Windows.Foundation;
@@ -52,7 +53,6 @@ namespace Microsoft.Plugin.Program.Programs
}
}
//
// Summary:
// 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.IO;
using Microsoft.Plugin.Program.Logger;
using Package = Windows.ApplicationModel.Package;
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.IO.Packaging;
using System.Security.Principal;
using Windows.Management.Deployment;
using Windows.ApplicationModel;
using Package = Windows.ApplicationModel.Package;
namespace Microsoft.Plugin.Program.Programs

View File

@@ -1,11 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
// 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.Runtime.InteropServices;
using System.IO;
using Accessibility;
using System.Runtime.InteropServices.ComTypes;
using System.Security.Policy;
using System.Text;
using Accessibility;
using Microsoft.Plugin.Program.Logger;
namespace Microsoft.Plugin.Program.Programs
@@ -17,7 +18,7 @@ namespace Microsoft.Plugin.Program.Programs
{
SLGP_SHORTPATH = 0x1,
SLGP_UNCPRIORITY = 0x2,
SLGP_RAWPATH = 0x4
SLGP_RAWPATH = 0x4,
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -48,10 +49,9 @@ namespace Microsoft.Plugin.Program.Programs
SLR_NOSEARCH = 0x10,
SLR_NOTRACK = 0x20,
SLR_NOLINKINFO = 0x40,
SLR_INVOKE_MSI = 0x80
SLR_INVOKE_MSI = 0x80,
}
// Reference : http://www.pinvoke.net/default.aspx/Interfaces.IShellLinkW
/// The IShellLink interface allows Shell links to be created, modified, and resolved
[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
public string Arguments { get; set; } = String.Empty;
public bool hasArguments { get; set; } = false;
// Retrieve the target path using Shell Link

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.Collections.Generic;
using System.IO;
using System.Linq;
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 Wox.Infrastructure.Logger;
using System.Xml.Linq;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure.Logger;
namespace Microsoft.Plugin.Program.Programs
{
@@ -21,8 +19,11 @@ namespace Microsoft.Plugin.Program.Programs
public partial class UWP
{
public string Name { get; }
public string FullName { get; }
public string FamilyName { get; }
public string Location { get; set; }
public IList<UWPApplication> Apps { get; private set; }
@@ -87,8 +88,6 @@ namespace Microsoft.Plugin.Program.Programs
}
}
/// http://www.hanselman.com/blog/GetNamespacesFromAnXMLDocumentWithXPathDocumentAndLINQToXML.aspx
private static string[] XmlNamespaces(string path)
{
@@ -195,7 +194,6 @@ namespace Microsoft.Plugin.Program.Programs
return false;
}
return valid;
});
@@ -229,7 +227,7 @@ namespace Microsoft.Plugin.Program.Programs
Windows10,
Windows81,
Windows8,
Unknown
Unknown,
}
[Flags]
@@ -244,6 +242,5 @@ namespace Microsoft.Plugin.Program.Programs
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.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Wox.Infrastructure;
using Microsoft.Plugin.Program.Logger;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Wox.Plugin;
using System.Windows.Input;
using Wox.Plugin.SharedCommands;
using System.Reflection;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Win32;
using Wox.Infrastructure;
using Wox.Infrastructure.Image;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
using Wox.Plugin.SharedCommands;
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
{
@@ -28,20 +31,29 @@ namespace Microsoft.Plugin.Program.Programs
public class UWPApplication : IProgram
{
public string AppListEntry { get; set; }
public string UniqueIdentifier { get; set; }
public string DisplayName { get; set; }
public string Description { get; set; }
public string UserModelId { get; set; }
public string BackgroundColor { get; set; }
public string EntryPoint { get; set; }
public string Name => DisplayName;
public string Location => Package.Location;
public bool Enabled { get; set; }
public bool CanRunElevated { get; set; }
public string LogoPath { get; set; }
public UWP Package { get; set; }
private string logoUri;
@@ -84,14 +96,13 @@ namespace Microsoft.Plugin.Program.Programs
{
Launch(api);
return true;
}
},
};
// To set the title to always be the displayname of the packaged application
result.Title = DisplayName;
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 toolTipText = string.Format(CultureInfo.CurrentCulture, "{0}: {1}", api.GetTranslation("powertoys_run_plugin_program_file_path"), Package.Location);
result.ToolTipData = new ToolTipData(toolTipTitle, toolTipText);
@@ -130,7 +141,7 @@ namespace Microsoft.Plugin.Program.Programs
Process.Start(info);
return true;
}
},
}
);
}
@@ -148,7 +159,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", Package.Location));
return true;
}
},
});
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);
return false;
}
}
},
});
return contextMenus;
@@ -318,7 +329,6 @@ namespace Microsoft.Plugin.Program.Programs
}
}
internal string LogoUriFromManifest(IAppxManifestApplication app)
{
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,
{ PackageVersion.Windows10, new List<int> { 100, 125, 150, 200, 400 } },
{ 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))
@@ -451,7 +461,6 @@ namespace Microsoft.Plugin.Program.Programs
return logo;
}
private BitmapImage ImageFromPath(string path)
{
if (File.Exists(path))

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.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Input;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Win32;
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 System.Globalization;
using Wox.Infrastructure.Logger;
using Wox.Plugin;
namespace Microsoft.Plugin.Program.Programs
{
@@ -25,22 +28,38 @@ namespace Microsoft.Plugin.Program.Programs
public class Win32Program : IProgram
{
public string Name { get; set; }
public string UniqueIdentifier { get; set; }
public string IcoPath { get; set; }
public string FullPath { get; set; }
public string LnkResolvedPath { get; set; }
public string ParentDirectory { get; set; }
public string ExecutableName { get; set; }
public string Description { get; set; } = String.Empty;
public bool Valid { get; set; }
public bool Enabled { get; set; }
public bool hasArguments { get; set; } = false;
public string Arguments { get; set; } = String.Empty;
public string Location => ParentDirectory;
public uint AppType { get; set; }
// Wrappers for File Operations
public static IFileVersionInfoWrapper FileVersionInfoWrapper { get; set;} = new FileVersionInfoWrapper();
public static IFileWrapper FileWrapper { get; set; } = new FileWrapper();
public static IShellLinkHelper Helper { get; set; } = new ShellLinkHelper();
private const string ShortcutExtension = "lnk";
@@ -56,7 +75,7 @@ namespace Microsoft.Plugin.Program.Programs
WEB_APPLICATION = 0,
INTERNET_SHORTCUT_APPLICATION = 1,
WIN32_APPLICATION = 2,
RUN_COMMAND = 3
RUN_COMMAND = 3,
}
// Function to calculate the score of a result
@@ -197,7 +216,7 @@ namespace Microsoft.Plugin.Program.Programs
Main.StartProcess(Process.Start, info);
return true;
}
},
};
// 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));
return true;
}
},
});
}
@@ -261,7 +280,7 @@ namespace Microsoft.Plugin.Program.Programs
{
Main.StartProcess(Process.Start, new ProcessStartInfo("explorer", ParentDirectory));
return true;
}
},
});
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);
return false;
}
}
},
});
return contextMenus;
}
public override string ToString()
{
return ExecutableName;
@@ -313,7 +330,7 @@ namespace Microsoft.Plugin.Program.Programs
Description = string.Empty,
Valid = true,
Enabled = true,
AppType = (uint)ApplicationTypes.WIN32_APPLICATION
AppType = (uint)ApplicationTypes.WIN32_APPLICATION,
};
return p;
}
@@ -378,7 +395,7 @@ namespace Microsoft.Plugin.Program.Programs
ParentDirectory = Directory.GetParent(path).FullName,
Valid = true,
Enabled = true,
AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION
AppType = (uint)ApplicationTypes.INTERNET_SHORTCUT_APPLICATION,
};
return p;
}
@@ -603,7 +620,6 @@ namespace Microsoft.Plugin.Program.Programs
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
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
{
internal interface IProgramRepository
{
void IndexPrograms();
void Load();
void Save();
}
}

View File

@@ -1,10 +1,12 @@
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Programs;
// 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.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Plugin.Program.Logger;
using Microsoft.Plugin.Program.Programs;
using Windows.ApplicationModel;
using Wox.Infrastructure.Storage;
@@ -19,6 +21,7 @@ namespace Microsoft.Plugin.Program.Storage
private IStorage<IList<UWPApplication>> _storage;
private IPackageCatalog _packageCatalog;
public PackageRepository(IPackageCatalog packageCatalog, IStorage<IList<UWPApplication>> storage)
{
_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 Wox.Infrastructure.Storage;
@@ -25,7 +29,7 @@ namespace Microsoft.Plugin.Program.Storage
{
Environment.GetFolderPath(Environment.SpecialFolder.Programs),
Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms),
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
};
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.ObjectModel;
using Microsoft.Plugin.Program.Programs;
using System.Globalization;
using System.IO;
using Wox.Infrastructure.Logger;
using Wox.Infrastructure.Storage;
using System.IO;
using System.Linq;
using System.Globalization;
using Win32Program = Microsoft.Plugin.Program.Programs.Win32Program;
namespace Microsoft.Plugin.Program.Storage
{
using Win32Program = Programs.Win32Program;
internal class Win32ProgramRepository : ListRepository<Programs.Win32Program>, IProgramRepository
{
private IStorage<IList<Programs.Win32Program>> _storage;
@@ -93,7 +95,6 @@ namespace Microsoft.Plugin.Program.Storage
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.
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.Windows.Data;
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.Linq;
namespace Microsoft.Plugin.Program.Views.Commands
{
internal static class ProgramSettingDisplay
@@ -18,7 +20,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Enabled = x.Enabled,
Location = x.Location,
Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier
UniqueIdentifier = x.UniqueIdentifier,
}
));
@@ -37,7 +39,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Enabled = x.Enabled,
Location = x.Location,
Name = x.Name,
UniqueIdentifier = x.UniqueIdentifier
UniqueIdentifier = x.UniqueIdentifier,
}
));
@@ -92,7 +94,7 @@ namespace Microsoft.Plugin.Program.Views.Commands
Name = x.Name,
Location = x.Location,
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.ComponentModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using Microsoft.Plugin.Program.Views.Commands;
using Microsoft.Plugin.Program.Programs;
using System.ComponentModel;
using System.Windows.Data;
using Wox.Plugin;
using System.Globalization;
namespace Microsoft.Plugin.Program.Views
{
@@ -136,7 +139,7 @@ namespace Microsoft.Plugin.Program.Views
var source = new ProgramSource
{
Location = directory,
UniqueIdentifier = directory
UniqueIdentifier = directory,
};
directoriesToAdd.Add(source);

View File

@@ -1,5 +1,8 @@
using System;
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;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;