dokan-dev / dokan-dotnet

Dokan DotNet Wrapper
http://dokan-dev.github.io
MIT License
461 stars 115 forks source link

Image read through Photos is truncated #75

Closed andysyncplicity closed 8 years ago

andysyncplicity commented 8 years ago

I'm currently evaluating Dokan with the .Net adaptor as a solution for implementing a virtual file system.

When I create a virtual file system in my application, and then open a .png file in Photos, (Windows 10, double-clicked via explorer,) the image displayed is truncated.

In contrast, I can successfully open the same .png file from a virtual file system from the sample Mirror.cs.

This leads me to believe that the problem is my application.

Any suggestions? I assume I'm making a silly mistake.

marinkobabic commented 8 years ago

File System requests you to download parts of your image. At the end the whole image should be complete. In your case you are missing some bytes.

Run your code in the way the operating system does the requests and write the file to the local disk. Compare the final file size with the original image and you should be able to figure out where the bug comes from.

andysyncplicity commented 8 years ago

I followed your suggestion.

Basically, in my implementation of ReadFile, I wrote out the exact same bytes to a file on disk. In this case, the file that I wrote out to disk is exactly what it should be.

(Furthermore, I can copy the image from my virtual drive to drive C, and then open it from drive C and it is correct.)

This leads me to believe that my ReadFile is correct; but that the problem is elsewhere in my IDokanOperations object.

(FYI, when I open the image in Photos, it looks similar to the corrupted image shown in https://github.com/dokan-dev/dokany/issues/154.)

Any ideas? Or, should I assume that I'm hitting the above-described issue and just move on?

marinkobabic commented 8 years ago

In your case you are not talking about the thumbnail? You have the problem when you open the image? What happens when when you open the image with different photo viewer? Do you face this problem with all images or with a specific one?

Von Samsung Mobile gesendet

-------- Ursprüngliche Nachricht -------- Von: Andrew Rondeau Datum:31.03.2016 17:32 (GMT+01:00) An: dokan-dev/dokan-dotnet Cc: Babic Marinko Betreff: Re: [dokan-dev/dokan-dotnet] Image read through Photos is truncated (#75)

I followed your suggestion.

Basically, in my implementation of ReadFile, I wrote out the exact same bytes to a file on disk. In this case, the file that I wrote out to disk is exactly what it should be.

(Furthermore, I can copy the image from my virtual drive to drive C, and then open it from drive C and it is correct.)

This leads me to believe that my ReadFile is correct; but that the problem is elsewhere in my IDokanOperations object.

(FYI, when I open the image in Photos, it looks similar to the corrupted image shown in dokan-dev/dokany#154https://github.com/dokan-dev/dokany/issues/154)

Any ideas? Or, should I assume that I'm hitting the above-described issue and just move on?

You are receiving this because you commented. Reply to this email directly or view it on GitHubhttps://github.com/dokan-dev/dokan-dotnet/issues/75#issuecomment-203987928

andysyncplicity commented 8 years ago

confluence-logo screen shot 2016-03-31 at 1 38 39 pm screen shot 2016-03-31 at 1 38 54 pm

I tried opening in Paint... It tries to load the wrong file.

I uploaded 3 images.

confluence-logo.jpg: The original image file that I'm trying to open. Screen Shot 2016-03-31 at 1.38.39 PM.png: Shows how the photos application doesn't show the image correctly. Screen Shot 2016-03-31 at 1.38.54 PM.png: Shows how paint is opening the wrong file. (See the wrong filename in the window's title.)

Thanks so much!

marinkobabic commented 8 years ago

There is something wrong in your code when the wrong file is opened.

Please can you modify your proxy to open and read files from local drive instead from the original remote source. Just for testing purposes to see if it makes any difference.

If it makes no difference so replace the read code using the original mirror read code and check if it then works properly.

Do you have this issue with all images?

Thanks Marinko

Von Samsung Mobile gesendet

marinkobabic commented 8 years ago

When I look at the picture it seems to me that you are reporting wrong file information resp. size to dokan driver. If you report to small size the os will just read a part of the file and we will get the output you have.

Please check the reported file size in your proxy.

andysyncplicity commented 8 years ago

The file length information listed in explorer is correct. Is there any other way to return the wrong length, other than via GetFileInformation?

I also tried reading directly from disk, but that didn't fix it. Here's what I did:

    public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info)
    {
        // Uncomment to diagnose issues reading a particular file
        if (fileName.EndsWith(Path.DirectorySeparatorChar + "Screen Shot 2016-02-26 at 5.50.24 PM.png"))
        {
            using (var readStream = File.OpenRead("C:\\Users\\GWBasic\\Syncplicity_Dev\\Screen Shot 2016-02-26 at 5.50.24 PM.png"))
            {
                readStream.Position = offset;
                bytesRead = readStream.Read(buffer, 0, buffer.Length);
            }

            return NtStatus.Success;
        }

...

marinkobabic commented 8 years ago

The code looks fine. Please do the same hack in GetFileInformation so that it works like in mirror sample. If it still does not work so please do the hack in all other methods as well. At the end it must work because the mirror works properly.

What I would do is to create a temp folder with just this one file and only work with this folder to get it work like in mirror. At the end you will figure out where the issue comes from. If not you can create a console application with the hacked example and we will look into the details.

andysyncplicity commented 8 years ago

Thanks, that's wonderful guidance. I'm going to close this for now and follow your suggestion!

Thanks so much!

andysyncplicity commented 8 years ago

Finally got time to look into this again. Looks like my problem was in FindFilesWithPattern. I needed to put . and .. at the end of the results, not at the beginning.

Thanks for all your help.

marinkobabic commented 8 years ago

Before somebody else has the same issue, the problem should be solved in .net, user library or even inside of the driver.

Liryna commented 8 years ago

You are right marinkokabic, I am going add it in the library :)