public async Task <SpecialFolder> GetSpecialFolder(string name, SpecialFolderType type, string itemType, CancellationToken cancellationToken) { var path = Path.Combine(_appPaths.ItemsByNamePath, "specialfolders", _fileSystem.GetValidFilename(name)); var id = (path + "_specialfolder_" + name).GetMBId(typeof(SpecialFolder)); var item = _libraryManager.GetItemById(id) as SpecialFolder; if (item == null) { Directory.CreateDirectory(Path.GetDirectoryName(path)); item = new SpecialFolder { Path = path, Id = id, DateCreated = DateTime.UtcNow, Name = name, SpecialFolderType = type, ItemTypeName = itemType }; await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } return(item); }
public FolderStucture(DirectoryInfo folder, SpecialFolderType ignoredSpecialFolders, IList <DefaultAsset> includedFolders, IList <DefaultAsset> excludedFolders) { _includedFolders = includedFolders; _excludedFolders = excludedFolders; _ignoredSpecialFolders = ignoredSpecialFolders; _parentFolder = folder; _subfolderIndecies = new List <int>(); }
public static string GetFolderPath(SpecialFolderType folderType) { StringBuilder path = new StringBuilder(Import.MAX_PATH); int result = Import.SHGetFolderPath(IntPtr.Zero, (int)folderType, IntPtr.Zero, 0, path); if (result != 0) { throw new Win32Exception(result); } return(path.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="SpecialFolder" /> class. /// </summary> /// <param name="type">The type.</param> public SpecialFolder(SpecialFolderType type) { Type = type; switch (type) { case SpecialFolderType.Desktop: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); break; case SpecialFolderType.UserProfile: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); break; case SpecialFolderType.MyDocuments: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); break; case SpecialFolderType.MyMusic: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); break; case SpecialFolderType.MyPictures: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); break; case SpecialFolderType.MyVideos: FullPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); break; case SpecialFolderType.Downloads: if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { FullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); } else { try { FullPath = KnownFolders.Downloads.Path; } catch { // Fall back since the library can throw exceptions FullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads"); } } break; default: break; } }
/// <summary> /// Localizes the folder. /// </summary> /// <param name="folder">The folder.</param> /// <param name="path">The path.</param> /// <returns>System.String.</returns> private static string LocalizeFolder(SpecialFolderType folder, string path) { InitLocalizationManager(); string localized = string.Empty; switch (folder) { case SpecialFolderType.Desktop: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Desktop); break; case SpecialFolderType.MyDocuments: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Documents); break; case SpecialFolderType.MyMusic: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Music); break; case SpecialFolderType.MyPictures: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Pictures); break; case SpecialFolderType.MyVideos: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Videos); break; case SpecialFolderType.Downloads: localized = localizationManager.GetResource(LocalizationResources.FileDialog.Folders.Downloads); break; default: break; } if (!string.IsNullOrWhiteSpace(localized)) { return(localized); } return(path); }
public ClientResult <string> GetSpecialFolderUrl(SpecialFolderType type, bool forceCreated, Guid existingGuid) => _list.GetSpecialFolderUrl(type, forceCreated, existingGuid);
public static string GetFolderPath(SpecialFolderType folderType) { StringBuilder path = new StringBuilder(Import.MAX_PATH); int result = Import.SHGetFolderPath(IntPtr.Zero, (int)folderType, IntPtr.Zero, 0, path); if(result != 0) throw new Win32Exception(result); return path.ToString(); }
public List <DataSourceShell> GetFolderByPage(int pageSize, int pageindex, out bool isEndPage) { ShellAPI.IEnumIDList shllEnum = null; IntPtr ptrIDLChild = IntPtr.Zero; Int32 isGotChild = 0; List <DataSourceShell> lst = new List <DataSourceShell>(); LogHelper.DebugFormat("shell GetFolderByPage ==>{0}", this.ParsingName); if (this._blibrary) //support for windows 7 library { #region For library ShellAPI.IShellItem psi; if (ShellAPI.SHCreateShellItem(IntPtr.Zero, null, PIDL, out psi) == 0) { Int32 length = 0; if (ShellAPI.SHLoadLibraryFromItem(psi, ref length) == 0) { for (int i = 0; i <= length; i++) { ShellAPI.IShellItem psiarry; if (ShellAPI.SHGetShellItemsAt(psi, i, out psiarry) == 0) { DataSourceShell shItem = new DataSourceShell(psiarry); lst.Add(shItem); } } isEndPage = true; return(lst); } } #endregion } #region init isEndPage = false; // Get the IEnumIDList interface pointer. ShellAPI.SHCONTF flags = ShellAPI.SHCONTF.SHCONTF_FOLDERS; if (shllEnum != null) { Marshal.ReleaseComObject(shllEnum); } uint result = ShellFolder.EnumObjects(IntPtr.Zero, flags , out shllEnum); if (result != 0) { isEndPage = true; LogHelper.Debug("result != 0 ==> true"); return(null); } #endregion #region reset enum ptrIDLChild = IntPtr.Zero; isGotChild = 0; shllEnum.Reset(); #endregion #region skip pageIndex*pageSize // Grab the first enumeration. for (int i = 0; i <= ((pageindex - 1) * pageSize); i++) { // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(ptrIDLChild); ptrIDLChild = IntPtr.Zero; isGotChild = 0; // Grab the next item. shllEnum.Next(1, out ptrIDLChild, out isGotChild); } #endregion LogHelper.Debug("enum ....."); #region enum item int itemIndex = 0; while (itemIndex < pageSize) { SpecialFolderType specialFolderType = CheckSpecialFolderType(shellFolder, ptrIDL, ptrIDLChild); if (specialFolderType != SpecialFolderType.Internet && specialFolderType != SpecialFolderType.RecycleBin && specialFolderType != SpecialFolderType.MyComputerControlPanel && specialFolderType != SpecialFolderType.DesktopControlPanel && (SpecialFolderType != SpecialFolderType.MyComputer || (specialFolderType != SpecialFolderType.MyDocuments && specialFolderType != SpecialFolderType.SharedDocuments)) ) { LogHelper.DebugFormat("enum-1 : {0}", ptrIDLChild); // Create the new ShellItem object. DataSourceShell shItem = new DataSourceShell(shellRoot, ptrIDLChild, this, false, specialFolderType); if (shItem.IsFolder && !shItem.IsStream) { lst.Add(shItem); } LogHelper.DebugFormat("enum : {0}", shItem.ParsingName); } // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(ptrIDLChild); ptrIDLChild = IntPtr.Zero; isGotChild = 0; // Grab the next item. shllEnum.Next(1, out ptrIDLChild, out isGotChild); if (ptrIDLChild.Equals(IntPtr.Zero) && isGotChild == 0) { LogHelper.Debug("ptrIDLChild.Equals(IntPtr.Zero) && iGotChild == 0 ==> true"); isEndPage = true; break; } itemIndex++; } #endregion LogHelper.Debug("enum <=="); #region sort item // AH: If _getfolders flag is true, sort treeview items. if (this.SpecialFolderType != SpecialFolderType.MyComputer) { List <DataSourceShell> tempLst = new List <DataSourceShell>(); IComparer <DataSourceShell> comparer = new SortAscending(); for (int i = 0; isRoot && i < lst.Count; i++) { if (lst[i].SpecialFolderType == SpecialFolderType.MyComputer || lst[i].SpecialFolderType == SpecialFolderType.DesktopControlPanel || lst[i].SpecialFolderType == SpecialFolderType.Network || lst[i].SpecialFolderType == SpecialFolderType.MyDocuments || lst[i].SpecialFolderType == SpecialFolderType.SharedDocuments || lst[i].SpecialFolderType == SpecialFolderType.CurrentUserProfile ) { tempLst.Add(lst[i]); lst.RemoveAt(i); i--; } } lst.Sort(comparer); for (int i = 0; isRoot && i < tempLst.Count; i++) { lst.Insert(i, tempLst[i]); } } #endregion LogHelper.Debug("enum end=="); return(lst); }
/// <summary> /// Gets the page. /// </summary> /// <param name="getNextPage">if set to <c>true</c> [get next page].</param> /// <param name="pageSize">Size of the page.</param> /// <returns></returns> List <DataSourceShell> GetPage(ShellAPI.IEnumIDList pEnum) { IntPtr pIDLChild = IntPtr.Zero; Int32 iGotChild = 0; List <DataSourceShell> lst = new List <DataSourceShell>(); pEnum.Next(1, out pIDLChild, out iGotChild); while (!pIDLChild.Equals(IntPtr.Zero) && iGotChild == 1) { SpecialFolderType specialFolderType = CheckSpecialFolderType(shellFolder, ptrIDL, pIDLChild); if (specialFolderType != SpecialFolderType.Internet && specialFolderType != SpecialFolderType.RecycleBin && specialFolderType != SpecialFolderType.MyComputerControlPanel && specialFolderType != SpecialFolderType.DesktopControlPanel && (SpecialFolderType != SpecialFolderType.MyComputer || (specialFolderType != SpecialFolderType.MyDocuments && specialFolderType != SpecialFolderType.SharedDocuments)) ) { // Create the new ShellItem object. DataSourceShell shItem = new DataSourceShell(shellRoot, pIDLChild, this, false, specialFolderType); if (shItem.IsFolder && !shItem.IsStream) { lst.Add(shItem); } } // Free the PIDL and reset counters. Marshal.FreeCoTaskMem(pIDLChild); pIDLChild = IntPtr.Zero; iGotChild = 0; // Grab the next item. pEnum.Next(1, out pIDLChild, out iGotChild); } if (this.SpecialFolderType != SpecialFolderType.MyComputer) { List <DataSourceShell> tempLst = new List <DataSourceShell>(); IComparer <DataSourceShell> comparer = new SortAscending(); for (int i = 0; isRoot && i < lst.Count; i++) { if (lst[i].SpecialFolderType == SpecialFolderType.MyComputer || lst[i].SpecialFolderType == SpecialFolderType.DesktopControlPanel || lst[i].SpecialFolderType == SpecialFolderType.Network || lst[i].SpecialFolderType == SpecialFolderType.MyDocuments || lst[i].SpecialFolderType == SpecialFolderType.SharedDocuments || lst[i].SpecialFolderType == SpecialFolderType.CurrentUserProfile ) { tempLst.Add(lst[i]); lst.RemoveAt(i); i--; } } lst.Sort(comparer); for (int i = 0; isRoot && i < tempLst.Count; i++) { lst.Insert(i, tempLst[i]); } } return(lst); }
/// <summary> /// Constructor. Create a sub-item shell item object. /// </summary> /// <param name="shFolder">IShellFolder interface of the Desktop</param> /// <param name="pIDL">The fully qualified PIDL for this shell item</param> /// <param name="shellDesktop">The ShellItem object for desktop</param> public DataSourceShell(ShellAPI.IShellFolder shellDesktop, IntPtr pIDL, DataSourceShell shellParent, bool hasOnlyFolders, SpecialFolderType folderType) { _specialFolderType = folderType; // We need the Desktop shell item to exist first. if (haveRootShell == false) { throw new Exception("The root shell item must be created before creating a sub-item"); } // Create the FQ PIDL for this new item. ptrIDL = ShellAPI.ILCombine(shellParent.PIDL, pIDL); shellItemPath = GetPath(); // Get the properties of this item. ShellAPI.SFGAOF uFlags = ShellAPI.SFGAOF.SFGAO_FOLDER | //ShellAPI.SFGAOF.SFGAO_HASSUBFOLDER | ShellAPI.SFGAOF.SFGAO_BROWSABLE | ShellAPI.SFGAOF.SFGAO_STREAM | ShellAPI.SFGAOF.SFGAO_LINK | ShellAPI.SFGAOF.SFGAO_FILESYSTEM | ShellAPI.SFGAOF.SFGAO_HIDDEN | ShellAPI.SFGAOF.SFGAO_REMOVABLE ; // Here we get some basic attributes. uint result = shellParent.shellFolder.GetAttributesOf(1, ref pIDL, ref uFlags); isFolder = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_FOLDER); hasSubFolder = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_HASSUBFOLDER); IsBrowsable = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_BROWSABLE); IsStream = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_STREAM); IsLink = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_LINK); isFileSystem = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_FILESYSTEM); IsHidden = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_HIDDEN); IsRemovable = Convert.ToBoolean(uFlags & ShellAPI.SFGAOF.SFGAO_REMOVABLE); ShellAPI.IShellItem pshellitem; if (ShellAPI.SHCreateShellItem(IntPtr.Zero, null, PIDL, out pshellitem) == 0) { Int32 length = 0; if (ShellAPI.SHLoadLibraryFromItem(pshellitem, ref length) == 0) { _blibrary = true; } } IntPtr parseString = IntPtr.Zero; pshellitem.GetDisplayName(ShellAPI.SIGDN.SIGDN_DESKTOPABSOLUTEPARSING, out parseString); this.ParsingName = Marshal.PtrToStringAuto(parseString); LoadFileInfo(ptrIDL); // [1/18/2010 jozhang #92129] //when IsStream and isFolder is true,it means the file is .cab or .zip so isFolder should be changed to false; if (IsStream && isFolder) { isFolder = false; // In case of zip } try { // Create the IShellFolder interface for this item. if (IsFolder) { result = shellParent.shellFolder.BindToObject(pIDL, IntPtr.Zero, ref ShellAPI.IID_IShellFolder, out shellFolder); if (result != 0) { Marshal.ThrowExceptionForHR((int)result); } } } catch (Exception ex) { LogHelper.Debug("shellParent.shellFolder.BindToObject Failed", ex); } }
FolderObject GetFolder(string path); // http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileSystemObjectGetFolder.htm string GetSpecialFolder(SpecialFolderType type); // http://www.java2s.com/Tutorial/JavaScript/0600__MS-JScript/FileSystemObjectGetSpecialFolder.htm
public async Task<SpecialFolder> GetSpecialFolder(string name, SpecialFolderType type, string itemType, CancellationToken cancellationToken) { var path = Path.Combine(_appPaths.ItemsByNamePath, "specialfolders", _fileSystem.GetValidFilename(name)); var id = (path + "_specialfolder_" + name).GetMBId(typeof(SpecialFolder)); var item = _libraryManager.GetItemById(id) as SpecialFolder; if (item == null) { Directory.CreateDirectory(Path.GetDirectoryName(path)); item = new SpecialFolder { Path = path, Id = id, DateCreated = DateTime.UtcNow, Name = name, SpecialFolderType = type, ItemTypeName = itemType }; await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } return item; }