From 3f64c770f99c558f8fe5237c34a03e579cc28b98 Mon Sep 17 00:00:00 2001 From: ricardo Date: Wed, 5 Jan 2022 00:23:21 +0000 Subject: [PATCH 1/4] #15247 Powertoys Run | VSCodeWorkspaces- add support for vscode 1.64 new workspace.json file --- .../VSCodeStorageWorkspaceFile.cs | 16 ++++++++++ .../WorkspacesHelper/VSCodeWorkspacesApi.cs | 31 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs new file mode 100644 index 000000000000..89bbe2c83f5e --- /dev/null +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs @@ -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\Backups\workspaces + public class VSCodeStorageWorkspaceFile + { + [JsonPropertyName("folderWorkspaceInfos")] + public List FolderWorkspaceInfos { get; set; } + } +} diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs index 635b96c7b1c4..c33da4906d52 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs @@ -62,6 +62,9 @@ public List Workspaces // storage.json contains opened Workspaces var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json"); + // Backups/workspace.json - vscode v1.64 or later + var vscode_storage_workspaces = Path.Combine(vscodeInstance.AppData, "Backups/workspaces.json"); + if (File.Exists(vscode_storage)) { var fileContent = File.ReadAllText(vscode_storage); @@ -70,7 +73,7 @@ public List Workspaces { VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize(fileContent); - if (vscodeStorageFile != null) + if (vscodeStorageFile != null && vscodeStorageFile.OpenedPathsList != null) { // for previous versions of vscode if (vscodeStorageFile.OpenedPathsList.Workspaces3 != null) @@ -98,6 +101,32 @@ public List Workspaces uri = entry.Workspace.ConfigPath; } + var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile); + if (workspace != null) + { + results.Add(workspace); + } + } + } + } + else if (File.Exists(vscode_storage_workspaces)) + { + // vscode 1.64 or later + fileContent = File.ReadAllText(vscode_storage_workspaces); + VSCodeStorageWorkspaceFile vscodeStorageWorkspaceFile = JsonSerializer.Deserialize(fileContent); + + if (vscodeStorageWorkspaceFile.FolderWorkspaceInfos != null) + { + foreach (var entry in vscodeStorageWorkspaceFile.FolderWorkspaceInfos) + { + 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) { From c18feec46382f9d281822afe81c28bcd91f483ab Mon Sep 17 00:00:00 2001 From: ricardo Date: Thu, 6 Jan 2022 21:58:22 +0000 Subject: [PATCH 2/4] Get previous open workspaces for sqlite file --- ...werToys.Run.Plugin.VSCodeWorkspaces.csproj | 207 +++++++++--------- ...rkspaceFile.cs => VSCodeStorageEntries.cs} | 8 +- .../WorkspacesHelper/VSCodeWorkspaceEntry.cs | 3 + .../WorkspacesHelper/VSCodeWorkspacesApi.cs | 61 ++++-- .../PowerLauncher/PowerLauncher.csproj | 1 + 5 files changed, 152 insertions(+), 128 deletions(-) rename src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/{VSCodeStorageWorkspaceFile.cs => VSCodeStorageEntries.cs} (58%) diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj index 692fa2e53a5b..7d8522242f18 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/Community.PowerToys.Run.Plugin.VSCodeWorkspaces.csproj @@ -1,108 +1,109 @@  - + - - netcoreapp3.1 - {4D971245-7A70-41D5-BAA0-DDB5684CAF51} - Properties - Community.PowerToys.Run.Plugin.VSCodeWorkspaces - Community.PowerToys.Run.Plugin.VSCodeWorkspaces - $(Version).0 - true - false - false - x64 - + + netcoreapp3.1 + {4D971245-7A70-41D5-BAA0-DDB5684CAF51} + Properties + Community.PowerToys.Run.Plugin.VSCodeWorkspaces + Community.PowerToys.Run.Plugin.VSCodeWorkspaces + $(Version).0 + true + false + false + x64 + - - true - ..\..\..\..\..\x64\Debug\modules\launcher\Plugins\VSCodeWorkspaces\ - DEBUG;TRACE - full - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - 4 - false - true - + + true + ..\..\..\..\..\x64\Debug\modules\launcher\Plugins\VSCodeWorkspaces\ + DEBUG;TRACE + full + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + 4 + false + true + - - ..\..\..\..\..\x64\Release\modules\launcher\Plugins\VSCodeWorkspaces\ - TRACE - true - pdbonly - x64 - 7.3 - prompt - MinimumRecommendedRules.ruleset - 4 - true - - - - - PreserveNewest - - - - - - - - - - - GlobalSuppressions.cs - - - StyleCop.json - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd - - - - - - Resources.resx - True - True - - - - - - Resources.Designer.cs - ResXFileCodeGenerator - - - - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - + + ..\..\..\..\..\x64\Release\modules\launcher\Plugins\VSCodeWorkspaces\ + TRACE + true + pdbonly + x64 + 7.3 + prompt + MinimumRecommendedRules.ruleset + 4 + true + + + + + PreserveNewest + + + + + + + + + + + GlobalSuppressions.cs + + + StyleCop.json + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + C:\Program Files (x86)\Windows Kits\10\References\10.0.18362.0\Windows.Foundation.UniversalApiContract\8.0.0.0\Windows.Foundation.UniversalApiContract.winmd + + + + + + Resources.resx + True + True + + + + + + Resources.Designer.cs + ResXFileCodeGenerator + + + + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + \ No newline at end of file diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageEntries.cs similarity index 58% rename from src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs rename to src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageEntries.cs index 89bbe2c83f5e..2e8f7658be66 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageWorkspaceFile.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeStorageEntries.cs @@ -7,10 +7,10 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper { - // v1.64 uses AppData\Roaming\Code\Backups\workspaces - public class VSCodeStorageWorkspaceFile + // v1.64 uses AppData\Roaming\Code\User\globalStorage\state.vscdb - history.recentlyOpenedPathsList + public class VSCodeStorageEntries { - [JsonPropertyName("folderWorkspaceInfos")] - public List FolderWorkspaceInfos { get; set; } + [JsonPropertyName("entries")] + public List Entries { get; set; } } } diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspaceEntry.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspaceEntry.cs index 1f245489bc3c..6493c412913d 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspaceEntry.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspaceEntry.cs @@ -14,6 +14,9 @@ public class VSCodeWorkspaceEntry [JsonPropertyName("label")] public string Label { get; set; } + [JsonPropertyName("remoteAuthority")] + public string RemoteAuthority { get; set; } + [JsonPropertyName("workspace")] public VSCodeWorkspaceProperty Workspace { get; set; } } diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs index c33da4906d52..8fd3471bcef6 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs @@ -8,6 +8,7 @@ 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 @@ public VSCodeWorkspacesApi() { } - 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 @@ private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance 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,8 +63,8 @@ public List Workspaces // storage.json contains opened Workspaces var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json"); - // Backups/workspace.json - vscode v1.64 or later - var vscode_storage_workspaces = Path.Combine(vscodeInstance.AppData, "Backups/workspaces.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)) { @@ -109,31 +110,49 @@ public List Workspaces } } } - else if (File.Exists(vscode_storage_workspaces)) + else if (File.Exists(vscode_storage_db)) { - // vscode 1.64 or later - fileContent = File.ReadAllText(vscode_storage_workspaces); - VSCodeStorageWorkspaceFile vscodeStorageWorkspaceFile = JsonSerializer.Deserialize(fileContent); + var sqliteConnection = new SqliteConnection($"Data Source={vscode_storage_db};mode=ReadOnly"); + sqliteConnection.Open(); - if (vscodeStorageWorkspaceFile.FolderWorkspaceInfos != null) + if (sqliteConnection.State == System.Data.ConnectionState.Open) { - foreach (var entry in vscodeStorageWorkspaceFile.FolderWorkspaceInfos) - { - bool isWorkspaceFile = false; - var uri = entry.FolderUri; - if (entry.Workspace != null && entry.Workspace.ConfigPath != null) - { - isWorkspaceFile = true; - uri = entry.Workspace.ConfigPath; - } + var sqlite_cmd = sqliteConnection.CreateCommand(); + sqlite_cmd.CommandText = "SELECT value FROM ItemTable WHERE key LIKE 'history.recentlyOpenedPathsList'"; - var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile); - if (workspace != null) + var sqlite_datareader = sqlite_cmd.ExecuteReader(); + + if (sqlite_datareader.Read()) + { + string entries = sqlite_datareader.GetString(0); + if (!string.IsNullOrEmpty(entries)) { - results.Add(workspace); + VSCodeStorageEntries vscodeStorageEntries = JsonSerializer.Deserialize(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) diff --git a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj index b9291a19137f..c50ad823a1fc 100644 --- a/src/modules/launcher/PowerLauncher/PowerLauncher.csproj +++ b/src/modules/launcher/PowerLauncher/PowerLauncher.csproj @@ -99,6 +99,7 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + From b77b5413c60949c0808702fbe136bb08f50e5279 Mon Sep 17 00:00:00 2001 From: ricardo Date: Thu, 6 Jan 2022 22:22:02 +0000 Subject: [PATCH 3/4] check-spelling-bot Report fix --- .github/actions/spell-check/expect.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index e761dcbed5cf..87491d3788ad 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -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 From d3d2a3507b1f828a3c416822f70d60546975e285 Mon Sep 17 00:00:00 2001 From: ricardo Date: Mon, 17 Jan 2022 19:10:42 +0000 Subject: [PATCH 4/4] add dlls to installer and set SqliteConnection to readonly --- installer/PowerToysSetup/Product.wxs | 2 +- .../WorkspacesHelper/VSCodeWorkspacesApi.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/PowerToysSetup/Product.wxs b/installer/PowerToysSetup/Product.wxs index 55c2a7eca581..52f4393f308d 100644 --- a/installer/PowerToysSetup/Product.wxs +++ b/installer/PowerToysSetup/Product.wxs @@ -1330,7 +1330,7 @@ - + diff --git a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs index 8fd3471bcef6..050fef95d6ee 100644 --- a/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs +++ b/src/modules/launcher/Plugins/Community.PowerToys.Run.Plugin.VSCodeWorkspaces/WorkspacesHelper/VSCodeWorkspacesApi.cs @@ -112,7 +112,7 @@ public List Workspaces } else if (File.Exists(vscode_storage_db)) { - var sqliteConnection = new SqliteConnection($"Data Source={vscode_storage_db};mode=ReadOnly"); + var sqliteConnection = new SqliteConnection($"Data Source={vscode_storage_db};Mode=ReadOnly;"); sqliteConnection.Open(); if (sqliteConnection.State == System.Data.ConnectionState.Open)