Пример #1
0
        private void ConnectToServer()
        {
            string[] args = System.Environment.GetCommandLineArgs();

            if (Properties.Settings.Default.Server == null || Properties.Settings.Default.Server.Length == 0 || args.Contains("-last-server") == false || _firstConnect == false)
            {
                //_firstConnect = false;

                int i = 0;

                for (i = 0; i < 100; i++)
                    Application.DoEvents();

                ServerSelector selector = new ServerSelector();
                selector.Parent = null;
                selector.TopMost = true;

                DialogResult dr = selector.ShowDialog();

                if ( (dr != DialogResult.OK) && (!_firstConnect)) {
                    this.Close();
                    return;
                }

            }

            if (Properties.Settings.Default.Server == null || Properties.Settings.Default.Server.Length == 0)
            {
                MessageBox.Show("Hmmm....  We got an empty server selection... That won't do.  Please report to the devs..","Connection Failure",MessageBoxButtons.OK,MessageBoxIcon.Error);
                if (!_firstConnect) {
                    this.Close();
                    return;
                }

            }

            _firstConnect = false;

            username = Properties.Settings.Default.Username;

            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);
            sw.Write(Properties.Settings.Default.Password);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            byte[] pwdBytes = SHA1.Create().ComputeHash(ms);

            string pwdHashString = "";

            foreach (byte b in pwdBytes)
                pwdHashString += String.Format("{0:x2}", b);

            ms.SetLength(0);
            sw.Write(Properties.Settings.Default.Username + pwdHashString);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            pwdBytes = SHA1.Create().ComputeHash(ms);

            pwdHashString = "";

            foreach (byte b in pwdBytes)
                pwdHashString += String.Format("{0:x2}", b);

            passwordHash = pwdHashString;

            if (username == null || username.Length == 0)
            {
                _useAuth = false;
            }
            else
            {
                _useAuth = true;
                _wc.Headers["X-Plex-User"] = username;
                _wc.Headers["X-Plex-Pass"] = passwordHash;

            }
            string baseuri = FQDN() + "/library/sections/";

            FillListFromUrl(baseuri, 0);
            _firstConnect = true;
        }
Пример #2
0
        private void ConnectToServer()
        {
            string[] args = System.Environment.GetCommandLineArgs();

            if (Properties.Settings.Default.Server == null || Properties.Settings.Default.Server.Length == 0 || args.Contains("-last-server") == false || _firstConnect == false)
            {
                //_firstConnect = false;

                int i = 0;

                for (i = 0; i < 100; i++)
                {
                    Application.DoEvents();
                }

                ServerSelector selector = new ServerSelector();
                selector.Parent  = null;
                selector.TopMost = true;

                DialogResult dr = selector.ShowDialog();

                if ((dr != DialogResult.OK) && (!_firstConnect))
                {
                    this.Close();
                    return;
                }
            }

            if (Properties.Settings.Default.Server == null || Properties.Settings.Default.Server.Length == 0)
            {
                MessageBox.Show("Hmmm....  We got an empty server selection... That won't do.  Please report to the devs..", "Connection Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (!_firstConnect)
                {
                    this.Close();
                    return;
                }
            }

            _firstConnect = false;

            username = Properties.Settings.Default.Username;

            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);

            sw.Write(Properties.Settings.Default.Password);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            byte[] pwdBytes = SHA1.Create().ComputeHash(ms);

            string pwdHashString = "";

            foreach (byte b in pwdBytes)
            {
                pwdHashString += String.Format("{0:x2}", b);
            }

            ms.SetLength(0);
            sw.Write(Properties.Settings.Default.Username + pwdHashString);
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            pwdBytes = SHA1.Create().ComputeHash(ms);

            pwdHashString = "";

            foreach (byte b in pwdBytes)
            {
                pwdHashString += String.Format("{0:x2}", b);
            }

            passwordHash = pwdHashString;

            if (username == null || username.Length == 0)
            {
                _useAuth = false;
            }
            else
            {
                _useAuth = true;
                _wc.Headers["X-Plex-User"] = username;
                _wc.Headers["X-Plex-Pass"] = passwordHash;
            }
            string baseuri = FQDN() + "/library/sections/";

            FillListFromUrl(baseuri, 0);
            _firstConnect = true;
        }