Пример #1
0
        public static async Task <StorageEntryLoadInfo> LoadMoreStorageItemAsync(StorageFolder destFolder, ObservableCollection <StorageEntry> collection, StorageEntryUsage usage, StorageEntryLoadInfo info)
        {
            IReadOnlyList <IStorageItem> storageItems = null;

            if (info.LeavingCount < PreferenceAgency.Default.MaxLoadCount)
            {
                storageItems = await destFolder.GetItemsAsync(info.loadedCount, info.LeavingCount);

                info.loadedCount = info.entriesCount;
                info.isLoadedAll = true;
            }
            else
            {
                storageItems = await destFolder.GetItemsAsync(info.loadedCount, PreferenceAgency.Default.MaxLoadCount);

                info.loadedCount += PreferenceAgency.Default.MaxLoadCount;
            }

            foreach (var eachItem in storageItems)
            {
                var newEntry = new StorageEntry(eachItem, usage);
                collection.Add(newEntry);
            }

            return(info);
        }
Пример #2
0
        public static async Task <StorageEntryLoadInfo> LoadStorageFolderAsync(StorageFolder destFolder, ObservableCollection <StorageEntry> collection, StorageEntryUsage usage)
        {
            var itemsCount = Directory.GetFileSystemEntries(destFolder.Path, "*", SearchOption.TopDirectoryOnly).Length;

            StorageEntryLoadInfo info;

            info.entriesCount = (uint)itemsCount;
            info.path         = destFolder.Path;

            IReadOnlyList <IStorageItem> storageItems = null;

            if (itemsCount > PreferenceAgency.Default.InitialMaxLoadCount)
            {
                storageItems = await destFolder.GetItemsAsync(0, PreferenceAgency.Default.InitialMaxLoadCount);

                info.isLoadedAll = false;
                info.loadedCount = PreferenceAgency.Default.InitialMaxLoadCount;
            }
            else
            {
                storageItems = await destFolder.GetItemsAsync();

                info.isLoadedAll = true;
                info.loadedCount = info.entriesCount;
            }

            foreach (var eachItem in storageItems)
            {
                var newEntry = new StorageEntry(eachItem, usage);
                collection.Add(newEntry);
            }

            return(info);
        }
Пример #3
0
        /// <summary> 重命名某个文件或文件夹 并将它从目前显示的list中删去 </summary>
        /// <param name="enrty">需要重命名的文件或文件夹</param>
        public async Task <bool> RenameEntryAsync(StorageEntry entry, string newName, NameCollisionOption option)
        {
            try {
                await entry.RawEntry.RenameAsync(newName, option);
            } catch {
                return(false);
            }

            return(true);
        }
Пример #4
0
        /// <summary> 常见一个新的文件或文件夹 </summary>
        /// <param name="destFolder">目标文件夹</param>
        /// <param name="name">文件项名</param>
        /// <param name="type">文件项的类型(文件或文件夹)</param>
        /// <returns>创建成功返回true,否则返回false</returns>
        public async Task <IStorageItem> CreatedNewEntry(StorageEntry destFolder, string name, StorageEntryType type, CreationCollisionOption option)
        {
            switch (type)
            {
            case StorageEntryType.File: return(await destFolder.Folder.CreateFileAsync(name, option));

            case StorageEntryType.Folder: return(await destFolder.Folder.CreateFolderAsync(name, option));

            default:  return(null);
            }
        }
Пример #5
0
        public static async Task <bool> EntryExistAsync(StorageEntry entry)
        {
            // FIXME: 对部分确实存在的文件返回不存在 "G:\STEINS;GATE 线形拘束のフェノグラム.rar"
            switch (entry.EntryType)
            {
            case StorageEntryType.File:
                return(await Task.Run(() => System.IO.File.Exists(entry.RawEntry.Path)));

            case StorageEntryType.Folder:
                return(await Task.Run(() => System.IO.Directory.Exists(entry.RawEntry.Path)));

            default: return(false);
            }
        }
Пример #6
0
 /// <summary> 删除文件或文件夹,删除的文件送往回收站  </summary>
 /// <param name="entry">需要删除的文件项</param>
 public async void DeleteEntryAsync(StorageEntry entry)
 {
     await entry.RawEntry.DeleteAsync(StorageDeleteOption.Default); // Default 表示删除的文件送往回收站
 }