예제 #1
0
 public ConfWindow()
 {
     InitializeComponent();
     DataContext = this;
     SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged;
     LoadConf(core.ConfPath);
     LoadConf(App.ConfPath);
     LoadSettings();
     InitialContent             = GetCompareString();
     SearchControl.Text         = RegistryHelp.GetString(App.RegPath, "ConfigEditorSearch");
     FilterListBox.SelectedItem = SearchControl.Text.TrimEnd(':');
 }
예제 #2
0
 public static void ExecuteMpvCommand() // deprecated 2019
 {
     InvokeOnMainThread(new Action(() => {
         string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString(App.RegPath, "RecentExecutedCommand"));
         if (string.IsNullOrEmpty(command))
         {
             return;
         }
         RegistryHelp.SetValue(App.RegPath, "RecentExecutedCommand", command);
         mp.command(command, false);
     }));
 }
예제 #3
0
        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            RegistryHelp.SetValue(App.RegPath, "ConfigEditorSearch", SearchControl.Text);

            if (InitialContent == GetCompareString())
            {
                return;
            }

            File.WriteAllText(mp.ConfPath, GetContent("mpv"));
            File.WriteAllText(App.ConfPath, GetContent("mpvnet"));
            Msg.Show("Changes will be available on next mpv.net startup.");
        }
예제 #4
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            SaveWindowProperties();
            RegistryHelp.SetValue(App.RegPath, "Recent", RecentFiles.ToArray());

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

            if (!core.ShutdownAutoResetEvent.WaitOne(10000))
            {
                Msg.ShowError("Shutdown thread failed to complete within 10 seconds.");
            }
        }
예제 #5
0
파일: Misc.cs 프로젝트: tyronebj/mpv.net
        public static void Unregister()
        {
            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");

            foreach (string id in Registry.ClassesRoot.GetSubKeyNames())
            {
                if (id.StartsWith(ExeFilenameNoExt + "."))
                {
                    Registry.ClassesRoot.DeleteSubKeyTree(id);
                }

                RegistryHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
                RegistryHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id);
            }
        }
예제 #6
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

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

            RegistryHelp.SetValue(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.");
            }
        }
예제 #7
0
파일: Misc.cs 프로젝트: tyronebj/mpv.net
        public static void Register(string[] types)
        {
            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)
            {
                RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, "");
                RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext);
                RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, "");

                if (App.VideoTypes.Contains(ext))
                {
                    RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video");
                }

                if (App.AudioTypes.Contains(ext))
                {
                    RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio");
                }

                if (App.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);
            }
        }
예제 #8
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);
            SaveWindowProperties();
            RegistryHelp.SetValue(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.");
            }

            try { // PowerShell 5.1 might not be available
                foreach (PowerShell ps in PowerShell.Instances)
                {
                    ps.Runspace.Dispose();
                }
            } catch {}
        }
예제 #9
0
        public static async void CheckOnline(bool showUpToDateMessage = false)
        {
            try
            {
                using (HttpClient client = new HttpClient())
                {
                    RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "UpdateCheckLast", DateTime.Now.DayOfYear);
                    client.DefaultRequestHeaders.Add("User-Agent", "mpv.net");
                    var response = await client.GetAsync("https://api.github.com/repos/stax76/mpv.net/releases/latest");

                    response.EnsureSuccessStatusCode();
                    string content = await response.Content.ReadAsStringAsync();

                    Match   match          = Regex.Match(content, @"""mpv\.net-([\d\.]+)-portable\.zip""");
                    Version onlineVersion  = Version.Parse(match.Groups[1].Value);
                    Version currentVersion = Assembly.GetEntryAssembly().GetName().Version;

                    if (onlineVersion <= currentVersion)
                    {
                        if (showUpToDateMessage)
                        {
                            Msg.Show($"{Application.ProductName} is up to date.");
                        }

                        return;
                    }

                    if ((RegistryHelp.GetString("UpdateCheckVersion")
                         != onlineVersion.ToString() || showUpToDateMessage) && Msg.ShowQuestion(
                            $"New version {onlineVersion} is available, update now?") == MsgResult.OK)
                    {
                        string url = $"https://github.com/stax76/mpv.net/releases/download/{onlineVersion}/mpv.net-{onlineVersion}-portable.zip";

                        using (Process proc = new Process())
                        {
                            proc.StartInfo.UseShellExecute  = true;
                            proc.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                            proc.StartInfo.FileName         = "powershell.exe";
                            proc.StartInfo.Arguments        = $"-NoExit -ExecutionPolicy Bypass -File \"{Folder.Startup + "Setup\\update.ps1"}\" \"{url}\" \"{Folder.Startup.TrimEnd(Path.DirectorySeparatorChar)}\"";

                            if (Folder.Startup.Contains("Program Files"))
                            {
                                proc.StartInfo.Verb = "runas";
                            }

                            proc.Start();
                        }

                        core.command("quit");
                    }

                    RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "UpdateCheckVersion", onlineVersion.ToString());
                }
            }
            catch (Exception ex)
            {
                if (showUpToDateMessage)
                {
                    Msg.ShowException(ex);
                }
            }
        }
예제 #10
0
        public MainForm()
        {
            InitializeComponent();

            try
            {
                object recent = RegistryHelp.GetValue(App.RegPath, "Recent");

                if (recent is string[] r)
                {
                    RecentFiles = new List <string>(r);
                }
                else
                {
                    RecentFiles = new List <string>();
                }

                Instance            = this;
                Hwnd                = Handle;
                ConsoleHelp.Padding = 60;
                core.Init();

                core.Shutdown         += Shutdown;
                core.VideoSizeChanged += VideoSizeChanged;
                core.FileLoaded       += FileLoaded;
                core.Idle             += Idle;
                core.Seek             += () => UpdateProgressBar();

                core.observe_property("window-maximized", PropChangeWindowMaximized);
                core.observe_property("window-minimized", PropChangeWindowMinimized);
                core.observe_property_bool("pause", PropChangePause);
                core.observe_property_bool("fullscreen", PropChangeFullscreen);
                core.observe_property_bool("ontop", PropChangeOnTop);
                core.observe_property_bool("border", PropChangeBorder);

                core.observe_property_string("sid", PropChangeSid);
                core.observe_property_string("aid", PropChangeAid);
                core.observe_property_string("vid", PropChangeVid);

                core.observe_property_int("edition", PropChangeEdition);
                core.observe_property_double("window-scale", PropChangeWindowScale);

                if (core.GPUAPI != "vulkan")
                {
                    core.ProcessCommandLine(false);
                }

                AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject);
                Application.ThreadException += (sender, e) => App.ShowException(e.Exception);
                Msg.SupportURL = "https://github.com/stax76/mpv.net#support";
                Text           = "mpv.net " + Application.ProductVersion;
                TaskbarButtonCreatedMessage = WinAPI.RegisterWindowMessage("TaskbarButtonCreated");

                ContextMenu          = new ContextMenuStripEx(components);
                ContextMenu.Opened  += ContextMenu_Opened;
                ContextMenu.Opening += ContextMenu_Opening;

                if (core.Screen == -1)
                {
                    core.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
                }

                int      targetIndex = core.Screen;
                Screen[] screens     = Screen.AllScreens;

                if (targetIndex < 0)
                {
                    targetIndex = 0;
                }

                if (targetIndex > screens.Length - 1)
                {
                    targetIndex = screens.Length - 1;
                }

                Screen    screen = screens[Array.IndexOf(screens, screens[targetIndex])];
                Rectangle target = screen.Bounds;
                Left = target.X + (target.Width - Width) / 2;
                Top  = target.Y + (target.Height - Height) / 2;

                if (!core.Border)
                {
                    FormBorderStyle = FormBorderStyle.None;
                }

                int posX = RegistryHelp.GetInt(App.RegPath, "PosX");
                int posY = RegistryHelp.GetInt(App.RegPath, "PosY");

                if (posX != 0 && posY != 0 && App.RememberPosition)
                {
                    Left = posX - Width / 2;
                    Top  = posY - Height / 2;
                }

                if (core.WindowMaximized)
                {
                    SetFormPosAndSize(1, true);
                    WindowState = FormWindowState.Maximized;
                }

                if (core.WindowMinimized)
                {
                    SetFormPosAndSize(1, true);
                    WindowState = FormWindowState.Minimized;
                }
            }
            catch (Exception ex)
            {
                Msg.ShowException(ex);
            }
        }
예제 #11
0
        void SetFormPosAndSize(double scale = 1, bool force = false)
        {
            if (!force)
            {
                if (WindowState != FormWindowState.Normal)
                {
                    return;
                }

                if (core.Fullscreen)
                {
                    CycleFullscreen(true);
                    return;
                }
            }

            Screen screen        = Screen.FromControl(this);
            int    autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * core.Autofit);

            if (core.VideoSize.Height == 0 || core.VideoSize.Width == 0 ||
                core.VideoSize.Width / (float)core.VideoSize.Height < App.MinimumAspectRatio)
            {
                core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight);
            }

            Size videoSize = core.VideoSize;
            int  height    = videoSize.Height;

            if (core.WasInitialSizeSet || scale != 1)
            {
                height = ClientSize.Height;
            }
            else
            {
                int savedHeight = RegistryHelp.GetInt(App.RegPath, "Height");

                if (App.StartSize == "always" && savedHeight != 0)
                {
                    height = savedHeight;
                }
                else
                if (App.StartSize != "video")
                {
                    height = autoFitHeight;
                }

                core.WasInitialSizeSet = true;
            }

            height = Convert.ToInt32(height * scale);
            int width     = height * videoSize.Width / videoSize.Height;
            int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height);
            int maxWidth  = screen.WorkingArea.Width - (Width - ClientSize.Width);

            if (height < maxHeight * core.AutofitSmaller)
            {
                height = Convert.ToInt32(maxHeight * core.AutofitSmaller);
                width  = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
            }

            if (height > maxHeight * core.AutofitLarger)
            {
                height = Convert.ToInt32(maxHeight * core.AutofitLarger);
                width  = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
            }

            if (width > maxWidth)
            {
                width  = maxWidth;
                height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width);
            }

            Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
            var   rect      = new WinAPI.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height));

            NativeHelp.AddWindowBorders(Handle, ref rect);
            int left = middlePos.X - rect.Width / 2;
            int top  = middlePos.Y - rect.Height / 2;

            Screen[] screens   = Screen.AllScreens;
            int      minLeft   = screens.Select(val => val.WorkingArea.X).Min();
            int      maxRight  = screens.Select(val => val.WorkingArea.Right).Max();
            int      minTop    = screens.Select(val => val.WorkingArea.Y).Min();
            int      maxBottom = screens.Select(val => val.WorkingArea.Bottom).Max();

            if (left < minLeft)
            {
                left = minLeft;
            }

            if (left + rect.Width > maxRight)
            {
                left = maxRight - rect.Width;
            }

            if (top < minTop)
            {
                top = minTop;
            }

            if (top + rect.Height > maxBottom)
            {
                top = maxBottom - rect.Height;
            }

            WinAPI.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */,
                                left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */);
        }
예제 #12
0
        void SetFormPosAndSize(bool force = false, bool checkAutofit = true)
        {
            if (!force)
            {
                if (WindowState != FormWindowState.Normal)
                {
                    return;
                }

                if (core.Fullscreen)
                {
                    CycleFullscreen(true);
                    return;
                }
            }

            Screen screen        = Screen.FromControl(this);
            int    autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * core.Autofit);

            if (core.VideoSize.Height == 0 || core.VideoSize.Width == 0 ||
                core.VideoSize.Width / (float)core.VideoSize.Height < App.MinimumAspectRatio)
            {
                core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight);
            }

            Size videoSize = core.VideoSize;

            int height = videoSize.Height;
            int width  = videoSize.Width;

            if (App.StartSize == "previous")
            {
                App.StartSize = "height-session";
            }

            if (core.WasInitialSizeSet)
            {
                if (App.StartSize == "always")
                {
                    width  = ClientSize.Width;
                    height = ClientSize.Height;
                }
                else if (App.StartSize == "height-always" || App.StartSize == "height-session")
                {
                    height = ClientSize.Height;
                    width  = height * videoSize.Width / videoSize.Height;
                }
                else if (App.StartSize == "width-always" || App.StartSize == "width-session")
                {
                    width  = ClientSize.Width;
                    height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width);
                }
            }
            else
            {
                int savedHeight = RegistryHelp.GetInt("Height");
                int savedWidth  = RegistryHelp.GetInt("Width");

                if (App.StartSize == "height-always" && savedHeight != 0)
                {
                    height = savedHeight;
                    width  = height * videoSize.Width / videoSize.Height;
                }
                else if (App.StartSize == "height-session")
                {
                    height = autoFitHeight;
                    width  = height * videoSize.Width / videoSize.Height;
                }
                if (App.StartSize == "width-always" && savedHeight != 0)
                {
                    width  = savedWidth;
                    height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width);
                }
                else if (App.StartSize == "width-session")
                {
                    width  = autoFitHeight / 9 * 16;
                    height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width);
                }
                else if (App.StartSize == "always" && savedHeight != 0)
                {
                    height = savedHeight;
                    width  = savedWidth;
                }

                core.WasInitialSizeSet = true;
            }

            SetSize(width, height, screen, checkAutofit);
        }