Ejemplo n.º 1
0
        private void openFreenetMenuItem_Click(object sender = null, EventArgs e = null)
        {
            Start();

            BeginInvoke(new Action(() =>
            {
                var fproxyListening = false;
                var showSlowOpen    = Settings.Default.ShowSlowOpenTip;
                var openArgs        = e as OpenArgs;
                if (openArgs != null)
                {
                    showSlowOpen = openArgs.ShowSlow;
                }

                /*
                 * TODO: Programatic way to get loopback address? This would not support IPv6.
                 * Use FProxy bind interface?
                 */
                var loopback = new IPAddress(new byte[] { 127, 0, 0, 1 });

                var timer = new Stopwatch();

                using (var sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
                {
                    timer.Start();
                    while (_node.IsRunning())
                    {
                        try
                        {
                            sock.Connect(loopback, _node.FProxyPort);
                            fproxyListening = true;
                            break;
                        }
                        catch (SocketException ex)
                        {
                            Log.Debug("Connecting got error: {0}",
                                      Enum.GetName(typeof(SocketError), ex.SocketErrorCode));
                            Thread.Sleep(SocketPollInterval);
                        }

                        // Show a startup notification if it's taking a while.
                        if (showSlowOpen && timer.ElapsedMilliseconds > SlowOpenThreshold)
                        {
                            trayIcon.BalloonTipText = strings.FreenetStarting;
                            trayIcon.ShowBalloonTip(SlowOpenTimeout);
                            showSlowOpen = false;
                        }
                    }
                    timer.Stop();
                }

                if (fproxyListening)
                {
                    Log.Debug("FProxy listening after {0}", timer.Elapsed);
                    BrowserUtil.Open(new Uri(String.Format("http://localhost:{0:d}", _node.FProxyPort)), true);
                }
            }));
        }
Ejemplo n.º 2
0
        private void FindNode()
        {
            while (true)
            {
                try
                {
                    _node = new NodeController();
                    break;
                }
                catch (FileNotFoundException e)
                {
                    Log.Error(e);
                }
                catch (DirectoryNotFoundException e)
                {
                    Log.Error(e);
                }
                catch (NodeController.MissingConfigValueException e)
                {
                    // If the configuration files exist but are missing required
                    // values it is sufficiently surprising to warrant an error
                    // dialog.
                    Log.Error(strings.MalformedConfig, e.Filename, e.Value);
                    MessageBox.Show(String.Format(strings.MalformedConfig, e.Filename, e.Value), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // TODO: Explain what happened to prompt a custom location?
                try
                {
                    PreferencesWindow.PromptCustomLocation(this);
                }
                catch (OperationCanceledException)
                {
                    /* User exited the file browser. */
                    Application.Exit();
                    return;
                }
            }

            _node.OnStarted += NodeStarted;
            _node.OnStopped += NodeStopped;
            _node.OnCrashed += NodeCrashed;

            foreach (var menuItem in new[]
            {
                openFreenetMenuItem,
                startFreenetMenuItem,
                stopFreenetMenuItem,
                downloadsMenuItem,
                viewLogsMenuItem,
                preferencesMenuItem,
                hideIconMenuItem,
            })
            {
                menuItem.Enabled = true;
            }

            // Set menu up for whether there is an existing node.
            RefreshMenu(_node.IsRunning());

            ReadCommandLine();
        }
Ejemplo n.º 3
0
        private void FindNode()
        {
            while (true)
            {
                try
                {
                    _node = new NodeController();
                    break;
                }
                catch (FileNotFoundException e)
                {
                    Log.Error(e);
                }
                catch (DirectoryNotFoundException e)
                {
                    Log.Error(e);
                }
                catch (NodeController.MissingConfigValueException e)
                {
                    // If the configuration files exist but are missing required
                    // values it is sufficiently surprising to warrant an error
                    // dialog.
                    Log.Error(strings.MalformedConfig, e.Filename, e.Value);
                    MessageBox.Show(String.Format(strings.MalformedConfig, e.Filename, e.Value), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                // TODO: Explain what happened to prompt a custom location?
                try
                {
                    PreferencesWindow.PromptCustomLocation(this);
                }
                catch (OperationCanceledException)
                {
                    /* User exited the file browser. */
                    Application.Exit();
                    return;
                }
            }

            _node.OnStarted += NodeStarted;
            _node.OnStopped += NodeStopped;
            _node.OnCrashed += NodeCrashed;

            foreach (var menuItem in new[]
            {
                openFreenetMenuItem,
                startFreenetMenuItem,
                stopFreenetMenuItem,
                downloadsMenuItem,
                viewLogsMenuItem,
                preferencesMenuItem,
                hideIconMenuItem,
            })
            {
                menuItem.Enabled = true;
            }

            // Set menu up for whether there is an existing node.
            RefreshMenu(_node.IsRunning());

            ReadCommandLine();
        }