Fix #825 properly

This commit is contained in:
Paddy Xu
2021-03-07 19:02:08 +01:00
parent 9f426326ba
commit a91261435a
9 changed files with 47 additions and 17 deletions

View File

@@ -15,7 +15,10 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Windows.Media.Imaging;
using QuickLook.Common.Helpers;
@@ -37,5 +40,32 @@ namespace QuickLook.Plugin.ImageViewer
dpiX?.SetValue(img, newDpiX);
dpiY?.SetValue(img, newDpiY);
}
public static Uri FilePathToFileUrl(string filePath)
{
var uri = new StringBuilder();
foreach (var v in filePath)
if (v >= 'a' && v <= 'z' || v >= 'A' && v <= 'Z' || v >= '0' && v <= '9' ||
v == '+' || v == '/' || v == ':' || v == '.' || v == '-' || v == '_' || v == '~' ||
v > '\x80')
uri.Append(v);
else if (v == Path.DirectorySeparatorChar || v == Path.AltDirectorySeparatorChar)
uri.Append('/');
else
uri.Append($"%{(int) v:X2}");
if (uri.Length >= 2 && uri[0] == '/' && uri[1] == '/') // UNC path
uri.Insert(0, "file:");
else
uri.Insert(0, "file:///");
try
{
return new Uri(uri.ToString());
}
catch
{
return null;
}
}
}
}