Skip to content

Commit

Permalink
fix: 修复带环境变量的快捷方式的索引问题
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Sep 11, 2024
1 parent da6ca9d commit dae4e4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System;
using System.IO;

namespace CurvaLauncher.Apis
{
Expand Down Expand Up @@ -87,6 +88,15 @@ enum SHGFI : uint

public static ImageSource? GetEmbededIconImage(string path, int iconSize, int? iconIndex)
{
if (path.Contains('%'))
{
path = Environment.ExpandEnvironmentVariables(path);
}

if (!File.Exists(path))
{
return null;
}

// https://github.com/CoenraadS/Windows-Control-Panel-Items/
// https://gist.github.com/jnm2/79ed8330ceb30dea44793e3aa6c03f5b
Expand Down Expand Up @@ -161,6 +171,16 @@ enum SHGFI : uint

public static ImageSource? GetAssociatedIconImage(string path, bool large)
{
if (path.Contains('%'))
{
path = Environment.ExpandEnvironmentVariables(path);
}

if (!File.Exists(path))
{
return null;
}

SHFILEINFO shFileInfo = new();
SHGFI flags = SHGFI.Icon;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ private ImageApi() { }

public ImageSource? GetEmbededIconImage(string filename, int iconSize, int? iconIndex)
{
if (!File.Exists(filename))
return null;

try
{
return FileIconHelper.GetEmbededIconImage(filename, iconSize, iconIndex);
Expand All @@ -37,9 +34,6 @@ private ImageApi() { }

public ImageSource? GetAssociatedIconImage(string filename, int iconSize)
{
if (!File.Exists(filename))
return null;

try
{
return FileIconHelper.GetAssociatedIconImage(filename, iconSize > 32);
Expand All @@ -52,9 +46,6 @@ private ImageApi() { }

public ImageSource? GetFileIcon(string filename, int iconSize)
{
if (!File.Exists(filename))
return null;

try
{
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public override Task InitializeAsync()
var ext = Path.GetExtension(target.FileName);
if (!string.Equals(ext, ".exe", StringComparison.OrdinalIgnoreCase))
return null;
if (!File.Exists(target.FileName))
if (!File.Exists(Environment.ExpandEnvironmentVariables(target.FileName)))
return null;

var name = Path.GetFileNameWithoutExtension(shortcut);
Expand Down

0 comments on commit dae4e4c

Please sign in to comment.