public TrueCryptSWObj(ProgramData thisProg) // initialize all static entries { tCryptRegEntry = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Classes\TrueCryptVolume\Shell\open\command", "", ""); if (tCryptRegEntry != null) { tcProgramFQN = tCryptRegEntry.Substring(1, tCryptRegEntry.Length - 10); //registry entry has a leading quote that needs to go tcProgramDirectory = tcProgramFQN.Substring(0, tcProgramFQN.Length - 14); if (!File.Exists(tcProgramFQN)) { MessageBox.Show("Windows has registry entries for the TrueCrypt Program but no program exists. Please reinstall", thisProg.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } if (thisProg.removable == true && string.Compare(FileVersionInfo.GetVersionInfo(tcProgramFQN).FileVersion, tcSetupVersion) < 0) { // we have host version that needs upgrading MessageBox.Show("The TrueCrypt software version on this Flash Drive will not work with the version of TrueCrypt on this host system. The Tax-Aide TrueCrypt Utility will be started so that the Host's TrueCrypt can be upgraded. Then restart this Start Tax-Aide drive program", thisProg.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); try { Process proc = Process.Start(thisProg.drvLetter + ":\\" + travDir + TAtcSetupProgramName, "hostupg"); Environment.Exit(1); } catch (Exception e) { MessageBox.Show("Exception on starting Tax-Aide TrueCrypt Utility\r\n" + e.ToString(), thisProg.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { if (thisProg.removable == true) { tcProgramFQN = thisProg.drvLetter + ":\\" + travDir + tcProgramName; tcProgramDirectory = thisProg.drvLetter + ":\\" + travDir; if (!File.Exists(tcProgramFQN)) { MessageBox.Show("The TrueCrypt Program does not exist on the Traveler drive. Please reinistall" + "\r" + tcProgramFQN, thisProg.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } } else { MessageBox.Show("The TrueCrypt program does not exist. Please run the Tax-Aide TrueCrypt Installer", thisProg.mbCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1); } } #if StartTADrive if (thisProg.removable == true) { //Incase shortcut exists delete it File.Delete(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Stop Traveler.lnk"); ShellLink desktopShortcut = new ShellLink(); desktopShortcut.ShortCutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Stop Traveler.lnk"; desktopShortcut.Target = thisProg.scriptExePath + stopTravDrv; desktopShortcut.IconPath = thisProg.scriptExePath + "\\" + "Stop_Tax-Aide_Drive.exe"; desktopShortcut.Save(); desktopShortcut.Dispose(); } #endif }
public static bool IsShortcut(string path) { if (!File.Exists(path)) { return(false); } var shellLink = new ShellLink(path); if (shellLink.Target.Length > 0 && Directory.Exists(shellLink.Target)) { shellLink.Dispose(); return(true); } shellLink.Dispose(); return(false); }
public static string ResolveShortcut(string path) { if (!ShortcutUtils.IsShortcut(path)) { return(string.Empty); } var shellLink = new ShellLink(path); string targetPath = null; if (shellLink.Target.Length > 0 && Directory.Exists(shellLink.Target)) { targetPath = shellLink.Target; } shellLink.Dispose(); return(targetPath); }
/// <summary> /// /// </summary> /// <param name="b2"></param> public static void func_新增或刪除開機自動啟動捷徑(bool b2) { //取得 windows啟動資料夾 的路徑 String s_啟動資料夾 = Environment.GetFolderPath(Environment.SpecialFolder.Startup); String s_捷徑儲存路徑 = Path.Combine(s_啟動資料夾, "TeifSee.lnk"); if (b2) //啟用「開機自動啟動程式」 { String s_啟動參數 = @"none"; String s_工作資料夾 = Directory.GetParent(System.AppDomain.CurrentDomain.BaseDirectory).ToString(); s_工作資料夾 = Directory.GetParent(s_工作資料夾).ToString(); String s_exe路徑 = Path.Combine(s_工作資料夾, "TiefSee.exe"); String s_圖示檔案 = s_exe路徑; if (File.Exists(s_exe路徑) == false) { MessageBox.Show("找不到\n" + s_exe路徑); return; } //產生捷徑 ShellLink slLinkObject = new ShellLink(); slLinkObject.WorkPath = s_工作資料夾; slLinkObject.IconLocation = s_圖示檔案 + ",0"; // 0 為圖示檔的 Index slLinkObject.ExecuteFile = s_exe路徑; slLinkObject.ExecuteArguments = s_啟動參數; slLinkObject.Save(s_捷徑儲存路徑); slLinkObject.Dispose(); } else //刪除捷徑 { if (File.Exists(s_捷徑儲存路徑)) { try { File.Delete(s_捷徑儲存路徑); } catch { } } } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public void Dispose() { if (!disposed) { disposed = true; if (handle != null) { handle.Dispose(); handle = null; } if (shellLink != null) { shellLink.Dispose(); shellLink = null; } current = null; state = -1; SetErrorModeWrapper(oldErrorMode); } }
private void CopyTAFilesFromThisAssembly(string destDir) { //CopyFileFromThisAssembly("decryption.ico", destDir); //CopyFileFromThisAssembly("encryption.ico", destDir); progOverall.Invoke(progUpdateLin2, new object[] { "Start Tax-Aide Drive Script Copying" }); CopyFileFromThisAssembly("Start_Tax-Aide_Drive.exe", destDir); progOverall.Invoke(progUpdateLin2, new object[] { "Tax-Aide Scripts Copying" }); CopyFileFromThisAssembly("Stop_Tax-Aide_Drive.exe", destDir); System.Reflection.Assembly assem = System.Reflection.Assembly.GetExecutingAssembly(); // to copy this file to folder string thisProgFilePath = assem.Location; File.Copy(thisProgFilePath, destDir + "\\" + programName, true); if (GetTasksHI.travUSBDrv.Exists(delegate(DrvInfo s) { return(s.drvName.Equals(destDir.Substring(0, 2).ToUpper())); })) //tests whether this is a usb connected drive { Log.WritWTime("Copying unique traveler files from Assembly to Drive"); CopyFileFromThisAssembly("autorun.inf", destDir.Substring(0, 3)); CopyFileFromThisAssembly("Start Traveler.exe", destDir.Substring(0, 3)); } else { ShellLink desktopShortcut = new ShellLink(); desktopShortcut.ShortCutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Start Tax-Aide Drive.lnk"; desktopShortcut.Target = destDir + "\\" + "Start_Tax-Aide_Drive.exe"; desktopShortcut.IconPath = destDir + "\\" + "Start_Tax-Aide_Drive.exe"; desktopShortcut.Save(); desktopShortcut.Dispose(); ShellLink desktopShortcut1 = new ShellLink(); desktopShortcut1.ShortCutFile = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\Stop Tax-Aide Drive.lnk"; desktopShortcut1.Target = destDir + "\\" + "Stop_Tax-Aide_Drive.exe"; desktopShortcut1.IconPath = destDir + "\\" + "Stop_Tax-Aide_Drive.exe"; desktopShortcut1.Save(); desktopShortcut1.Dispose(); } progOverall.Invoke(progUpdateLin2, new object[] { "Tax-Aide Scripts Copying" }); progOverall.Invoke(progUpdateLin2notVis); }
void updateLink(ShellLink shortcut, string newAppPath) { this.Log().Info("Processing shortcut '{0}'", shortcut.ShortCutFile); var target = Environment.ExpandEnvironmentVariables(shortcut.Target); var targetIsUpdateDotExe = target.EndsWith("update.exe", StringComparison.OrdinalIgnoreCase); this.Log().Info("Old shortcut target: '{0}'", target); if (!targetIsUpdateDotExe) { target = Path.Combine(newAppPath, Path.GetFileName(shortcut.Target)); } this.Log().Info("New shortcut target: '{0}'", target); shortcut.WorkingDirectory = newAppPath; shortcut.Target = target; // NB: If the executable was in a previous version but not in this // one, we should disappear this pin. if (!File.Exists(target)) { shortcut.Dispose(); this.ErrorIfThrows(() => Utility.DeleteFileHarder(target), "Failed to delete outdated pinned shortcut to: " + target); return; } this.Log().Info("Old iconPath is: '{0}'", shortcut.IconPath); if (!File.Exists(shortcut.IconPath) || shortcut.IconPath.IndexOf("app-", StringComparison.OrdinalIgnoreCase) > 1) { var iconPath = Path.Combine(newAppPath, Path.GetFileName(shortcut.IconPath)); if (!File.Exists(iconPath) && targetIsUpdateDotExe) { var executable = shortcut.Arguments.Replace("--processStart ", ""); iconPath = Path.Combine(newAppPath, executable); } this.Log().Info("Setting iconPath to: '{0}'", iconPath); shortcut.IconPath = iconPath; if (!File.Exists(iconPath)) { this.Log().Warn("Tried to use {0} for icon path but didn't exist, falling back to EXE", iconPath); shortcut.IconPath = target; shortcut.IconIndex = 0; } } this.ErrorIfThrows(() => Utility.Retry(() => shortcut.Save(), 2), "Couldn't write shortcut " + shortcut.ShortCutFile); this.Log().Info("Finished shortcut successfully"); }
private void ShellTreeView_AfterSelect(object sender, TreeViewEventArgs e) { if (!this._AcceptSelection) { this._AcceptSelection = true; return; } //var sho = e.Node != null ? e.Node.Tag as IListItemEx : null; var sho = e?.Node?.Tag as IListItemEx; if (sho != null) { IListItemEx linkSho = null; if (sho.IsLink) { try { var shellLink = new ShellLink(sho.ParsingName); var linkTarget = shellLink.TargetPIDL; linkSho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, linkTarget); shellLink.Dispose(); } catch { } } this.isFromTreeview = true; if (this._IsNavigate) { this.ShellListView.Navigate_Full(linkSho ?? sho, true, true); } this._IsNavigate = false; this.isFromTreeview = false; } }
private void ShellTreeView_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (e.Action == TreeViewAction.Collapse) this._AcceptSelection = false; if (e.Action == TreeViewAction.Expand) { this._ResetEvent.Set(); if (e.Node.Nodes.Count > 0 && (e.Node.Nodes[0].Text == this._EmptyItemString || e.Node.Nodes[0].Text == this._SearchingForFolders)) { e.Node.Nodes.Clear(); imagesQueue.Clear(); childsQueue.Clear(); var sho = e.Node.Tag as IListItemEx; //var lvSho = this.ShellListView != null && this.ShellListView.CurrentFolder != null ? this.ShellListView.CurrentFolder.Clone() : null; var lvSho = this.ShellListView?.CurrentFolder?.Clone(); var node = e.Node; node.Nodes.Add(this._SearchingForFolders); new Thread(() => { var nodesTemp = new List<TreeNode>(); if (sho?.IsLink == true) { try { var shellLink = new ShellLink(sho.ParsingName); var linkTarget = shellLink.TargetPIDL; sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, linkTarget); shellLink.Dispose(); } catch { } } foreach (var item in sho?.Where(w => !sho.IsFileSystem && Path.GetExtension(sho?.ParsingName).ToLowerInvariant() != ".library-ms" || ((w.IsFolder || w.IsLink) && (this.IsShowHiddenItems || w.IsHidden == false)))) { if (item?.IsLink == true) { try { var shellLink = new ShellLink(item.ParsingName); var linkTarget = shellLink.TargetPIDL; var itemLinkReal = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, linkTarget); shellLink.Dispose(); if (!itemLinkReal.IsFolder) continue; } catch { } } var itemNode = new TreeNode(item.DisplayName); //IListItemEx itemReal = null; //if (item.Parent?.Parent != null && item.Parent.Parent.ParsingName == KnownFolders.Libraries.ParsingName) { IListItemEx itemReal = item?.Parent?.Parent?.ParsingName == KnownFolders.Libraries.ParsingName ? FileSystemListItem.ToFileSystemItem(IntPtr.Zero, item.ParsingName.ToShellParsingName()) : item; itemNode.Tag = itemReal; if ((sho.IsNetworkPath || sho.IsNetworkPath) && sho.ParsingName != KnownFolders.Network.ParsingName) { itemNode.ImageIndex = this.folderImageListIndex; } else if (itemReal.IconType == IExtractIconPWFlags.GIL_PERCLASS || sho.ParsingName == KnownFolders.Network.ParsingName) { itemNode.ImageIndex = itemReal.GetSystemImageListIndex(itemReal.PIDL, ShellIconType.SmallIcon, ShellIconFlags.OpenIcon); itemNode.SelectedImageIndex = itemNode.ImageIndex; } else { itemNode.ImageIndex = this.folderImageListIndex; } itemNode.Nodes.Add(this._EmptyItemString); if (item.ParsingName.EndsWith(".library-ms")) { var library = ShellLibrary.Load(Path.GetFileNameWithoutExtension(item.ParsingName), false); if (library.IsPinnedToNavigationPane) nodesTemp.Add(itemNode); library.Close(); } else { nodesTemp.Add(itemNode); } //Application.DoEvents(); } this.BeginInvoke((Action)(() => { if (node.Nodes.Count == 1 && node.Nodes[0].Text == _SearchingForFolders) node.Nodes.RemoveAt(0); node.Nodes.AddRange(nodesTemp.ToArray()); if (lvSho != null) this.SelItem(lvSho); })); }).Start(); } } }
private void btnFavorites_Click(object sender, RoutedEventArgs e) { var selectedItems = _ShellListView.SelectedItems; if (selectedItems.Count == 1) { var link = new ShellLink(); link.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; link.Target = _ShellListView.GetFirstSelectedItem().ParsingName; link.Save($@"{KnownFolders.Links.ParsingName}\{_ShellListView.GetFirstSelectedItem().DisplayName}.lnk"); link.Dispose(); } if (selectedItems.Count == 0) { var link = new ShellLink(); link.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; link.Target = _ShellListView.CurrentFolder.ParsingName; link.Save($@"{KnownFolders.Links.ParsingName}\{_ShellListView.CurrentFolder.DisplayName}.lnk"); link.Dispose(); } }
private void mnuPinToStart_Click(object sender, RoutedEventArgs e) { if (_ShellListView.GetSelectedCount() == 1) { string loc = KnownFolders.StartMenu.ParsingName + @"\" + _ShellListView.GetFirstSelectedItem().DisplayName + ".lnk"; var link = new ShellLink(); link.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; link.Target = _ShellListView.GetFirstSelectedItem().ParsingName; link.Save(loc); link.Dispose(); User32.PinUnpinToStartMenu(loc); } if (_ShellListView.GetSelectedCount() == 0) { string loc = KnownFolders.StartMenu.ParsingName + @"\" + _ShellListView.CurrentFolder.DisplayName + ".lnk"; ShellLink link = new ShellLink(); link.DisplayMode = ShellLink.LinkDisplayMode.edmNormal; link.Target = _ShellListView.CurrentFolder.ParsingName; link.Save(loc); link.Dispose(); User32.PinUnpinToStartMenu(loc); } }
void ShellTree_NodeClick(object sender, WIN.Forms.TreeNodeMouseClickEventArgs e) { if (e.Button == WIN.Forms.MouseButtons.Middle) { var item = e.Node?.Tag as IListItemEx; if ((item?.IsLink).Value) { var shellLink = new ShellLink(item.ParsingName); item = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, shellLink.TargetPIDL); shellLink.Dispose(); } if (item != null) tcMain.NewTab(item, false); } }
protected override void WndProc(ref Message m) { try { if (m.Msg == (Int32)WM.WM_PARENTNOTIFY && User32.LOWORD((Int32)m.WParam) == (Int32)WM.WM_MBUTTONDOWN) OnItemMiddleClick(); base.WndProc(ref m); if (m.Msg == ShellNotifications.WM_SHNOTIFY) { this.ProcessShellNotifications(ref m); } #region m.Msg == 78 if (m.Msg == 78) { #region Starting var nmhdrHeader = (NMHEADER)(m.GetLParam(typeof(NMHEADER))); if (nmhdrHeader.hdr.code == (Int32)HDN.HDN_DROPDOWN) Column_OnClick(nmhdrHeader.iItem); //F.MessageBox.Show(nmhdrHeader.iItem.ToString()); else if (nmhdrHeader.hdr.code == (Int32)HDN.HDN_BEGINTRACKW) if (this.View != ShellViewStyle.Details) m.Result = (IntPtr)1; /* else if (nmhdrHeader.hdr.code == (int)HDN.HDN_BEGINTRACKW) if (this.View != ShellViewStyle.Details) m.Result = (IntPtr)1; */ #endregion Starting var nmhdr = (NMHDR)m.GetLParam(typeof(NMHDR)); switch (nmhdr.code) { case WNM.LVN_GETEMPTYMARKUP: if (this._IsDisplayEmptyText) { var nmlvem = (NMLVEMPTYMARKUP)m.GetLParam(typeof(NMLVEMPTYMARKUP)); nmlvem.dwFlags = 0x1; nmlvem.szMarkup = "Working on it..."; Marshal.StructureToPtr(nmlvem, m.LParam, false); m.Result = (IntPtr)1; } else { m.Result = IntPtr.Zero; } break; case WNM.LVN_ENDLABELEDITW: #region Case var nmlvedit = (NMLVDISPINFO)m.GetLParam(typeof(NMLVDISPINFO)); if (!String.IsNullOrEmpty(nmlvedit.item.pszText)) { var item = this.Items[nmlvedit.item.iItem]; RenameShellItem(item.ComInterface, nmlvedit.item.pszText, (item.DisplayName != Path.GetFileName(item.ParsingName)) && !item.IsFolder, item.Extension); this.EndLabelEdit(); } this._EditorSubclass?.DestroyHandle(); break; #endregion Case case WNM.LVN_GETDISPINFOW: #region Case var nmlv = (NMLVDISPINFO)m.GetLParam(typeof(NMLVDISPINFO)); if (Items.Count == 0 || Items.Count - 1 < nmlv.item.iItem) break; var currentItem = this.IsSearchNavigating ? Items[nmlv.item.iItem].Clone() : Items[nmlv.item.iItem]; if ((nmlv.item.mask & LVIF.LVIF_TEXT) == LVIF.LVIF_TEXT) { if (nmlv.item.iSubItem == 0) { nmlv.item.pszText = currentItem.DisplayName; Marshal.StructureToPtr(nmlv, m.LParam, false); } else { if ((View == ShellViewStyle.List || View == ShellViewStyle.SmallIcon || View == ShellViewStyle.Details) || (this.View == ShellViewStyle.Tile && this.AllAvailableColumns.Count >= nmlv.item.iSubItem)) { var currentCollumn = this.View == ShellViewStyle.Tile ? this.AllAvailableColumns.Values.ToArray()[nmlv.item.iSubItem] : this.Collumns[nmlv.item.iSubItem]; Object valueCached; if (currentItem.ColumnValues.TryGetValue(currentCollumn.pkey, out valueCached)) { String val = String.Empty; if (valueCached != null) { if (currentCollumn.CollumnType == typeof(DateTime)) val = ((DateTime)valueCached).ToString(Thread.CurrentThread.CurrentUICulture); else if (currentCollumn.CollumnType == typeof(Int64)) val = $"{Math.Ceiling(Convert.ToDouble(valueCached.ToString()) / 1024):# ### ### ##0} KB"; else if (currentCollumn.CollumnType == typeof(PerceivedType)) val = ((PerceivedType)valueCached).ToString(); else if (currentCollumn.CollumnType == typeof(FileAttributes)) val = this.GetFilePropertiesString(valueCached); else val = valueCached.ToString(); } nmlv.item.pszText = val.Trim(); } else { var temp = currentItem; var isi2 = (IShellItem2)temp.ComInterface; var guid = new Guid(InterfaceGuids.IPropertyStore); IPropertyStore propStore = null; isi2.GetPropertyStore(GetPropertyStoreOptions.FastPropertiesOnly, ref guid, out propStore); PROPERTYKEY pk = currentCollumn.pkey; var pvar = new PropVariant(); if (propStore != null && propStore.GetValue(ref pk, pvar) == HResult.S_OK) { if (pvar.Value == null) { if (this.IconSize == 16) { this.SmallImageList.EnqueueSubitemsGet(Tuple.Create(nmlv.item.iItem, nmlv.item.iSubItem, pk)); } else { this.LargeImageList.EnqueueSubitemsGet(Tuple.Create(nmlv.item.iItem, nmlv.item.iSubItem, pk)); } } else { var val = String.Empty; if (currentCollumn.CollumnType == typeof(DateTime)) val = ((DateTime)pvar.Value).ToString(Thread.CurrentThread.CurrentUICulture); else if (currentCollumn.CollumnType == typeof(Int64)) val = $"{Math.Ceiling(Convert.ToDouble(pvar.Value.ToString()) / 1024):# ### ### ##0} KB"; else if (currentCollumn.CollumnType == typeof(PerceivedType)) val = ((PerceivedType)pvar.Value).ToString(); else if (currentCollumn.CollumnType == typeof(FileAttributes)) val = this.GetFilePropertiesString(pvar.Value); else val = pvar.Value.ToString(); nmlv.item.pszText = val.Trim(); pvar.Dispose(); } } } } Marshal.StructureToPtr(nmlv, m.LParam, false); } } if ((nmlv.item.mask & LVIF.LVIF_COLUMNS) == LVIF.LVIF_COLUMNS && this.CurrentFolder?.ParsingName.Equals(KnownFolders.Computer.ParsingName) == false) { int[] columns = null; var refGuidPDL = typeof(IPropertyDescriptionList).GUID; var refGuidPD = typeof(IPropertyDescription).GUID; var iShellItem2 = (IShellItem2)currentItem.ComInterface; var ptrPDL = IntPtr.Zero; iShellItem2.GetPropertyDescriptionList(SpecialProperties.PropListTileInfo, ref refGuidPDL, out ptrPDL); IPropertyDescriptionList propertyDescriptionList = (IPropertyDescriptionList)Marshal.GetObjectForIUnknown(ptrPDL); var descriptionsCount = 0u; propertyDescriptionList.GetCount(out descriptionsCount); nmlv.item.cColumns = (int)descriptionsCount; columns = new int[nmlv.item.cColumns]; Marshal.Copy(nmlv.item.puColumns, columns, 0, nmlv.item.cColumns); for (uint i = 0; i < descriptionsCount; i++) { IPropertyDescription propertyDescription = null; propertyDescriptionList.GetAt(i, ref refGuidPD, out propertyDescription); PROPERTYKEY pkey; propertyDescription.GetPropertyKey(out pkey); Collumns column = null; if (this.AllAvailableColumns.TryGetValue(pkey, out column)) { columns[i] = column.Index; } else { columns[i] = 0; } } Marshal.Copy(columns, 0, nmlv.item.puColumns, nmlv.item.cColumns); Marshal.StructureToPtr(nmlv, m.LParam, false); } break; #endregion Case case WNM.LVN_COLUMNCLICK: #region Case var nlcv = (NMLISTVIEW)m.GetLParam(typeof(NMLISTVIEW)); var sortOrder = SortOrder.Ascending; if (this.LastSortedColumnId == this.Collumns[nlcv.iSubItem].ID) { sortOrder = this.LastSortOrder == SortOrder.Ascending ? SortOrder.Descending : SortOrder.Ascending; } if (!this.IsGroupsEnabled) { SetSortCollumn(true, this.Collumns[nlcv.iSubItem], sortOrder); } else if (this.LastGroupCollumn == this.Collumns[nlcv.iSubItem]) { this.SetGroupOrder(); } else { SetSortCollumn(true, this.Collumns[nlcv.iSubItem], sortOrder); this.SetGroupOrder(false); } break; #endregion Case case WNM.LVN_GETINFOTIP: #region Case var nmGetInfoTip = (NMLVGETINFOTIP)m.GetLParam(typeof(NMLVGETINFOTIP)); if (this.Items.Count == 0) break; if (ToolTip == null) ToolTip = new ToolTip(this); var itemInfotip = this.Items[nmGetInfoTip.iItem]; Char[] charBuf = ("\0").ToCharArray(); Marshal.Copy(charBuf, 0, nmGetInfoTip.pszText, Math.Min(charBuf.Length, nmGetInfoTip.cchTextMax)); Marshal.StructureToPtr(nmGetInfoTip, m.LParam, false); if (ToolTip.IsVisible) ToolTip.HideTooltip(); ToolTip.CurrentItem = itemInfotip; ToolTip.ItemIndex = nmGetInfoTip.iItem; ToolTip.Type = nmGetInfoTip.dwFlags; ToolTip.Left = -500; ToolTip.Top = -500; ToolTip.ShowTooltip(); break; #endregion Case case WNM.LVN_ODFINDITEM: #region Case if (this.ToolTip != null && this.ToolTip.IsVisible) this.ToolTip.HideTooltip(); var findItem = (NMLVFINDITEM)m.GetLParam(typeof(NMLVFINDITEM)); KeyJumpString = findItem.lvfi.psz; KeyJumpKeyDown?.Invoke(this, new KeyEventArgs(Keys.A)); Int32 startindex = this.GetFirstSelectedItemIndex() + (KeyJumpString.Length > 1 ? 0 : 1); Int32 selind = GetFirstIndexOf(KeyJumpString, startindex); if (selind != -1) { m.Result = (IntPtr)(selind); if (IsGroupsEnabled) this.SelectItemByIndex(selind, true, true); } else { int selindOver = GetFirstIndexOf(KeyJumpString, 0); if (selindOver != -1) { m.Result = (IntPtr)(selindOver); if (IsGroupsEnabled) this.SelectItemByIndex(selindOver, true, true); } } break; #endregion Case case -175: #region Case var nmlvLe = (NMLVDISPINFO)m.GetLParam(typeof(NMLVDISPINFO)); if (this.ToolTip != null && this.ToolTip.IsVisible) this.ToolTip.HideTooltip(); this.IsFocusAllowed = false; this._IsCanceledOperation = false; this._ItemForRename = nmlvLe.item.iItem; this.BeginItemLabelEdit?.Invoke(this, new RenameEventArgs(this._ItemForRename)); m.Result = (IntPtr)0; var editControl = User32.SendMessage(this.LVHandle, 0x1018, 0, 0); var indexLastDot = this.Items[this._ItemForRename].DisplayName.LastIndexOf(".", StringComparison.Ordinal); User32.SendMessage(editControl, 0x00B1, 0, indexLastDot); break; #endregion Case case WNM.LVN_ITEMACTIVATE: #region Case if (this.ToolTip != null && this.ToolTip.IsVisible) this.ToolTip.HideTooltip(); if (_ItemForRealNameIsAny && this.IsRenameInProgress) { this.EndLabelEdit(); } else { var iac = (NMITEMACTIVATE)m.GetLParam(typeof(NMITEMACTIVATE)); var selectedItem = Items[iac.iItem]; if (selectedItem.IsFolder) { Navigate_Full(selectedItem, true); } else if (selectedItem.IsLink || selectedItem.ParsingName.EndsWith(".lnk")) { var shellLink = new ShellLink(selectedItem.ParsingName); var newSho = FileSystemListItem.ToFileSystemItem(this.LVHandle, shellLink.TargetPIDL); if (newSho.IsFolder) Navigate_Full(newSho, true); } else { StartProcessInCurrentDirectory(selectedItem); } } break; #endregion Case case WNM.LVN_BEGINSCROLL: #region Case this.EndLabelEdit(); this.LargeImageList.ResetEvent.Reset(); _ResetEvent.Reset(); _ResetTimer.Stop(); this.ToolTip?.HideTooltip(); break; #endregion Case case WNM.LVN_ENDSCROLL: #region Case _ResetTimer.Start(); //this.resetEvent.Set(); break; #endregion Case case -100: #region Case F.MessageBox.Show("AM"); break; #endregion Case case WNM.LVN_ITEMCHANGED: #region Case var nlv = (NMLISTVIEW)m.GetLParam(typeof(NMLISTVIEW)); if ((nlv.uChanged & LVIF.LVIF_STATE) == LVIF.LVIF_STATE) { this._IsDragSelect = nlv.uNewState; if (nlv.iItem != _LastItemForRename) _LastItemForRename = -1; if (!_SelectionTimer.Enabled) _SelectionTimer.Start(); } break; #endregion Case case WNM.LVN_ODSTATECHANGED: #region Case OnSelectionChanged(); break; #endregion Case case WNM.LVN_KEYDOWN: #region Case var nkd = (NMLVKEYDOWN)m.GetLParam(typeof(NMLVKEYDOWN)); if (!ShellView_KeyDown((Keys)((int)nkd.wVKey))) { m.Result = (IntPtr)1; break; } if (nkd.wVKey == (short)Keys.F2 && !(System.Windows.Input.Keyboard.FocusedElement is System.Windows.Controls.TextBox)) { RenameSelectedItem(); } if (!_ItemForRealNameIsAny && !this.IsRenameInProgress && !(System.Windows.Input.Keyboard.FocusedElement is System.Windows.Controls.TextBox)) { switch (nkd.wVKey) { case (short)Keys.Enter: if (this._IsCanceledOperation) { //this.IsRenameInProgress = false; break; } var selectedItem = this.GetFirstSelectedItem(); if (selectedItem.IsFolder) { Navigate(selectedItem, false, false, this.IsNavigationInProgress); } else if (selectedItem.IsLink && selectedItem.ParsingName.EndsWith(".lnk")) { var shellLink = new ShellLink(selectedItem.ParsingName); var newSho = new FileSystemListItem(); newSho.Initialize(this.LVHandle, shellLink.TargetPIDL); if (newSho.IsFolder) Navigate(newSho, false, false, this.IsNavigationInProgress); else StartProcessInCurrentDirectory(newSho); shellLink.Dispose(); } else { StartProcessInCurrentDirectory(selectedItem); } break; } this.Focus(); } else { switch (nkd.wVKey) { case (Int16)Keys.Enter: if (!this.IsRenameInProgress) this.EndLabelEdit(); this.Focus(); break; case (Int16)Keys.Escape: this.EndLabelEdit(true); this.Focus(); break; default: break; } if (System.Windows.Input.Keyboard.FocusedElement is System.Windows.Controls.TextBox) { m.Result = (IntPtr)1; break; } } break; #endregion Case case WNM.LVN_GROUPINFO: //TODO: Deal with this useless code #region Case //RedrawWindow(); break; #endregion Case case WNM.LVN_HOTTRACK: #region Case var nlvHotTrack = (NMLISTVIEW)m.GetLParam(typeof(NMLISTVIEW)); if (ToolTip != null && nlvHotTrack.iItem != ToolTip.ItemIndex && ToolTip.ItemIndex > -1) { ToolTip.HideTooltip(); this.Focus(); } break; #endregion Case case WNM.LVN_BEGINDRAG: #region Case this._DraggedItemIndexes.Clear(); var dataObjPtr = IntPtr.Zero; _DataObject = this.SelectedItems.ToArray().GetIDataObject(out dataObjPtr); //uint ef = 0; var ishell2 = (DataObject.IDragSourceHelper2)new DragDropHelper(); ishell2.SetFlags(1); var wp = new DataObject.Win32Point() { X = Cursor.Position.X, Y = Cursor.Position.Y }; ishell2.InitializeFromWindow(this.Handle, ref wp, _DataObject); DoDragDrop(_DataObject, F.DragDropEffects.All | F.DragDropEffects.Link); //Shell32.SHDoDragDrop(this.Handle, dataObject, null, unchecked((uint)F.DragDropEffects.All | (uint)F.DragDropEffects.Link), out ef); break; #endregion Case case WNM.NM_RCLICK: #region Case var nmhdrHdn = (NMHEADER)(m.GetLParam(typeof(NMHEADER))); var itemActivate = (NMITEMACTIVATE)m.GetLParam(typeof(NMITEMACTIVATE)); this.ToolTip?.HideTooltip(); if (nmhdrHdn.iItem != -1 && nmhdrHdn.hdr.hwndFrom == this.LVHandle) { //Workaround for cases where on right click over an ites the item is not actually selected if (this.GetSelectedCount() == 0) { this.SelectItemByIndex(nmhdrHdn.iItem); } var selitems = this.SelectedItems; var cm = new ShellContextMenu(selitems.ToArray(), SVGIO.SVGIO_SELECTION, this); cm.ShowContextMenu(this, itemActivate.ptAction, CMF.CANRENAME); } else if (nmhdrHdn.iItem == -1) { var cm = new ShellContextMenu(new IListItemEx[1] { this.CurrentFolder }, SVGIO.SVGIO_BACKGROUND, this); cm.ShowContextMenu(this, itemActivate.ptAction, 0, true); } else { this.ColumnHeaderRightClick?.Invoke(this, new MouseEventArgs(F.MouseButtons.Right, 1, MousePosition.X, MousePosition.Y, 0)); } break; #endregion Case case WNM.NM_CLICK: //TODO: Deal with this useless code #region Case break; #endregion Case case WNM.NM_SETFOCUS: #region Case if (IsGroupsEnabled) RedrawWindow(); ShellView_GotFocus(); this.IsFocusAllowed = true; break; #endregion Case case WNM.NM_KILLFOCUS: #region Case if (this._ItemForRename != -1 && !this.IsRenameInProgress) EndLabelEdit(); if (IsGroupsEnabled) RedrawWindow(); this.ToolTip?.HideTooltip(); //OnLostFocus(); if (this.IsRenameInProgress) { this.Focus(false); } break; #endregion Case case CustomDraw.NM_CUSTOMDRAW: this.ProcessCustomDraw(ref m, ref nmhdr); break; } } #endregion m.Msg == 78 } catch { } }