mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-12 18:29:24 +08:00
[Run][VSCode]Fix plugin initialization failing with trailing backslash in path (#29547)
This commit is contained in:
parent
4875564a59
commit
d5b9c31847
@ -71,16 +71,23 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
if (Directory.Exists(path))
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(path)
|
||||
.Where(x => (x.Contains("code", StringComparison.OrdinalIgnoreCase) || x.Contains("codium", StringComparison.OrdinalIgnoreCase))
|
||||
&& !x.EndsWith(".cmd", StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
|
||||
var iconPath = Path.GetDirectoryName(path);
|
||||
// Remove the trailing backslash to always get the correct path
|
||||
var iconPath = Path.GetDirectoryName(path.TrimEnd('\\'));
|
||||
|
||||
if (files.Length > 0)
|
||||
if (files.Length == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var file = files[0];
|
||||
var version = string.Empty;
|
||||
|
||||
@ -115,34 +122,40 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper
|
||||
instance.VSCodeVersion = VSCodeVersion.Insiders;
|
||||
}
|
||||
|
||||
if (version != string.Empty)
|
||||
if (string.IsNullOrEmpty(version))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var portableData = Path.Join(iconPath, "data");
|
||||
instance.AppData = Directory.Exists(portableData) ? Path.Join(portableData, "user-data") : Path.Combine(_userAppDataPath, version);
|
||||
|
||||
var vsCodeIconPath = Path.Join(iconPath, $"{version}.exe");
|
||||
if (!File.Exists(vsCodeIconPath))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var vsCodeIcon = Icon.ExtractAssociatedIcon(vsCodeIconPath);
|
||||
|
||||
if (vsCodeIcon != null)
|
||||
if (vsCodeIcon == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
using var vsCodeIconBitmap = vsCodeIcon.ToBitmap();
|
||||
|
||||
// workspace
|
||||
// Workspace
|
||||
using var folderIcon = (Bitmap)Image.FromFile(Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images//folder.png"));
|
||||
using var bitmapFolderIcon = BitmapOverlayToCenter(folderIcon, vsCodeIconBitmap);
|
||||
instance.WorkspaceIconBitMap = Bitmap2BitmapImage(bitmapFolderIcon);
|
||||
|
||||
// remote
|
||||
// Remote
|
||||
using var monitorIcon = (Bitmap)Image.FromFile(Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images//monitor.png"));
|
||||
using var bitmapMonitorIcon = BitmapOverlayToCenter(monitorIcon, vsCodeIconBitmap);
|
||||
instance.RemoteIconBitMap = Bitmap2BitmapImage(bitmapMonitorIcon);
|
||||
}
|
||||
|
||||
Instances.Add(instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user