예제 #1
0
파일: MainForm.cs 프로젝트: minute/mpv.net
        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.");
            }

            foreach (PowerShell ps in PowerShell.Instances)
            {
                ps.Runspace.Dispose();
            }
        }
예제 #2
0
        public static void Register(string perceivedType, string[] extensions)
        {
            string[] protocols = { "ytdl", "rtsp", "srt", "srtp" };

            if (perceivedType != "unreg")
            {
                foreach (string i in protocols)
                {
                    RegistryHelp.SetValue($@"HKCR\{i}", $"{i.ToUpper()} Protocol", "");
                    RegistryHelp.SetValue($@"HKCR\{i}\shell\open\command", null, $"\"{ExePath}\" \"%1\"");
                }

                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(@"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");
                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");

                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
            {
                foreach (string i in protocols)
                {
                    RegistryHelp.RemoveKey($@"HKCR\{i}");
                }

                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);
                }
            }
        }
예제 #3
0
 void SaveWindowProperties()
 {
     if (WindowState == FormWindowState.Normal)
     {
         RegistryHelp.SetValue(App.RegPath, "PosX", Left + Width / 2);
         RegistryHelp.SetValue(App.RegPath, "PosY", Top + Height / 2);
         RegistryHelp.SetValue(App.RegPath, "Height", ClientSize.Height);
     }
 }
예제 #4
0
        void SaveWindowProperties()
        {
            if (WindowState == FormWindowState.Normal)
            {
                SavePosition();

                RegistryHelp.SetValue(App.RegPath, "Width", ClientSize.Width);
                RegistryHelp.SetValue(App.RegPath, "Height", ClientSize.Height);
            }
        }
예제 #5
0
파일: Command.cs 프로젝트: tyronebj/mpv.net
 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);
     }));
 }
예제 #6
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.");
        }
예제 #7
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.");
            }
        }
예제 #8
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);
            }
        }
예제 #9
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 {}
        }
예제 #10
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);
                }
            }
        }