Skip to content

Commit ac8a979

Browse files
authored
Merge pull request #3552 from onesounds/250517-FixZombieExplorer
Fix prevent zombie explorer.exe processes when opening folders
2 parents bb25c53 + 87d11c0 commit ac8a979

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,37 @@ public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null
318318
{
319319
using var explorer = new Process();
320320
var explorerInfo = _settings.CustomExplorer;
321-
322-
explorer.StartInfo = new ProcessStartInfo
321+
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
322+
var targetPath = FileNameOrFilePath is null
323+
? DirectoryPath
324+
: Path.IsPathRooted(FileNameOrFilePath)
325+
? FileNameOrFilePath
326+
: Path.Combine(DirectoryPath, FileNameOrFilePath);
327+
328+
if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
323329
{
324-
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
325-
UseShellExecute = true,
326-
Arguments = FileNameOrFilePath is null
327-
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
328-
: explorerInfo.FileArgument
329-
.Replace("%d", DirectoryPath)
330-
.Replace("%f",
331-
Path.IsPathRooted(FileNameOrFilePath) ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath)
332-
)
333-
};
330+
// Windows File Manager
331+
// We should ignore and pass only the path to Shell to prevent zombie explorer.exe processes
332+
explorer.StartInfo = new ProcessStartInfo
333+
{
334+
FileName = targetPath, // Not explorer, Only path.
335+
UseShellExecute = true // Must be true to open folder
336+
};
337+
}
338+
else
339+
{
340+
// Custom File Manager
341+
explorer.StartInfo = new ProcessStartInfo
342+
{
343+
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
344+
UseShellExecute = true,
345+
Arguments = FileNameOrFilePath is null
346+
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
347+
: explorerInfo.FileArgument
348+
.Replace("%d", DirectoryPath)
349+
.Replace("%f", targetPath)
350+
};
351+
}
334352
explorer.Start();
335353
}
336354

0 commit comments

Comments
 (0)