예제 #1
0
        /// <summary>
        /// Initializes a new instance of the Sharpcraft Launcher.
        /// </summary>
        public Launcher()
        {
            InitializeComponent();
            _log = LogManager.GetLogger(this);
            PassBox.PasswordChar = (char)0x25CF;
            _auth = new Authenticator(McVersion);
            _auth.OnLoginEvent += LoginEvent;
            if (File.Exists(Constants.GitInfoFile))
            {
                using (var reader = new StreamReader(Constants.GitInfoFile))
                {
                    string content = reader.ReadLine();
                    if (!string.IsNullOrEmpty(content))
                    {
                        string[] gitInfo = content.Split(':');
                        if (gitInfo.Length >= 4)
                        {
                            _hash      = gitInfo[0];
                            _shortHash = gitInfo[1];
                            _author    = gitInfo[2];
                            if (_author.Contains(" "))
                            {
                                _author = _author.Split(' ')[0];
                            }
                            _time = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(double.Parse(gitInfo[3])).ToLocalTime();
                        }
                    }
                }
            }

            VersionLabel.Text = VersionString;

            if (File.Exists(Constants.LauncherSettings))
            {
                _log.Info("Loading launcher settings from file...");
                var reader = new StreamReader(Constants.LauncherSettings);
                _settings = new JsonSerializer().Deserialize <LauncherSettings>(new JsonTextReader(reader));
                _log.Info("Launcher settings loaded successfully!");
                reader.Close();
            }
            else
            {
                _settings = new LauncherSettings(Constants.LauncherSettings);
            }
            if (!string.IsNullOrEmpty(_settings.Username))
            {
                _userBoxInactive  = false;
                UserBox.Text      = _settings.Username;
                UserBox.ForeColor = Color.Black;
            }
            RememberCheckbox.Checked = _settings.Remember;
            if (_settings.Remember && !string.IsNullOrEmpty(_settings.GetPassword()))
            {
                _passBoxInactive  = false;
                PassBox.Text      = _settings.GetPassword();
                PassBox.ForeColor = Color.Black;
            }
            UpdateForm();
            _log.Info("Launcher initialized.");
        }