示例#1
0
文件: Misc.cs 项目: vmackey/mpv.net
        public static void Register(string[] types)
        {
            Types = types;

            RegHelp.SetObject($"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\{ExeFilename}", null, ExePath);
            RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}", "FriendlyAppName", "mpv.net media player");
            RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\"");
            RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player");
            RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net");
            RegHelp.SetObject($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}", null, "");
            RegHelp.SetObject($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}", null, "");
            RegHelp.SetObject(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities");

            foreach (string ext in Types)
            {
                RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\SupportedTypes", "." + ext, "");
                RegHelp.SetObject($"HKCR\\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
                RegHelp.SetObject($"HKCR\\" + "." + ext + "\\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");
                if (App.VideoTypes.Contains(ext))
                {
                    RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "video");
                }
                if (App.AudioTypes.Contains(ext))
                {
                    RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "audio");
                }
                if (App.ImageTypes.Contains(ext))
                {
                    RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "image");
                }
                RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open", null, "Play with " + Application.ProductName);
                RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\"");
                RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext);
            }
        }
示例#2
0
 protected override void OnFormClosed(FormClosedEventArgs e)
 {
     base.OnFormClosed(e);
     RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray());
     App.Exit();
     mp.commandv("quit");
     mp.AutoResetEvent.WaitOne(3000);
 }
示例#3
0
 public static void ExecuteMpvCommand() // deprecated 2019
 {
     InvokeOnMainThread(new Action(() => {
         string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegHelp.GetString(App.RegPath, "RecentExecutedCommand"));
         if (string.IsNullOrEmpty(command))
         {
             return;
         }
         RegHelp.SetObject(App.RegPath, "RecentExecutedCommand", command);
         mp.command(command, false);
     }));
 }
示例#4
0
 public static void execute_mpv_command(string[] args)
 {
     MainForm.Instance.Invoke(new Action(() => {
         string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegHelp.GetString(App.RegPath, "RecentExecutedCommand"));
         if (string.IsNullOrEmpty(command))
         {
             return;
         }
         RegHelp.SetObject(App.RegPath, "RecentExecutedCommand", command);
         mp.command_string(command, false);
     }));
 }
示例#5
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (WindowState == FormWindowState.Normal)
            {
                RegHelp.SetObject(App.RegPath, "PosX", Left + Width / 2);
                RegHelp.SetObject(App.RegPath, "PosY", Top + Height / 2);
            }

            RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray());
            mp.commandv("quit");
            mp.ShutdownAutoResetEvent.WaitOne(3000);
        }
示例#6
0
        protected static void ProcessCommandLine()
        {
            var           args  = Environment.GetCommandLineArgs().Skip(1);
            List <string> files = new List <string>();

            foreach (string i in args)
            {
                if (!i.StartsWith("--") && (i == "-" || i.Contains("://") || File.Exists(i)))
                {
                    files.Add(i);
                    if (i.Contains("://"))
                    {
                        RegHelp.SetObject(App.RegPath, "LastURL", i);
                    }
                }
            }

            Load(files.ToArray(), App.ProcessInstance != "queue", Control.ModifierKeys.HasFlag(Keys.Control));

            if (files.Count == 0)
            {
                VideoSizeAutoResetEvent.Set();
                VideoSizeChanged?.Invoke();
            }

            foreach (string i in args)
            {
                if (i.StartsWith("--"))
                {
                    try
                    {
                        if (i.Contains("="))
                        {
                            string left  = i.Substring(2, i.IndexOf("=") - 2);
                            string right = i.Substring(left.Length + 3);
                            set_property_string(left, right, true);
                        }
                        else
                        {
                            set_property_string(i.Substring(2), "yes", true);
                        }
                    }
                    catch (Exception e)
                    {
                        Msg.ShowException(e);
                    }
                }
            }
        }
示例#7
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            RegHelp.SetObject(App.RegPath, "ConfigEditorSearch", SearchControl.Text);
            string content    = GetContent(mp.ConfPath, Conf, SettingsDefinitions);
            string netContent = GetContent(App.ConfPath, NetConf, NetSettingsDefinitions);

            if (InitialContent == content + netContent)
            {
                return;
            }
            File.WriteAllText(mp.ConfPath, content);
            File.WriteAllText(App.ConfPath, netContent);
            Msg.Show("Changes will be available on next mpv.net startup.");
        }
示例#8
0
        void CheckClipboardForURL()
        {
            string clipboard = Clipboard.GetText();

            foreach (string url in App.UrlWhitelist)
            {
                if (clipboard.Contains("://") && !clipboard.Contains("\n") &&
                    !clipboard.Contains(" ") && clipboard.Contains(url.ToLower().Trim()) &&
                    RegHelp.GetString(App.RegPath, "LastURL") != clipboard && Visible)
                {
                    RegHelp.SetObject(App.RegPath, "LastURL", clipboard);

                    if (Msg.ShowQuestion("Play URL?", clipboard) == MsgResult.OK)
                    {
                        mp.Load(new[] { clipboard }, true, Control.ModifierKeys.HasFlag(Keys.Control));
                    }
                }
            }
        }
示例#9
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            if (WindowState == FormWindowState.Normal)
            {
                RegHelp.SetObject(App.RegPath, "PosX", Left + Width / 2);
                RegHelp.SetObject(App.RegPath, "PosY", Top + Height / 2);
            }

            RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray());

            if (mp.IsQuitNeeded)
            {
                mp.commandv("quit");
            }

            if (!mp.ShutdownAutoResetEvent.WaitOne(10000))
            {
                Msg.ShowError("Shutdown thread failed to complete within 10 seconds.");
            }
        }
示例#10
0
文件: mp.cs 项目: Revan654/mpv.net
        protected static void ProcessCommandLine()
        {
            var           args  = Environment.GetCommandLineArgs().Skip(1);
            List <string> files = new List <string>();

            foreach (string i in args)
            {
                if (!i.StartsWith("--") && (File.Exists(i) || i == "-" || i.StartsWith("http")))
                {
                    files.Add(i);
                    if (i.StartsWith("http"))
                    {
                        RegHelp.SetObject(App.RegPath, "LastURL", i);
                    }
                }
            }

            Load(files.ToArray(), App.ProcessInstance != "queue", Control.ModifierKeys.HasFlag(Keys.Control));

            foreach (string i in args)
            {
                if (i.StartsWith("--"))
                {
                    if (i.Contains("="))
                    {
                        string left  = i.Substring(2, i.IndexOf("=") - 2);
                        string right = i.Substring(left.Length + 3);
                        set_property_string(left, right);
                    }
                    else
                    {
                        set_property_string(i.Substring(2), "yes");
                    }
                }
            }
        }
示例#11
0
        static void Main()
        {
            try
            {
                string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();

                if (args.Length == 2 && args[0] == "--reg-file-assoc")
                {
                    if (args[1] == "audio")
                    {
                        FileAssociation.Register(App.AudioTypes);
                    }
                    if (args[1] == "video")
                    {
                        FileAssociation.Register(App.VideoTypes);
                    }
                    if (args[1] == "unreg")
                    {
                        FileAssociation.Unregister();
                    }
                    return;
                }

                App.Init();
                Mutex mutex = new Mutex(true, "mpvnetProcessInstance", out bool isFirst);

                if ((App.ProcessInstance == "single" || App.ProcessInstance == "queue") && !isFirst)
                {
                    List <string> files = new List <string>();

                    foreach (string arg in args)
                    {
                        if (!arg.StartsWith("--") && (File.Exists(arg) || arg == "-" || arg.StartsWith("http")))
                        {
                            files.Add(arg);
                        }
                    }

                    if (files.Count > 0)
                    {
                        RegHelp.SetObject(App.RegPath, "ShellFiles", files.ToArray());
                    }

                    RegHelp.SetObject(App.RegPath, "ProcessInstanceMode", App.ProcessInstance);

                    foreach (Process process in Process.GetProcessesByName("mpvnet"))
                    {
                        try {
                            SingleProcess.AllowSetForegroundWindow(process.Id);
                            Native.SendMessage(process.MainWindowHandle, SingleProcess.Message, IntPtr.Zero, IntPtr.Zero);
                        } catch {}
                    }

                    mutex.Dispose();
                    return;
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
                mutex.Dispose();
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
示例#12
0
 protected override void OnClosed(EventArgs e)
 {
     base.OnClosed(e);
     WriteToDisk();
     RegHelp.SetObject(App.RegPath, "config editor search", SearchControl.Text);
 }