private async Task LoadFolder(StorageFolder folder, DateTime lastSync) { if (isCanceled) return; IReadOnlyList<IStorageItem> fileList = await folder.GetItemsAsync(); foreach (IStorageItem storageItem in fileList) { if (storageItem.IsOfType(StorageItemTypes.File)) { StorageFile storageFile = DebugHelper.CastAndAssert<StorageFile>(storageItem); await LoadFile(storageFile); } else if (storageItem.IsOfType(StorageItemTypes.Folder)) { StorageFolder storageFolder = DebugHelper.CastAndAssert<StorageFolder>(storageItem); BasicProperties basicProperties = await storageFolder.GetBasicPropertiesAsync(); DateTime candidateTime = basicProperties.DateModified.UtcDateTime; if (candidateTime > lastSync) { await LoadFolder(storageFolder, lastSync); } } } }
private async Task <bool> VerificarDirectorio(int posicion) { // var watch = System.Diagnostics.Stopwatch.StartNew(); String directorio = Mangas.ElementAt(posicion).GetDirectory(); try { Windows.Storage.StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(directorio); var items = await folder.GetItemsAsync(0, 1); if (items.Count == 0) { await Clases.Functions.CreateMessageAsync("El Directorio de " + directorio.Split('\\').Last() + "esta vacio"); return(false); } // watch.Stop(); // Debug.WriteLine("Tiempo revisión: " + watch.ElapsedMilliseconds); return(true); } catch (Exception) { if (await Clases.Functions.SiNoMensaje(("Ha ocurrido un error en la lectura de: " + directorio.Split('\\').Last() + "\n¿Desea eliminarlo de la lista de mangas?")) == 1) { Mangas.RemoveAt(posicion); DeleteGrid(posicion + 1); SaveData(); } return(false); } }
public static async Task<bool> DeleteFolder(StorageFolder folder) { var folders = await folder.GetItemsAsync(); for (int i = 0; i < folders.Count; i++) { DeletItem(folders[i]); } return true; }
public static async Task ClearFiles(StorageFolder folder) { try { foreach (IStorageItem item in await folder.GetItemsAsync()) { if (item.IsOfType(StorageItemTypes.Folder)) { await ClearFiles((StorageFolder) item); } else { await item.DeleteAsync(); } } } catch (FileNotFoundException) { } }
private async Task GetAllFiles(StorageFolder storageFolder, List<StorageFile> musicFiles) { foreach (var item in await storageFolder.GetItemsAsync()) if (item is StorageFile) { var file = item as StorageFile; if (file.ContentType.StartsWith("audio") && !file.ContentType.EndsWith("url")) musicFiles.Add(file); } else { var folder = item as StorageFolder; await this.GetAllFiles(folder, musicFiles); } }
private static async Task GetFilesFromSubFolders(StorageFolder folder, List<StorageFile> files) { try { var items = await folder.GetItemsAsync(); foreach (IStorageItem storageItem in items) { if (storageItem.IsOfType(StorageItemTypes.Folder)) await GetFilesFromSubFolders(storageItem as StorageFolder, files); else if (storageItem.IsOfType(StorageItemTypes.File)) { var file = storageItem as StorageFile; if (VLCFileExtensions.VideoExtensions.Contains(file.FileType.ToLower())) { files.Add(file); } } } } catch (Exception e) { ExceptionHelper.CreateMemorizedException("VideoLibraryManagement.GetFilesFromSubFolders", e); } }
private async Task FilesNumber(StorageFolder cartella) { var Items = await cartella.GetItemsAsync(); foreach(IStorageItem Item in Items) { if(Item.IsOfType(StorageItemTypes.Folder)) { await FilesNumber((StorageFolder)Item); } else if(Item.IsOfType(StorageItemTypes.File)) { file_count++; BasicProperties bp = await ((StorageFile)Item).GetBasicPropertiesAsync(); file_size+= bp.Size; } } }
public static async Task<byte[]> CreateBackup(StorageFolder folder) { using (var autcpStream = new MemoryStream()) { // add header now AddHeader(autcpStream); using (var zipArchive = new ZipArchive(autcpStream, ZipArchiveMode.Create)) { var filesToCompress = await folder.GetItemsAsync(); foreach (var item in filesToCompress) { var files = new List<StorageFile>(); if (item is StorageFile) { var file = item as StorageFile; if (file.FileType == ".autcp" || file.Name.ToLower().StartsWith("xam") || file.Name.StartsWith("_")) { continue; } files.Add(file); } else if (item is StorageFolder) { var name = (item as StorageFolder).Name; if (name == "SOMA" || name == "Logs" || name == "AdMediator" || name == "artists" || name == "artworks") { continue; } files.AddRange(await (item as StorageFolder).GetFilesAsync()); } foreach (var file in files) { var buffer = await FileIO.ReadBufferAsync(file); if (buffer.Length == 0) { continue; } var bytes = buffer.ToArray(); var path = file.Path.Replace(folder.Path + "\\", string.Empty).Replace("\\", "/"); var entry = zipArchive.CreateEntry(path, CompressionLevel.Optimal); using (var entryStream = entry.Open()) { await entryStream.WriteAsync(bytes, 0, bytes.Length); await entryStream.FlushAsync(); } } } } return autcpStream.ToArray(); } }
private IObservable<StorageFile> GetFilesAsync(StorageFolder folder) { var obsItems = folder.GetItemsAsync().ToObservable(); var files = (from item in obsItems from i in item select i is StorageFile ? Observable.Return((StorageFile)i) : GetFilesAsync((StorageFolder)i)) .SelectMany(i => i); return files; }
/// <summary> /// Copy a <see cref="StorageFolder"/> and its content to a specified directory /// </summary> /// <param name="source">the source folder</param> /// <param name="destination">the destination folder where create the copy</param> /// <param name="directoryName">the copy directory</param> /// <returns></returns> public async Task<bool> CopyFolder(StorageFolder source, StorageFolder destination, string directoryName) { //using (await InstanceLock.LockAsync()) //{ var isCopied = true; try { directoryName = directoryName.Replace("/", "\\"); await CreateDirectory(destination, directoryName); var folderDest = await destination.GetFolderAsync(directoryName); if (folderDest != null) { var items = await source.GetItemsAsync(); foreach (var item in items) { if (item.IsOfType(StorageItemTypes.File) == true) { isCopied = await CopyFile(source, folderDest, item.Name); } else if (item.IsOfType(StorageItemTypes.Folder) == true) { isCopied = await CopyFolder(source, folderDest, item.Name); } if (isCopied == false) { throw new Exception("Fail to copy item"); } } } else { throw new Exception("Fail to create new directory"); } } catch { isCopied = false; } return isCopied; //} }
public static async Task<List<IStorageFile>> SearchAllinFolder(StorageFolder tempFolder) { try { IReadOnlyList<IStorageItem> tempList = await tempFolder.GetItemsAsync(); List<IStorageFile> finalList = new List<IStorageFile>(); if (tempList.Count == 0) return finalList; foreach (var item in tempList) { if (item is StorageFolder) { finalList.AddRange(await SearchAllinFolder((StorageFolder)item)); } if (item is StorageFile) { if (tempTypeStrings.Contains(((StorageFile)item).FileType)) { finalList.Add((StorageFile)item); } } } return finalList; } catch (Exception) { return new List<IStorageFile>(); } }
public static async Task DeleteFolderContentAsync(StorageFolder folder) { var items = await folder.GetItemsAsync(); foreach (var storageItem in items) await storageItem.DeleteAsync(); }
private async void showSequenceForFolder(StorageFolder sf, bool repeat) { if (stopSequence) return; IReadOnlyList<IStorageItem> snapList = await sf.GetItemsAsync(); try { for (int i=0; i < snapList.Count; i++) { StorageFile currFile = await sf.GetFileAsync(snapList[i].Name); BitmapImage bmpimg = await ImageController.GetImage(currFile); sequenceElement.Source = bmpimg; screensaverView.Source = bmpimg; await Task.Delay(TimeSpan.FromMilliseconds(150)); } } catch (Exception ex) { addMessage("exception caught in sequence: " + ex.Message); } if (repeat) this.showSequenceForFolder(sf,repeat); }
private async Task ScanDirectoryAsync(StorageFolder storageFolder, bool doSha1, IObserver<string> starts, IObserver<FileInfo> completes) { foreach (var entry in await storageFolder.GetItemsAsync()) { var folder = entry as StorageFolder; // folder if (folder != null) { starts.OnNext(folder.Name); var innerStarts = new Subject<string>(); var innerCompletes = new Subject<FileInfo>(); var _ = Task.Run(() => ScanDirectoryAsync(folder, false, innerStarts, innerCompletes)); var totalSize = await innerStarts .Zip(innerCompletes, (s, f) => (double)f.Size) .Sum(x => x).FirstAsync(); completes.OnNext(new FileInfo { Name = folder.Name, Size = (ulong)totalSize }); } var file = entry as StorageFile; // file if (file != null) { starts.OnNext(file.Name); var fileInfo = await ScanFile(file, doSha1).ConfigureAwait(false); completes.OnNext(fileInfo); } } starts.OnCompleted(); completes.OnCompleted(); }