예제 #1
0
        private FolderOrFile ConvertToHierachy(string rootName, string prefixToRemove, Func <string, bool> predicate)
        {
            var rootFolder = new FolderOrFile(rootName);

            files.Sort();

            foreach (var file in files.Where(predicate))
            {
                var relativeFileName = file.Replace(prefixToRemove, "");
                if (relativeFileName.Contains(@"\"))
                {
                    FolderOrFile folder;
                    var          directory = GetDirectory(relativeFileName);
                    if (rootFolder.Children.Any(x => x.Name == directory))
                    {
                        folder = rootFolder.Children.First(x => x.Name == directory);
                    }
                    else
                    {
                        folder = new FolderOrFile(directory);
                        rootFolder.Children.Add(folder);
                    }
                    folder.Children.Add(new FolderOrFile(GetFile(relativeFileName)));
                }
                else
                {
                    rootFolder.Children.Add(new FolderOrFile(relativeFileName));
                }
            }
            return(rootFolder);
        }
예제 #2
0
        private bool AddContextMenuToFiles(FolderOrFile folderOrFile, string name, string command)
        {
            RegistryKey regmenu = null;
            RegistryKey regcmd = null;
            string keyName;
            switch (folderOrFile)
            {
                case FolderOrFile.File:
                    keyName = "*\\shell\\" + name;
                    break;
                case FolderOrFile.Folder:
                    keyName = "Directory\\shell\\" + name;
                    break;
                default:
                    throw new NotImplementedException();
            }

            bool result;
            try
            {
                regmenu = Registry.ClassesRoot.CreateSubKey(keyName);
                regcmd = Registry.ClassesRoot.CreateSubKey(keyName + "\\command");
                regcmd.SetValue("", command);
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (regmenu != null)
                    regmenu.Dispose();
                if (regcmd != null)
                    regcmd.Dispose();
            }

            return result;
        }
예제 #3
0
 private bool RemoveContextMenuOfFiles(FolderOrFile folderOrFile, string name)
 {
     try
     {
         string keyName;
         switch (folderOrFile)
         {
             case FolderOrFile.File:
                 keyName = "*\\shell\\" + name;
                 break;
             case FolderOrFile.Folder:
                 keyName = "Directory\\shell\\" + name;
                 break;
             default:
                 throw new NotImplementedException();
         }
         Registry.ClassesRoot.DeleteSubKeyTree(keyName);
         return true;
     }
     catch
     {
         return false;
     }
 }