Add FilePath helper class

This commit is contained in:
ClemensFischer 2022-12-06 18:07:38 +01:00
parent 7d1d7dbe23
commit 421f323116
5 changed files with 27 additions and 4 deletions

View file

@ -0,0 +1,21 @@
// XAML Map Control - https://github.com/ClemensFischer/XAML-Map-Control
// © 2022 Clemens Fischer
// Licensed under the Microsoft Public License (Ms-PL)
using System;
using System.IO;
namespace MapControl
{
public static class FilePath
{
public static string GetFullPath(string path)
{
#if WINUI
return Path.GetFullPath(path, AppDomain.CurrentDomain.BaseDirectory);
#else
return Path.GetFullPath(path);
#endif
}
}
}

View file

@ -174,7 +174,7 @@ namespace MapControl
private static async Task<IEnumerable<ImageOverlay>> ReadGroundOverlaysFromFileAsync(string docFilePath)
{
docFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, docFilePath);
docFilePath = FilePath.GetFullPath(docFilePath);
var docUri = new Uri(docFilePath);

View file

@ -71,6 +71,9 @@
<Compile Include="..\Shared\EquirectangularProjection.cs">
<Link>EquirectangularProjection.cs</Link>
</Compile>
<Compile Include="..\Shared\FilePath.cs">
<Link>FilePath.cs</Link>
</Compile>
<Compile Include="..\Shared\GeoImage.cs">
<Link>GeoImage.cs</Link>
</Compile>

View file

@ -20,8 +20,7 @@ namespace MapControl
{
public static async Task<Tuple<BitmapSource, Matrix>> ReadGeoTiff(string sourcePath)
{
var file = await StorageFile.GetFileFromPathAsync(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, sourcePath));
var file = await StorageFile.GetFileFromPathAsync(FilePath.GetFullPath(sourcePath));
using (var stream = await file.OpenReadAsync())
{

View file

@ -50,7 +50,7 @@ namespace MapControl
{
ImageSource image = null;
path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
path = FilePath.GetFullPath(path);
if (File.Exists(path))
{