Skip to content

Commit a912614

Browse files
committed
Fix #825 properly
1 parent 9f42632 commit a912614

File tree

9 files changed

+47
-17
lines changed

9 files changed

+47
-17
lines changed

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/AnimatedImage.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public void Dispose()
5050

5151
private static AnimationProvider InitAnimationProvider(Uri path, MetaProvider meta)
5252
{
53-
var ext = Path.GetExtension(path.OriginalString).ToLower();
53+
var ext = Path.GetExtension(path.LocalPath).ToLower();
5454
var type = Providers.First(p => p.Key.Contains(ext) || p.Key.Contains("*")).Value;
5555

56-
var provider = type.CreateInstance<AnimationProvider>(path.OriginalString, meta);
56+
var provider = type.CreateInstance<AnimationProvider>(path, meta);
5757

5858
return provider;
5959
}

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/AnimationProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage
2525
{
2626
internal abstract class AnimationProvider : IDisposable
2727
{
28-
protected AnimationProvider(string path, MetaProvider meta)
28+
protected AnimationProvider(Uri path, MetaProvider meta)
2929
{
3030
Path = path;
3131
Meta = meta;
3232
}
3333

34-
public string Path { get; }
34+
public Uri Path { get; }
3535

3636
public MetaProvider Meta { get; }
3737

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/APngProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ internal class APngProvider : AnimationProvider
3737
private int _lastEffectivePreviousPreviousFrameIndex;
3838
private NativeProvider _nativeImageProvider;
3939

40-
public APngProvider(string path, MetaProvider meta) : base(path, meta)
40+
public APngProvider(Uri path, MetaProvider meta) : base(path, meta)
4141
{
42-
if (!IsAnimatedPng(path))
42+
if (!IsAnimatedPng(path.LocalPath))
4343
{
4444
_nativeImageProvider = new NativeProvider(path, meta);
4545
Animator = _nativeImageProvider.Animator;
4646
return;
4747
}
4848

49-
var decoder = new APNGBitmap(path);
49+
var decoder = new APNGBitmap(path.LocalPath);
5050

5151
_baseFrame = decoder.DefaultImage;
5252
_frames = new List<FrameInfo>(decoder.Frames.Length);

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/DcrawProvider.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
2121
{
2222
internal class DcrawProvider : NativeProvider
2323
{
24-
public DcrawProvider(string path, MetaProvider meta) : base(path, meta)
24+
public DcrawProvider(Uri path, MetaProvider meta) : base(path, meta)
2525
{
2626
throw new NotImplementedException();
2727
}

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/GifProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ internal class GifProvider : AnimationProvider
3333
private bool _isPlaying;
3434
private NativeProvider _nativeProvider;
3535

36-
public GifProvider(string path, MetaProvider meta) : base(path, meta)
36+
public GifProvider(Uri path, MetaProvider meta) : base(path, meta)
3737
{
38-
if (!ImageAnimator.CanAnimate(Image.FromFile(path)))
38+
if (!ImageAnimator.CanAnimate(Image.FromFile(path.LocalPath)))
3939
{
4040
_nativeProvider = new NativeProvider(path, meta);
4141
return;
4242
}
4343

44-
_fileHandle = (Bitmap) Image.FromFile(path);
44+
_fileHandle = (Bitmap) Image.FromFile(path.LocalPath);
4545

4646
_fileHandle.SetResolution(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
4747
DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/ImageMagickProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
3030
{
3131
internal class ImageMagickProvider : AnimationProvider
3232
{
33-
public ImageMagickProvider(string path, MetaProvider meta) : base(path, meta)
33+
public ImageMagickProvider(Uri path, MetaProvider meta) : base(path, meta)
3434
{
3535
Animator = new Int32AnimationUsingKeyFrames();
3636
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
@@ -90,7 +90,7 @@ public override Task<BitmapSource> GetRenderedFrame(int index)
9090

9191
try
9292
{
93-
using (var mi = new MagickImage(Path, settings))
93+
using (var mi = new MagickImage(Path.LocalPath, settings))
9494
{
9595
var profile = mi.GetColorProfile();
9696
if (mi.ColorSpace == ColorSpace.RGB || mi.ColorSpace == ColorSpace.sRGB ||

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/AnimatedImage/Providers/NativeProvider.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace QuickLook.Plugin.ImageViewer.AnimatedImage.Providers
2727
{
2828
internal class NativeProvider : AnimationProvider
2929
{
30-
public NativeProvider(string path, MetaProvider meta) : base(path, meta)
30+
public NativeProvider(Uri path, MetaProvider meta) : base(path, meta)
3131
{
3232
Animator = new Int32AnimationUsingKeyFrames();
3333
Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0,
@@ -55,7 +55,7 @@ public override Task<BitmapSource> GetThumbnail(Size renderSize)
5555
{
5656
var img = new BitmapImage();
5757
img.BeginInit();
58-
img.UriSource = new Uri(Path);
58+
img.UriSource = Path;
5959
img.CacheOption = BitmapCacheOption.OnLoad;
6060
// specific renderSize to avoid .net's double to int conversion
6161
img.DecodePixelWidth = rotate ? decodeHeight : decodeWidth;
@@ -94,7 +94,7 @@ public override Task<BitmapSource> GetRenderedFrame(int index)
9494
{
9595
var img = new BitmapImage();
9696
img.BeginInit();
97-
img.UriSource = new Uri(Path);
97+
img.UriSource = Path;
9898
img.CacheOption = BitmapCacheOption.OnLoad;
9999
img.DecodePixelWidth = (int) (rotate ? fullSize.Height : fullSize.Width);
100100
img.DecodePixelHeight = (int) (rotate ? fullSize.Width : fullSize.Height);

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Helper.cs

+30
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
// You should have received a copy of the GNU General Public License
1616
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
using System;
19+
using System.IO;
1820
using System.Reflection;
21+
using System.Text;
1922
using System.Windows.Media.Imaging;
2023
using QuickLook.Common.Helpers;
2124

@@ -37,5 +40,32 @@ public static void DpiHack(BitmapSource img)
3740
dpiX?.SetValue(img, newDpiX);
3841
dpiY?.SetValue(img, newDpiY);
3942
}
43+
44+
public static Uri FilePathToFileUrl(string filePath)
45+
{
46+
var uri = new StringBuilder();
47+
foreach (var v in filePath)
48+
if (v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' || v >= '0' && v <= '9' ||
49+
v == '+' || v == '/' || v == ':' || v == '.' || v == '-' || v == '_' || v == '~' ||
50+
v > '\x80')
51+
uri.Append(v);
52+
else if (v == Path.DirectorySeparatorChar || v == Path.AltDirectorySeparatorChar)
53+
uri.Append('/');
54+
else
55+
uri.Append($"%{(int) v:X2}");
56+
if (uri.Length >= 2 && uri[0] == '/' && uri[1] == '/') // UNC path
57+
uri.Insert(0, "file:");
58+
else
59+
uri.Insert(0, "file:///");
60+
61+
try
62+
{
63+
return new Uri(uri.ToString());
64+
}
65+
catch
66+
{
67+
return null;
68+
}
69+
}
4070
}
4171
}

QuickLook.Plugin/QuickLook.Plugin.ImageViewer/Plugin.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void View(string path, ContextObject context)
8686
? $"{Path.GetFileName(path)}"
8787
: $"{size.Width}×{size.Height}: {Path.GetFileName(path)}";
8888

89-
_ip.ImageUriSource = new Uri(path);
89+
_ip.ImageUriSource = Helper.FilePathToFileUrl(path);
9090
}
9191

9292
public void Cleanup()

0 commit comments

Comments
 (0)