Skip to content

Commit 118e100

Browse files
Fix opening containing folder for lnk
open parent dir of .lnk instead of its target
1 parent 5f2b944 commit 118e100

File tree

1 file changed

+33
-10
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+33
-10
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,19 @@ public class Win32 : IProgram, IEquatable<Win32>
2525
public string Name { get; set; }
2626
public string UniqueIdentifier { get => _uid; set => _uid = value == null ? string.Empty : value.ToLowerInvariant(); } // For path comparison
2727
public string IcoPath { get; set; }
28+
/// <summary>
29+
/// Path of the file. It's the path of .lnk or .url for .lnk and .url.
30+
/// </summary>
2831
public string FullPath { get; set; }
32+
/// <summary>
33+
/// Path of the excutable for .lnk, or the URL for .url.
34+
/// </summary>
2935
public string LnkResolvedPath { get; set; }
36+
/// <summary>
37+
/// Path of the actual executable file.
38+
/// </summary>
39+
public string ExecutablePath => LnkResolvedPath ?? FullPath;
40+
public string WorkingDir => Directory.GetParent(ExecutablePath)?.FullName ?? string.Empty;
3041
public string ParentDirectory { get; set; }
3142
public string ExecutableName { get; set; }
3243
public string Description { get; set; }
@@ -97,10 +108,23 @@ public Result Result(string query, IPublicAPI api)
97108
matchResult.MatchData = new List<int>();
98109
}
99110

111+
string subtitle = string.Empty;
112+
if (!Main._settings.HideAppsPath)
113+
{
114+
if (Extension(FullPath) == UrlExtension)
115+
{
116+
subtitle = LnkResolvedPath;
117+
}
118+
else
119+
{
120+
subtitle = FullPath;
121+
}
122+
}
123+
100124
var result = new Result
101125
{
102126
Title = title,
103-
SubTitle = Main._settings.HideAppsPath ? string.Empty : LnkResolvedPath ?? FullPath,
127+
SubTitle = subtitle,
104128
IcoPath = IcoPath,
105129
Score = matchResult.Score,
106130
TitleHighlightData = matchResult.MatchData,
@@ -116,8 +140,8 @@ public Result Result(string query, IPublicAPI api)
116140

117141
var info = new ProcessStartInfo
118142
{
119-
FileName = LnkResolvedPath ?? FullPath,
120-
WorkingDirectory = ParentDirectory,
143+
FileName = ExecutablePath,
144+
WorkingDirectory = WorkingDir,
121145
UseShellExecute = true,
122146
Verb = runAsAdmin ? "runas" : null
123147
};
@@ -143,8 +167,8 @@ public List<Result> ContextMenus(IPublicAPI api)
143167
{
144168
var info = new ProcessStartInfo
145169
{
146-
FileName = FullPath,
147-
WorkingDirectory = ParentDirectory,
170+
FileName = ExecutablePath,
171+
WorkingDirectory = WorkingDir,
148172
UseShellExecute = true
149173
};
150174

@@ -162,8 +186,8 @@ public List<Result> ContextMenus(IPublicAPI api)
162186
{
163187
var info = new ProcessStartInfo
164188
{
165-
FileName = FullPath,
166-
WorkingDirectory = ParentDirectory,
189+
FileName = ExecutablePath,
190+
WorkingDirectory = WorkingDir,
167191
Verb = "runas",
168192
UseShellExecute = true
169193
};
@@ -250,8 +274,7 @@ private static Win32 LnkProgram(string path)
250274
var extension = Extension(target);
251275
if (extension == ExeExtension && File.Exists(target))
252276
{
253-
program.LnkResolvedPath = program.FullPath;
254-
program.FullPath = Path.GetFullPath(target).ToLowerInvariant();
277+
program.LnkResolvedPath = Path.GetFullPath(target);
255278
program.ExecutableName = Path.GetFileName(target);
256279

257280
var description = _helper.description;
@@ -550,7 +573,7 @@ public static IEnumerable<T> DistinctBy<T, R>(IEnumerable<T> source, Func<T, R>
550573

551574
private static IEnumerable<Win32> ProgramsHasher(IEnumerable<Win32> programs)
552575
{
553-
return programs.GroupBy(p => p.FullPath.ToLowerInvariant())
576+
return programs.GroupBy(p => p.ExecutablePath.ToLowerInvariant())
554577
.AsParallel()
555578
.SelectMany(g =>
556579
{

0 commit comments

Comments
 (0)