Beispiel #1
0
        private void Button_Step1(object sender, RoutedEventArgs e)
        {
            global.Email       = emailBox.Text;
            global.Pwd         = passwordBox.Password;
            global.DropboxPath = pathBox.Text;

            if (global.Email.Length == 0)
            {
                MessageBox.Show("Email cannot be empty.", "ConflictReaper");
                return;
            }

            if (global.Pwd.Length == 0)
            {
                MessageBox.Show("Password cannot be empty.", "ConflictReaper");
                return;
            }

            if (global.DropboxPath.Length == 0)
            {
                MessageBox.Show("Work folder cannot be empty.", "ConflictReaper");
                return;
            }

            if (!global.setBasePath())
            {
                MessageBox.Show(global.DropboxPath + "is not a dropbox shared folder.", "ConflictReaper");
                return;
            }
            global.setPathPerfix();

            Properties.Settings.Default.email       = global.Email;
            Properties.Settings.Default.pwd         = global.Pwd;
            Properties.Settings.Default.dropboxPath = global.DropboxPath;
            Properties.Settings.Default.Save();

            if (global.ProxyState == 2)
            {
                if (ProxyIP.Text.Length == 0 || ProxyPort.Text.Length == 0)
                {
                    MessageBox.Show("Please Input the IP Address of your Proxy Server", "ConflictReaper");
                    return;
                }
                string[] ip = ProxyIP.Text.Split('.');
                if (ip.Length != 4)
                {
                    MessageBox.Show("Wrong IP Address", "ConflictReaper");
                    return;
                }
                if (!(global.checkIP(ip[0]) && global.checkIP(ip[1]) && global.checkIP(ip[2]) && global.checkIP(ip[3])))
                {
                    MessageBox.Show("Wrong IP Address", "ConflictReaper");
                    return;
                }
                try
                {
                    int port = int.Parse(ProxyPort.Text);
                    if (port < 0 || port > 65535)
                    {
                        MessageBox.Show("Wrong Proxy Port", "ConflictReaper");
                        return;
                    }
                }
                catch
                {
                    MessageBox.Show("Wrong Proxy Port", "ConflictReaper");
                    return;
                }
                global.ProxyHost = ProxyIP.Text;
                Int32.TryParse(ProxyPort.Text, out global.ProxyPort);
            }

            mswin.confirm("Checking if you need to authorize...");

            flowMeasureDevicePool = new FlowMeasureDevicePool();
            scanFiles(global.DropboxPath);
            setFileSystemWatcher();
            //setOpeningFileHook();

            dropboxclient = new DropboxConnection(
                new DropboxConnectionArg(
                    Properties.Settings.Default.accessToken, global.User, global.Email,
                    global.ProxyState, global.ProxyHost, global.ProxyPort, global.DropboxBasePath));

            new Thread(new ThreadStart(() =>
            {
                if (!dropboxclient.IsInitialized)
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        mswin.Hide();
                        if (global.ProxyState != 0)
                        {
                            var settings = new CefSettings();
                            settings.CefCommandLineArgs.Add("--proxy-server", global.ProxyHost + ":" + global.ProxyPort);
                            Cef.Initialize(settings, false, null);
                        }

                        var authorizeUri = dropboxclient.getAuthUri();

                        this.ResizeMode = ResizeMode.CanResize;
                        webView         = new ChromiumWebBrowser();
                        Browser.Children.Add(webView);
                        Width  = 1024;
                        Height = 768;
                        Top    = (SystemParameters.WorkArea.Size.Height - Height) / 2;
                        Left   = (SystemParameters.WorkArea.Size.Width - Width) / 2;
                        mswin.confirm("Connecting to " + authorizeUri.Host + "...");
                        webView.Address         = authorizeUri.ToString();
                        webView.FrameLoadStart += WebView_FrameLoadStart;
                        webView.FrameLoadEnd   += WebView_FrameLoadEnd;

                        FirstStepGrid.Visibility = System.Windows.Visibility.Collapsed;
                        Browser.Visibility       = System.Windows.Visibility.Visible;
                        webView.Focus();
                    }));
                }
                else
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        Title = "ConflictReaper: " + global.User + "(" + global.Email + ")";
                        mswin.Hide();
                        FirstStepGrid.Visibility = System.Windows.Visibility.Collapsed;
                        AfterAuth();
                    }));
                }
            })).Start();
        }
Beispiel #2
0
 public ConflictReaperWebSocketHandler(DropboxConnection dropboxclient, GlobalUtil g)
 {
     client = dropboxclient;
     global = g;
 }