Example #1
0
        /// <summary>
        /// Loads a zip file
        /// </summary>
        /// <param name="fse"></param>
        /// <param name="thumbnailOptions"></param>
        private async void LoadZip(FileSystemElement fse, FileSystemRetrieveService.ThumbnailFetchOptions thumbnailOptions, CancellationToken token)
        {
            elements.Clear();
            currentDepth   = 0;
            folderIndex    = 0;
            currentZIPFile = await FileSystem.GetFileAsync(fse);

            currentFSE = fse;

            using (Stream stream = await currentZIPFile.OpenStreamForReadAsync())
            {
                var reader = ReaderFactory.Open(stream);
                while (reader.MoveToNextEntry())
                {
                    if (token.IsCancellationRequested)
                    {
                        return;
                    }

                    var entry    = reader.Entry;
                    var keySplit = entry.Key.Split("/");
                    var subPath  = string.Join(@"\", keySplit, 0, keySplit.Length - 1);

                    int            depth;
                    ZipFileElement element;
                    if (entry.IsDirectory)
                    {
                        var name = keySplit[keySplit.Length - 2];
                        depth = keySplit.Length - 2;

                        element = new ZipFileElement(
                            name,
                            fse.Path + @"\" + subPath,
                            entry.LastModifiedTime.Value,
                            (ulong)entry.Size,
                            entry.Key,
                            depth
                            );

                        elements.AddFirst(depth, element);
                    }
                    else
                    {
                        var name = keySplit[keySplit.Length - 1];
                        depth = keySplit.Length - 1;

                        string fileExtension = "";
                        var    fileName      = entry.Key.Split(".");
                        if (fileName.Length > 1)
                        {
                            fileExtension = fileName[fileName.Length - 1];
                        }

                        //Store fileStream to access it later
                        var elementStream = new MemoryStream();
                        reader.WriteEntryTo(elementStream);
                        await elementStream.FlushAsync();

                        var thumbnail = await FileSystem.GetFileExtensionThumbnail(fileExtension, thumbnailOptions.Mode, thumbnailOptions.Size, thumbnailOptions.Scale);

                        element = new ZipFileElement(
                            name,
                            fse.Path + @"\" + subPath,
                            entry.LastModifiedTime.Value,
                            (ulong)entry.Size,
                            thumbnail,
                            "." + fileExtension,
                            fileExtension,
                            entry.Key,
                            depth,
                            elementStream
                            );

                        elements.Add(depth, element);
                    }

                    AddToViewItems(element);
                }
            }
        }