コード例 #1
0
ファイル: NodeController.cs プロジェクト: rajeshwarn/wintray
        /*
         * TODO: What are the function documentation comments supposed to be formatted like?
         * Start the node if it is not already started.
         *
         * Throws FileNotFoundException
         */
        public void Start()
        {
            if (IsRunning())
            {
                return;
            }

            try
            {
                // TODO: Under what circumstances will Process.Start() return null?
                _wrapper = Process.Start(_wrapperInfo);
                _wrapper.EnableRaisingEvents = true;
                _wrapper.Exited += Wrapper_Exited;
            }
            catch (Win32Exception ex)
            {
                // http://msdn.microsoft.com/en-us/library/0w4h05yb%28v=vs.110%29.aspx
                switch (ex.NativeErrorCode)
                {
                case ERROR_FILE_NOT_FOUND:
                    FNLog.Error("Cannot start Freenet: wrapper executable not found.");
                    OnCrashed(CrashType.WrapperFileNotFound);
                    return;

                case ERROR_INSUFFICIENT_BUFFER:
                case ERROR_ACCESS_DENIED:
                    FNLog.Error("Cannot start Freenet: the file path is too long.");
                    OnCrashed(CrashType.PathTooLong);
                    return;

                default:
                    FNLog.ErrorException(ex, "Cannot start Freenet: Process.Start() gave an error code it is not documented as giving.");
                    throw;
                }
            }

            OnStarted(this, null);
        }
コード例 #2
0
ファイル: CommandsMenu.cs プロジェクト: rajeshwarn/wintray
        private void FindNode()
        {
            while (true)
            {
                try
                {
                    _node = new NodeController();
                    break;
                }
                catch (FileNotFoundException e)
                {
                    FNLog.ErrorException(e, "Failed to find file");
                }
                catch (DirectoryNotFoundException e)
                {
                    FNLog.ErrorException(e, "Failed to find directory");
                }
                catch (NodeController.MissingConfigValueException e)
                {
                    // If the configuration files exist but are missing required
                    // values it is sufficiently surprising to warrant an error
                    // dialog.
                    FNLog.Error(strings.MalformedConfig, e.Filename, e.Value);
                    MessageBox.Show(String.Format(strings.MalformedConfig, e.Filename, e.Value), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (MissingJRE)
                {
                    // No JRE was found
                    FNLog.Error(strings.JRENotFound);
                    MessageBox.Show(strings.JRENotFound, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    /* Cannot continue for now */
                    Application.Exit();
                    return;
                }
                // 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();
        }