File associations and auto-load-folder can be customized

This commit is contained in:
Frank Skare
2021-03-09 06:56:55 +01:00
parent 28c9b2710c
commit 8db8e497a5
9 changed files with 60 additions and 29 deletions

View File

@@ -1,12 +1,14 @@
5.4.8.7 Beta (202?-??-??) 5.4.8.7 Beta (2021-03-??)
========================= =========================
- History feature can be configured to ingore defined strings: - History feature can be configured to ingore defined strings:
script-opt = history-discard=value1;value2 script-opt = history-discard=value1;value2
- Web stream audio and subtitle track selection. - Web stream audio and subtitle track selection.
- On Windows 10 1903 and later the default code page was changed to UTF8. - On Windows 10 1903 and later the default code page was changed to UTF-8.
- Support of --version command. - Support of --version command.
- File associations and auto-load-folder can be customized with
video-file-extensions, audio-file-extensions and image-file-extensions
5.4.8.6 Beta (2020-12-24) 5.4.8.6 Beta (2020-12-24)

View File

@@ -12,9 +12,9 @@ namespace mpvnet
{ {
public static class App public static class App
{ {
public static string[] VideoTypes { get; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' '); public static string[] VideoTypes { get; set; } = "264 265 asf avc avi avs dav flv h264 h265 hevc m2t m2ts m2v m4v mkv mov mp4 mpeg mpg mpv mts ts vob vpy webm wmv y4m".Split(' ');
public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' '); public static string[] AudioTypes { get; set; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' ');
public static string[] ImageTypes { get; } = { "jpg", "bmp", "gif", "png" }; public static string[] ImageTypes { get; set; } = { "jpg", "bmp", "gif", "png" };
public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" }; public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" };
public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
@@ -190,6 +190,9 @@ namespace mpvnet
case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true; case "minimum-aspect-ratio": MinimumAspectRatio = value.ToFloat(); return true;
case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true;
case "light-theme": LightTheme = value.Trim('\'', '"'); return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true;
case "video-file-extensions": VideoTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
case "audio-file-extensions": AudioTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
case "image-file-extensions": ImageTypes = value.Split(" ,;".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); return true;
default: default:
if (writeError) if (writeError)
ConsoleHelp.WriteError($"unknown mpvnet.conf property: {name}"); ConsoleHelp.WriteError($"unknown mpvnet.conf property: {name}");

View File

@@ -28,11 +28,17 @@ namespace mpvnet
string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray(); string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();
if (args.Length == 2 && args[0] == "--reg-file-assoc") if (args.Length >= 2 && args[0] == "--reg-file-assoc")
{ {
if (args[1] == "audio") FileAssociation.Register(App.AudioTypes); if (args[1] == "audio")
if (args[1] == "video") FileAssociation.Register(App.VideoTypes); FileAssociation.Register(App.AudioTypes);
if (args[1] == "image") FileAssociation.Register(App.ImageTypes); else if (args[1] == "video")
FileAssociation.Register(App.VideoTypes);
else if (args[1] == "image")
FileAssociation.Register(App.ImageTypes);
else
FileAssociation.Register(args.Skip(1).ToArray());
return; return;
} }

View File

@@ -570,6 +570,27 @@ file = "mpvnet"
filter = "General" filter = "General"
help = "<int> Amount of recent files to be remembered. Default: 15 (mpv.net specific setting)" help = "<int> Amount of recent files to be remembered. Default: 15 (mpv.net specific setting)"
[[settings]]
name = "video-file-extensions"
file = "mpvnet"
filter = "General"
width = 500
help = "Video file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific setting)"
[[settings]]
name = "audio-file-extensions"
file = "mpvnet"
filter = "General"
width = 500
help = "Audio file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific setting)"
[[settings]]
name = "image-file-extensions"
file = "mpvnet"
filter = "General"
width = 500
help = "Image file extensions used to create file associations and used by the auto-load-folder feature. (mpv.net specific setting)"
[[settings]] [[settings]]
name = "debug-mode" name = "debug-mode"
file = "mpvnet" file = "mpvnet"

View File

@@ -17,7 +17,7 @@
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
<RowDefinition></RowDefinition> <RowDefinition />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox Name="FilterTextBox" <TextBox Name="FilterTextBox"

View File

@@ -2,7 +2,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@@ -11,6 +10,7 @@ using System.Windows.Controls;
using System.Windows.Input; using System.Windows.Input;
using DynamicGUI; using DynamicGUI;
using static mpvnet.Core; using static mpvnet.Core;
namespace mpvnet namespace mpvnet
@@ -56,12 +56,10 @@ namespace mpvnet
switch (setting) switch (setting)
{ {
case StringSetting s: case StringSetting s:
var sc = new StringSettingControl(s); MainStackPanel.Children.Add(new StringSettingControl(s));
MainStackPanel.Children.Add(sc);
break; break;
case OptionSetting s: case OptionSetting s:
var oc = new OptionSettingControl(s); MainStackPanel.Children.Add(new OptionSettingControl(s));
MainStackPanel.Children.Add(oc);
break; break;
} }
} }

View File

@@ -142,9 +142,7 @@ namespace mpvnet
Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity); Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity);
string ext = sb.ToString().Ext(); string ext = sb.ToString().Ext();
if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext) || App.ImageTypes.Contains(ext))
|| App.ImageTypes.Contains(ext))
items.Add(sb.ToString()); items.Add(sb.ToString());
if (items.Count > 100) if (items.Count > 100)

View File

@@ -1,7 +1,6 @@
 
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows; using System.Windows;
@@ -31,27 +30,29 @@ namespace mpvnet
} }
} }
void RegisterFileAssociations(string value) void RegFileAssoc(string[] extensions)
{ {
try try
{ {
using (Process proc = new Process()) using (Process proc = new Process())
{ {
proc.StartInfo.FileName = WinForms.Application.ExecutablePath; proc.StartInfo.FileName = WinForms.Application.ExecutablePath;
proc.StartInfo.Arguments = "--reg-file-assoc " + value; proc.StartInfo.Arguments = "--reg-file-assoc " + String.Join(" ", extensions);
proc.StartInfo.Verb = "runas"; proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true; proc.StartInfo.UseShellExecute = true;
proc.Start(); proc.Start();
proc.WaitForExit();
if (proc.ExitCode == 0)
Msg.Show("File associations successfully created.");
} }
Msg.Show(value[0].ToString().ToUpper() + value.Substring(1) +
" file associations successfully created.");
} catch {} } catch {}
} }
void AddVideo_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("video"); void AddVideo_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.VideoTypes);
void AddAudio_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("audio"); void AddAudio_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.AudioTypes);
void AddImage_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("image"); void AddImage_Click(object sender, RoutedEventArgs e) => RegFileAssoc(App.ImageTypes);
void RemoveFileAssociations_Click(object sender, RoutedEventArgs e) void RemoveFileAssociations_Click(object sender, RoutedEventArgs e)
{ {
@@ -60,7 +61,7 @@ namespace mpvnet
using (Process proc = new Process()) using (Process proc = new Process())
{ {
proc.StartInfo.FileName = "powershell.exe"; proc.StartInfo.FileName = "powershell.exe";
proc.StartInfo.Arguments = "-NoLogo -NoExit -ExecutionPolicy Bypass -File \"" + proc.StartInfo.Arguments = "-NoLogo -NoExit -NoProfile -ExecutionPolicy Bypass -File \"" +
Folder.Startup + "Setup\\remove file associations.ps1\""; Folder.Startup + "Setup\\remove file associations.ps1\"";
proc.StartInfo.Verb = "runas"; proc.StartInfo.Verb = "runas";
proc.StartInfo.UseShellExecute = true; proc.StartInfo.UseShellExecute = true;
@@ -96,7 +97,8 @@ namespace mpvnet
void ExecutePowerShellScript(string file) void ExecutePowerShellScript(string file)
{ {
ProcessHelp.Execute("powershell.exe", "-NoLogo -NoExit -ExecutionPolicy Bypass -File \"" + file + "\""); ProcessHelp.Execute("powershell.exe",
"-NoLogo -NoExit -NoProfile -ExecutionPolicy Bypass -File \"" + file + "\"");
} }
void EditDefaultApp_Click(object sender, RoutedEventArgs e) void EditDefaultApp_Click(object sender, RoutedEventArgs e)

View File

@@ -1,4 +1,5 @@
using System; 
using System;
using System.Linq; using System.Linq;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;