private async void Login(object sender, RoutedEventArgs e) { prog.IsIndeterminate = true; if (Logging != true) { Logging = true; AT.T = await Auth.AuthorizeAsync(textBox_Copy.Text, Passwordbox.Password); if (Auth.statuscode == "OK") { INIClass ini = new INIClass(".\\config.ini"); ini.IniWriteValue("Pixiv", "AccessToken", AT.T.AccessToken); ini.IniWriteValue("Pixiv", "Username", textBox_Copy.Text); ini.IniWriteValue("Pixiv", "Passwd", Passwordbox.Password); (new MainWindow()).Show(); Close(); } else { ErrorCode.Text = string.Format("登陆失败 原因: {0}", Auth.statuscode); } Logging = false; } prog.IsIndeterminate = false; }
private void Init() { if (File.Exists("avatar.png")) { var ib = new ImageBrush(); BinaryReader binReader = new BinaryReader(File.Open("avatar.png", FileMode.Open)); FileInfo fileInfo = new FileInfo("avatar.png"); byte[] bytes = binReader.ReadBytes((int)fileInfo.Length); binReader.Close(); var bi = new BitmapImage(); bi.BeginInit(); bi.StreamSource = new MemoryStream(bytes); bi.EndInit(); ib.ImageSource = bi; ib.TileMode = TileMode.None; ib.Stretch = Stretch.UniformToFill; avat.Fill = ib; } INIClass ini = new INIClass(".\\config.ini"); if (ini.ExistINIFile()) { string username = ini.IniReadValue("Pixiv", "Username"); string passwd = ini.IniReadValue("Pixiv", "Passwd"); if (!string.IsNullOrEmpty(username)) { textBox_Copy.Text = username; if (!string.IsNullOrEmpty(username)) { Passwordbox.Password = passwd; } } Login(this, new RoutedEventArgs()); } }