Skip to content

Commit

Permalink
Add Export(1357310795#4
Browse files Browse the repository at this point in the history
  • Loading branch information
1357310795 committed Jul 12, 2022
1 parent b4246ff commit a5d0d9c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions MyComputerManager/Models/NamespaceItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public bool IsEnabled

public string RegKey_Namespace
{
get {
return RegKey.Name + @"\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\NameSpace\" + CLSID;
get {
return RegKey.Name + @"\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\MyComputer\" + (IsEnabled ? "NameSpace" : "NameSpaceDisabled") + @"\" + CLSID;
}
}

Expand Down
42 changes: 42 additions & 0 deletions MyComputerManager/ViewModels/DetailPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public DetailPageViewModel(INavigationService navigationService, IDataService da
ClearIconCommand = new RelayCommand(ButtonClearIcon_Click);
DropCommand = new RelayCommand(ImageDrop);
DeleteCommand = new AsyncRelayCommand(ButtonDelete_Click);
ExportCommand = new AsyncRelayCommand(ButtonExport_Click);
}

private NamespaceItem OriItem;
Expand Down Expand Up @@ -128,6 +129,7 @@ public CommonResult SaveToOrigin()
public RelayCommand ClearIconCommand { get; set; }
public RelayCommand DropCommand { get; set; }
public AsyncRelayCommand DeleteCommand { get; set; }
public AsyncRelayCommand ExportCommand { get; set; }

public void ButtonOpenIcon_Click(object obj)
{
Expand Down Expand Up @@ -236,5 +238,45 @@ public async Task ButtonDelete_Click()
}
}
}

public async Task ButtonExport_Click()
{
var dialog = new SaveFileDialog();
dialog.Filter = "registry file|*.reg";
if (dialog.ShowDialog() != true)
return;
var res1 = await Task.Run(() =>
{
var filename1 = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
var filename2 = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
ProcessStartInfo psi1 = new ProcessStartInfo("regedit", $"-e {filename1} {Item.RegKey_CLSID}");
ProcessStartInfo psi2 = new ProcessStartInfo("regedit", $"-e {filename2} {Item.RegKey_Namespace}");
Process p1 = Process.Start(psi1);
p1.WaitForExit();
Process p2 = Process.Start(psi2);
p2.WaitForExit();

try
{
var text1 = File.ReadAllText(filename1);
var text2 = File.ReadAllText(filename2);
text2 = text2.Replace("Windows Registry Editor Version 5.00", "");
File.WriteAllText(dialog.FileName, text1 + text2, Encoding.Unicode);
return 0;
}
catch(Exception ex)
{
return 1;
}
});
if (res1 == 0)
{
_snackBarService.Show("已导出到", dialog.FileName, SymbolRegular.Info16, ControlAppearance.Secondary, 3000);
}
else
{
_snackBarService.Show("操作失败", "原因未知", SymbolRegular.ShieldError16);
}
}
}
}
8 changes: 7 additions & 1 deletion MyComputerManager/Views/DetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
Background="{DynamicResource ControlFillColorDefaultBrush}"
d:DesignHeight="400" d:DesignWidth="400"
mc:Ignorable="d">

<StackPanel x:Name="RootPanel"
Margin="10"
Orientation="Vertical">
Expand Down Expand Up @@ -134,6 +133,13 @@
Appearance="Danger">
<ui:SymbolIcon Foreground="White" Symbol="Delete16" />
</ui:Button>
<ui:Button Width="30" Height="30"
Margin="0,0,4,0" Padding="0"
Command="{Binding ExportCommand}"
DockPanel.Dock="Left" ToolTip="导出项目"
Appearance="Success">
<ui:SymbolIcon Foreground="White" Symbol="ArrowExportLtr16" />
</ui:Button>
</DockPanel>
</StackPanel>
</Page>

0 comments on commit a5d0d9c

Please sign in to comment.