[PowerToys Run] Plugins StyleCop and warnings fix (#12623)

This commit is contained in:
Davide Giacometti
2021-08-11 17:22:30 +02:00
committed by GitHub
parent 7ea1f26209
commit 1791246a79
25 changed files with 251 additions and 128 deletions

View File

@@ -190,7 +190,7 @@ namespace Microsoft.ColorPicker.UnitTests
} }
Assert.IsTrue(hexValue.Length >= 6); Assert.IsTrue(hexValue.Length >= 6);
var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
@@ -287,7 +287,7 @@ namespace Microsoft.ColorPicker.UnitTests
Assert.IsTrue(hexValue.Length >= 6); Assert.IsTrue(hexValue.Length >= 6);
var red = int.Parse( hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var red = int.Parse(hexValue.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var green = int.Parse(hexValue.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture); var blue = int.Parse(hexValue.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture);
@@ -322,6 +322,7 @@ namespace Microsoft.ColorPicker.UnitTests
_ = ColorHelper.ConvertToCMYKColor(color); _ = ColorHelper.ConvertToCMYKColor(color);
} }
#pragma warning disable CA1031 // Do not catch general exception types #pragma warning disable CA1031 // Do not catch general exception types
// intentionally trying to catch // intentionally trying to catch
catch (Exception ex) catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types #pragma warning restore CA1031 // Do not catch general exception types

View File

@@ -35,6 +35,10 @@
</PackageReference> </PackageReference>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.3" /> <PackageReference Include="MSTest.TestAdapter" Version="2.2.3" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.3" /> <PackageReference Include="MSTest.TestFramework" Version="2.2.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -42,4 +46,12 @@
<ProjectReference Include="..\ColorPickerUI\ColorPickerUI.csproj" /> <ProjectReference Include="..\ColorPickerUI\ColorPickerUI.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\codeAnalysis\GlobalSuppressions.cs">
<Link>GlobalSuppressions.cs</Link>
</Compile>
<AdditionalFiles Include="..\..\..\codeAnalysis\StyleCop.json">
<Link>StyleCop.json</Link>
</AdditionalFiles>
</ItemGroup>
</Project> </Project>

View File

@@ -1,3 +1,7 @@
// 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.Globalization; using System.Globalization;
using NUnit.Framework; using NUnit.Framework;
using Wox.Plugin; using Wox.Plugin;

View File

@@ -1,4 +1,7 @@
using System.Globalization; // 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.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;

View File

@@ -26,7 +26,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -39,6 +39,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,5 +1,7 @@
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.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;

View File

@@ -1,13 +1,15 @@
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.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using ManagedCommon; using ManagedCommon;
using UnitsNet;
using Wox.Plugin; using Wox.Plugin;
namespace Community.PowerToys.Run.Plugin.UnitConverter namespace Community.PowerToys.Run.Plugin.UnitConverter
@@ -142,7 +144,7 @@ namespace Community.PowerToys.Run.Plugin.UnitConverter
return Properties.Resources.plugin_description; return Properties.Resources.plugin_description;
} }
private void OnThemeChanged(Theme _, Theme newTheme) private void OnThemeChanged(Theme currentTheme, Theme newTheme)
{ {
UpdateIconPath(newTheme); UpdateIconPath(newTheme);
} }

View File

@@ -1,4 +1,8 @@
using UnitsNet; // 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 UnitsNet;
namespace Community.PowerToys.Run.Plugin.UnitConverter namespace Community.PowerToys.Run.Plugin.UnitConverter
{ {

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.Globalization; using System.Globalization;
using System.Linq; using System.Linq;

View File

@@ -25,6 +25,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
@@ -37,6 +38,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -50,10 +52,22 @@
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" /> <ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj" />
</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> <ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" /> <PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Runtime" Version="4.3.1" /> <PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

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.ComponentModel; using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
@@ -13,7 +17,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
{ {
public class Main : IPlugin, IPluginI18n public class Main : IPlugin, IPluginI18n
{ {
public PluginInitContext _context { get; private set; } private PluginInitContext _context;
public string Name => GetTranslatedPluginTitle(); public string Name => GetTranslatedPluginTitle();
@@ -24,9 +28,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
VSCodeInstances.LoadVSCodeInstances(); VSCodeInstances.LoadVSCodeInstances();
} }
public readonly VSCodeWorkspacesApi _workspacesApi = new VSCodeWorkspacesApi(); private readonly VSCodeWorkspacesApi _workspacesApi = new VSCodeWorkspacesApi();
public readonly VSCodeRemoteMachinesApi _machinesApi = new VSCodeRemoteMachinesApi(); private readonly VSCodeRemoteMachinesApi _machinesApi = new VSCodeRemoteMachinesApi();
public List<Result> Query(Query query) public List<Result> Query(Query query)
{ {
@@ -49,12 +53,12 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
title += $" - {(a.ExtraInfo != null ? $"{a.ExtraInfo} ({typeWorkspace})" : typeWorkspace)}"; title += $" - {(a.ExtraInfo != null ? $"{a.ExtraInfo} ({typeWorkspace})" : typeWorkspace)}";
} }
var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}"); var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}");
results.Add(new Result results.Add(new Result
{ {
Title = title, Title = title,
SubTitle = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : "")}: {SystemPath.RealPath(a.RelativePath)}", SubTitle = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}",
Icon = a.VSCodeInstance.WorkspaceIcon, Icon = a.VSCodeInstance.WorkspaceIcon,
ToolTipData = tooltip, ToolTipData = tooltip,
Action = c => Action = c =>
@@ -67,7 +71,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
FileName = a.VSCodeInstance.ExecutablePath, FileName = a.VSCodeInstance.ExecutablePath,
UseShellExecute = true, UseShellExecute = true,
Arguments = $"--folder-uri {a.Path}", Arguments = $"--folder-uri {a.Path}",
WindowStyle = ProcessWindowStyle.Hidden WindowStyle = ProcessWindowStyle.Hidden,
}; };
Process.Start(process); Process.Start(process);
@@ -80,13 +84,13 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
_context.API.ShowMsg(name, msg, string.Empty); _context.API.ShowMsg(name, msg, string.Empty);
hide = false; hide = false;
} }
return hide; return hide;
}, },
ContextData = a, ContextData = a,
}); });
}); });
// Search opened remote machines // Search opened remote machines
_machinesApi.Machines.ForEach(a => _machinesApi.Machines.ForEach(a =>
{ {
@@ -128,6 +132,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
_context.API.ShowMsg(name, msg, string.Empty); _context.API.ShowMsg(name, msg, string.Empty);
hide = false; hide = false;
} }
return hide; return hide;
}, },
ContextData = a, ContextData = a,
@@ -147,20 +152,20 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
x.Score = 100; x.Score = 100;
} }
//intersect the title with the query // intersect the title with the query
var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count()); var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count());
var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7); var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7);
x.Score = x.Score - differenceWithQuery + intersection; x.Score = x.Score - differenceWithQuery + intersection;
//if is a remote machine give it 12 extra points // if is a remote machine give it 12 extra points
if (x.ContextData is VSCodeRemoteMachine) if (x.ContextData is VSCodeRemoteMachine)
{ {
x.Score = Convert.ToInt32(x.Score + intersection * 2); x.Score = Convert.ToInt32(x.Score + (intersection * 2));
} }
}); });
results = results.OrderByDescending(x => x.Score).ToList(); results = results.OrderByDescending(x => x.Score).ToList();
if (query.Search == string.Empty || query.Search.Replace(" ", "") == string.Empty) if (query.Search == string.Empty || query.Search.Replace(" ", string.Empty) == string.Empty)
{ {
results = results.OrderBy(x => x.Title).ToList(); results = results.OrderBy(x => x.Title).ToList();
} }

View File

@@ -1,4 +1,8 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper; // 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 Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{ {

View File

@@ -1,16 +1,22 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser; // Copyright (c) Microsoft Corporation
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper; // The Microsoft Corporation licenses this file to you under the MIT license.
using Newtonsoft.Json; // 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 Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Newtonsoft.Json;
using Wox.Plugin.Logger; using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{ {
public class VSCodeRemoteMachinesApi public class VSCodeRemoteMachinesApi
{ {
public VSCodeRemoteMachinesApi() { } public VSCodeRemoteMachinesApi()
{
}
public List<VSCodeRemoteMachine> Machines public List<VSCodeRemoteMachine> Machines
{ {
@@ -18,7 +24,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
{ {
var results = new List<VSCodeRemoteMachine>(); var results = new List<VSCodeRemoteMachine>();
foreach (var vscodeInstance in VSCodeInstances.instances) foreach (var vscodeInstance in VSCodeInstances.Instances)
{ {
// settings.json contains path of ssh_config // settings.json contains path of ssh_config
var vscode_settings = Path.Combine(vscodeInstance.AppData, "User\\settings.json"); var vscode_settings = Path.Combine(vscodeInstance.AppData, "User\\settings.json");
@@ -40,8 +46,8 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
var machine = new VSCodeRemoteMachine(); var machine = new VSCodeRemoteMachine();
machine.Host = h.Host; machine.Host = h.Host;
machine.VSCodeInstance = vscodeInstance; machine.VSCodeInstance = vscodeInstance;
machine.HostName = h.HostName != null ? h.HostName : String.Empty; machine.HostName = h.HostName != null ? h.HostName : string.Empty;
machine.User = h.User != null ? h.User : String.Empty; machine.User = h.User != null ? h.User : string.Empty;
results.Add(machine); results.Add(machine);
} }
@@ -57,8 +63,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.RemoteMachinesHelper
} }
return results; return results;
} }
} }
} }
} }

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 System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
@@ -7,8 +11,8 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser
{ {
public class SshConfig public class SshConfig
{ {
private static readonly Regex SSH_CONFIG = new Regex(@"^(\w[\s\S]*?\w)$(?=(?:\s+^\w|\z))", RegexOptions.Multiline); private static readonly Regex _sshConfig = new Regex(@"^(\w[\s\S]*?\w)$(?=(?:\s+^\w|\z))", RegexOptions.Multiline);
private static readonly Regex KEY_VALUE = new Regex(@"(\w+\s\S+)", RegexOptions.Multiline); private static readonly Regex _keyValue = new Regex(@"(\w+\s\S+)", RegexOptions.Multiline);
public static IEnumerable<SshHost> ParseFile(string path) public static IEnumerable<SshHost> ParseFile(string path)
{ {
@@ -17,23 +21,24 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser
public static IEnumerable<SshHost> Parse(string str) public static IEnumerable<SshHost> Parse(string str)
{ {
str = str.Replace('\r', '\0');
str = str.Replace("\r", "");
var list = new List<SshHost>(); var list = new List<SshHost>();
foreach (Match match in SSH_CONFIG.Matches(str)) foreach (Match match in _sshConfig.Matches(str))
{ {
var sshHost = new SshHost(); var sshHost = new SshHost();
string content = match.Groups.Values.ToList()[0].Value; string content = match.Groups.Values.ToList()[0].Value;
foreach (Match match1 in KEY_VALUE.Matches(content)) foreach (Match match1 in _keyValue.Matches(content))
{ {
var split = match1.Value.Split(" "); var split = match1.Value.Split(" ");
var key = split[0]; var key = split[0];
var value = split[1]; var value = split[1];
sshHost.Properties[key] = value; sshHost.Properties[key] = value;
} }
list.Add(sshHost); list.Add(sshHost);
} }
return list; return list;
} }
} }
} }

View File

@@ -1,33 +1,39 @@
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;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser
{ {
public class SshHost public class SshHost
{ {
public string IdentityFile public string IdentityFile
{ {
get => this[nameof(IdentityFile)]?.ToString(); get => this[nameof(IdentityFile)]?.ToString();
set => this[nameof(IdentityFile)] = value; set => this[nameof(IdentityFile)] = value;
} }
public string Host public string Host
{ {
get => this[nameof(Host)]?.ToString(); get => this[nameof(Host)]?.ToString();
set => this[nameof(Host)] = value; set => this[nameof(Host)] = value;
} }
public string HostName public string HostName
{ {
get => this[nameof(HostName)]?.ToString(); get => this[nameof(HostName)]?.ToString();
set => this[nameof(HostName)] = value; set => this[nameof(HostName)] = value;
} }
public string User { public string User
{
get => this[nameof(User)]?.ToString(); get => this[nameof(User)]?.ToString();
set => this[nameof(User)] = value; set => this[nameof(User)] = value;
} }
public string ForwardAgent { public string ForwardAgent
{
get => this[nameof(ForwardAgent)]?.ToString(); get => this[nameof(ForwardAgent)]?.ToString();
set => this[nameof(ForwardAgent)] = value; set => this[nameof(ForwardAgent)] = value;
} }
@@ -36,7 +42,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser
public object this[string key] public object this[string key]
{ {
get get
{ {
if (Properties.TryGetValue(key, out var value)) if (Properties.TryGetValue(key, out var value))
{ {
@@ -45,9 +51,13 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.SshConfigParser
return null; return null;
} }
set { Properties[key] = value; }
set
{
Properties[key] = value;
}
} }
public IEnumerable<string> Keys => Properties.Keys; public IEnumerable<string> Keys => Properties.Keys;
} }
} }

View File

@@ -1,9 +1,12 @@
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.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
{ {
class SystemPath internal class SystemPath
{ {
private static readonly Regex WindowsPath = new Regex(@"^([a-zA-Z]:)", RegexOptions.Compiled); private static readonly Regex WindowsPath = new Regex(@"^([a-zA-Z]:)", RegexOptions.Compiled);
@@ -11,8 +14,8 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
{ {
if (WindowsPath.IsMatch(path)) if (WindowsPath.IsMatch(path))
{ {
String windowsPath = path.Replace("/", "\\"); string windowsPath = path.Replace("/", "\\");
return $"{windowsPath[0]}".ToUpper() + windowsPath.Remove(0,1); return $"{windowsPath[0]}".ToUpper() + windowsPath.Remove(0, 1);
} }
else else
{ {

View File

@@ -1,4 +1,7 @@
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.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
@@ -8,20 +11,20 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
{ {
Stable = 1, Stable = 1,
Insiders = 2, Insiders = 2,
Exploration = 3 Exploration = 3,
} }
public class VSCodeInstance public class VSCodeInstance
{ {
public VSCodeVersion VSCodeVersion { get; set; } public VSCodeVersion VSCodeVersion { get; set; }
public string ExecutablePath { get; set; } = String.Empty; public string ExecutablePath { get; set; } = string.Empty;
public string AppData { get; set; } = String.Empty; public string AppData { get; set; } = string.Empty;
public ImageSource WorkspaceIcon(){ return WorkspaceIconBitMap; } public ImageSource WorkspaceIcon() => WorkspaceIconBitMap;
public ImageSource RemoteIcon(){ return RemoteIconBitMap; } public ImageSource RemoteIcon() => RemoteIconBitMap;
public BitmapImage WorkspaceIconBitMap { get; set; } public BitmapImage WorkspaceIconBitMap { get; set; }

View File

@@ -1,28 +1,25 @@
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.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
{ {
static class VSCodeInstances public static class VSCodeInstances
{ {
private static readonly string PathUserAppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); private static string _systemPath = string.Empty;
private static string _systemPath = String.Empty;
private static string _userAppDataPath = Environment.GetEnvironmentVariable("AppData"); private static string _userAppDataPath = Environment.GetEnvironmentVariable("AppData");
public static List<VSCodeInstance> instances = new List<VSCodeInstance>(); public static List<VSCodeInstance> Instances { get; set; } = new List<VSCodeInstance>();
private static BitmapImage Bitmap2BitmapImage(Bitmap bitmap) private static BitmapImage Bitmap2BitmapImage(Bitmap bitmap)
{ {
@@ -42,15 +39,15 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
} }
} }
public static Bitmap bitmapOverlayToCenter(Bitmap bitmap1, Bitmap overlayBitmap) public static Bitmap BitmapOverlayToCenter(Bitmap bitmap1, Bitmap overlayBitmap)
{ {
int bitmap1Width = bitmap1.Width; int bitmap1Width = bitmap1.Width;
int bitmap1Height = bitmap1.Height; int bitmap1Height = bitmap1.Height;
Bitmap overlayBitmapResized = new Bitmap(overlayBitmap, new System.Drawing.Size(bitmap1Width / 2, bitmap1Height / 2)); Bitmap overlayBitmapResized = new Bitmap(overlayBitmap, new System.Drawing.Size(bitmap1Width / 2, bitmap1Height / 2));
float marginLeft = (float)(bitmap1Width * 0.7 - overlayBitmapResized.Width * 0.5); float marginLeft = (float)((bitmap1Width * 0.7) - (overlayBitmapResized.Width * 0.5));
float marginTop = (float)(bitmap1Height * 0.7 - overlayBitmapResized.Height * 0.5); float marginTop = (float)((bitmap1Height * 0.7) - (overlayBitmapResized.Height * 0.5));
Bitmap finalBitmap = new Bitmap(bitmap1Width, bitmap1Height); Bitmap finalBitmap = new Bitmap(bitmap1Width, bitmap1Height);
using (Graphics g = Graphics.FromImage(finalBitmap)) using (Graphics g = Graphics.FromImage(finalBitmap))
@@ -58,6 +55,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
g.DrawImage(bitmap1, System.Drawing.Point.Empty); g.DrawImage(bitmap1, System.Drawing.Point.Empty);
g.DrawImage(overlayBitmapResized, marginLeft, marginTop); g.DrawImage(overlayBitmapResized, marginLeft, marginTop);
} }
return finalBitmap; return finalBitmap;
} }
@@ -66,8 +64,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
{ {
if (_systemPath != Environment.GetEnvironmentVariable("PATH")) if (_systemPath != Environment.GetEnvironmentVariable("PATH"))
{ {
Instances = new List<VSCodeInstance>();
instances = new List<VSCodeInstance>();
_systemPath = Environment.GetEnvironmentVariable("PATH"); _systemPath = Environment.GetEnvironmentVariable("PATH");
var paths = _systemPath.Split(";"); var paths = _systemPath.Split(";");
@@ -83,7 +80,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
if (files.Length > 0) if (files.Length > 0)
{ {
var file = files[0]; var file = files[0];
var version = String.Empty; var version = string.Empty;
var instance = new VSCodeInstance var instance = new VSCodeInstance
{ {
@@ -106,23 +103,23 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
instance.VSCodeVersion = VSCodeVersion.Exploration; instance.VSCodeVersion = VSCodeVersion.Exploration;
} }
if (version != String.Empty) if (version != string.Empty)
{ {
instance.AppData = Path.Combine(_userAppDataPath, version); instance.AppData = Path.Combine(_userAppDataPath, version);
var iconVSCode = Path.Join(iconPath, $"{version}.exe"); var iconVSCode = Path.Join(iconPath, $"{version}.exe");
var bitmapIconVscode = Icon.ExtractAssociatedIcon(iconVSCode).ToBitmap(); var bitmapIconVscode = Icon.ExtractAssociatedIcon(iconVSCode).ToBitmap();
//workspace // workspace
var folderIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//folder.png"); var folderIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//folder.png");
instance.WorkspaceIconBitMap = Bitmap2BitmapImage(bitmapOverlayToCenter(folderIcon, bitmapIconVscode)); instance.WorkspaceIconBitMap = Bitmap2BitmapImage(BitmapOverlayToCenter(folderIcon, bitmapIconVscode));
//remote // remote
var monitorIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//monitor.png"); var monitorIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//monitor.png");
instance.RemoteIconBitMap = Bitmap2BitmapImage(bitmapOverlayToCenter(monitorIcon, bitmapIconVscode)); instance.RemoteIconBitMap = Bitmap2BitmapImage(BitmapOverlayToCenter(monitorIcon, bitmapIconVscode));
instances.Add(instance); Instances.Add(instance);
} }
} }
} }

View File

@@ -0,0 +1,15 @@
// 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;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class OpenedPathsList
{
public List<dynamic> Workspaces3 { get; set; }
public List<VSCodeWorkspaceEntry> Entries { get; set; }
}
}

View File

@@ -1,4 +1,7 @@
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.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -13,7 +16,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
private static readonly Regex CodespacesWorkspace = new Regex(@"^vscode-remote://vsonline\+(.+?(?=\/))(.+)$", RegexOptions.Compiled); private static readonly Regex CodespacesWorkspace = new Regex(@"^vscode-remote://vsonline\+(.+?(?=\/))(.+)$", RegexOptions.Compiled);
public static (TypeWorkspace? TypeWorkspace, String MachineName, String Path) GetTypeWorkspace(string uri) public static (TypeWorkspace? TypeWorkspace, string MachineName, string Path) GetTypeWorkspace(string uri)
{ {
if (LocalWorkspace.IsMatch(uri)) if (LocalWorkspace.IsMatch(uri))
{ {
@@ -48,7 +51,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
if (match.Groups.Count > 1) if (match.Groups.Count > 1)
{ {
return (TypeWorkspace.Codespaces, String.Empty, match.Groups[2].Value); return (TypeWorkspace.Codespaces, string.Empty, match.Groups[2].Value);
} }
} }

View File

@@ -1,22 +1,11 @@
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.
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{ {
public class VSCodeStorageFile public class VSCodeStorageFile
{ {
public openedPathsList openedPathsList { get; set; } public OpenedPathsList OpenedPathsList { get; set; }
}
public class VSCodeWorkspaceEntry
{
public string folderUri { get; set; }
public string label { get; set; }
}
public class openedPathsList
{
public List<dynamic> workspaces3 { get; set; }
public List<VSCodeWorkspaceEntry> entries { get; set; }
} }
} }

View File

@@ -1,4 +1,8 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties; // 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 Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper; using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -38,6 +42,6 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
Codespaces = 2, Codespaces = 2,
RemoteWSL = 3, RemoteWSL = 3,
RemoteSSH = 4, RemoteSSH = 4,
RemoteContainers = 5 RemoteContainers = 5,
} }
} }

View File

@@ -0,0 +1,13 @@
// 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 Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class VSCodeWorkspaceEntry
{
public string FolderUri { get; set; }
public string Label { get; set; }
}
}

View File

@@ -1,23 +1,29 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper; // Copyright (c) Microsoft Corporation
using Newtonsoft.Json; // 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.Text.Json;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Wox.Plugin.Logger; using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{ {
public class VSCodeWorkspacesApi public class VSCodeWorkspacesApi
{ {
public VSCodeWorkspacesApi() { } public VSCodeWorkspacesApi()
private VSCodeWorkspace parseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
{ {
if (uri != null && uri is String) }
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
{
if (uri != null && uri is string)
{ {
string unescapeUri = Uri.UnescapeDataString(uri); string unescapeUri = Uri.UnescapeDataString(uri);
var typeWorkspace = ParseVSCodeUri.GetTypeWorkspace(unescapeUri); var typeWorkspace = WorkspacesHelper.ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
if (typeWorkspace.TypeWorkspace.HasValue) if (typeWorkspace.TypeWorkspace.HasValue)
{ {
var folderName = Path.GetFileName(unescapeUri); var folderName = Path.GetFileName(unescapeUri);
@@ -28,7 +34,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
FolderName = folderName, FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName, ExtraInfo = typeWorkspace.MachineName,
TypeWorkspace = typeWorkspace.TypeWorkspace.Value, TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
VSCodeInstance = vscodeInstance VSCodeInstance = vscodeInstance,
}; };
} }
} }
@@ -40,10 +46,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{ {
get get
{ {
var results = new List<VSCodeWorkspace>(); var results = new List<VSCodeWorkspace>();
foreach (var vscodeInstance in VSCodeInstances.instances) foreach (var vscodeInstance in VSCodeInstances.Instances)
{ {
// storage.json contains opened Workspaces // storage.json contains opened Workspaces
var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json"); var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json");
@@ -54,16 +59,21 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
try try
{ {
VSCodeStorageFile vscodeStorageFile = JsonConvert.DeserializeObject<VSCodeStorageFile>(fileContent); var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent, options);
if (vscodeStorageFile != null) if (vscodeStorageFile != null)
{ {
//for previous versions of vscode // for previous versions of vscode
if (vscodeStorageFile.openedPathsList.workspaces3 != null) if (vscodeStorageFile.OpenedPathsList.Workspaces3 != null)
{ {
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.workspaces3) foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Workspaces3)
{ {
var uri = parseVSCodeUri(workspaceUri, vscodeInstance); var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null) if (uri != null)
{ {
results.Add(uri); results.Add(uri);
@@ -71,19 +81,18 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
} }
} }
//vscode v1.55.0 or later // vscode v1.55.0 or later
if (vscodeStorageFile.openedPathsList.entries != null) if (vscodeStorageFile.OpenedPathsList.Entries != null)
{ {
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.entries.Select(x => x.folderUri)) foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Entries.Select(x => x.FolderUri))
{ {
var uri = parseVSCodeUri(workspaceUri, vscodeInstance); var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null) if (uri != null)
{ {
results.Add(uri); results.Add(uri);
} }
} }
} }
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -91,12 +100,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
var message = $"Failed to deserialize ${vscode_storage}"; var message = $"Failed to deserialize ${vscode_storage}";
Log.Exception(message, ex, GetType()); Log.Exception(message, ex, GetType());
} }
} }
} }
return results; return results;
} }
} }

View File

@@ -0,0 +1,14 @@
{
// ACTION REQUIRED: This file was automatically added to your project, but it
// will not take effect until additional steps are taken to enable it. See the
// following page for additional information:
//
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/EnableConfiguration.md
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "PlaceholderCompany"
}
}
}