/// <summary> /// From http://www.fluxbytes.com/csharp/unzipping-files-using-shell32-in-c/ but with /// args packed in object array so can be called from new STA Thread in UnZipFromMTAThread(). /// </summary> /// <param name="param">object array containing: [string zipFile, string destinationFolderPath]</param> private static void UnZip(string zipFile, string folderPath) { if (!File.Exists(zipFile)) { throw new FileNotFoundException(); } if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } // implemented according to https://stackoverflow.com/a/26717274 // using reflection, rather than referencing specific types with specific versions\libraries Type shellAppType = Type.GetTypeFromProgID("Shell.Application"); object objShell = Activator.CreateInstance(shellAppType); Folder destinationFolder = (Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, objShell, new[] { folderPath }); Folder sourceFile = (Folder)shellAppType.InvokeMember("NameSpace", System.Reflection.BindingFlags.InvokeMethod, null, objShell, new[] { zipFile }); FolderItems items = sourceFile.Items(); // Flags are: No progress displayed, Respond with 'Yes to All' for any dialog, no UI on error // I added 1024 although not sure it's relevant with Zip files. // See https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 destinationFolder.CopyHere(items, 4 | 16 | 1024); }
public void DisposeItems() { FolderItems.DisposeAll(); ArchiveFileItems.DisposeAll(); ImageFileItems.DisposeAll(); EBookFileItems.DisposeAll(); }
private void AddItems(IEnumerable <CatalogItemModel> items) { foreach (var item in items) { FolderItems.Add(item); } }
public static List <ExplorerPaths> GetExplorerFiles() { string windowName; List <ExplorerPaths> ret = new List <ExplorerPaths>(); ShellWindows winClass = new ShellWindows(); int cnt = 0; foreach (InternetExplorer window in winClass) { windowName = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (windowName.ToLowerInvariant() == "explorer") { var doc = (IShellFolderViewDual2)window.Document; ExplorerPaths expl = new ExplorerPaths(cnt++, doc.Folder.Title); FolderItems items = doc.SelectedItems(); foreach (FolderItem item in items) { expl.Paths.Add(item.Path); } ret.Add(expl); } } return(ret); }
internal void Refresh() { folderItems = folderItems.EnsureDispose(); ClearFolders(); lazyChildren = new LazyLoadingList(LoadChildren); Children = lazyChildren; }
protected override void StopBusiness() { base.StopBusiness(); if (!FolderItems.Any()) { IsEmpty = true; } }
/// <summary> /// Shells the copy to. /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> private static void ShellCopyTo(string from, string to) { Shell sc = new Shell(); Folder SrcFolder = sc.NameSpace(from); Folder DestFolder = sc.NameSpace(to); FolderItems items = SrcFolder.Items(); DestFolder.CopyHere(items, 20); }
private bool Undelete() { TextBlockControl.Visibility = Visibility.Visible; if (DeletedFiles.Count == 0) { topTextBoxClass.messageDisplayStart("No more files to undelete.", 5); return(false); } string LastDeleted = DeletedFiles.Pop(); if (LastDeleted == "") { topTextBoxClass.messageDisplayStart(LastDeleted + " UNDELETE ERROR.", 5); return(false); } FolderItems folderItems = RecyclingBin.Items(); for (int i = 0; i < folderItems.Count; i++) { FolderItem FI = folderItems.Item(i); string FileName = RecyclingBin.GetDetailsOf(FI, 0); if (Path.GetExtension(FileName) == "") { FileName += Path.GetExtension(FI.Path); } //Necessary for systems with hidden file extensions. string FilePath = RecyclingBin.GetDetailsOf(FI, 1); if (String.Compare(LastDeleted, Path.Combine(FilePath, FileName), true) == 0) { FileInfo undelFile; try { DoVerb(FI, "ESTORE"); undelFile = new FileInfo(LastDeleted); } catch { topTextBoxClass.messageDisplayStart(LastDeleted + " Could not be undeleted, file not found.", 5); return(false); } topTextBoxClass.messageDisplayStart(LastDeleted + " Restored.", 5); Array.Resize(ref ImageList, ImageList.Length + 1); ImageList[ImageList.Length - 1] = undelFile; Array.Resize(ref ImageIdxList, ImageIdxList.Length + 1); ImageIdxList[ImageIdxList.Length - 1] = ImageIdxList.Length - 1; ImagesNotNull++; return(true); } } return(false); }
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { var Shl = new Shell(); dirCount = fileCount = 0; Folder Recycler = Shl.NameSpace(10); FolderItems items = Recycler.Items(); for (int i = 0; i < items.Count; i++) { try { timer.Enabled = true; timer.Start(); FolderItem FI = items.Item(i); string FileName = Recycler.GetDetailsOf(FI, 0); string FilePath = Recycler.GetDetailsOf(FI, 1); string RecyleDate = Recycler.GetDetailsOf(FI, 2); if (FI.IsFolder) { Directory.Delete(FI.Path, true); dirCount++; } else { File.Delete(FI.Path); fileCount++; } } catch (Exception) { } finished = true; timer.Stop(); timer.Enabled = false; } lRecBin1.Visible = true; lRecBin1.Text = String.Format("Удалено папок {0}; файлов {1}. Время:{2} мин {3} сек {4} мсек", dirCount, fileCount, min, sec, msec); }
public static (bool Ok, string FilePath) GetCurrentFilePath() { var cpr = GetCurrentProcessInfo(); if (cpr.ProcessName != "explorer") { return(false, string.Empty); } var status = GetGUICursorStatus(cpr.ProcessId); if (status.Ok) { if ((int)status.GUIInfo.hwndCaret != 0) { return(false, string.Empty); } } try { var windows = new SHDocVw.ShellWindowsClass(); FolderItems fi = null; foreach (SHDocVw.InternetExplorer window in windows) { var filename = Path.GetFileNameWithoutExtension(window.FullName).ToLowerInvariant(); if (filename == "explorer" && window.HWND == cpr.Hwnd.ToInt32()) { fi = ((IShellFolderViewDual2)window.Document).SelectedItems(); if (fi != null && fi.Count == 1) { return(true, fi.Item(0).Path); } } } SendKeys.SendWait("^c"); DataObject data = new DataObject(OleGetClipboard()); var files = data.GetFileDropList(); if (files.Count == 1) { return(true, files[0].ToString()); } } catch (Exception e) { } return(false, string.Empty); }
public FoldersPageVM() { //id = navigation.GetID(); //Parameters param = navigation.GetParameters(id); //switch (param) //{ // case VoidParameters vp: // break; // default: // break; //} model.ShowFolder = (bmi, str) => { var fi = new FolderItem(bmi, str); fi.ShowThumbnail(); FolderItems.Add(fi); }; model.ShowFolders(); }
public static void Zip(string inputFolderName, string outputZipFileName) { if (!Directory.Exists(inputFolderName)) { throw new InvalidOperationException("Source Folder '" + inputFolderName + "' does not exist."); } if (File.Exists(outputZipFileName)) { File.Delete(outputZipFileName); } initZipFile(outputZipFileName); //Copy a folder and its contents into the newly created zip file IShellDispatch sc = createShellClass(); Folder input = sc.NameSpace(inputFolderName); Folder output = sc.NameSpace(outputZipFileName); FolderItems items = input.Items(); output.CopyHere(items, 20); }
public static void Unzip(string inputZipFilename, string outputFolderName) { if (!File.Exists(inputZipFilename)) { throw new InvalidOperationException("Source Zip File '" + inputZipFilename + "' does not exist."); } if (Directory.Exists(outputFolderName)) { Directory.Delete(outputFolderName, true); } Directory.CreateDirectory(outputFolderName); //ShellClass sc = new ShellClass(); IShellDispatch sc = createShellClass(); Folder input = sc.NameSpace(inputZipFilename); Folder output = sc.NameSpace(outputFolderName); FolderItems items = input.Items(); output.CopyHere(items, 20); }
static void Main(string[] args) { string filename; ArrayList selected = new ArrayList(); ShellWindows winClass = new ShellWindows(); int cnt = 1; foreach (InternetExplorer window in winClass) { filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (filename.ToLowerInvariant() == "explorer") { Console.WriteLine("Windows Explorer Instance #{0}:", cnt++); Console.WriteLine(((IShellFolderViewDual2)window.Document).Folder.Title.ToString()); FolderItems items = ((IShellFolderViewDual2)window.Document).SelectedItems(); foreach (FolderItem item in items) { selected.Add(item.Path); } if (selected.Count > 0) { foreach (var path in selected) { Console.WriteLine(path); } } else { Console.WriteLine("No files selected"); } Console.WriteLine(); } selected.Clear(); } Console.ReadKey(); }
public override void Dispose() { folderItems = folderItems.EnsureDispose(); base.Dispose(); }
internal static ContextMenu FolderItemsContextMenu(FolderItems folderItems, ListItem listItem, Action delete) { ContextMenuCommands commands = folderItems.ParentFolder.ParentList.BaseType == BaseType.DocumentLibrary ? libraryCommands : listCommands; ContextMenuCommand[] menuItems = commands.None; if (listItem != null) { menuItems = listItem.FileSystemObjectType == FileSystemObjectType.Folder ? commands.Folder : commands.Item; } return(new ContextMenu() { List = new ObservableList <ContextMenuCommand>(menuItems), Execute = delegate(IHierarchyLevel menuLevel, long menuIndex) { ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex]; switch (command.EditMode) { case EditMode.Refresh: folderItems.Refresh(); break; case EditMode.Edit: ListItemEditor.Show(new EditAction() { EditMode = command.EditMode, ListItem = listItem, TargetList = listItem.ParentList }); break; case EditMode.Open: HtmlWindow.Current.Open(listItem.AbsoluteUrl); break; case EditMode.Upload: Uploader.Upload(folderItems.ParentFolder); break; case EditMode.AddItem: case EditMode.AddFolder: ListItemEditor.Show(new EditAction() { EditMode = command.EditMode, TargetFolder = folderItems.ParentFolder, TargetList = folderItems.ParentFolder.ParentList }); break; case EditMode.Copy: ListItemEditor.Show(new EditAction() { EditMode = command.EditMode, ListItem = listItem, TargetFolder = folderItems.ParentFolder, TargetList = folderItems.ParentFolder.ParentList }); break; default: delete(); break; } }, Renderer = delegate(IMenuItem menuItem, IHierarchyLevel menuLevel, long menuIndex) { ContextMenuCommand command = (ContextMenuCommand)menuLevel.List[menuIndex]; menuItem.Text = command.Name; menuItem.ImageClass = command.Image + "Icon"; menuItem.SeparatorBefore = (command.EditMode == EditMode.Refresh || command.EditMode == EditMode.Delete || command.EditMode == EditMode.Copy); switch (command.EditMode) { case EditMode.AddFolder: menuItem.Enabled = folderItems.ParentFolder.IsRootFolder || (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems) == BasePermissions.AddListItems; break; case EditMode.AddItem: case EditMode.Copy: menuItem.Enabled = folderItems.ParentFolder.ParentList.BaseType != BaseType.DocumentLibrary && (folderItems.ParentFolder.IsRootFolder || (folderItems.ParentFolder.Item.EffectiveBasePermissions & BasePermissions.AddListItems) == BasePermissions.AddListItems); break; case EditMode.Delete: menuItem.Enabled = (listItem.EffectiveBasePermissions & BasePermissions.DeleteListItems) == BasePermissions.DeleteListItems; break; case EditMode.Edit: menuItem.Enabled = BasePermissions.EditListItems == (BasePermissions.EditListItems & listItem.EffectiveBasePermissions); break; case EditMode.Refresh: menuItem.Enabled = folderItems.CanRefresh; break; } } }); }
public override void Undo() { //TODO: Loading dialog for duplicates form. //controller.ShowLoading(LOADING_TITLE, LOADING_DESCRIPTION); bool fileRecovered = false; Shell shell = new Shell(); Folder recycler = shell.NameSpace(10); FolderItems items = recycler.Items(); int count = items.Count; Parallel.For(0, count, (i, state) => { FolderItem folderItem = items.Item(i); string itemFilename = recycler.GetDetailsOf(folderItem, 0); if (Path.GetExtension(itemFilename) == "") { itemFilename += Path.GetExtension(folderItem.Path); //Necessary for systems with hidden file extensions. } string itemPath = recycler.GetDetailsOf(folderItem, 1); if (deletedFileFilepath == Path.Combine(itemPath, itemFilename)) { DoVerb(folderItem, "ESTORE"); fileRecovered = true; state.Break(); } }); if (fileRecovered) { //File should be recovered by this point. //controller.ReloadMatch(Path.GetFileName(leftFilepath), duplicateIndex); //controller.model.Duplicates.Insert(duplicateIndex, duplicate); //If the kept file was renamed change its name back to what it was. if (!string.IsNullOrWhiteSpace(keptFileNewName)) { File.Move(Path.Combine(Path.GetDirectoryName(keptFileFilepath), keptFileNewName), keptFileFilepath); } //Reinsert all duplicate entries that had that the recovered file. for (int i = 0; i < allDuplicatesWithFile.Count; i++) { controller.model.Duplicates.Insert(allDuplicatesWithFile[i].Index, allDuplicatesWithFile[i].Duplicate); } controller.form.matchesDataGridView.CurrentCell = controller.form.matchesDataGridView.Rows[duplicateIndex].Cells[0]; controller.MatchSelectionChanged(); Successful = true; } else { System.Windows.Forms.MessageBox.Show( "The deleted file could be found in the recycling bin and thus could not be undeleted. " + "You can attempt to search for the files yourself.", "Delete Undo Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); Successful = false; } //controller.HideLoading(); base.Undo(); }
public static List <SelectedItem> GetSelectedItems(IntPtr windowHandle) { var results = new List <SelectedItem>(); IntPtr handle = WinApi.GetForegroundWindow(); if (handle == progmanHandle || handle == windowHandle) { Logger.Debug("Desktop listview is active", LogSource.Interop); // Desktop has focus foreach (var file in GetSelectedItemsOnDesktop()) { results.Add(file); } } else { Logger.Debug("Desktop listview was not active, expected handle for desktop {0} or for window {1}, actual handle {2}", LogSource.Interop, progmanHandle, windowHandle, handle); // Other window, try to determine if is a shell window Shell shell = new Shell(); ShellWindows windows = (ShellWindows)shell.Windows(); foreach (InternetExplorer window in windows) { string processName = Path.GetFileNameWithoutExtension(window.FullName).ToLower(); if (processName.Equals("iexplore")) { if ((int)handle == window.HWND) { Logger.Debug("Active window was internet explorer instance {0}", LogSource.Interop, handle); Logger.Debug(" Adding {0}", LogSource.Interop, window.LocationURL); results.Add(new BrowserSelectedUrl() { Url = window.LocationURL }); } } else if (processName.Equals("explorer")) { if ((int)handle == window.HWND) { Logger.Debug("Active window was windows explorer instance {0}", LogSource.Interop, handle); ShellFolderView view = (ShellFolderView)window.Document; FolderItems items = view.SelectedItems(); foreach (FolderItem item in items) { Logger.Debug(" Adding path {0}", LogSource.Interop, item.Path); results.Add(new ExplorerSelectedFile() { Location = Path.GetDirectoryName(item.Path), Filename = Path.GetFileName(item.Path) }); } } } } } return(results); }
public FileFolder(string path) { Path = path; Folders = new FolderItems(path); Pages = new PageItems(path); }
public override void Undo() { controller.ShowLoading(LOADING_TITLE, LOADING_DESCRIPTION); bool itemFound = false; Shell shell = new Shell(); Folder recycler = shell.NameSpace(10); FolderItems items = recycler.Items(); int count = items.Count; Parallel.For(0, count, (i, state) => { FolderItem folderItem = items.Item(i); string itemFilename = recycler.GetDetailsOf(folderItem, 0); if (Path.GetExtension(itemFilename) == "") { itemFilename += Path.GetExtension(folderItem.Path); } //Necessary for systems with hidden file extensions. string itemPath = recycler.GetDetailsOf(folderItem, 1); if (filepath == Path.Combine(itemPath, itemFilename)) { DoVerb(folderItem, "ESTORE"); itemFound = true; state.Break(); //break; } }); /*for (int i = 0; i < count; i++) * { * FolderItem folderItem = items.Item(i); * * string FileName = recycler.GetDetailsOf(folderItem, 0); * if (Path.GetExtension(FileName) == "") * FileName += Path.GetExtension(folderItem.Path); * * //Necessary for systems with hidden file extensions. * string FilePath = recycler.GetDetailsOf(folderItem, 1); * if (filepath == Path.Combine(FilePath, FileName)) * { * DoVerb(folderItem, "ESTORE"); * itemFound = true; * break; * } * }*/ if (itemFound) { //File should be recovered by this point. controller.ReloadFile(Path.GetFileName(filepath), fileIndex); Successful = true; } else { System.Windows.Forms.MessageBox.Show( "The file could not be found in the recycling bin and thus could not be undeleted. " + "You can attempt to search for it yourself.", "Delete Undo Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); Successful = false; } controller.HideLoading(); base.Undo(); }
public override void Undo() { //TODO: Loading dialog for duplicates form. //controller.ShowLoading(LOADING_TITLE, LOADING_DESCRIPTION); bool leftItemFound = false, rightItemFound = false; Shell shell = new Shell(); Folder recycler = shell.NameSpace(10); FolderItems items = recycler.Items(); int count = items.Count; Parallel.For(0, count, (i, state) => { if (leftItemFound && rightItemFound) { state.Break(); } FolderItem folderItem = items.Item(i); string itemFilename = recycler.GetDetailsOf(folderItem, 0); if (Path.GetExtension(itemFilename) == "") { itemFilename += Path.GetExtension(folderItem.Path); //Necessary for systems with hidden file extensions. } string itemPath = recycler.GetDetailsOf(folderItem, 1); if (!leftItemFound && duplicate.fileprint1.Filepath == Path.Combine(itemPath, itemFilename)) { DoVerb(folderItem, "ESTORE"); leftItemFound = true; } else if (!rightItemFound && duplicate.fileprint2.Filepath == Path.Combine(itemPath, itemFilename)) { DoVerb(folderItem, "ESTORE"); rightItemFound = true; } }); if (leftItemFound && rightItemFound) { //File should be recovered by this point. //controller.ReloadMatch(Path.GetFileName(leftFilepath), duplicateIndex); //controller.model.Duplicates.Insert(duplicateIndex, duplicate); //Reinsert all duplicate entries that had that the recovered files. for (int i = 0; i < allDuplicatesWithFile.Count; i++) { controller.model.Duplicates.Insert(allDuplicatesWithFile[i].Index, allDuplicatesWithFile[i].Duplicate); } controller.form.matchesDataGridView.CurrentCell = controller.form.matchesDataGridView.Rows[duplicateIndex].Cells[0]; controller.MatchSelectionChanged(); Successful = true; } else if (leftItemFound || rightItemFound) { string side = leftItemFound ? "right" : "left"; System.Windows.Forms.MessageBox.Show( $"The {side} file could be found in the recycling bin and thus could not be undeleted. " + "You can attempt to search for the file yourself.", "Delete Undo Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); Successful = true; } else //Neither found. { System.Windows.Forms.MessageBox.Show( "Neither file could be found in the recycling bin and thus could not be undeleted. " + "You can attempt to search for the files yourself.", "Delete Undo Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); Successful = false; } //controller.HideLoading(); base.Undo(); }