This commit is contained in:
stax76
2021-11-13 23:43:47 +01:00
parent 975f918703
commit 4efe85aad7
35 changed files with 412 additions and 402 deletions

View File

@@ -1,134 +0,0 @@
<Window
x:Class="mpvnet.SetupWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="mpv.net Setup"
FontSize="13"
Foreground="{Binding Theme.Foreground}"
Background="{Binding Theme.Background}"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
>
<Window.Resources>
<ControlTemplate x:Key="ShieldButtonTemplate" TargetType="Button">
<Border x:Name="border"
CornerRadius="3"
BorderBrush="{DynamicResource PrimaryTextBrush}"
BorderThickness="1"
Background="{DynamicResource BorderBrush}">
<Grid>
<Image Source="{x:Static mpvnet:SetupWindow.ShieldIcon}"
HorizontalAlignment="Left"
Margin="9,0,0,0"
Width="20"
Height="20" />
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" TargetName="border" Value="{DynamicResource HighlightBrush}"/>
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="BorderBrush" TargetName="border" Value="#2C628B"/>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" TargetName="border" Value="0.25"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Window.Resources>
<Grid>
<StackPanel Orientation="Horizontal">
<StackPanel Width="140" Margin="25,5,5,5">
<Border Height="50">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
>Start Menu Shortcut</TextBlock>
</Border>
<Button Name="AddStartMenuShortcut"
Height="30"
Margin="3"
Click="AddStartMenuShortcut_Click"
>Add</Button>
<Button Name="RemoveStartMenuShortcut"
Height="30"
Margin="3"
Click="RemoveStartMenuShortcut_Click"
>Remove</Button>
</StackPanel>
<StackPanel Width="140" Margin="20,5,5,25">
<Border Height="50">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
>File Extensions</TextBlock>
</Border>
<Button Name="AddVideo"
Height="30"
Margin="3"
Click="AddVideo_Click"
Template="{StaticResource ShieldButtonTemplate}"
>Add Video</Button>
<Button Name="AddAudio"
Height="30"
Margin="3"
Click="AddAudio_Click"
Template="{StaticResource ShieldButtonTemplate}"
>Add Audio</Button>
<Button Name="AddImage"
Height="30"
Margin="3"
Click="AddImage_Click"
Template="{StaticResource ShieldButtonTemplate}"
>Add Image</Button>
<Button Name="RemoveFileAssociations"
Margin="3,15,3,3"
Height="30"
Click="RemoveFileAssociations_Click"
Template="{StaticResource ShieldButtonTemplate}"
>Remove All</Button>
<Button Name="EditDefaultApp"
Height="30"
Margin="3"
Click="EditDefaultApp_Click"
>Edit Default App</Button>
</StackPanel>
<StackPanel Width="140" Margin="20,5,25,5">
<Border Height="50">
<TextBlock TextWrapping="Wrap"
TextAlignment="Center"
VerticalAlignment="Center"
FontSize="14"
>Path Environment Variable</TextBlock>
</Border>
<Button Name="AddToPathEnvVar"
Height="30"
Margin="3"
Click="AddToPathEnvVar_Click"
>Add</Button>
<Button Name="RemoveFromPathEnvVar"
Height="30"
Margin="3"
Click="RemoveFromPathEnvVar_Click"
>Remove</Button>
<Button Name="ShowEnvVarEditor"
Height="30"
Margin="3"
Click="ShowEnvVarEditor_Click"
>Show Editor</Button>
</StackPanel>
</StackPanel>
</Grid>
</Window>

View File

@@ -1,116 +0,0 @@

using System;
using System.Diagnostics;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
using System.Windows;
using WinForms = System.Windows.Forms;
using static StockIcon;
namespace mpvnet
{
public partial class SetupWindow : Window
{
public SetupWindow()
{
InitializeComponent();
DataContext = this;
}
public Theme Theme => Theme.Current;
static BitmapSource _ShieldIcon;
public static BitmapSource ShieldIcon {
get {
if (_ShieldIcon == null)
{
IntPtr icon = GetIcon(SHSTOCKICONID.Shield, SHSTOCKICONFLAGS.SHGSI_ICON);
_ShieldIcon = Imaging.CreateBitmapSourceFromHIcon(
icon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
DestroyIcon(icon);
}
return _ShieldIcon;
}
}
void RegFileAssoc(string[] extensions)
{
try
{
using (Process proc = new Process())
{
proc.StartInfo.FileName = WinForms.Application.ExecutablePath;
proc.StartInfo.Arguments = "--reg-file-assoc " + string.Join(" ", extensions);
proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true;
proc.Start();
proc.WaitForExit();
if (proc.ExitCode == 0)
Msg.ShowInfo("File associations successfully created.");
else
Msg.ShowError("Error creating file associations.");
}
} catch {}
}
void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(CorePlayer.VideoTypes);
void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(CorePlayer.AudioTypes);
void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(CorePlayer.ImageTypes);
void RemoveFileAssociations_Click(object sender, RoutedEventArgs e)
{
try
{
using (Process proc = new Process())
{
proc.StartInfo.FileName = "powershell.exe";
proc.StartInfo.Arguments = "-NoLogo -NoExit -NoProfile -ExecutionPolicy Bypass -File \"" +
Folder.Startup + "Setup\\remove file associations.ps1\"";
proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true;
proc.Start();
}
} catch { }
}
void AddToPathEnvVar_Click(object sender, RoutedEventArgs e)
{
ExecutePowerShellScript(Folder.Startup + "Setup\\add environment variable.ps1");
}
void RemoveFromPathEnvVar_Click(object sender, RoutedEventArgs e)
{
ExecutePowerShellScript(Folder.Startup + "Setup\\remove environment variable.ps1");
}
void AddStartMenuShortcut_Click(object sender, RoutedEventArgs e)
{
ExecutePowerShellScript(Folder.Startup + "Setup\\create start menu shortcut.ps1");
}
void RemoveStartMenuShortcut_Click(object sender, RoutedEventArgs e)
{
ExecutePowerShellScript(Folder.Startup + "Setup\\remove start menu shortcut.ps1");
}
void ShowEnvVarEditor_Click(object sender, RoutedEventArgs e)
{
ProcessHelp.Execute("rundll32.exe", "sysdm.cpl,EditEnvironmentVariables");
}
void ExecutePowerShellScript(string file)
{
ProcessHelp.Execute("powershell.exe",
"-NoLogo -NoExit -NoProfile -ExecutionPolicy Bypass -File \"" + file + "\"");
}
void EditDefaultApp_Click(object sender, RoutedEventArgs e)
{
ProcessHelp.ShellExecute("ms-settings:defaultapps");
}
}
}