Exemplo n.º 1
0
        public bool Run()
        {
            // If we have already detected that there is one commander,
            // then it is time to exit.
            if (OneCmdr)
            {
                return(false);
            }

            // Try to load Journal path from Registry
            var pathGuess = Config.JournalPath;

            // If that is no good, then try to guess the save game path
            if (pathGuess == null)
            {
                pathGuess = Filesystem.GuessJournalPath();
            }

            // If that is no good, get the user home directory
            if (pathGuess == null)
            {
                pathGuess = Filesystem.GetRelativeUserHome();
            }

            Form = new ChooseCmdrForm(pathGuess);
            Form.SetInvalidJournalState();

            // See if the path contains journals
            if (TestJournalDirectory(pathGuess) == JournalDirResult.OK)
            {
                // Path contains journals
                JournalPath = pathGuess;
                Form.SetNoCmdrSelectedState();

                // If there is only one commander, select it and return
                var cmdrs = GetCmdrs(JournalPath);
                if (cmdrs.Count == 1)
                {
                    CmdrName = cmdrs.First();
                    OneCmdr  = true;
                    return(true);
                }

                // Otherwise, populate the form
                Form.AddCmdrs(cmdrs);

                // Select the last commander if applicable
                Form.SelectedCmdr = Config.LastCmdr;
            }

            // If we get this far, then show the form so the user can
            // make some decisions
            Form.Load             += (o, e) => Form.FirstLoad = false;
            Form.LocationSelected += PathChanged;
            Form.CmdrSelected     += OnCmdrSelected;

            var ret = Form.ShowDialog() == DialogResult.OK;

            Config.JournalPath = Form.JournalPath;

            return(ret);
        }