Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 76 additions & 20 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -50,7 +51,7 @@

// Must use getter to avoid circular dependency
private Updater _updater;
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();

Check warning on line 54 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)

private readonly object _saveSettingsLock = new();

Expand Down Expand Up @@ -148,7 +149,7 @@
ShellCommand.Execute(startInfo);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]

Check warning on line 152 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)
public async void CopyToClipboard(string stringToCopy, bool directCopy = false, bool showDefaultNotification = true)
{
if (string.IsNullOrEmpty(stringToCopy))
Expand Down Expand Up @@ -320,44 +321,98 @@
((PluginJsonStorage<T>)_pluginJsonStorages[type]).Save();
}

public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
private static extern int SHParseDisplayName(
[MarshalAs(UnmanagedType.LPWStr)] string name,
IntPtr bindingContext,
out IntPtr pidl,
uint sfgaoIn,
out uint psfgaoOut
);

[DllImport("shell32.dll")]
private static extern int SHOpenFolderAndSelectItems(
IntPtr pidlFolder,
uint cidl,
[MarshalAs(UnmanagedType.LPArray)] IntPtr[] apidl,
uint dwFlags
);

[DllImport("ole32.dll")]
private static extern void CoTaskMemFree(IntPtr pv);

private void OpenFolderAndSelectItem(string filePath)
{
IntPtr pidlFolder = IntPtr.Zero;
IntPtr pidlFile = IntPtr.Zero;
uint attr;

string folderPath = Path.GetDirectoryName(filePath);

try
{
using var explorer = new Process();
SHParseDisplayName(folderPath, IntPtr.Zero, out pidlFolder, 0, out attr);
SHParseDisplayName(filePath, IntPtr.Zero, out pidlFile, 0, out attr);

if (pidlFolder != IntPtr.Zero && pidlFile != IntPtr.Zero)
{
SHOpenFolderAndSelectItems(pidlFolder, 1, new[] { pidlFile }, 0);
}
}
finally
{
if (pidlFile != IntPtr.Zero)
CoTaskMemFree(pidlFile);
if (pidlFolder != IntPtr.Zero)
CoTaskMemFree(pidlFolder);
}
}

public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null)
{
try
{
string targetPath = fileNameOrFilePath is null
? directoryPath
: Path.IsPathRooted(fileNameOrFilePath)
? fileNameOrFilePath
: Path.Combine(directoryPath, fileNameOrFilePath);

var explorerInfo = _settings.CustomExplorer;
var explorerPath = explorerInfo.Path.Trim().ToLowerInvariant();
var targetPath = FileNameOrFilePath is null
? DirectoryPath
: Path.IsPathRooted(FileNameOrFilePath)
? FileNameOrFilePath
: Path.Combine(DirectoryPath, FileNameOrFilePath);

if (Path.GetFileNameWithoutExtension(explorerPath) == "explorer")
{
// Windows File Manager
explorer.StartInfo = new ProcessStartInfo
if (fileNameOrFilePath is null)
{
FileName = targetPath,
UseShellExecute = true
};
// 폴더만 열기
Process.Start(new ProcessStartInfo
{
FileName = directoryPath,
UseShellExecute = true
})?.Dispose();
}
else
{
// SHOpenFolderAndSelectItems 방식
OpenFolderAndSelectItem(targetPath);
}
}
else
{
// Custom File Manager
explorer.StartInfo = new ProcessStartInfo
// 커스텀 파일 관리자
var shellProcess = new ProcessStartInfo
{
FileName = explorerInfo.Path.Replace("%d", DirectoryPath),
FileName = explorerInfo.Path.Replace("%d", directoryPath),
UseShellExecute = true,
Arguments = FileNameOrFilePath is null
? explorerInfo.DirectoryArgument.Replace("%d", DirectoryPath)
Arguments = fileNameOrFilePath is null
? explorerInfo.DirectoryArgument.Replace("%d", directoryPath)
: explorerInfo.FileArgument
.Replace("%d", DirectoryPath)
.Replace("%d", directoryPath)
.Replace("%f", targetPath)
};
Process.Start(shellProcess)?.Dispose();
}

explorer.Start();
}
catch (Win32Exception ex) when (ex.NativeErrorCode == 2)
{
Expand All @@ -381,6 +436,7 @@
}
}


private void OpenUri(Uri uri, bool? inPrivate = null)
{
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
Expand Down
Loading