Skip to content

Commit 96cc6da

Browse files
committed
支持了在MSIX运行模式下也能调用explorer打开指定的目录
1 parent b13258a commit 96cc6da

File tree

8 files changed

+40
-25
lines changed

8 files changed

+40
-25
lines changed

EGIS.Projections/EGIS.Projections.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFramework>netstandard2.1</TargetFramework>
44
<OutputType>Library</OutputType>
55
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
66
</PropertyGroup>

EGIS.ShapeFileLib/EGIS.ShapeFileLib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFramework>netstandard2.1</TargetFramework>
44
<OutputType>Library</OutputType>
55
<SignAssembly>true</SignAssembly>
66
<DelaySign>false</DelaySign>

MapBoard.Package/MapBoard.Package.wapproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,34 +67,34 @@
6767
<AppxPackageDir>D:\临时\20181208-地图画板\Generation\Package\</AppxPackageDir>
6868
</PropertyGroup>
6969
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
70-
<AppxBundle>Always</AppxBundle>
70+
<AppxBundle>Auto</AppxBundle>
7171
</PropertyGroup>
7272
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
73-
<AppxBundle>Always</AppxBundle>
73+
<AppxBundle>Auto</AppxBundle>
7474
</PropertyGroup>
7575
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
76-
<AppxBundle>Always</AppxBundle>
76+
<AppxBundle>Auto</AppxBundle>
7777
</PropertyGroup>
7878
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
79-
<AppxBundle>Always</AppxBundle>
79+
<AppxBundle>Auto</AppxBundle>
8080
</PropertyGroup>
8181
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
82-
<AppxBundle>Always</AppxBundle>
82+
<AppxBundle>Auto</AppxBundle>
8383
</PropertyGroup>
8484
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
85-
<AppxBundle>Always</AppxBundle>
85+
<AppxBundle>Auto</AppxBundle>
8686
</PropertyGroup>
8787
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
88-
<AppxBundle>Always</AppxBundle>
88+
<AppxBundle>Auto</AppxBundle>
8989
</PropertyGroup>
9090
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
91-
<AppxBundle>Always</AppxBundle>
91+
<AppxBundle>Auto</AppxBundle>
9292
</PropertyGroup>
9393
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
94-
<AppxBundle>Always</AppxBundle>
94+
<AppxBundle>Auto</AppxBundle>
9595
</PropertyGroup>
9696
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
97-
<AppxBundle>Always</AppxBundle>
97+
<AppxBundle>Auto</AppxBundle>
9898
</PropertyGroup>
9999
<ItemGroup>
100100
<AppxManifest Include="Package.appxmanifest">

MapBoard.UI/MapBoard.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<PackageReference Include="CsvHelper">
9595
<Version>27.2.1</Version>
9696
</PackageReference>
97+
<PackageReference Include="DesktopBridge.Helpers" Version="1.2.2" />
9798
<PackageReference Include="Esri.ArcGISRuntime.WPF" Version="100.13.0" />
9899
<PackageReference Include="gong-wpf-dragdrop" Version="3.0.0" />
99100
<PackageReference Include="log4net" Version="2.0.14" />

MapBoard.UI/UI/GpxToolbox/GpxBrowseWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private async Task StopRecordAsync()
211211
ResizeMode = ResizeMode.CanResize;
212212
if (await CommonDialog.ShowYesNoDialogAsync("是否打开目录?") == true)
213213
{
214-
Process.Start("explorer.exe", GetRecordPath());
214+
IOUtility.OpenFolder(GetRecordPath());
215215
}
216216
}
217217

MapBoard.UI/UI/IOUtility.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public static void OpenFileOrFolder(string path)
406406
{
407407
new Process()
408408
{
409-
StartInfo = new ProcessStartInfo(Path.GetFullPath(path))
409+
StartInfo = new ProcessStartInfo(GetRealPath(path))
410410
{
411411
UseShellExecute = true
412412
}
@@ -415,7 +415,7 @@ public static void OpenFileOrFolder(string path)
415415

416416
public static void OpenFolder(string path)
417417
{
418-
var p = '"' + Path.GetFullPath(path) + '"';
418+
var p = '"' + GetRealPath(path) + '"';
419419
if (Directory.Exists(path))
420420
{
421421
new Process()
@@ -437,6 +437,27 @@ public static void OpenFolder(string path)
437437
}.Start();
438438
}
439439
}
440+
441+
/// <summary>
442+
/// 在MSIX下运行时,程序数据目录的位置被重定向。在程序内访问时不需要修改,但通过外部程序调用时,需要获取真实的路径。
443+
/// </summary>
444+
/// <param name="path"></param>
445+
/// <returns></returns>
446+
public static string GetRealPath(string path)
447+
{
448+
path = Path.GetFullPath(path);
449+
var helper = new DesktopBridge.Helpers();
450+
if (helper.IsRunningAsUwp())
451+
{
452+
string virtualAppData = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
453+
string local = new DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).Parent.FullName;
454+
if (path.Contains(local))
455+
{
456+
path = path.Replace(local, virtualAppData);
457+
}
458+
}
459+
return path;
460+
}
440461
}
441462

442463
public enum ImportMapType

MapBoard.UI/UI/MainWindow.xaml.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private void ImportButton_Click(SplitButton sender, SplitButtonClickEventArgs ar
605605
/// </summary>
606606
/// <param name="sender"></param>
607607
/// <param name="e"></param>
608-
private async void OpenFolderButtonClick(object sender, RoutedEventArgs e)
608+
private void OpenFolderButtonClick(object sender, RoutedEventArgs e)
609609
{
610610
string path = ((sender as FrameworkElement).Tag as string) switch
611611
{
@@ -615,14 +615,7 @@ private async void OpenFolderButtonClick(object sender, RoutedEventArgs e)
615615
"4" => Parameters.BackupPath,
616616
_ => throw new ArgumentOutOfRangeException()
617617
};
618-
if (Directory.Exists(path))
619-
{
620-
IOUtility.OpenFileOrFolder(path);
621-
}
622-
else
623-
{
624-
await CommonDialog.ShowErrorDialogAsync("目录不存在");
625-
}
618+
IOUtility.OpenFileOrFolder(path);
626619
}
627620

628621
private void OpenFolderButtonClick(SplitButton sender, SplitButtonClickEventArgs args)

MapBoard.UI/UI/TileDownloader/TileDownloaderWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ private async void OpenFolderButtonClick(object sender, RoutedEventArgs e)
595595
{
596596
Directory.CreateDirectory(Config.Tile_DownloadFolder);
597597
}
598-
Process.Start("explorer.exe", Config.Tile_DownloadFolder);
598+
IOUtility.OpenFolder(Config.Tile_DownloadFolder);
599599
}
600600
catch (Exception ex)
601601
{

0 commit comments

Comments
 (0)