mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
* #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:
committed by
GitHub
parent
167ec5a3a8
commit
758a21a22f
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user