private void DownloadFile(string url)
        {
            downloadButton.Enabled      = false;
            downloadProgressBar.Visible = true;

            m_File             = new TemporaryWebFile(new Uri(url));
            m_File.Downloaded += o =>
            {
                m_File.Start();
                GuiThread.DoAsync(() =>
                {
                    ResetDlButtonProgressBar();
                    Close();
                });
            };
            m_File.DownloadProgressChanged +=
                (o, args) => GuiThread.DoAsync(() => { downloadProgressBar.Value = args.ProgressPercentage; });

            m_File.DownloadFailed += (sender, error) => GuiThread.DoAsync(() =>
            {
                ResetDlButtonProgressBar();
                MessageBox.Show(error.Message, "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            });

            m_File.Cancelled += sender =>
            {
                Trace.WriteLine("Download Cancelled");
                ResetDlButtonProgressBar();
            };

            m_File.DownloadFile();
        }
            private void PlayerStateChanged(object sender, PlayerStateEventArgs e)
            {
                if (e.OldState != PlayerState.Closed)
                {
                    return;
                }
                GuiThread.DoAsync(delegate
                {
                    if (Media.AudioTrack == null)
                    {
                        return;
                    }

                    // This has to be done via GuiThread.DoAsync because when this method is called
                    // Player.Filters has not been populated
                    // Using GuiThread.DoAsync essentially queues this delegate until the media file
                    // is actually opened and all Player fields have been populated
                    if (Player.Filters.Any(f => f.ClsId == s_SanearSoundClsId))
                    {
                        m_Sanear = true;
                    }
                    else if (Player.Filters.Any(f => f.ClsId == s_DirectSoundClsId || f.ClsId == s_WaveOutClsId))
                    {
                        m_DirectSoundWaveOut = true;
                    }
                    else
                    {
                        Player.OsdText.Show("Warning: Audio renderer is incompatible with Reclock. Reclock disabled!");
                    }
                });
            }
Exemple #3
0
        protected override void ParseChangelog(string changelog)
        {
            var result           = JsonConvert.DeserializeObject <GitHubVersion>(changelog);
            var version          = new ExtensionVersion(result.tag_name);
            var changelogStarted = false;

            foreach (var line in Regex.Split(result.body, "\r\n|\r|\n").Where(line => !string.IsNullOrWhiteSpace(line)))
            {
                if (changelogStarted)
                {
                    version.ChangelogLines.Add(line);
                }
                if (line.StartsWith("#### Changelog"))
                {
                    changelogStarted = true;
                }
            }
            version.Files = result.assets;

            GuiThread.DoAsync(() =>
            {
                if (Settings.ExtensionVersionOnServer == version)
                {
                    return;
                }

                Settings.ExtensionVersionOnServer = version;
                Settings.ForgetExtensionVersion   = false;
            });
        }
Exemple #4
0
        protected virtual void ParseChangelog(string changelog)
        {
            Version serverVersion = null;

            foreach (var line in Regex.Split(changelog, "\r\n|\r|\n"))
            {
                if (Version.ContainsVersionString(line))
                {
                    if (serverVersion == null)
                    {
                        serverVersion = new Version(line);
                    }
                    else
                    {
                        break;
                    }
                }
                else if (serverVersion != null && !string.IsNullOrWhiteSpace(line))
                {
                    serverVersion.ChangelogLines.Add(line);
                }
            }

            GuiThread.DoAsync(() =>
            {
                if (Settings.MpdnVersionOnServer == serverVersion)
                {
                    return;
                }

                Settings.MpdnVersionOnServer = serverVersion;
                Settings.ForgetMpdnVersion   = false;
            });
        }
 private void OpenMedia(object file)
 {
     Task.Factory.StartNew(() =>
     {
         SafeCall(() =>
         {
             var media = Media.Load(file.ToString());
             GuiThread.DoAsync(() => Media.Open(media));
         });
     });
 }
 private void SafeCall(Action action)
 {
     try
     {
         action();
     }
     catch (Exception ex)
     {
         GuiThread.DoAsync(() => PushToAllListeners("Error|" + "Failed to open media!\r\n" + ex.Message));
     }
 }
Exemple #7
0
        private void InstallerOnDownloadFailed(object sender, Exception error)
        {
            var file = ((WebFile)sender);

            GuiThread.DoAsync(() =>
            {
                downloadProgressBar.Visible = false;
                installButton.Enabled       = true;
                MessageBox.Show(Gui.VideoBox,
                                string.Format("Problem while downloading: {0}\n{1}", file.FileUri, error.Message),
                                "Download Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            });
        }
Exemple #8
0
 private void UpdateBoth()
 {
     m_DownloadingWebFile = UpdateExtensions();
     m_DownloadingWebFile.DownloadFailed          += InstallerOnDownloadFailed;
     m_DownloadingWebFile.DownloadProgressChanged += InstallerOnDownloadProgressChanged;
     m_DownloadingWebFile.Downloaded += (o =>
     {
         var downloadedExtensionInstaller = (WebFile)o;
         downloadedExtensionInstaller.Start(string.Format("/ARCH={0} /MPDN_VERSION=\"{1}\"",
                                                          ArchitectureHelper.GetPlayerArtchitecture(), m_Settings.MpdnVersionOnServer));
         GuiThread.Do((Application.Exit));
     });
     m_DownloadingWebFile.DownloadFile();
 }
Exemple #9
0
        private void AddFilesToPlaylist(string files)
        {
            var filesToAdd = new List <string>();
            var filePaths  = Regex.Split(files, ">>");

            if (filePaths.Any())
            {
                filesToAdd.AddRange(filePaths.Where(File.Exists));
            }
            if (filesToAdd.Any())
            {
                GuiThread.DoAsync(() => _playlistInstance.GetPlaylistForm.AddFiles(filesToAdd.ToArray()));
            }
        }
Exemple #10
0
        protected virtual void ParseChangelog(string changelog)
        {
            var jsonVersion   = JsonConvert.DeserializeObject <JsonVersion>(changelog);
            var serverVersion = new Version(jsonVersion.Version)
            {
                ExtensionApiVersion = jsonVersion.API,
                ChangelogLines      = jsonVersion.Changelog
            };

            GuiThread.DoAsync(() =>
            {
                if (Settings.MpdnVersionOnServer == serverVersion)
                {
                    return;
                }

                Settings.MpdnVersionOnServer = serverVersion;
                Settings.ForgetMpdnVersion   = false;
            });
        }
Exemple #11
0
        private void MouseClick(object sender, MouseEventArgs e)
        {
            if (m_CloseBtnHover && e.Button == MouseButtons.Left)
            {
                Player.ActiveForm.Close();
            }

            if (m_PrevBtnHover && e.Button == MouseButtons.Left)
            {
                GuiThread.DoAsync(new Action(() => {
                    PlaylistForm.PlayPrevious();
                }));
            }

            if (m_NextBtnHover && e.Button == MouseButtons.Left)
            {
                GuiThread.DoAsync(new Action(() => {
                    PlaylistForm.PlayNext();
                }));
            }
        }
Exemple #12
0
        public void Post()
        {
            this.ErrorMessage = "";

            Task.Run(async() =>
            {
                try
                {
                    await this.client.PostStatus(this.Text, Visibility.Public);
                    GuiThread.Run(() =>
                    {
                        this.Text = "";
                    });
                }
                catch (Exception e)
                {
                    GuiThread.Run(() =>
                    {
                        this.ErrorMessage = "エラーが発生しました";
                    });
                }
            });
        }
 private void PushToAllListeners(string msg)
 {
     foreach (var writer in m_Writers)
     {
         var w    = writer.Value;
         var guid = writer.Key;
         Task.Factory.StartNew(() =>
         {
             try
             {
                 lock (w)
                 {
                     w.WriteLine(SanatiseMessage(msg));
                     w.Flush();
                 }
             }
             catch
             {
                 GuiThread.DoAsync(() => RemoveWriter(guid));
             }
         });
     }
 }
        private void ClientAuth(StreamWriter writer, string msgValue, Guid clientGuid)
        {
            WriteToSpecificClient(writer, "AuthCode|" + msgValue);
            var allow = false;

            GuiThread.Do(() =>
                         allow =
                             MessageBox.Show(Gui.VideoBox, "Allow Remote Connection for " + msgValue, "Remote Authentication",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes);
            if (allow)
            {
                WriteToSpecificClient(writer, "Connected|Authorized");
                WriteToSpecificClient(writer, "ClientGUID|" + clientGuid);
                m_AuthHandler.AddAuthedClient(msgValue);
                if (m_ClientManager.Visible)
                {
                    m_ClientManager.ForceUpdate();
                }
            }
            else
            {
                DisconnectClient(writer, "Unauthorized", clientGuid);
            }
        }
Exemple #15
0
 private void InstallerOnDownloaded(object sender)
 {
     ((WebFile)sender).Start();
     GuiThread.Do((Application.Exit));
 }
Exemple #16
0
 private void InstallerOnDownloadProgressChanged(object sender,
                                                 DownloadProgressChangedEventArgs downloadProgressChangedEventArgs)
 {
     GuiThread.DoAsync(() => { downloadProgressBar.Value = downloadProgressChangedEventArgs.ProgressPercentage; });
 }
        private void ClientHandler(Socket client)
        {
            Guid clientGuid = Guid.NewGuid();

            Clients.AddOrUpdate(clientGuid, client, (guid, socket) => client);

            NetworkStream nStream = new NetworkStream(client);
            StreamReader  reader  = new StreamReader(nStream);
            StreamWriter  writer  = new StreamWriter(nStream)
            {
                AutoFlush = false
            };

            m_Writers.TryAdd(clientGuid, writer);
            var authGuid = reader.ReadLine();

            if (!m_AuthHandler.IsGUIDAuthed(authGuid) && Settings.ValidateClients)
            {
                ClientAuth(writer, authGuid, clientGuid);
            }
            else
            {
                WriteToSpecificClient(writer, "Connected|Authorized");
                WriteToSpecificClient(writer, "ClientGUID|" + clientGuid);
                if (!m_AuthHandler.IsGUIDAuthed(authGuid))
                {
                    m_AuthHandler.AddAuthedClient(authGuid);
                }
                if (m_ClientManager.Visible)
                {
                    m_ClientManager.ForceUpdate();
                }
            }
            GuiThread.DoAsync(() =>
            {
                Player.RedirectExceptionHandler(ex =>
                {
                    GuiThread.DoAsync(() => PushToAllListeners("Error|" + ex.Message));
                });
            });
            while (true)
            {
                try
                {
                    var data = reader.ReadLine();
                    try
                    {
                        if (string.IsNullOrWhiteSpace(data))
                        {
                            break;
                        }
                        data = UnsanatiseMessage(data);
                        if (data == "Exit")
                        {
                            HandleData(writer, data);
                            client.Close();
                        }
                        else
                        {
                            if (!HandleData(writer, data))
                            {
                                WriteToSpecificClient(writer, "Error|Command not supported on server");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                }
                catch
                {
                    break;
                }
            }
            GuiThread.DoAsync(() => RemoveWriter(clientGuid));
        }
        private void HandleData(string data)
        {
            var command = data.Split('|');

            switch (command[0])
            {
            case "Exit":
                DisplayTextMessage("Remote Disconnected");
                RemoveWriter(command[1]);
                break;

            case "Open":
                GuiThread.DoAsync(() => OpenMedia(command[1]));
                break;

            case "Pause":
                GuiThread.DoAsync(() => PauseMedia(command[1]));
                break;

            case "Play":
                GuiThread.DoAsync(() => PlayMedia(command[1]));
                break;

            case "Stop":
                GuiThread.DoAsync(() => StopMedia(command[1]));
                break;

            case "Seek":
                GuiThread.DoAsync(() => SeekMedia(command[1]));
                break;

            case "GetDuration":
                GuiThread.DoAsync(() => GetFullDuration(command[1]));
                break;

            case "GetCurrentState":
                GuiThread.DoAsync(() => GetCurrentState(command[1]));
                break;

            case "FullScreen":
                GuiThread.DoAsync(() => FullScreen(command[1]));
                break;

            case "MoveWindow":
                GuiThread.DoAsync(() => MoveWindow(command[1]));
                break;

            case "WriteToScreen":
                DisplayTextMessage(command[1]);
                break;

            case "Mute":
                bool mute = false;
                Boolean.TryParse(command[1], out mute);
                GuiThread.DoAsync(() => Mute(mute));
                break;

            case "Volume":
                int vol = 0;
                int.TryParse(command[1], out vol);
                GuiThread.DoAsync(() => SetVolume(vol));
                break;

            case "ActiveSubTrack":
                GuiThread.DoAsync(() => SetSubtitle(command[1]));
                break;

            case "ActiveAudioTrack":
                GuiThread.DoAsync(() => SetAudioTrack(command[1]));
                break;

            case "AddFilesToPlaylist":
                AddFilesToPlaylist(command[1]);
                break;

            case "InsertFileInPlaylist":
                GuiThread.DoAsync(() => InsertIntoPlaylist(command[1], command[2]));
                break;

            case "ClearPlaylist":
                GuiThread.DoAsync(ClearPlaylist);
                break;

            case "FocusPlayer":
                GuiThread.DoAsync(FocusMpdn);
                break;

            case "PlayNext":
                GuiThread.DoAsync(PlaylistPlayNext);
                break;

            case "PlayPrevious":
                GuiThread.DoAsync(PlaylistPlayPrevious);
                break;

            case "ShowPlaylist":
                GuiThread.DoAsync(ShowPlaylist);
                break;

            case "HidePlaylist":
                GuiThread.DoAsync(HidePlaylist);
                break;

            case "GetPlaylist":
                GuiThread.DoAsync(() => GetPlaylist(command[1]));
                break;

            case "PlaySelectedFile":
                GuiThread.DoAsync(() => PlaySelectedFile(command[1]));
                break;

            case "RemoveFile":
                GuiThread.DoAsync(() => RemoveFromPlaylist(command[1]));
                break;

            case "ActiveVideoTrack":
                GuiThread.DoAsync(() => SetVideoTrack(command[1]));
                break;
            }
        }
        private bool HandleData(StreamWriter writer, string command)
        {
            var seperator = command.IndexOf('|');

            if (seperator < 0)
            {
                return(false);
            }
            var cmd   = command.Substring(0, seperator);
            var param = command.Substring(seperator + 1);

            switch (cmd)
            {
            case "Exit":
                Guid clientGuid;
                if (Guid.TryParse(param, out clientGuid))
                {
                    GuiThread.DoAsync(() => RemoveWriter(clientGuid));
                }
                break;

            case "Open":
                GuiThread.DoAsync(() => OpenMedia(param));
                break;

            case "Pause":
                GuiThread.DoAsync(() => PauseMedia(param));
                break;

            case "Play":
                GuiThread.DoAsync(() => PlayMedia(param));
                break;

            case "Stop":
                GuiThread.DoAsync(() => StopMedia(param));
                break;

            case "Close":
                GuiThread.DoAsync(() => CloseMedia(param));
                break;

            case "Seek":
                GuiThread.DoAsync(() => SeekMedia(param));
                break;

            case "GetDuration":
                GuiThread.DoAsync(() => GetFullDuration(writer));
                break;

            case "GetCurrentState":
                GuiThread.DoAsync(() => GetCurrentState(writer));
                break;

            case "FullScreen":
                GuiThread.DoAsync(() => FullScreen(param));
                break;

            case "MoveWindow":
                GuiThread.DoAsync(() => MoveWindow(param));
                break;

            case "WriteToScreen":
                DisplayTextMessage(param);
                break;

            case "Mute":
                bool mute;
                bool.TryParse(param, out mute);
                GuiThread.DoAsync(() => Mute(mute));
                break;

            case "Volume":
                int vol;
                int.TryParse(param, NumberStyles.Number, CultureInfo.InvariantCulture, out vol);
                GuiThread.DoAsync(() => SetVolume(vol));
                break;

            case "ActiveSubTrack":
                GuiThread.DoAsync(() => SetSubtitle(param));
                break;

            case "ActiveAudioTrack":
                GuiThread.DoAsync(() => SetAudioTrack(param));
                break;

            case "AddFilesToPlaylist":
                AddFilesToPlaylist(param);
                break;

            case "InsertFileInPlaylist":
            {
                var parameters = param.Split('|');
                if (parameters.Length != 2)
                {
                    return(false);
                }
                GuiThread.DoAsync(() => InsertIntoPlaylist(parameters[0], parameters[1]));
                break;
            }

            case "UpdatePlaylist":
            {
                var data = Deserialize <UpdatePlaylistData>(param);
                GuiThread.DoAsync(() => UpdatePlaylist(data.Playlist, data.ActiveIndex, data.CloseMedia));
                break;
            }

            case "ClearPlaylist":
                GuiThread.DoAsync(ClearPlaylist);
                break;

            case "FocusPlayer":
                GuiThread.DoAsync(FocusMpdn);
                break;

            case "PlayNext":
                GuiThread.DoAsync(PlaylistPlayNext);
                break;

            case "PlayPrevious":
                GuiThread.DoAsync(PlaylistPlayPrevious);
                break;

            case "ShowPlaylist":
                GuiThread.DoAsync(ShowPlaylist);
                break;

            case "HidePlaylist":
                GuiThread.DoAsync(HidePlaylist);
                break;

            case "GetPlaylist":
                GuiThread.DoAsync(() => GetPlaylist(writer));
                break;

            case "PlaySelectedFile":
                GuiThread.DoAsync(() => PlaySelectedFile(param));
                break;

            case "RemoveFile":
                GuiThread.DoAsync(() => RemoveFromPlaylist(param));
                break;

            case "ActiveVideoTrack":
                GuiThread.DoAsync(() => SetVideoTrack(param));
                break;

            case "Dir":
            {
                var parameters = param.Split('|');
                if (parameters.Length == 1)
                {
                    HandleDir(writer, param);
                }
                else
                {
                    HandleDir(writer, parameters[0], parameters[1]);
                }
                break;
            }

            case "GetDriveLetters":
                GetDriveLetters(writer);
                break;

            default:
                return(false);
            }
            return(true);
        }