Skip to content

Commit

Permalink
Add support to portable vscode base on microsoft/PowerToys#19442
Browse files Browse the repository at this point in the history
  • Loading branch information
taooceros committed Dec 21, 2022
1 parent 3f86b81 commit 546c714
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions VSCodeHelper/VSCodeInstances.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,21 @@ public static void LoadVSCodeInstances()
Instances = new List<VSCodeInstance>();

_systemPath = Environment.GetEnvironmentVariable("PATH") ?? "";
var paths = _systemPath.Split(";");
paths = paths.Where(x => x.Contains("VS Code")).Distinct().ToArray();
var paths = _systemPath.Split(";").Where(x =>
x.Contains("VS Code", StringComparison.OrdinalIgnoreCase) ||
x.Contains("VSCodium", StringComparison.OrdinalIgnoreCase) ||
x.Contains("vscode", StringComparison.OrdinalIgnoreCase));
foreach (var path in paths)
{
if (Directory.Exists(path))
{
var files = Directory.GetFiles(path);
var iconPath = Path.GetDirectoryName(path);
files = files.Where(x => x.Contains("code") && !x.EndsWith(".cmd")).ToArray();
files = files.Where(x =>
(x.Contains("code", StringComparison.OrdinalIgnoreCase) ||
x.Contains("VSCodium", StringComparison.OrdinalIgnoreCase))
&& !x.EndsWith(".cmd", StringComparison.OrdinalIgnoreCase)).ToArray();


if (files.Length > 0)
{
Expand Down Expand Up @@ -105,17 +111,18 @@ public static void LoadVSCodeInstances()

if (version != string.Empty)
{
instance.AppData = Path.Combine(_userAppDataPath, version);
var portableData = Path.Join(iconPath, "data");
instance.AppData = Directory.Exists(portableData) ? Path.Join(portableData, "user-data") : Path.Combine(_userAppDataPath, version);
var iconVSCode = Path.Join(iconPath, $"{version}.exe");

var bitmapIconVscode = Icon.ExtractAssociatedIcon(iconVSCode)?.ToBitmap();

// workspace
var folderIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//folder.png");
var folderIcon = (Bitmap)Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//folder.png");
instance.WorkspaceIconBitMap = Bitmap2BitmapImage(BitmapOverlayToCenter(folderIcon, bitmapIconVscode));

// remote
var monitorIcon = (Bitmap)System.Drawing.Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//monitor.png");
var monitorIcon = (Bitmap)Image.FromFile(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "//Images//monitor.png");

instance.RemoteIconBitMap = Bitmap2BitmapImage(BitmapOverlayToCenter(monitorIcon, bitmapIconVscode));

Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ActionKeyword": "{",
"Name": "VS Code Workspaces",
"Author": "ricardosantos9521",
"Version": "1.1.3",
"Version": "1.2.0",
"Language": "csharp",
"Website": "https://github.com/ricardosantos9521/PowerToys/",
"ExecuteFileName": "Flow.Plugin.VSCodeWorkspaces.dll",
Expand Down

0 comments on commit 546c714

Please sign in to comment.