improved error handling, new setup dialog
This commit is contained in:
@@ -10,6 +10,11 @@
|
||||
- the input editor no longer as known limitations, 'alt gr' and ctrl+alt are working now
|
||||
- the help in the input editor was simplified and the filter logic was improved
|
||||
- fixed issue in file associations causing mpv.net not to appear in OS default apps
|
||||
- 'Tools > Manage File Associations' was replaced by 'Tools > OS Setup',
|
||||
it has now a feature to add and remove mpv.net to and from the Path
|
||||
environment variable and the OS default apps settings can be opened (Win 10 only)
|
||||
- Error messages are shown when unknown scripts and extensions are found in the startup folder
|
||||
because user scripts are supposed to be located in the config folder instead
|
||||
|
||||
### 5.0
|
||||
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
// This extension implements the C# scripting feature of mpv.net which
|
||||
// is based on CS-Script (https://www.cs-script.net).
|
||||
|
||||
// Furthermore I use this extension to code and debug scripts
|
||||
// because writing script code without debugger is not much fun.
|
||||
|
||||
// Once the code was developed and debugged, I move the code
|
||||
// from the extension to a standalone script.
|
||||
// I also use this extension to code scripts in order to have full
|
||||
// code completion and debugger support, once the script code is
|
||||
// finished I move it from the extension to a standalone script.
|
||||
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
@@ -21,7 +19,7 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten
|
||||
[Export(typeof(IExtension))]
|
||||
public class ScriptingExtension : IExtension
|
||||
{
|
||||
Script Script;
|
||||
//Script Script;
|
||||
|
||||
public ScriptingExtension()
|
||||
{
|
||||
@@ -32,7 +30,8 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten
|
||||
scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs"));
|
||||
|
||||
if (Directory.Exists(Application.StartupPath + "\\scripts"))
|
||||
scriptFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs"));
|
||||
foreach (string file in Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs"))
|
||||
Msg.ShowError("Failed to load script.", "Only scripts that ship with mpv.net are allowed in <startup>\\scripts.\n\nUser scripts have to use <config folder>\\scripts.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + file);
|
||||
|
||||
if (scriptFiles.Count == 0) return;
|
||||
CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom;
|
||||
@@ -47,4 +46,4 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,7 @@ namespace mpvnet
|
||||
case "show-about": ShowDialog(typeof(AboutWindow)); break;
|
||||
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
|
||||
case "show-input-editor": ShowDialog(typeof(InputWindow)); break;
|
||||
case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break;
|
||||
case "open-conf-folder": Process.Start(mp.ConfigFolder); break;
|
||||
case "open-files": OpenFiles(args); break;
|
||||
case "shell-execute": Process.Start(args[0]); break;
|
||||
@@ -230,31 +231,6 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
|
||||
public static void ManageFileAssociations()
|
||||
{
|
||||
using (var td = new TaskDialog<string>())
|
||||
{
|
||||
td.MainInstruction = "Choose an option.";
|
||||
td.MainIcon = MsgIcon.Shield;
|
||||
|
||||
td.AddCommandLink("Register video file extensions", "video");
|
||||
td.AddCommandLink("Register audio file extensions", "audio");
|
||||
td.AddCommandLink("Register image file extensions", "image");
|
||||
td.AddCommandLink("Unregister file extensions", "unreg");
|
||||
|
||||
string result = td.Show();
|
||||
|
||||
if (!string.IsNullOrEmpty(result))
|
||||
{
|
||||
using (var proc = new Process())
|
||||
{
|
||||
proc.StartInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
|
||||
proc.StartInfo.Arguments = "--reg-file-assoc " + result;
|
||||
proc.StartInfo.Verb = "runas";
|
||||
try { proc.Start(); } catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void ManageFileAssociations() => ShowDialog(typeof(SetupWindow)); // deprecated 2019
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.ComponentModel.Composition;
|
||||
using System.ComponentModel.Composition.Hosting;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using System.Linq;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
@@ -19,12 +20,20 @@ namespace mpvnet
|
||||
try
|
||||
{
|
||||
AggregateCatalog catalog = new AggregateCatalog();
|
||||
|
||||
string dir = Application.StartupPath + "\\Extensions";
|
||||
|
||||
if (Directory.Exists(dir))
|
||||
foreach (string i in Directory.GetDirectories(dir))
|
||||
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Extension.dll"));
|
||||
{
|
||||
string[] knownExtensions = { "RatingExtension", "ScriptingExtension" };
|
||||
|
||||
foreach (string path in Directory.GetDirectories(dir))
|
||||
{
|
||||
if (knownExtensions.Contains(Path.GetFileName(path)))
|
||||
catalog.Catalogs.Add(new DirectoryCatalog(path, "*Extension.dll"));
|
||||
else
|
||||
Msg.ShowError("Failed to load extension", "Only extensions that ship with mpv.net are allowed in <startup>\\extensions.\n\nUser extensions have to use <config folder>\\extensions.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + path);
|
||||
}
|
||||
}
|
||||
|
||||
dir = mp.ConfigFolder + "\\Extensions";
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@
|
||||
l ab-loop #menu: Tools > Set/clear A-B loop points
|
||||
L cycle-values loop-file "inf" "no" #menu: Tools > Toggle infinite file looping
|
||||
Ctrl+h cycle-values hwdec "auto" "no" #menu: Tools > Toggle Hardware Decoding
|
||||
_ script-message mpv.net manage-file-associations #menu: Tools > Manage File Associations...
|
||||
_ script-message mpv.net show-setup-dialog #menu: Tools > OS Setup...
|
||||
|
||||
_ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/Manual.md #menu: Help > mpv.net Manual
|
||||
_ script-message mpv.net shell-execute https://github.com/stax76/mpv.net #menu: Help > mpv.net GitHub
|
||||
|
||||
19
mpv.net/WPF/SetupWindow.xaml
Normal file
19
mpv.net/WPF/SetupWindow.xaml
Normal file
@@ -0,0 +1,19 @@
|
||||
<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"
|
||||
mc:Ignorable="d"
|
||||
Title="mpv.net OS Setup" SizeToContent="WidthAndHeight" WindowStartupLocation="CenterOwner">
|
||||
<Grid>
|
||||
<StackPanel>
|
||||
<Button Name="RegisterVideo" Margin="5" Click="RegisterVideo_Click">Register video file extensions (requires elevated privileges)</Button>
|
||||
<Button Name="RegisterAudio" Margin="5" Click="RegisterAudio_Click">Register audio file extensions (requires elevated privileges)</Button>
|
||||
<Button Name="RegisterImage" Margin="5" Click="RegisterImage_Click">Register image file extensions (requires elevated privileges)</Button>
|
||||
<Button Name="AddToPathEnvVar" Margin="5" Click="AddToPathEnvVar_Click">Add mpv.net to Path environment variable</Button>
|
||||
<Button Name="ManageDefaultApps" Margin="5" Click="ManageDefaultApps_Click">Manage Default Apps (Win 10 or higher)</Button>
|
||||
<Button Name="UnregisterFileAssociations" Margin="5,20,5,5" Click="UnregisterFileAssociations_Click">Unregister file extensions (requires elevated privileges)</Button>
|
||||
<Button Name="RemoveFromPathEnvVar" Margin="5" Click="RemoveFromPathEnvVar_Click">Remove mpv.net from Path environment variable</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</Window>
|
||||
57
mpv.net/WPF/SetupWindow.xaml.cs
Normal file
57
mpv.net/WPF/SetupWindow.xaml.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using WF = System.Windows.Forms;
|
||||
|
||||
namespace mpvnet
|
||||
{
|
||||
public partial class SetupWindow : Window
|
||||
{
|
||||
public SetupWindow() => InitializeComponent();
|
||||
|
||||
void RegisterFileAssociations(string value)
|
||||
{
|
||||
using (var proc = new Process())
|
||||
{
|
||||
proc.StartInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
|
||||
proc.StartInfo.Arguments = "--reg-file-assoc " + value;
|
||||
proc.StartInfo.Verb = "runas";
|
||||
try { proc.Start(); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
private void RegisterVideo_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("video");
|
||||
private void RegisterAudio_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("audio");
|
||||
private void RegisterImage_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("image");
|
||||
private void UnregisterFileAssociations_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("unreg");
|
||||
private void ManageDefaultApps_Click(object sender, RoutedEventArgs e) => Process.Start("ms-settings:defaultapps");
|
||||
|
||||
private void AddToPathEnvVar_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string var = WF.Application.StartupPath + ";";
|
||||
string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User);
|
||||
|
||||
if (path.Contains(var))
|
||||
Msg.ShowWarning("Path was already containing mpv.net.");
|
||||
else
|
||||
{
|
||||
Environment.SetEnvironmentVariable("Path", var + path, EnvironmentVariableTarget.User);
|
||||
Msg.Show("mpv.net was successfully added to Path.", (var + path).Replace(";","\n"));
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveFromPathEnvVar_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string var = WF.Application.StartupPath + ";";
|
||||
string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User);
|
||||
|
||||
if (path.Contains(var))
|
||||
{
|
||||
Environment.SetEnvironmentVariable("Path", path.Replace(var, ""), EnvironmentVariableTarget.User);
|
||||
Msg.Show("mpv.net was successfully removed from Path.");
|
||||
}
|
||||
else
|
||||
Msg.ShowWarning("Path was not containing mpv.net.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,6 +119,10 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="WPF\SetupWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Page Include="WPF\AboutWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
@@ -172,6 +176,9 @@
|
||||
<Compile Include="Misc\Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Native\TaskDialog.cs" />
|
||||
<Compile Include="WPF\SetupWindow.xaml.cs">
|
||||
<DependentUpon>SetupWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="WPF\EverythingWindow.xaml.cs">
|
||||
<DependentUpon>EverythingWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -156,7 +156,6 @@ namespace mpvnet
|
||||
td.AddCommandLink(@"AppData\Roaming\mpv.net", appdataFolder, appdataFolder);
|
||||
td.AddCommandLink(@"AppData\Roaming\mpv", appdataFolderMpv, appdataFolderMpv);
|
||||
td.AddCommandLink("<startup>\\portable_config", portableFolder, portableFolder);
|
||||
td.AddCommandLink("<startup>", startupFolder, startupFolder);
|
||||
td.AddCommandLink("Choose custom folder", "custom");
|
||||
td.AllowCancel = false;
|
||||
_ConfigFolder = td.Show();
|
||||
@@ -214,36 +213,45 @@ namespace mpvnet
|
||||
}
|
||||
}
|
||||
|
||||
public static void UnknownScriptError(string path) => Msg.ShowError("Failed to load script", "Only scripts that ship with mpv.net are allowed in <startup>\\scripts.\n\nUser scripts have to use <config folder>\\scripts.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + path);
|
||||
|
||||
public static void LoadMpvScripts()
|
||||
{
|
||||
string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
|
||||
|
||||
foreach (string scriptPath in startupScripts)
|
||||
if (scriptPath.EndsWith(".lua") || scriptPath.EndsWith(".js"))
|
||||
commandv("load-script", $"{scriptPath}");
|
||||
foreach (string path in startupScripts)
|
||||
if (path.EndsWith(".lua") || path.EndsWith(".js"))
|
||||
if (KnownScripts.Contains(Path.GetFileName(path)))
|
||||
commandv("load-script", $"{path}");
|
||||
else
|
||||
UnknownScriptError(path);
|
||||
}
|
||||
|
||||
public static string[] KnownScripts { get; } = { "osc-visibility.js", "show-playlist.js", "seek-show-position.py" };
|
||||
|
||||
public static void LoadScripts()
|
||||
{
|
||||
|
||||
if (Directory.Exists(Application.StartupPath + "\\Scripts"))
|
||||
{
|
||||
string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts");
|
||||
|
||||
foreach (string scriptPath in startupScripts)
|
||||
if (Path.GetExtension(scriptPath) == ".py")
|
||||
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||
|
||||
foreach (string scriptPath in startupScripts)
|
||||
if (Path.GetExtension(scriptPath) == ".ps1")
|
||||
PowerShellScript.Init(scriptPath);
|
||||
foreach (string path in Directory.GetFiles(Application.StartupPath + "\\Scripts"))
|
||||
{
|
||||
if (KnownScripts.Contains(Path.GetFileName(path)))
|
||||
{
|
||||
if (path.EndsWith(".py"))
|
||||
PythonScripts.Add(new PythonScript(File.ReadAllText(path)));
|
||||
else if (path.EndsWith(".ps1"))
|
||||
PowerShellScript.Init(path);
|
||||
}
|
||||
else
|
||||
UnknownScriptError(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (Directory.Exists(ConfigFolder + "Scripts"))
|
||||
foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "Scripts"))
|
||||
if (Path.GetExtension(scriptPath) == ".py")
|
||||
if (scriptPath.EndsWith(".py"))
|
||||
PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)));
|
||||
else if (Path.GetExtension(scriptPath) == ".ps1")
|
||||
else if (scriptPath.EndsWith(".ps1"))
|
||||
PowerShellScript.Init(scriptPath);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user