misc...
This commit is contained in:
@@ -245,5 +245,14 @@ namespace mpvnet
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CopyMpvnetCom()
|
||||
{
|
||||
string dir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).AddSep() +
|
||||
"Microsoft\\WindowsApps\\";
|
||||
|
||||
if (File.Exists(dir + "mpvnet.exe") && !File.Exists(dir + "mpvnet.com"))
|
||||
File.Copy(Folder.Startup + "mpvnet.com", dir + "mpvnet.com");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -9,6 +10,8 @@ using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
using System.Windows.Interop;
|
||||
|
||||
using WinForms = System.Windows.Forms;
|
||||
|
||||
using static mpvnet.Global;
|
||||
|
||||
namespace mpvnet
|
||||
@@ -30,6 +33,7 @@ namespace mpvnet
|
||||
case "open-url": OpenURL(); break;
|
||||
case "playlist-first": PlaylistFirst(); break;
|
||||
case "playlist-last": PlaylistLast(); break;
|
||||
case "reg-file-assoc": RegisterFileAssociations(args[0]); break;
|
||||
case "scale-window": ScaleWindow(float.Parse(args[0], CultureInfo.InvariantCulture)); break;
|
||||
case "shell-execute": ProcessHelp.ShellExecute(args[0]); break;
|
||||
case "show-about": ShowDialog(typeof(AboutWindow)); break;
|
||||
@@ -49,7 +53,6 @@ namespace mpvnet
|
||||
case "show-properties": ShowProperties(); break;
|
||||
case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break;
|
||||
case "show-recent": ShowRecent(); break;
|
||||
case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break;
|
||||
case "show-text": ShowText(args[0], Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); break;
|
||||
case "update-check": UpdateCheck.CheckOnline(true); break;
|
||||
case "window-scale": WindowScale(float.Parse(args[0], CultureInfo.InvariantCulture)); break;
|
||||
@@ -467,5 +470,38 @@ namespace mpvnet
|
||||
CommandPalette.Instance.SetItems(items);
|
||||
MainForm.Instance.ShowCommandPalette();
|
||||
}
|
||||
|
||||
public static void RegisterFileAssociations(string perceivedType)
|
||||
{
|
||||
string[] extensions = { };
|
||||
|
||||
switch (perceivedType)
|
||||
{
|
||||
case "video": extensions = CorePlayer.VideoTypes; break;
|
||||
case "audio": extensions = CorePlayer.AudioTypes; break;
|
||||
case "image": extensions = CorePlayer.ImageTypes; break;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
using (Process proc = new Process())
|
||||
{
|
||||
proc.StartInfo.FileName = WinForms.Application.ExecutablePath;
|
||||
proc.StartInfo.Arguments = "--register-file-associations " +
|
||||
perceivedType + " " + string.Join(" ", extensions);
|
||||
proc.StartInfo.Verb = "runas";
|
||||
proc.StartInfo.UseShellExecute = true;
|
||||
proc.Start();
|
||||
proc.WaitForExit();
|
||||
|
||||
if (proc.ExitCode == 0)
|
||||
Msg.ShowInfo("File associations were successfully " +
|
||||
(perceivedType == "unreg" ? "removed" : "created") +
|
||||
".\n\nFile Explorer icons will refresh after process restart.");
|
||||
else
|
||||
Msg.ShowError("Error creating file associations.");
|
||||
}
|
||||
} catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ namespace mpvnet
|
||||
|
||||
public string ConfPath { get => ConfigFolder + "mpv.conf"; }
|
||||
public string GPUAPI { get; set; } = "auto";
|
||||
public string VO { get; set; } = "gpu";
|
||||
public string InputConfPath { get => ConfigFolder + "input.conf"; }
|
||||
|
||||
public string VID { get; set; } = "";
|
||||
@@ -219,6 +220,7 @@ namespace mpvnet
|
||||
case "taskbar-progress": TaskbarProgress = value == "yes"; break;
|
||||
case "screen": Screen = Convert.ToInt32(value); break;
|
||||
case "gpu-api": GPUAPI = value; break;
|
||||
case "vo": VO = value; break;
|
||||
}
|
||||
|
||||
if (AutofitLarger > 1)
|
||||
@@ -234,24 +236,8 @@ namespace mpvnet
|
||||
_ConfigFolder = Folder.Startup + "portable_config";
|
||||
|
||||
if (!Directory.Exists(_ConfigFolder))
|
||||
{
|
||||
_ConfigFolder = Folder.AppData + "mpv.net";
|
||||
|
||||
if (!Directory.Exists(_ConfigFolder))
|
||||
{
|
||||
_ConfigFolder = Folder.CustomSettings;
|
||||
|
||||
if (!Directory.Exists(_ConfigFolder))
|
||||
_ConfigFolder = Folder.AppData + "mpv.net";
|
||||
}
|
||||
}
|
||||
|
||||
if (Folder.Startup.IsIdenticalFolder(_ConfigFolder))
|
||||
{
|
||||
Msg.ShowError("Startup folder and config folder cannot be identical, using portable_config instead.");
|
||||
_ConfigFolder = Folder.Startup + "portable_config";
|
||||
}
|
||||
|
||||
if (!Directory.Exists(_ConfigFolder))
|
||||
Directory.CreateDirectory(_ConfigFolder);
|
||||
|
||||
|
||||
@@ -117,12 +117,4 @@ public static class PathStringExtension
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static bool IsIdenticalFolder(this string instance, string testFolder)
|
||||
{
|
||||
if (string.IsNullOrEmpty(instance) || string.IsNullOrEmpty(testFolder))
|
||||
return false;
|
||||
|
||||
return instance.ToLowerInvariant().AddSep() == testFolder.ToLowerInvariant().AddSep();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace mpvnet
|
||||
|
||||
Core.ObservePropertyDouble("window-scale", WindowScale);
|
||||
|
||||
if (Core.GPUAPI != "vulkan")
|
||||
if (!IsVulkanOrGpuNext)
|
||||
Core.ProcessCommandLine(false);
|
||||
|
||||
AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject);
|
||||
@@ -196,6 +196,8 @@ namespace mpvnet
|
||||
|
||||
bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible;
|
||||
|
||||
bool IsVulkanOrGpuNext => Core.GPUAPI == "vulkan" || Core.VO == "gpu-next";
|
||||
|
||||
bool KeepSize() => App.StartSize == "session" || App.StartSize == "always";
|
||||
|
||||
bool IsMouseInOSC()
|
||||
@@ -1033,7 +1035,7 @@ namespace mpvnet
|
||||
if (WindowState == FormWindowState.Maximized)
|
||||
Core.SetPropertyBool("window-maximized", true);
|
||||
|
||||
if (Core.GPUAPI == "vulkan")
|
||||
if (IsVulkanOrGpuNext)
|
||||
Core.ProcessCommandLine(false);
|
||||
|
||||
WPF.Init();
|
||||
@@ -1047,10 +1049,11 @@ namespace mpvnet
|
||||
BuildMenu();
|
||||
System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
|
||||
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
|
||||
UpdateCheck.DailyCheck();
|
||||
Core.LoadScripts();
|
||||
GlobalHotkey.RegisterGlobalHotkeys(Handle);
|
||||
App.RunTask(() => App.Extension = new Extension());
|
||||
UpdateCheck.DailyCheck();
|
||||
App.RunTask(() => App.CopyMpvnetCom());
|
||||
CSharpScriptHost.ExecuteScriptsInFolder(Core.ConfigFolder + "scripts-cs");
|
||||
WasShown = true;
|
||||
}
|
||||
|
||||
@@ -75,38 +75,47 @@ namespace mpvnet
|
||||
static string ExePath = Application.ExecutablePath;
|
||||
static string ExeFilename = Path.GetFileName(Application.ExecutablePath);
|
||||
static string ExeFilenameNoExt = Path.GetFileNameWithoutExtension(Application.ExecutablePath);
|
||||
static string[] Types;
|
||||
|
||||
public static void Register(string[] types)
|
||||
public static void Register(string perceivedType, string[] extensions)
|
||||
{
|
||||
Types = types;
|
||||
|
||||
RegistryHelp.SetValue(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath);
|
||||
RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename, "FriendlyAppName", "mpv.net media player");
|
||||
RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net");
|
||||
RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, "");
|
||||
RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, "");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities");
|
||||
|
||||
foreach (string ext in Types)
|
||||
if (perceivedType != "unreg")
|
||||
{
|
||||
RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, "");
|
||||
RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
|
||||
RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");
|
||||
RegistryHelp.SetValue(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath);
|
||||
RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename, "FriendlyAppName", "mpv.net media player");
|
||||
RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net");
|
||||
RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, "");
|
||||
RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, "");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities");
|
||||
|
||||
if (CorePlayer.VideoTypes.Contains(ext))
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video");
|
||||
foreach (string ext in extensions)
|
||||
{
|
||||
RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, "");
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", perceivedType);
|
||||
RegistryHelp.SetValue(@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
RegistryHelp.RemoveKey(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename);
|
||||
RegistryHelp.RemoveKey(@"HKCR\Applications\" + ExeFilename);
|
||||
RegistryHelp.RemoveKey(@"HKLM\SOFTWARE\Clients\Media\mpv.net");
|
||||
RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename);
|
||||
RegistryHelp.RemoveKey(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename);
|
||||
RegistryHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net");
|
||||
|
||||
if (CorePlayer.AudioTypes.Contains(ext))
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio");
|
||||
foreach (string id in Registry.ClassesRoot.GetSubKeyNames())
|
||||
{
|
||||
if (id.StartsWith(ExeFilenameNoExt + "."))
|
||||
Registry.ClassesRoot.DeleteSubKeyTree(id);
|
||||
|
||||
if (CorePlayer.ImageTypes.Contains(ext))
|
||||
RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image");
|
||||
|
||||
RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
|
||||
RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext);
|
||||
RegistryHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
|
||||
RegistryHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,25 +217,6 @@ namespace mpvnet
|
||||
{
|
||||
public static string Startup { get; } = Application.StartupPath.AddSep();
|
||||
public static string AppData { get; } = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).AddSep();
|
||||
|
||||
public static string CustomSettings {
|
||||
get {
|
||||
string linkFile = Startup + "settings-directory.txt";
|
||||
|
||||
if (File.Exists(linkFile))
|
||||
{
|
||||
string linkTarget = File.ReadAllText(linkFile).Trim();
|
||||
|
||||
if (linkTarget.StartsWithEx("."))
|
||||
linkTarget = Startup + linkTarget;
|
||||
|
||||
if (Directory.Exists(linkTarget))
|
||||
return linkTarget.AddSep();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandPaletteItem
|
||||
|
||||
@@ -23,17 +23,9 @@ namespace mpvnet
|
||||
|
||||
string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();
|
||||
|
||||
if (args.Length >= 2 && args[0] == "--reg-file-assoc")
|
||||
if (args.Length > 0 && args[0] == "--register-file-associations")
|
||||
{
|
||||
if (args[1] == "audio")
|
||||
FileAssociation.Register(CorePlayer.AudioTypes);
|
||||
else if (args[1] == "video")
|
||||
FileAssociation.Register(CorePlayer.VideoTypes);
|
||||
else if (args[1] == "image")
|
||||
FileAssociation.Register(CorePlayer.ImageTypes);
|
||||
else
|
||||
FileAssociation.Register(args.Skip(1).ToArray());
|
||||
|
||||
FileAssociation.Register(args[1], args.Skip(1).ToArray());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user