public static async Task CreateGzipAsync(FileSystemStorageFile Source, string NewZipPath, CompressionLevel Level, ProgressChangedEventHandler ProgressHandler = null)
        {
            if (Level == CompressionLevel.Undefine)
            {
                throw new ArgumentException("Undefine is not allowed in this function", nameof(Level));
            }

            if (await FileSystemStorageItemBase.CreateAsync(NewZipPath, StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
            {
                using (FileStream SourceFileStream = await Source.GetFileStreamFromFileAsync(AccessMode.Read))
                    using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Exclusive))
                        using (GZipOutputStream GZipStream = new GZipOutputStream(NewFileStream))
                        {
                            GZipStream.SetLevel((int)Level);
                            GZipStream.IsStreamOwner = false;
                            GZipStream.FileName      = Source.Name;

                            await SourceFileStream.CopyToAsync(GZipStream, ProgressHandler : ProgressHandler).ConfigureAwait(false);
                        }
            }
            else
            {
                throw new UnauthorizedAccessException();
            }
        }
Beispiel #2
0
        /// <summary>
        /// 提供图片转码
        /// </summary>
        /// <param name="SourceFile">源文件</param>
        /// <param name="DestinationFile">目标文件</param>
        /// <param name="IsEnableScale">是否启用缩放</param>
        /// <param name="ScaleWidth">缩放宽度</param>
        /// <param name="ScaleHeight">缩放高度</param>
        /// <param name="InterpolationMode">插值模式</param>
        /// <returns></returns>
        public static async Task TranscodeFromImageAsync(FileSystemStorageFile SourceFile, FileSystemStorageFile DestinationFile, bool IsEnableScale = false, uint ScaleWidth = default, uint ScaleHeight = default, BitmapInterpolationMode InterpolationMode = default)
        {
            IsAnyTransformTaskRunning = true;

            using (IRandomAccessStream OriginStream = await SourceFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.Read).ConfigureAwait(false))
            {
                try
                {
                    BitmapDecoder Decoder = await BitmapDecoder.CreateAsync(OriginStream);

                    using (SoftwareBitmap TranscodeImage = await Decoder.GetSoftwareBitmapAsync())
                        using (IRandomAccessStream TargetStream = await DestinationFile.GetRandomAccessStreamFromFileAsync(FileAccessMode.ReadWrite).ConfigureAwait(false))
                        {
                            BitmapEncoder Encoder = DestinationFile.Type.ToLower() switch
                            {
                                ".png" => await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, TargetStream),
                                ".jpg" => await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, TargetStream),
                                ".bmp" => await BitmapEncoder.CreateAsync(BitmapEncoder.BmpEncoderId, TargetStream),
                                ".heic" => await BitmapEncoder.CreateAsync(BitmapEncoder.HeifEncoderId, TargetStream),
                                ".tiff" => await BitmapEncoder.CreateAsync(BitmapEncoder.TiffEncoderId, TargetStream),
                                _ => throw new InvalidOperationException("Unsupport image format"),
                            };

                            if (IsEnableScale)
                            {
                                Encoder.BitmapTransform.ScaledWidth       = ScaleWidth;
                                Encoder.BitmapTransform.ScaledHeight      = ScaleHeight;
                                Encoder.BitmapTransform.InterpolationMode = InterpolationMode;
                            }

                            Encoder.SetSoftwareBitmap(TranscodeImage);

                            await Encoder.FlushAsync();
                        }
                }
                catch (Exception)
                {
                    await DestinationFile.DeleteAsync(true);

                    await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
                    {
                        QueueContentDialog dialog = new QueueContentDialog
                        {
                            Title           = Globalization.GetString("Common_Dialog_ErrorTitle"),
                            Content         = Globalization.GetString("EnDecode_Dialog_Content"),
                            CloseButtonText = Globalization.GetString("Common_Dialog_CloseButton")
                        };

                        _ = await dialog.ShowAsync();
                    });
                }
            }

            IsAnyTransformTaskRunning = false;
        }
Beispiel #3
0
 public static async Task <ProgramPickerItem> CreateAsync(FileSystemStorageFile File)
 {
     if (await File.GetStorageItemAsync() is StorageFile ExecuteFile)
     {
         return(await CreateAsync(ExecuteFile));
     }
     else
     {
         return(new ProgramPickerItem(File.DisplayName, Globalization.GetString("Application_Admin_Name"), File.Path));
     }
 }
        public static async Task <FileSystemStorageItemBase> OpenAsync(string Path)
        {
            if (System.IO.Path.GetPathRoot(Path) != Path && WIN_Native_API.GetStorageItem(Path) is FileSystemStorageItemBase Item)
            {
                return(Item);
            }
            else
            {
                LogTracer.Log($"Native API could not found the path: \"{Path}\", fall back to UWP storage API");

                try
                {
                    string DirectoryPath = System.IO.Path.GetDirectoryName(Path);

                    if (string.IsNullOrEmpty(DirectoryPath))
                    {
                        StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(Path);

                        return(await FileSystemStorageFolder.CreateFromExistingStorageItem(Folder));
                    }
                    else
                    {
                        StorageFolder ParentFolder = await StorageFolder.GetFolderFromPathAsync(DirectoryPath);

                        switch (await ParentFolder.TryGetItemAsync(System.IO.Path.GetFileName(Path)))
                        {
                        case StorageFolder Folder:
                        {
                            return(await FileSystemStorageFolder.CreateFromExistingStorageItem(Folder));
                        }

                        case StorageFile File:
                        {
                            return(await FileSystemStorageFile.CreateFromExistingStorageItem(File));
                        }

                        default:
                        {
                            LogTracer.Log($"UWP storage API could not found the path: \"{Path}\"");
                            return(null);
                        }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"UWP storage API could not found the path: \"{Path}\"");
                    return(null);
                }
            }
        }
 public static async Task ExtractGZipAsync(FileSystemStorageFile Item, ProgressChangedEventHandler ProgressHandler = null)
 {
     if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(Path.GetDirectoryName(Item.Path), Path.GetFileNameWithoutExtension(Item.Name)), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
     {
         using (FileStream SourceFileStream = await Item.GetFileStreamFromFileAsync(AccessMode.Exclusive).ConfigureAwait(false))
             using (FileStream NewFileStrem = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write))
                 using (GZipInputStream GZipStream = new GZipInputStream(SourceFileStream))
                 {
                     await GZipStream.CopyToAsync(NewFileStrem, ProgressHandler).ConfigureAwait(false);
                 }
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
 public static async Task ExtractBZip2Async(FileSystemStorageFile Source, string NewDirectoryPath, ProgressChangedEventHandler ProgressHandler = null)
 {
     if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(NewDirectoryPath, Path.GetFileNameWithoutExtension(Source.Name)), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
     {
         using (FileStream SourceFileStream = await Source.GetFileStreamFromFileAsync(AccessMode.Exclusive).ConfigureAwait(false))
             using (FileStream NewFileStrem = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write))
                 using (BZip2InputStream BZip2Stream = new BZip2InputStream(SourceFileStream))
                 {
                     BZip2Stream.IsStreamOwner = false;
                     await BZip2Stream.CopyToAsync(NewFileStrem, ProgressHandler : ProgressHandler).ConfigureAwait(false);
                 }
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
 public static async Task CreateBZip2Async(FileSystemStorageFile Source, string NewZipPath, ProgressChangedEventHandler ProgressHandler = null)
 {
     if (await FileSystemStorageItemBase.CreateAsync(NewZipPath, StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
     {
         using (FileStream SourceFileStream = await Source.GetFileStreamFromFileAsync(AccessMode.Read))
             using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Exclusive))
                 using (BZip2OutputStream BZip2Stream = new BZip2OutputStream(NewFileStream))
                 {
                     BZip2Stream.IsStreamOwner = false;
                     await SourceFileStream.CopyToAsync(BZip2Stream, ProgressHandler : ProgressHandler).ConfigureAwait(false);
                 }
     }
     else
     {
         throw new UnauthorizedAccessException();
     }
 }
        public static async Task ExtractGZipAsync(FileSystemStorageFile Source, string NewDirectoryPath, ProgressChangedEventHandler ProgressHandler = null)
        {
            using (FileStream SourceFileStream = await Source.GetFileStreamFromFileAsync(AccessMode.Exclusive))
            {
                string NewFilePath = Path.Combine(NewDirectoryPath, Path.GetFileNameWithoutExtension(Source.Path));

                using (GZipInputStream GZipStream = new GZipInputStream(SourceFileStream))
                {
                    GZipStream.IsStreamOwner = false;

                    await GZipStream.ReadAsync(new byte[128], 0, 128);

                    string GZipInnerFileName = GZipStream.GetFilename();

                    if (!string.IsNullOrEmpty(GZipInnerFileName))
                    {
                        NewFilePath = Path.Combine(NewDirectoryPath, GZipInnerFileName);
                    }
                }

                SourceFileStream.Seek(0, SeekOrigin.Begin);

                using (GZipInputStream GZipStream = new GZipInputStream(SourceFileStream))
                {
                    GZipStream.IsStreamOwner = false;

                    if (await FileSystemStorageItemBase.CreateAsync(NewFilePath, StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
                    {
                        using (FileStream NewFileStrem = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write))
                        {
                            await GZipStream.CopyToAsync(NewFileStrem, ProgressHandler : ProgressHandler).ConfigureAwait(false);
                        }
                    }
                    else
                    {
                        throw new UnauthorizedAccessException();
                    }
                }
            }
        }
Beispiel #9
0
 /// <summary>
 /// 初始化PhotoDisplaySupport的实例
 /// </summary>
 /// <param name="ImageSource">缩略图</param>
 /// <param name="File">文件</param>
 public PhotoDisplaySupport(FileSystemStorageFile Item)
 {
     PhotoFile = Item;
 }
Beispiel #10
0
        public static async Task ExtractTarAsync(FileSystemStorageFolder NewFolder, FileSystemStorageFile File, ProgressChangedEventHandler ProgressHandler = null)
        {
            using (FileStream BaseStream = await File.GetFileStreamFromFileAsync(AccessMode.Exclusive).ConfigureAwait(false))
                using (TarInputStream InputTarStream = new TarInputStream(BaseStream, Encoding.UTF8))
                {
                    BaseStream.Seek(0, SeekOrigin.Begin);

                    InputTarStream.IsStreamOwner = false;

                    long CurrentPosition = 0;

                    while (InputTarStream.GetNextEntry() is TarEntry Entry)
                    {
                        if (Entry.Name.Contains("/"))
                        {
                            string[] SplitFolderPath = Entry.Name.Split('/', StringSplitOptions.RemoveEmptyEntries);

                            string TempFolderPath = NewFolder.Path;

                            for (int i = 0; i < SplitFolderPath.Length - 1; i++)
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath[i]), StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(false) is FileSystemStorageFolder NextFolder)
                                {
                                    TempFolderPath = NextFolder.Path;
                                }
                                else
                                {
                                    throw new UnauthorizedAccessException("Could not create directory");
                                }
                            }

                            if (Entry.Name.Last() == '/')
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath.Last()), StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(false) == null)
                                {
                                    throw new UnauthorizedAccessException("Could not create directory");
                                }
                            }
                            else
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath.Last()), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
                                {
                                    using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write).ConfigureAwait(false))
                                    {
                                        if (Entry.Size > 0)
                                        {
                                            await InputTarStream.CopyToAsync(NewFileStream, (s, e) =>
                                            {
                                                ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToInt64(e.ProgressPercentage / 100d * Entry.Size)) * 100d / BaseStream.Length), null));
                                            }).ConfigureAwait(false);
                                        }
                                        else
                                        {
                                            await InputTarStream.CopyToAsync(NewFileStream).ConfigureAwait(false);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new UnauthorizedAccessException();
                                }
                            }
                        }
                        else
                        {
                            if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(NewFolder.Path, Entry.Name), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
                            {
                                using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write).ConfigureAwait(false))
                                {
                                    if (Entry.Size > 0)
                                    {
                                        await InputTarStream.CopyToAsync(NewFileStream, (s, e) =>
                                        {
                                            ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToInt64(e.ProgressPercentage / 100d * Entry.Size)) * 100d / BaseStream.Length), null));
                                        }).ConfigureAwait(false);
                                    }
                                    else
                                    {
                                        await InputTarStream.CopyToAsync(NewFileStream).ConfigureAwait(false);
                                    }
                                }
                            }
                            else
                            {
                                throw new UnauthorizedAccessException();
                            }
                        }

                        ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition = BaseStream.Position) * 100d / BaseStream.Length), null));
                    }
                }
        }
        public static async Task <FileSystemStorageItemBase> CreateAsync(string Path, StorageItemTypes ItemTypes, CreateOption Option)
        {
            switch (ItemTypes)
            {
            case StorageItemTypes.File:
            {
                if (WIN_Native_API.CreateFileFromPath(Path, Option, out string NewPath))
                {
                    return(await OpenAsync(NewPath));
                }
                else
                {
                    LogTracer.Log($"Native API could not create file: \"{Path}\", fall back to UWP storage API");

                    try
                    {
                        StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(Path));

                        switch (Option)
                        {
                        case CreateOption.GenerateUniqueName:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.GenerateUniqueName);

                            return(await FileSystemStorageFile.CreateFromExistingStorageItem(NewFile));
                        }

                        case CreateOption.OpenIfExist:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.OpenIfExists);

                            return(await FileSystemStorageFile.CreateFromExistingStorageItem(NewFile));
                        }

                        case CreateOption.ReplaceExisting:
                        {
                            StorageFile NewFile = await Folder.CreateFileAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.ReplaceExisting);

                            return(await FileSystemStorageFile.CreateFromExistingStorageItem(NewFile));
                        }

                        default:
                        {
                            return(null);
                        }
                        }
                    }
                    catch
                    {
                        LogTracer.Log($"UWP storage API could not create file: \"{Path}\"");
                        return(null);
                    }
                }
            }

            case StorageItemTypes.Folder:
            {
                if (WIN_Native_API.CreateDirectoryFromPath(Path, Option, out string NewPath))
                {
                    return(await OpenAsync(NewPath));
                }
                else
                {
                    LogTracer.Log($"Native API could not create file: \"{Path}\", fall back to UWP storage API");

                    try
                    {
                        StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(System.IO.Path.GetDirectoryName(Path));

                        switch (Option)
                        {
                        case CreateOption.GenerateUniqueName:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.GenerateUniqueName);

                            return(await FileSystemStorageFolder.CreateFromExistingStorageItem(NewFolder));
                        }

                        case CreateOption.OpenIfExist:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.OpenIfExists);

                            return(await FileSystemStorageFolder.CreateFromExistingStorageItem(NewFolder));
                        }

                        case CreateOption.ReplaceExisting:
                        {
                            StorageFolder NewFolder = await Folder.CreateFolderAsync(System.IO.Path.GetFileName(Path), CreationCollisionOption.ReplaceExisting);

                            return(await FileSystemStorageFolder.CreateFromExistingStorageItem(NewFolder));
                        }

                        default:
                        {
                            return(null);
                        }
                        }
                    }
                    catch
                    {
                        LogTracer.Log($"UWP storage API could not create folder: \"{Path}\"");
                        return(null);
                    }
                }
            }

            default:
            {
                return(null);
            }
            }
        }
Beispiel #12
0
        public async Task <List <FileSystemStorageItemBase> > GetChildItemsAsync(bool IncludeHiddenItems, bool IncludeSystemItem, ItemFilters Filter = ItemFilters.File | ItemFilters.Folder)
        {
            if (WIN_Native_API.CheckLocationAvailability(Path))
            {
                return(WIN_Native_API.GetStorageItems(Path, IncludeHiddenItems, IncludeSystemItem, Filter));
            }
            else
            {
                LogTracer.Log($"Native API could not enum subitems in path: \"{Path}\", fall back to UWP storage API");

                try
                {
                    if (await GetStorageItemAsync() is StorageFolder Folder)
                    {
                        QueryOptions Options = new QueryOptions
                        {
                            FolderDepth   = FolderDepth.Shallow,
                            IndexerOption = IndexerOption.DoNotUseIndexer
                        };
                        Options.SetThumbnailPrefetch(ThumbnailMode.ListView, 150, ThumbnailOptions.UseCurrentScale);
                        Options.SetPropertyPrefetch(PropertyPrefetchOptions.BasicProperties, new string[] { "System.Size", "System.DateModified" });

                        StorageItemQueryResult Query = Folder.CreateItemQueryWithOptions(Options);

                        List <FileSystemStorageItemBase> Result = new List <FileSystemStorageItemBase>();

                        for (uint i = 0; ; i += 25)
                        {
                            IReadOnlyList <IStorageItem> ReadOnlyItemList = await Query.GetItemsAsync(i, 25);

                            if (ReadOnlyItemList.Count > 0)
                            {
                                foreach (IStorageItem Item in ReadOnlyItemList.Where((Item) => (Item.IsOfType(StorageItemTypes.Folder) && Filter.HasFlag(ItemFilters.Folder)) || (Item.IsOfType(StorageItemTypes.File) && Filter.HasFlag(ItemFilters.File))))
                                {
                                    if (Item is StorageFolder SubFolder)
                                    {
                                        Result.Add(await CreateFromExistingStorageItem(SubFolder));
                                    }
                                    else if (Item is StorageFile SubFile)
                                    {
                                        Result.Add(await FileSystemStorageFile.CreateFromExistingStorageItem(SubFile));
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        return(Result);
                    }
                    else
                    {
                        return(new List <FileSystemStorageItemBase>(0));
                    }
                }
                catch
                {
                    LogTracer.Log($"UWP API could not enum subitems in path: \"{Path}\"");
                    return(new List <FileSystemStorageItemBase>(0));
                }
            }
        }
Beispiel #13
0
        public async IAsyncEnumerable <FileSystemStorageItemBase> SearchAsync(string SearchWord, bool SearchInSubFolders = false, bool IncludeHiddenItem = false, bool IncludeSystemItem = false, bool IsRegexExpresstion = false, bool IgnoreCase = true, [EnumeratorCancellation] CancellationToken CancelToken = default)
        {
            if (WIN_Native_API.CheckLocationAvailability(Path))
            {
                foreach (FileSystemStorageItemBase Item in await Task.Run(() => WIN_Native_API.Search(Path, SearchWord, SearchInSubFolders, IncludeHiddenItem, IncludeSystemItem, IsRegexExpresstion, IgnoreCase, CancelToken)))
                {
                    yield return(Item);
                }
            }
            else
            {
                if (await GetStorageItemAsync() is StorageFolder Folder)
                {
                    QueryOptions Options = new QueryOptions
                    {
                        FolderDepth   = SearchInSubFolders ? FolderDepth.Deep : FolderDepth.Shallow,
                        IndexerOption = IndexerOption.DoNotUseIndexer
                    };
                    Options.SetThumbnailPrefetch(ThumbnailMode.ListView, 150, ThumbnailOptions.UseCurrentScale);
                    Options.SetPropertyPrefetch(PropertyPrefetchOptions.BasicProperties, new string[] { "System.FileName", "System.Size", "System.DateModified", "System.DateCreated" });

                    if (!IsRegexExpresstion)
                    {
                        Options.ApplicationSearchFilter = $"System.FileName:~=\"{SearchWord}\"";
                    }

                    StorageItemQueryResult Query = Folder.CreateItemQueryWithOptions(Options);

                    for (uint Index = 0; !CancelToken.IsCancellationRequested; Index += 25)
                    {
                        IReadOnlyList <IStorageItem> ReadOnlyItemList = await Query.GetItemsAsync(Index, 25);

                        if (ReadOnlyItemList.Count > 0)
                        {
                            IEnumerable <IStorageItem> Result = IsRegexExpresstion
                                                                ? ReadOnlyItemList.Where((Item) => Regex.IsMatch(Item.Name, SearchWord, IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None))
                                                                : ReadOnlyItemList.Where((Item) => Item.Name.Contains(SearchWord, IgnoreCase ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal));

                            foreach (IStorageItem Item in Result)
                            {
                                if (CancelToken.IsCancellationRequested)
                                {
                                    yield break;
                                }

                                switch (Item)
                                {
                                case StorageFolder SubFolder:
                                {
                                    yield return(await CreateFromExistingStorageItem(SubFolder));

                                    break;
                                }

                                case StorageFile SubFile:
                                {
                                    yield return(await FileSystemStorageFile.CreateFromExistingStorageItem(SubFile));

                                    break;
                                }
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
        }
Beispiel #14
0
        /// <summary>
        /// 执行ZIP解压功能
        /// </summary>
        /// <param name="File">ZIP文件</param>
        /// <returns>无</returns>
        public static async Task ExtractZipAsync(FileSystemStorageFolder NewFolder, FileSystemStorageFile File, ProgressChangedEventHandler ProgressHandler = null)
        {
            ZipStrings.CodePage = EncodingSetting.CodePage;

            using (FileStream BaseStream = await File.GetFileStreamFromFileAsync(AccessMode.Exclusive).ConfigureAwait(false))
                using (ZipInputStream InputZipStream = new ZipInputStream(BaseStream))
                {
                    BaseStream.Seek(0, SeekOrigin.Begin);

                    InputZipStream.IsStreamOwner = false;

                    long CurrentPosition = 0;

                    while (InputZipStream.GetNextEntry() is ZipEntry Entry)
                    {
                        if (!InputZipStream.CanDecompressEntry || Entry.IsCrypted)
                        {
                            throw new NotImplementedException();
                        }

                        if (Entry.Name.Contains("/"))
                        {
                            string[] SplitFolderPath = Entry.Name.Split('/', StringSplitOptions.RemoveEmptyEntries);

                            string TempFolderPath = NewFolder.Path;

                            for (int i = 0; i < SplitFolderPath.Length - 1; i++)
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath[i]), StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(false) is FileSystemStorageFolder NextFolder)
                                {
                                    TempFolderPath = NextFolder.Path;
                                }
                                else
                                {
                                    throw new UnauthorizedAccessException("Could not create directory");
                                }
                            }

                            if (Entry.Name.Last() == '/')
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath.Last()), StorageItemTypes.Folder, CreateOption.OpenIfExist).ConfigureAwait(false) == null)
                                {
                                    throw new UnauthorizedAccessException("Could not create directory");
                                }
                            }
                            else
                            {
                                if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(TempFolderPath, SplitFolderPath.Last()), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
                                {
                                    using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write).ConfigureAwait(false))
                                    {
                                        //For some files in Zip, CompressedSize or Size might less than zero, then we could not get progress by reading ZipInputStream.Length
                                        if (Entry.CompressedSize > 0 && Entry.Size > 0)
                                        {
                                            await InputZipStream.CopyToAsync(NewFileStream, (s, e) =>
                                            {
                                                ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToInt64(e.ProgressPercentage / 100d * Entry.CompressedSize)) * 100d / BaseStream.Length), null));
                                            }).ConfigureAwait(false);
                                        }
                                        else
                                        {
                                            await InputZipStream.CopyToAsync(NewFileStream).ConfigureAwait(false);
                                        }
                                    }
                                }
                                else
                                {
                                    throw new UnauthorizedAccessException();
                                }
                            }
                        }
                        else
                        {
                            if (await FileSystemStorageItemBase.CreateAsync(Path.Combine(NewFolder.Path, Entry.Name), StorageItemTypes.File, CreateOption.GenerateUniqueName).ConfigureAwait(false) is FileSystemStorageFile NewFile)
                            {
                                using (FileStream NewFileStream = await NewFile.GetFileStreamFromFileAsync(AccessMode.Write).ConfigureAwait(false))
                                {
                                    //For some files in Zip, CompressedSize or Size might less than zero, then we could not get progress by reading ZipInputStream.Length
                                    if (Entry.CompressedSize > 0 && Entry.Size > 0)
                                    {
                                        await InputZipStream.CopyToAsync(NewFileStream, (s, e) =>
                                        {
                                            ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition + Convert.ToInt64(e.ProgressPercentage / 100d * Entry.CompressedSize)) * 100d / BaseStream.Length), null));
                                        }).ConfigureAwait(true);
                                    }
                                    else
                                    {
                                        await InputZipStream.CopyToAsync(NewFileStream).ConfigureAwait(false);
                                    }
                                }
                            }
                            else
                            {
                                throw new UnauthorizedAccessException();
                            }
                        }

                        ProgressHandler?.Invoke(null, new ProgressChangedEventArgs(Convert.ToInt32((CurrentPosition = BaseStream.Position) * 100d / BaseStream.Length), null));
                    }
                }
        }