From 379545c1aeceda4127899377596af544a3b9c981 Mon Sep 17 00:00:00 2001 From: Rambalac Date: Tue, 28 Mar 2017 02:09:15 +0900 Subject: [PATCH] Small refactoring --- amazon-clouddrive-dokan/SmallFileBlockStream.cs | 11 +++++------ .../Cloud.DokanNet.Tests.csproj | 4 ++++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/amazon-clouddrive-dokan/SmallFileBlockStream.cs b/amazon-clouddrive-dokan/SmallFileBlockStream.cs index 799b769..67c4b89 100644 --- a/amazon-clouddrive-dokan/SmallFileBlockStream.cs +++ b/amazon-clouddrive-dokan/SmallFileBlockStream.cs @@ -120,14 +120,13 @@ public override async Task Read(long position, byte[] buffer, int offset, i try { stream.Position = position; - if (downloader == null) + var toread = (int)Math.Min(count, (downloader?.Downloaded ?? item.Length) - position); + if (toread < 0) { - red = await stream.ReadAsync(buffer, offset, (int)Math.Min(count, item.Length - position), timeoutcancel.Token); - } - else - { - red = await stream.ReadAsync(buffer, offset, (int)Math.Min(count, downloader.Downloaded - position), timeoutcancel.Token); + Log.ErrorTrace("toread less than zero:" + item.Name); } + + red = await stream.ReadAsync(buffer, offset, toread, timeoutcancel.Token); } finally { diff --git a/amazon-clouddrive-dokanTests/Cloud.DokanNet.Tests.csproj b/amazon-clouddrive-dokanTests/Cloud.DokanNet.Tests.csproj index 23c0df3..0a778fe 100644 --- a/amazon-clouddrive-dokanTests/Cloud.DokanNet.Tests.csproj +++ b/amazon-clouddrive-dokanTests/Cloud.DokanNet.Tests.csproj @@ -100,6 +100,10 @@ + + {2C611335-3D92-492F-B3EB-2CF3955F63A1} + AmazonCloudDriveApi + {213AA535-DB16-4CF9-B3F1-324FF9347F8D} Cloud.DokanNet