mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Refactor OpenDirectory method to improve path handling and streamline process start logic
This commit is contained in:
parent
bb25c53f08
commit
050c2cb647
1 changed files with 36 additions and 12 deletions
|
|
@ -314,24 +314,48 @@ namespace Flow.Launcher
|
||||||
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
|
public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
|
||||||
{
|
{
|
||||||
using var explorer = new Process();
|
string targetPath;
|
||||||
var explorerInfo = _settings.CustomExplorer;
|
|
||||||
|
|
||||||
explorer.StartInfo = new ProcessStartInfo
|
if (fileNameOrFilePath is null)
|
||||||
{
|
{
|
||||||
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
|
targetPath = directoryPath;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
targetPath = Path.IsPathRooted(fileNameOrFilePath)
|
||||||
|
? fileNameOrFilePath
|
||||||
|
: Path.Combine(directoryPath, fileNameOrFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
var explorerInfo = _settings.CustomExplorer;
|
||||||
|
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
|
||||||
|
|
||||||
|
// If explorer.exe, ignore and pass only the path to Shell
|
||||||
|
if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
|
||||||
|
{
|
||||||
|
Process.Start(new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = targetPath, // Not explorer, Only path.
|
||||||
|
UseShellExecute = true // Must be true to open folder
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom File Manager
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = explorerInfo.Path.Replace("%d", directoryPath),
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
Arguments = FileNameOrFilePath is null
|
Arguments = fileNameOrFilePath is null
|
||||||
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
|
? explorerInfo.DirectoryArgument.Replace("%d", directoryPath)
|
||||||
: explorerInfo.FileArgument
|
: explorerInfo.FileArgument
|
||||||
.Replace("%d", DirectoryPath)
|
.Replace("%d", directoryPath)
|
||||||
.Replace("%f",
|
.Replace("%f", targetPath)
|
||||||
Path.IsPathRooted(FileNameOrFilePath) ? FileNameOrFilePath : Path.Combine(DirectoryPath, FileNameOrFilePath)
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
explorer.Start();
|
|
||||||
|
Process.Start(psi);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenUri(Uri uri, bool? inPrivate = null)
|
private void OpenUri(Uri uri, bool? inPrivate = null)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue