//this is ~300 times slower than AFile.Move. SHFileOperation too. Use only for files or other shell items in virtual folders. Unfinished. public static void RenameFileOrDirectory(string path, string newName) { APerf.First(); if (APath.IsInvalidFileName(newName)) { throw new ArgumentException("Invalid filename.", nameof(newName)); } path = _PreparePath(path, nameof(path)); APerf.Next(); var si = _ShellItem(path, "*rename"); APerf.Next(); var fo = new Api.FileOperation() as Api.IFileOperation; APerf.Next(); try { fo.SetOperationFlags(4); //FOF_SILENT. Without it shows a hidden dialog that becomes the active window. AuException.ThrowIfFailed(fo.RenameItem(si, newName, null), "*rename"); APerf.Next(); AuException.ThrowIfFailed(fo.PerformOperations(), "*rename"); APerf.Next(); } finally { Api.ReleaseComObject(fo); Api.ReleaseComObject(si); } APerf.NW(); }
/// <summary> /// Saves to the shortcut file (.lnk). /// </summary> /// <exception cref="AuException">Failed to save.</exception> /// <remarks> /// Creates parent folder if need. /// </remarks> public void Save() { if (_changedHotkey && !_isOpen && filesystem.exists(_lnkPath).File) { _UnregisterHotkey(_lnkPath); } filesystem.createDirectoryFor(_lnkPath); AuException.ThrowIfHresultNot0(_ipf.Save(_lnkPath, true), "*save"); }
/// <summary> /// Saves the Shortcut variable properties to the shortcut file. /// </summary> /// <exception cref="AuException">Failed to save .lnk file.</exception> /// <remarks> /// Creates parent folder if need. /// </remarks> public void Save() { if (_changedHotkey && !_isOpen && AFile.ExistsAsFile(_lnkPath)) { _UnregisterHotkey(_lnkPath); } AFile.CreateDirectoryFor(_lnkPath); AuException.ThrowIfHresultNot0(_ipf.Save(_lnkPath, true), "*save"); }
//This could be public, but then need to make IShellLink public. It is defined in a non-standard way. Never mind, it is not important. shortcutFile(string lnkPath, uint mode) { _isl = new Api.ShellLink() as Api.IShellLink; _ipf = _isl as Api.IPersistFile; _lnkPath = pathname.normalize(lnkPath); if (mode != Api.STGM_WRITE && (mode == Api.STGM_READ || filesystem.exists(_lnkPath).File)) { AuException.ThrowIfHresultNot0(_ipf.Load(_lnkPath, mode), "*open"); _isOpen = true; } }
//This could be public, but then need to make IShellLink public. It is defined in a non-standard way. Never mind, it is not important. AShortcutFile(string lnkPath, uint mode) { _isl = new Api.ShellLink() as Api.IShellLink; _ipf = _isl as Api.IPersistFile; _lnkPath = lnkPath; if (mode != Api.STGM_WRITE && (mode == Api.STGM_READ || AFile.ExistsAsFile(_lnkPath))) { AuException.ThrowIfHresultNot0(_ipf.Load(_lnkPath, mode), "*open"); _isOpen = true; } }