8
8
using System . Linq ;
9
9
using System . Net ;
10
10
using System . Runtime . CompilerServices ;
11
- using System . Runtime . InteropServices ;
12
11
using System . Threading ;
13
12
using System . Threading . Tasks ;
14
13
using System . Windows ;
15
- using System . Windows . Input ;
16
14
using System . Windows . Media ;
17
15
using CommunityToolkit . Mvvm . DependencyInjection ;
18
16
using Flow . Launcher . Core ;
@@ -320,88 +318,44 @@ public void SavePluginSettings()
320
318
321
319
( ( PluginJsonStorage < T > ) _pluginJsonStorages [ type ] ) . Save ( ) ;
322
320
}
323
-
324
- [ DllImport ( "shell32.dll" , CharSet = CharSet . Unicode ) ]
325
- private static extern int SHParseDisplayName (
326
- [ MarshalAs ( UnmanagedType . LPWStr ) ] string name ,
327
- IntPtr bindingContext ,
328
- out IntPtr pidl ,
329
- uint sfgaoIn ,
330
- out uint psfgaoOut
331
- ) ;
332
-
333
- [ DllImport ( "shell32.dll" ) ]
334
- private static extern int SHOpenFolderAndSelectItems (
335
- IntPtr pidlFolder ,
336
- uint cidl ,
337
- [ MarshalAs ( UnmanagedType . LPArray ) ] IntPtr [ ] apidl ,
338
- uint dwFlags
339
- ) ;
340
-
341
- [ DllImport ( "ole32.dll" ) ]
342
- private static extern void CoTaskMemFree ( IntPtr pv ) ;
343
-
344
- private void OpenFolderAndSelectItem ( string filePath )
345
- {
346
- IntPtr pidlFolder = IntPtr . Zero ;
347
- IntPtr pidlFile = IntPtr . Zero ;
348
- uint attr ;
349
-
350
- string folderPath = Path . GetDirectoryName ( filePath ) ;
351
-
352
- try
353
- {
354
- SHParseDisplayName ( folderPath , IntPtr . Zero , out pidlFolder , 0 , out attr ) ;
355
- SHParseDisplayName ( filePath , IntPtr . Zero , out pidlFile , 0 , out attr ) ;
356
-
357
- if ( pidlFolder != IntPtr . Zero && pidlFile != IntPtr . Zero )
358
- {
359
- SHOpenFolderAndSelectItems ( pidlFolder , 1 , new [ ] { pidlFile } , 0 ) ;
360
- }
361
- }
362
- finally
363
- {
364
- if ( pidlFile != IntPtr . Zero )
365
- CoTaskMemFree ( pidlFile ) ;
366
- if ( pidlFolder != IntPtr . Zero )
367
- CoTaskMemFree ( pidlFolder ) ;
368
- }
369
- }
370
321
371
322
public void OpenDirectory ( string directoryPath , string fileNameOrFilePath = null )
372
323
{
373
324
try
374
325
{
375
- string targetPath = fileNameOrFilePath is null
326
+ var explorerInfo = _settings . CustomExplorer ;
327
+ var explorerPath = explorerInfo . Path . Trim ( ) . ToLowerInvariant ( ) ;
328
+ var targetPath = fileNameOrFilePath is null
376
329
? directoryPath
377
330
: Path . IsPathRooted ( fileNameOrFilePath )
378
331
? fileNameOrFilePath
379
332
: Path . Combine ( directoryPath , fileNameOrFilePath ) ;
380
333
381
- var explorerInfo = _settings . CustomExplorer ;
382
- var explorerPath = explorerInfo . Path . Trim ( ) . ToLowerInvariant ( ) ;
383
-
384
334
if ( Path . GetFileNameWithoutExtension ( explorerPath ) == "explorer" )
385
335
{
336
+ // Windows File Manager
386
337
if ( fileNameOrFilePath is null )
387
338
{
388
- // 폴더만 열기
389
- Process . Start ( new ProcessStartInfo
339
+ // Only Open the directory
340
+ using var explorer = new Process ( ) ;
341
+ explorer . StartInfo = new ProcessStartInfo
390
342
{
391
343
FileName = directoryPath ,
392
344
UseShellExecute = true
393
- } ) ? . Dispose ( ) ;
345
+ } ;
346
+ explorer . Start ( ) ;
394
347
}
395
348
else
396
349
{
397
- // SHOpenFolderAndSelectItems 방식
398
- OpenFolderAndSelectItem ( targetPath ) ;
350
+ // Open the directory and select the file
351
+ Win32Helper . OpenFolderAndSelectFile ( targetPath ) ;
399
352
}
400
353
}
401
354
else
402
355
{
403
- // 커스텀 파일 관리자
404
- var shellProcess = new ProcessStartInfo
356
+ // Custom File Manager
357
+ using var explorer = new Process ( ) ;
358
+ explorer . StartInfo = new ProcessStartInfo
405
359
{
406
360
FileName = explorerInfo . Path . Replace ( "%d" , directoryPath ) ,
407
361
UseShellExecute = true ,
@@ -411,7 +365,7 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
411
365
. Replace ( "%d" , directoryPath )
412
366
. Replace ( "%f" , targetPath )
413
367
} ;
414
- Process . Start ( shellProcess ) ? . Dispose ( ) ;
368
+ explorer . Start ( ) ;
415
369
}
416
370
}
417
371
catch ( Win32Exception ex ) when ( ex . NativeErrorCode == 2 )
0 commit comments