1- using System . Diagnostics ;
1+ using System ;
2+ using System . Diagnostics ;
3+ using System . Runtime . InteropServices ;
24using System . Windows . Media ;
35using CurvaLauncher . Views . Dialogs ;
46
57namespace CurvaLauncher . Apis
68{
79 public class CommonApi : ICommonApi
810 {
11+ [ DllImport ( "shell32.dll" , ExactSpelling = true ) ]
12+ static extern void ILFree ( IntPtr pidlList ) ;
13+
14+ [ DllImport ( "shell32.dll" , CharSet = CharSet . Unicode ) ]
15+ static extern IntPtr ILCreateFromPathW ( [ MarshalAs ( UnmanagedType . LPWStr ) ] string pszPath ) ;
16+
17+ [ DllImport ( "shell32.dll" ) ]
18+ static extern int SHOpenFolderAndSelectItems ( IntPtr pidlList , uint cidl , IntPtr [ ] ? apidl , uint dwFlags ) ;
19+
20+ [ DllImport ( "shell32.dll" , CharSet = CharSet . Unicode ) ]
21+ public static extern bool SHObjectProperties ( IntPtr hwnd , uint shopObjectType , string pszObjectName , string ? pszPropertyPage ) ;
22+
23+ [ DllImport ( "shell32.dll" , CharSet = CharSet . Unicode ) ]
24+ public static extern int ShellExecute ( IntPtr hwnd , string lpOperation , string lpFile , string ? lpParameters , string ? lpDirectory , int nShowCmd ) ;
25+
926 private CommonApi ( ) { }
1027
1128 public static CommonApi Instance { get ; } = new ( ) ;
@@ -24,6 +41,29 @@ public void OpenExecutable(string file) => Process.Start(
2441 UseShellExecute = false
2542 } ) ;
2643
44+ public void ShowInFileExplorer ( string path )
45+ {
46+ IntPtr pidlList = ILCreateFromPathW ( path ) ;
47+ if ( pidlList == IntPtr . Zero )
48+ {
49+ throw new ArgumentException ( "Invalid path" ) ;
50+ }
51+
52+ try
53+ {
54+ SHOpenFolderAndSelectItems ( pidlList , 0 , null , 0 ) ;
55+ }
56+ finally
57+ {
58+ ILFree ( pidlList ) ;
59+ }
60+ }
61+
62+ public void ShowPropertiesWindow ( string path )
63+ {
64+ bool invoked = SHObjectProperties ( IntPtr . Zero , 2 , path , null ) ;
65+ }
66+
2767 public void ShowImage ( ImageSource image , ImageOptions options )
2868 {
2969 new SimpleImageDialog ( image , options )
0 commit comments