Example #1
0
 public static void DailyCheck()
 {
     if (App.UpdateCheck && RegistryHelp.GetInt("UpdateCheckLast")
         != DateTime.Now.DayOfYear)
     {
         CheckOnline();
     }
 }
Example #2
0
        void SetFormPosAndSize(double scale             = 1,
                               bool force               = false,
                               bool checkAutofitSmaller = true,
                               bool checkAutofitLarger  = 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;

            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);
            SetSize(new Size(height * videoSize.Width / videoSize.Height, height),
                    videoSize, screen, checkAutofitSmaller, checkAutofitLarger);
        }
Example #3
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);
            }
        }
Example #4
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 */);
        }
Example #5
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);
        }