@@ -8,20 +8,26 @@ namespace PasteIntoFile
88{
99 public class RegistryUtil
1010 {
11- // Please note that registry keys are also created by installer
12- // and removed upon uninstall
11+ // Please note that registry keys are also created by installer and removed upon uninstall
12+ // Always keep the "Installer/PasteIntoFile.wxs" up to date with the keys used below!
13+
1314
1415 private static string PRIMARY_KEY_NAME = "PasteIntoFile" ;
16+
17+ /// <summary>
18+ /// Opens a number of class sub keys according to the requested type.
19+ /// Passing type=null (default) will return all keys for all types
20+ /// </summary>
21+ /// <param name="type">Class type, one of "Directory", "*" or null</param>
22+ /// <returns>List of registry keys</returns>
1523 private static IEnumerable < RegistryKey > OpenClassKeys ( string type = null ) {
16- if ( type == null ) // return all class type keys (dirs and files)
17- {
18- return OpenClassKeys ( "Directory" ) . Concat ( OpenClassKeys ( "*" ) ) ;
19- }
20- var node = Registry . CurrentUser . CreateSubKey ( @"Software\Classes\" + type ) ;
21- return new [ ] {
22- node . CreateSubKey ( @"Background\shell" ) ,
23- node . CreateSubKey ( @"shell" ) ,
24- } ;
24+ var classes = Registry . CurrentUser . CreateSubKey ( @"Software\Classes" ) ;
25+ var keys = new List < RegistryKey > ( ) ;
26+ if ( type == null || type == "Directory" )
27+ keys . AddRange ( new [ ] { classes . CreateSubKey ( @"Directory\shell" ) , classes . CreateSubKey ( @"Directory\Background\shell" ) } ) ;
28+ if ( type == null || type == "*" )
29+ keys . Add ( classes . CreateSubKey ( @"*\shell" ) ) ;
30+ return keys ;
2531 }
2632
2733
0 commit comments