private bool TestFile(string file) { if (_shouldCancelSearch.WaitOne(0)) { return(false); } if (file == null || File.Exists(file) == false) { return(false); } if (SearchBookmarksActive()) { BookmarkFileInfo bfi = new BookmarkFileInfo(file, false); if (bfi == null || !bfi.IsValid || (theTask.Option1 && bfi.IsOrphan) || /* for BMK files: option 1 = non-orphan bookmarks */ (theTask.Option2 && !bfi.IsOrphan)) /* for BMK files: option 2 = orphan bookmarks */ { return(false); // skip this file } } else if (SearchMediaFilesActive()) { if (!MediaRenderer.IsSupportedMedia(file)) { return(false); // not a media file } MediaFileInfo mfi = MediaFileInfo.FromPath(file); if (mfi == null || !mfi.IsValid || (theTask.Option1 && mfi.Bookmarks.Count < 1) || /* for media files: option 1 = files with bookmarks */ (theTask.Option2 && mfi.Bookmarks.Count > 0)) /* for media files: option 2 = files w/o bookmarks */ { return(false); // skip this file } } if (!theTask.UseAttributes || AttributesMatch(File.GetAttributes(file), true)) { bool match = (theTask.SearchText.Length == 0) || (theTask.SearchProperties && ContainsProperty(file)) || (!theTask.SearchProperties && ContainsText(file)); if (match && !_matchingItems.Contains(file.ToLowerInvariant())) { _matchingItems.Add(file.ToLowerInvariant()); _displayItems.Add(file); return(true); } } return(false); }
private bool ContainsProperty(string file) { if (_shouldCancelSearch.WaitOne(0)) { return(false); } try { // So far only media files can have "text" properties if (MediaRenderer.IsSupportedMedia(file)) { MediaFileInfo mfi = MediaFileInfo.FromPath(file); if (mfi != null) { foreach (KeyValuePair <string, string> kvp in mfi.ExtendedInfo) { string keyword = theTask.SearchText; string name = kvp.Key; string value = kvp.Value; if (theTask.IsCaseInsensitive) { keyword = keyword != null?keyword.ToLowerInvariant() : string.Empty; name = name != null?name.ToLowerInvariant() : string.Empty; value = value != null?value.ToLowerInvariant() : string.Empty; } if (name.Contains(keyword) || value.Contains(keyword)) { return(true); } } } } return(false); } finally { GC.Collect(); } }
private void OnMenuOpening(object sender, CancelEventArgs e) { bool playerInstalled = File.Exists(ProTONEConfig.PlayerInstallationPath); tsmiSepProTONE.Visible = tsmiProTONEEnqueue.Visible = tsmiProTONEPlay.Visible = playerInstalled; bool enable = false; foreach (string path in GetSelectedItems()) { if (MediaRenderer.IsSupportedMedia(path)) { enable = true; break; } } tsmiProTONEEnqueue.Enabled = tsmiProTONEPlay.Enabled = enable; tsmiTaggingWizard.Enabled = (lvResults.SelectedItems.Count == 1); }
private void OnMenuOpening(object sender, CancelEventArgs e) { bool playerInstalled = File.Exists(ProTONEConfig.PlayerInstallationPath); tsmiSepProTONE.Visible = tsmiProTONEEnqueue.Visible = tsmiProTONEPlay.Visible = playerInstalled; bool enable = false; foreach (string vpath in GetSelectedItems()) { CatalogItem ci = (BkgTask as Task).Catalog.GetByVPath(vpath); if (ci != null && MediaRenderer.IsSupportedMedia(ci.OrigItemPath)) { enable = true; break; } } tsmiProTONEEnqueue.Enabled = tsmiProTONEPlay.Enabled = enable; //tsmiTaggingWizard.Enabled = (lvResults.SelectedItems.SelectedItems.Count == 1); }
private void OnUpdateUi(ToolStripItemCollection tsic) { if (tsic == null) { return; } bool playerInstalled = File.Exists(ProTONEConfig.PlayerInstallationPath); tsmiSepProTONE.Visible = tsmiProTONEEnqueue.Visible = tsmiProTONEPlay.Visible = playerInstalled; for (int i = 0; i < tsic.Count; i++) { ToolStripItem btn = tsic[i] as ToolStripItem; if (btn == null) { continue; } btn.Enabled = true; string tag = btn.Tag as string; if (string.IsNullOrEmpty(tag)) { continue; } ToolAction action = ToolAction.ToolActionNothing; try { action = (ToolAction)Enum.Parse(typeof(ToolAction), tag); } catch { action = ToolAction.ToolActionNothing; } if (action == ToolAction.ToolActionNothing) { continue; } List <string> selItems = GetSelectedVPaths(); switch (action) { case ToolAction.ToolActionNew: BuildMenuText(btn, "TXT_NEW", string.Empty, OPMShortcut.CmdGenericNew); break; case ToolAction.ToolActionOpen: BuildMenuText(btn, "TXT_OPEN", string.Empty, OPMShortcut.CmdGenericOpen); break; case ToolAction.ToolActionSave: BuildMenuText(btn, "TXT_SAVE", string.Empty, OPMShortcut.CmdGenericSave); btn.Enabled = (_cat != null); break; case ToolAction.ToolActionSaveAs: BuildMenuText(btn, "TXT_SAVE_AS", string.Empty, OPMShortcut.CmdOutOfRange); btn.Enabled = (_cat != null); break; case ToolAction.ToolActionBack: btn.Enabled = ExploreBackTarget != null; BuildMenuText(btn, "TXT_BACK", ExploreBackTarget, OPMShortcut.CmdNavigateBack); break; case ToolAction.ToolActionFwd: btn.Enabled = ExploreForwardTarget != null; BuildMenuText(btn, "TXT_FORWARD", ExploreForwardTarget, OPMShortcut.CmdNavigateForward); break; case ToolAction.ToolActionUp: btn.Enabled = _cat != null; string parentName = (ParentFolderTarget == null) ? Translator.Translate("TXT_ROOT") : ParentFolderTarget.OrigItemPath.Replace("$:", ParentFolderTarget.RootItemLabel); BuildMenuText(btn, "TXT_UP", parentName, OPMShortcut.CmdNavigateUp); break; case ToolAction.ToolActionSearch: BuildMenuText(btn, "TXT_SEARCH", string.Empty, OPMShortcut.CmdGenericSearch); btn.Enabled = (_cat != null); break; case ToolAction.ToolActionReload: BuildMenuText(btn, "TXT_REFRESH", string.Empty, OPMShortcut.CmdGenericRefresh); btn.Enabled = (_curFolder != null); break; case ToolAction.ToolActionDelete: BuildMenuText(btn, "TXT_DELETE", string.Empty, OPMShortcut.CmdGenericDelete); btn.Enabled = GetSelectedVPaths().Count > 0; break; case ToolAction.ToolActionCopy: case ToolAction.ToolActionCut: #if MC_COPY_PASTE btn.Visible = true; btn.Enabled = GetSelectedVPaths().Count > 0; #else btn.Visible = false; btn.Enabled = false; #endif break; case ToolAction.ToolActionPaste: #if MC_COPY_PASTE btn.Enabled = (_fileTask != null && (_fileTask.FileTaskType == FileTaskType.Copy || _fileTask.FileTaskType == FileTaskType.Move)); btn.Visible = true; #else btn.Visible = false; btn.Enabled = false; #endif break; case ToolAction.ToolActionMerge: BuildMenuText(btn, "TXT_MERGECATALOGS", string.Empty, OPMShortcut.CmdCatalogMerge); btn.Enabled = (_cat != null && _cat.IsValid); break; case ToolAction.ToolActionCatalog: BuildMenuText(btn, "TXT_CATALOG", string.Empty, OPMShortcut.CmdCatalogWizard); btn.Enabled = (_cat == null || !_cat.IsInDefaultLocation); break; case ToolAction.ToolActionRename: BuildMenuText(btn, "TXT_RENAME", string.Empty, OPMShortcut.CmdGenericRename); btn.Enabled = GetSelectedVPaths().Count == 1; break; case ToolAction.ToolActionProTONEEnqueue: case ToolAction.ToolActionProTONEPlay: if (btn.Visible) { string text = (action == ToolAction.ToolActionProTONEEnqueue) ? "TXT_PROTONE_ENQUEUE" : "TXT_PROTONE_PLAY"; BuildMenuText(btn, text, string.Empty, OPMShortcut.CmdOutOfRange); bool enable = false; foreach (string path in GetSelectedOrigPaths()) { if (MediaRenderer.IsSupportedMedia(path)) { enable = true; break; } } btn.Enabled = enable; } break; } } }
private void OnUpdateUi(ToolStripItemCollection tsic) { if (tsic == null) { return; } bool playerInstalled = File.Exists(ProTONEConfig.PlayerInstallationPath); tsmiSepProTONE.Visible = tsmiProTONEEnqueue.Visible = tsmiProTONEPlay.Visible = playerInstalled; for (int i = 0; i < tsic.Count; i++) { ToolStripItem btn = tsic[i] as ToolStripItem; if (btn == null) { continue; } btn.Enabled = true; string tag = btn.Tag as string; if (string.IsNullOrEmpty(tag)) { continue; } ToolAction action = ToolAction.ToolActionNothing; try { action = (ToolAction)Enum.Parse(typeof(ToolAction), tag); } catch { action = ToolAction.ToolActionNothing; } if (action == ToolAction.ToolActionNothing) { continue; } List <string> selItems = opmShellList.SelectedPaths; switch (action) { case ToolAction.ToolActionNewFolder: btn.Enabled = true; btn.Visible = true; BuildMenuText(btn, "TXT_NEWFOLDER", string.Empty, OPMShortcut.CmdGenericNew); break; case ToolAction.ToolActionBack: btn.Enabled = opmShellList.ExploreBackTarget.Length > 0; BuildMenuText(btn, "TXT_BACK", opmShellList.ExploreBackTarget, OPMShortcut.CmdNavigateBack); break; case ToolAction.ToolActionFwd: btn.Enabled = opmShellList.ExploreForwardTarget.Length > 0; BuildMenuText(btn, "TXT_FORWARD", opmShellList.ExploreForwardTarget, OPMShortcut.CmdNavigateForward); break; case ToolAction.ToolActionUp: btn.Enabled = !opmShellList.IsInDriveRoot; BuildMenuText(btn, "TXT_UP", opmShellList.ParentFolderTarget, OPMShortcut.CmdNavigateUp); break; case ToolAction.ToolActionSearch: BuildMenuText(btn, "TXT_SEARCH", string.Empty, OPMShortcut.CmdGenericSearch); btn.Enabled = !string.IsNullOrEmpty(opmShellList.Path); break; case ToolAction.ToolActionReload: BuildMenuText(btn, "TXT_REFRESH", string.Empty, OPMShortcut.CmdGenericRefresh); btn.Enabled = !string.IsNullOrEmpty(opmShellList.Path); break; case ToolAction.ToolActionCopy: BuildMenuText(btn, "TXT_COPY", string.Empty, OPMShortcut.CmdGenericCopy); btn.Enabled = opmShellList.SelectedPaths.Count > 0; break; case ToolAction.ToolActionCut: BuildMenuText(btn, "TXT_CUT", string.Empty, OPMShortcut.CmdGenericCut); btn.Enabled = opmShellList.SelectedPaths.Count > 0; break; case ToolAction.ToolActionDelete: BuildMenuText(btn, "TXT_DELETE", string.Empty, OPMShortcut.CmdGenericDelete); btn.Enabled = opmShellList.SelectedPaths.Count > 0; break; case ToolAction.ToolActionPaste: BuildMenuText(btn, "TXT_PASTE", string.Empty, OPMShortcut.CmdGenericPaste); btn.Enabled = (_pasteFileTask != null && (_pasteFileTask.FileTaskType == FileTaskType.Copy || _pasteFileTask.FileTaskType == FileTaskType.Move)); break; case ToolAction.ToolActionRename: BuildMenuText(btn, "TXT_RENAME", string.Empty, OPMShortcut.CmdGenericRename); btn.Enabled = opmShellList.SelectedPaths.Count == 1; break; case ToolAction.ToolActionProTONEEnqueue: case ToolAction.ToolActionProTONEPlay: if (btn.Visible) { string text = (action == ToolAction.ToolActionProTONEEnqueue) ? "TXT_PROTONE_ENQUEUE" : "TXT_PROTONE_PLAY"; BuildMenuText(btn, text, string.Empty, OPMShortcut.CmdOutOfRange); bool enable = false; foreach (string path in opmShellList.SelectedPaths) { if (MediaRenderer.IsSupportedMedia(path)) { enable = true; break; } } btn.Enabled = enable; } break; case ToolAction.ToolActionTaggingWizard: BuildMenuText(btn, "TXT_TAGGINGWIZARD", string.Empty, OPMShortcut.CmdTaggingWizard); break; case ToolAction.ToolActionCdRipper: BuildMenuText(btn, "TXT_CDRIPPERWIZARD", string.Empty, OPMShortcut.CmdCdRipperWizard); break; case ToolAction.ToolActionListDrives: BuildMenuText(btn, "TXT_DRIVES", string.Empty, OPMShortcut.CmdChangeDisk); break; case ToolAction.ToolActionFavoritesAdd: btn.Visible = true; BuildMenuText(btn, "TXT_FAVORITES_ADD", string.Empty, OPMShortcut.CmdOutOfRange); break; case ToolAction.ToolActionFavoritesManage: btn.Visible = true; BuildMenuText(btn, "TXT_FAVORITES_MANAGE", string.Empty, OPMShortcut.CmdFavManager); break; case ToolAction.ToolActionFavoriteFolders: btn.Visible = true; BuildMenuText(btn, "TXT_FAVORITES", string.Empty, OPMShortcut.CmdOutOfRange); break; } } }
public void Initialize(IntPtr pidlFolder, IntPtr pDataObj, IntPtr hKeyProgID) { if (pDataObj == IntPtr.Zero) { throw new ArgumentException(); } ApplicationInfo.RegisterAppName(GetType().Assembly); Translator.RegisterTranslationAssembly(GetType().Assembly); Translator.SetInterfaceLanguage(AppConfig.LanguageID); FORMATETC fe = new FORMATETC(); fe.cfFormat = (short)CLIPFORMAT.CF_HDROP; fe.ptd = IntPtr.Zero; fe.dwAspect = DVASPECT.DVASPECT_CONTENT; fe.lindex = -1; fe.tymed = TYMED.TYMED_HGLOBAL; STGMEDIUM stm = new STGMEDIUM(); // The pDataObj pointer contains the objects being acted upon. In this // example, we get an HDROP handle for enumerating the selected files // and folders. IDataObject dataObject = (IDataObject)Marshal.GetObjectForIUnknown(pDataObj); dataObject.GetData(ref fe, out stm); try { // Get an HDROP handle. IntPtr hDrop = stm.unionmember; if (hDrop == IntPtr.Zero) { throw new ArgumentException(); } // Determine how many files are involved in this operation. uint nFiles = Shell32.DragQueryFile(hDrop, UInt32.MaxValue, null, 0); // Enumerate the selected files and folders. if (nFiles > 0) { this.fileList = new List <string>(); StringBuilder fileName = new StringBuilder(Kernel32.MAX_FILE_BUFFER); for (uint i = 0; i < Math.Min(nFiles, Kernel32.MAX_FILES); i++) { // Get the next file name. if (Shell32.DragQueryFile(hDrop, i, fileName, fileName.Capacity) != 0 && MediaRenderer.IsSupportedMedia(fileName.ToString())) { // Add the file name to the list. fileList.Add(fileName.ToString()); } } // If we did not find any files we can work with, throw // exception. if (fileList.Count == 0) { Marshal.ThrowExceptionForHR(WinError.E_FAIL); } } else { Marshal.ThrowExceptionForHR(WinError.E_FAIL); } } catch (Exception ex) { //ErrorDispatcher.DispatchException(ex); Logger.LogException(ex); fileList.Clear(); } finally { Ole32.ReleaseStgMedium(ref stm); } }