示例#1
0
        private static void RetrieveKoi(ConfuserContext ctx)
        {
            if (settings.NoUI)
            {
                ctx.Logger.Debug("Retrieving Koi...");

                var sys  = new KoiSystem();
                var hnd  = new ManualResetEvent(false);
                var okay = false;
                sys.Progress += _ => { };
                sys.Finish   += f =>
                {
                    okay = f;
                    hnd.Set();
                };
                sys.Login(settings.KoiID);
                hnd.WaitOne();
                if (!okay)
                {
                    throw new InvalidOperationException("Authentication failed.");
                }
            }
            else
            {
                Application.EnableVisualStyles();
                if (new LoginPrompt {
                    TopLevel = true
                }.ShowDialog() != DialogResult.OK)
                {
                    throw new InvalidOperationException("Authentication failed.");
                }
            }
        }
示例#2
0
文件: KoiInfo.cs 项目: hmyit/KoiVM-1
        static void CheckUpdate(ConfuserContext ctx)
        {
            var ver = new KoiSystem().GetVersion(settings.KoiID);

            if (ver == settings.Version)
            {
                return;
            }

            ctx.Logger.DebugFormat("New version of KoiVM: {0}", ver);
            ctx.Logger.DebugFormat("Current version of KoiVM: {0}", settings.Version);

            if (settings.NoUI)
            {
                ctx.Logger.DebugFormat("Updating...");
                var  sys  = new KoiSystem();
                var  hnd  = new ManualResetEvent(false);
                bool okay = false;
                sys.Progress += _ => { };
                sys.Finish   += f => {
                    okay = f;
                    hnd.Set();
                };
                sys.Login(settings.KoiID);
                hnd.WaitOne();
                if (!okay)
                {
                    throw new InvalidOperationException("Authentication failed.");
                }
                else
                {
                    settings.Version = ver;
                    settings.Save();
                }
            }
            else
            {
                Application.EnableVisualStyles();
                if (new UpdatePrompt(ver)
                {
                    TopLevel = true
                }.ShowDialog() != DialogResult.OK)
                {
                    throw new InvalidOperationException("Authentication failed.");
                }
            }
        }
示例#3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            this.btnLogin.Enabled  = false;
            this.txtId.Enabled     = false;
            KoiInfo.settings.KoiID = this.txtId.Text;
            KoiInfo.settings.Save();

            var    sys = new KoiSystem();
            string ver = sys.GetVersion(KoiInfo.settings.KoiID);

            sys.Progress += value => this.BeginInvoke(new Action(() =>
            {
                if (value != 0)
                {
                    this.progress.Style = ProgressBarStyle.Continuous;
                    this.progress.Value = (int)(value * 1000);
                }
                else
                {
                    this.progress.Value = 0;
                    this.progress.Style = ProgressBarStyle.Marquee;
                }
            }));
            sys.Finish += success =>
            {
                this.BeginInvoke(new Action(() =>
                {
                    this.btnLogin.Enabled = true;
                    this.txtId.Enabled    = true;
                    if (!success)
                    {
                        KoiInfo.settings.Version = "";
                        KoiInfo.settings.Save();
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        KoiInfo.settings.Version = ver;
                        KoiInfo.settings.Save();
                        this.DialogResult = DialogResult.OK;
                    }
                }));
            };
            sys.Login(this.txtId.Text);
        }
示例#4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            btnUpdate.Enabled = false;

            var sys = new KoiSystem();

            sys.Progress += value => BeginInvoke(new Action(() =>
            {
                if (value == 0)
                {
                    progress.Value = 0;
                    progress.Style = ProgressBarStyle.Marquee;
                }
                else
                {
                    progress.Style = ProgressBarStyle.Continuous;
                    progress.Value = (int)(value * 1000);
                }
            }));
            sys.Finish += success =>
            {
                BeginInvoke(new Action(() =>
                {
                    btnUpdate.Enabled = true;

                    if (success)
                    {
                        KoiInfo.settings.Version = newVersion;
                        KoiInfo.settings.Save();
                        DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        failed = true;
                        KoiInfo.settings.Version = "";
                        KoiInfo.settings.Save();
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            };
            sys.Login(KoiInfo.settings.KoiID);
        }
        private void btnDl_Click(object sender, EventArgs e)
        {
            this.txtId.Enabled = this.btnRefr.Enabled = this.btnDl.Enabled = false;

            var    sys = new KoiSystem();
            string ver = sys.GetVersion(KoiInfo.settings.KoiID);

            sys.Progress += value => this.BeginInvoke(new Action(() =>
            {
                if (value != 0)
                {
                    this.progress.Style = ProgressBarStyle.Continuous;
                    this.progress.Value = (int)(value * 1000);
                }
                else
                {
                    this.progress.Value = 0;
                    this.progress.Style = ProgressBarStyle.Marquee;
                }
            }));
            sys.Finish += success =>
            {
                this.BeginInvoke(new Action(() =>
                {
                    this.txtId.Enabled = this.btnRefr.Enabled = this.btnDl.Enabled = true;
                    if (success)
                    {
                        this.verCurrent.Text = KoiInfo.settings.Version = ver;
                        MessageBox.Show("Download finished.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        this.verCurrent.Text     = "<< None >>";
                        KoiInfo.settings.Version = "";
                        MessageBox.Show("Login failed.", "Koi System", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }));
            };
            sys.Login(this.txtId.Text);
        }
示例#6
0
 void CheckVersion()
 {
     verServer.Text  = "<< Loading... >>";
     btnRefr.Enabled = btnDl.Enabled = false;
     ThreadPool.QueueUserWorkItem(_ => {
         var sys = new KoiSystem();
         string ver;
         if (string.IsNullOrEmpty(KoiInfo.settings.KoiID))
         {
             ver = "<< Enter your Koi ID >>";
         }
         else
         {
             ver = sys.GetVersion(KoiInfo.settings.KoiID);
             ver = ver ?? "<< Fail to retrieve version >>";
         }
         BeginInvoke(new Action(() => {
             verServer.Text  = ver;
             btnRefr.Enabled = btnDl.Enabled = true;
         }));
     });
 }