Powertoys Run | VSCodeWorkspaces- add support for vscode 1.64 - bug fix #15247 (#15259)

* #15247 Powertoys Run | VSCodeWorkspaces- add support for vscode 1.64 new workspace.json file

* Get previous open workspaces for sqlite file

* check-spelling-bot Report fix

* add dlls to installer and set SqliteConnection to readonly
This commit is contained in:
ricardosantos9521
2022-01-18 11:44:32 +00:00
committed by GitHub
parent 167ec5a3a8
commit 758a21a22f
7 changed files with 179 additions and 107 deletions

View File

@@ -359,6 +359,7 @@ dacl
DARKPURPLE
DARKTEAL
DARKYELLOW
datareader
Datavalue
DATAW
davidegiacometti
@@ -1815,6 +1816,7 @@ spsi
spsia
spsrm
spsv
sqlite
SRCCOPY
sre
sregex
@@ -2114,6 +2116,7 @@ Vpn
VREDRAW
VSC
VSCBD
vscdb
vscode
VSCROLL
vsonline

View File

@@ -1330,7 +1330,7 @@
<Component Id="launcherInstallComponent" Directory="LauncherInstallFolder" Guid="5E688DB4-C522-4268-BA54-ED1CDFFE9DB6">
<File Source="$(var.BinX64Dir)modules\Launcher\PowerToys.Launcher.dll" />
<?foreach File in concrt140_app.dll;ICSharpCode.SharpZipLib.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerToys.PowerLauncher.deps.json;PowerToys.PowerLauncher.dll;PowerToys.PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerToys.PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToys.Interop.dll;PowerToys.ManagedTelemetry.dll;PowerToys.PowerLauncher.Telemetry.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;PowerToys.ManagedCommon.dll;System.IO.Abstractions.dll;PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;System.Runtime.CompilerServices.Unsafe.dll;System.Text.Encodings.Web.dll?>
<?foreach File in concrt140_app.dll;e_sqlite3.dll;ICSharpCode.SharpZipLib.dll;JetBrains.Annotations.dll;Mages.Core.dll;Microsoft.Search.Interop.dll;Mono.Cecil.dll;Mono.Cecil.Mdb.dll;Mono.Cecil.Pdb.dll;Mono.Cecil.Rocks.dll;msvcp140_1_app.dll;msvcp140_2_app.dll;msvcp140_app.dll;NLog.dll;NLog.Extensions.Logging.dll;PowerToys.PowerLauncher.deps.json;PowerToys.PowerLauncher.dll;PowerToys.PowerLauncher.exe;Microsoft.Xaml.Behaviors.dll;System.Text.Json.dll;PowerToys.PowerLauncher.runtimeconfig.json;System.Data.OleDb.dll;UnitsNet.dll;vcamp140_app.dll;vccorlib140_app.dll;vcomp140_app.dll;vcruntime140_1_app.dll;vcruntime140_app.dll;Wox.Infrastructure.dll;Wox.Plugin.dll;PowerToys.Interop.dll;PowerToys.ManagedTelemetry.dll;PowerToys.PowerLauncher.Telemetry.dll;Microsoft.Data.Sqlite.dll;SQLitePCLRaw.batteries_v2.dll;SQLitePCLRaw.core.dll;SQLitePCLRaw.provider.e_sqlite3.dll;Microsoft.Extensions.Configuration.Abstractions.dll;Microsoft.Extensions.Configuration.Binder.dll;Microsoft.Extensions.Configuration.dll;Microsoft.Extensions.DependencyInjection.Abstractions.dll;Microsoft.Extensions.DependencyInjection.dll;Microsoft.Extensions.Logging.Abstractions.dll;Microsoft.Extensions.Logging.dll;Microsoft.Extensions.Options.dll;Microsoft.Extensions.Primitives.dll;ControlzEx.dll;PowerToys.ManagedCommon.dll;System.IO.Abstractions.dll;PowerToys.Common.UI.dll;System.ServiceProcess.ServiceController.dll;Microsoft.Toolkit.Uwp.Notifications.dll;ModernWpf.Controls.dll;ModernWpf.dll;System.Runtime.CompilerServices.Unsafe.dll;System.Text.Encodings.Web.dll?>
<File Id="File_$(var.File)" Source="$(var.BinX64Dir)modules\launcher\$(var.File)" />
<?endforeach?>
<File Source="$(var.BinX64Dir)Settings\PowerToys.Settings.UI.Lib.dll" />

View File

@@ -63,6 +63,7 @@
<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -0,0 +1,16 @@
// 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.Json.Serialization;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
// v1.64 uses AppData\Roaming\Code\User\globalStorage\state.vscdb - history.recentlyOpenedPathsList
public class VSCodeStorageEntries
{
[JsonPropertyName("entries")]
public List<VSCodeWorkspaceEntry> Entries { get; set; }
}
}

View File

@@ -14,6 +14,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
[JsonPropertyName("label")]
public string Label { get; set; }
[JsonPropertyName("remoteAuthority")]
public string RemoteAuthority { get; set; }
[JsonPropertyName("workspace")]
public VSCodeWorkspaceProperty Workspace { get; set; }
}

View File

@@ -8,6 +8,7 @@ using System.IO;
using System.Linq;
using System.Text.Json;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Microsoft.Data.Sqlite;
using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -18,7 +19,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
}
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance, bool isWorkspaceFile = false)
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance, bool isWorkspace = false)
{
if (uri != null && uri is string)
{
@@ -38,7 +39,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
return new VSCodeWorkspace()
{
Path = uri,
WorkspaceType = isWorkspaceFile ? WorkspaceType.WorkspaceFile : WorkspaceType.ProjectFolder,
WorkspaceType = isWorkspace ? WorkspaceType.WorkspaceFile : WorkspaceType.ProjectFolder,
RelativePath = typeWorkspace.Path,
FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName,
@@ -62,6 +63,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
// storage.json contains opened Workspaces
var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json");
// User/globalStorage/state.vscdb - history.recentlyOpenedPathsList - vscode v1.64 or later
var vscode_storage_db = Path.Combine(vscodeInstance.AppData, "User/globalStorage/state.vscdb");
if (File.Exists(vscode_storage))
{
var fileContent = File.ReadAllText(vscode_storage);
@@ -70,7 +74,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent);
if (vscodeStorageFile != null)
if (vscodeStorageFile != null && vscodeStorageFile.OpenedPathsList != null)
{
// for previous versions of vscode
if (vscodeStorageFile.OpenedPathsList.Workspaces3 != null)
@@ -106,6 +110,50 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
}
}
}
else if (File.Exists(vscode_storage_db))
{
var sqliteConnection = new SqliteConnection($"Data Source={vscode_storage_db};Mode=ReadOnly;");
sqliteConnection.Open();
if (sqliteConnection.State == System.Data.ConnectionState.Open)
{
var sqlite_cmd = sqliteConnection.CreateCommand();
sqlite_cmd.CommandText = "SELECT value FROM ItemTable WHERE key LIKE 'history.recentlyOpenedPathsList'";
var sqlite_datareader = sqlite_cmd.ExecuteReader();
if (sqlite_datareader.Read())
{
string entries = sqlite_datareader.GetString(0);
if (!string.IsNullOrEmpty(entries))
{
VSCodeStorageEntries vscodeStorageEntries = JsonSerializer.Deserialize<VSCodeStorageEntries>(entries);
if (vscodeStorageEntries.Entries != null)
{
vscodeStorageEntries.Entries = vscodeStorageEntries.Entries.Where(x => x != null).ToList();
foreach (var entry in vscodeStorageEntries.Entries)
{
bool isWorkspaceFile = false;
var uri = entry.FolderUri;
if (entry.Workspace != null && entry.Workspace.ConfigPath != null)
{
isWorkspaceFile = true;
uri = entry.Workspace.ConfigPath;
}
var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile);
if (workspace != null)
{
results.Add(workspace);
}
}
}
}
}
}
sqliteConnection.Close();
}
}
catch (Exception ex)
{

View File

@@ -99,6 +99,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.1" />
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="6.1.1" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.19" />
<PackageReference Include="ModernWpfUI" Version="0.9.4" />