예제 #1
0
파일: Misc.cs 프로젝트: ScriptBox21/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 (VideoTypes.Contains(ext))
                {
                    RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video");
                }

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

                if (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);
            }
        }
예제 #2
0
        public static void ShowInfo()
        {
            try
            {
                string performer, title, album, genre, date, duration, text = "";
                long   fileSize = 0;
                string path     = core.get_property_string("path");

                if (path.Contains("://"))
                {
                    path = core.get_property_string("media-title");
                }

                int width  = core.get_property_int("video-params/w");
                int height = core.get_property_int("video-params/h");

                if (File.Exists(path))
                {
                    fileSize = new FileInfo(path).Length;

                    if (AudioTypes.Contains(path.Ext()))
                    {
                        using (MediaInfo mediaInfo = new MediaInfo(path))
                        {
                            performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer");
                            title     = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title");
                            album     = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album");
                            genre     = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre");
                            date      = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date");
                            duration  = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String");

                            if (performer != "")
                            {
                                text += "Artist: " + performer + "\n";
                            }
                            if (title != "")
                            {
                                text += "Title: " + title + "\n";
                            }
                            if (album != "")
                            {
                                text += "Album: " + album + "\n";
                            }
                            if (genre != "")
                            {
                                text += "Genre: " + genre + "\n";
                            }
                            if (date != "")
                            {
                                text += "Year: " + date + "\n";
                            }
                            if (duration != "")
                            {
                                text += "Length: " + duration + "\n";
                            }
                            text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
                            text += "Type: " + path.Ext().ToUpper();

                            core.commandv("show-text", text, "5000");
                            return;
                        }
                    }
                    else if (ImageTypes.Contains(path.Ext()))
                    {
                        using (MediaInfo mediaInfo = new MediaInfo(path))
                        {
                            text =
                                "Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
                                "Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
                                "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
                                "Type: " + path.Ext().ToUpper();

                            core.commandv("show-text", text, "5000");
                            return;
                        }
                    }
                }

                TimeSpan position    = TimeSpan.FromSeconds(core.get_property_number("time-pos"));
                TimeSpan duration2   = TimeSpan.FromSeconds(core.get_property_number("duration"));
                string   videoFormat = core.get_property_string("video-format").ToUpper();
                string   audioCodec  = core.get_property_string("audio-codec-name").ToUpper();

                text = path.FileName() + "\n" +
                       FormatTime(position.TotalMinutes) + ":" +
                       FormatTime(position.Seconds) + " / " +
                       FormatTime(duration2.TotalMinutes) + ":" +
                       FormatTime(duration2.Seconds) + "\n" +
                       $"{width} x {height}\n";

                if (fileSize > 0)
                {
                    text += Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n";
                }

                text += $"{videoFormat}\n{audioCodec}";

                core.commandv("show-text", text, "5000");
                string FormatTime(double value) => ((int)value).ToString("00");
            }
            catch (Exception e)
            {
                App.ShowException(e);
            }
        }
예제 #3
0
        private void btnVideo_Click(object sender, EventArgs e)
        {
            errProv.Dispose();

            try
            {
                if (txtFileSamp.Text == "")
                {
                    throw new Exception("No file chosen.");
                }
                else if (!File.Exists(txtFileSamp.Text))
                {
                    throw new Exception("That file does not exist, and thus can't be ran.");
                }

                string ext = Path.GetExtension(txtFileSamp.Text);


                if (VideoTypes.Contains(ext.ToLower()))
                {
                    Video videoFile = new Video(txtFileSamp.Text);

                    videoFile.ViewFile();
                }
                else if (GraphicTypes.Contains(ext.ToLower()))
                {
                    Graphic graphicFile = new Graphic(txtFileSamp.Text);


                    graphicFile.ViewFile();
                }
                else if (AudioTypes.Contains(ext.ToLower()))
                {
                    Audio audioFile = new Audio(txtFileSamp.Text);

                    audioFile.ViewFile();
                }
                else if (ArchiveTypes.Contains(ext.ToLower()))
                {
                    Archive archiveFile = new Archive(txtFileSamp.Text);



                    archiveFile.ViewFile();
                }
                else if (DocumentTypes.Contains(ext.ToLower()))
                {
                    Document docFile = new Document(txtFileSamp.Text);



                    docFile.ViewFile();
                }
                else
                {
                    throw new Exception("File type not found: the chosen file type is not supported.");
                    //System.IO.FileInfo newFile = new System.IO.FileInfo(txtFileSamp.Text);
                    //System.IO.FileAttributes b = newFile.Attributes;
                }
            }
            catch (Exception ex)
            {
                errProv.SetError(btnDisplay, ex.Message);
            }
        }