コード例 #1
0
 // load Packlist from server
 public void LoadAvailablePacks(string sPlayerName, string sMCUID)
 {
     try
     {
         string sPackListJson = Http.GET(_sPackServer + @"/packs.php?player=" + sPlayerName + @"&uid=" + sMCUID);
         PacksAvailable = MCAvailablePacks.FromJson(sPackListJson);
     }
     catch (WebException ex)
     {
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            bool refreshUser = (bool)e.Argument;   // the 'argument' parameter resurfaces here


            BackgroundWorker worker = sender as BackgroundWorker;

            // Check Environment
            Launcher L = new Launcher(Offline);
            Manager  U = new Manager();

            L.CheckDirectories();

            // Test User
            string MCPlayerName = null;
            string UserAccount  = "none";
            string MCUID        = null;

            worker.ReportProgress(25);


            if (refreshUser == true)
            {
                if (U.GetDefault() != Guid.Empty)
                {
                    // Get Account
                    MCUserAccount Account = U.GetAccount(U.GetDefault());

                    // Validate Account
                    AuthHandler A = new AuthHandler();
                    try
                    {
                        Account.accessToken = A.Refresh(Account.accessToken, Account.clientToken);
                        U.SaveAccount(Account);
                    }
                    catch (MCInvalidTokenException)
                    {
                        FrmRefreshToken fTokRefresh = new FrmRefreshToken(Account);
                        DialogResult    res         = fTokRefresh.ShowDialog();
                        if (res == DialogResult.Cancel)
                        {
                            U.SetDefault(Guid.Empty);
                        }
                        fTokRefresh.Dispose();
                    }
                    catch (Exception)
                    {
                        DialogResult res = DialogResult.No;
                        Invoke(new Action(() =>
                        {
                            res = MessageBox.Show(this, "In Offlinemodus wechseln?", "Verbindungsfehler zu Mojang!", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                        }));

                        if (res == DialogResult.Yes)
                        {
                            Offline = true;
                            Invoke(new Action(() =>
                            {
                                MnuAccounts.Enabled = false;
                            }));
                        }
                        else
                        {
                            U.SetDefault(Guid.Empty);
                        }
                    }
                }
            }

            if (U.GetDefault() != Guid.Empty)
            {
                MCPlayerName = U.GetPlayerName(U.GetDefault());
                MCUID        = U.GetMCProfileID(U.GetDefault());
                UserAccount  = U.GetAccount(U.GetDefault()).username;
            }
            // set statusbar
            Invoke(new Action(() =>
            {
                LblDefaultAccount.Text = UserAccount;
                LstPacks.Clear();
                lst_packs_images.Images.Clear();
            }));

            worker.ReportProgress(50);

            // Get Packs from Server
            try
            {
                if (Offline == false)
                {
                    L.LoadAvailablePacks(MCPlayerName, MCUID);
                    MCAvailablePacks packs = L.GetAvailablePacks();
                    if (packs.Packs != null)
                    {
                        foreach (MCAvailablePack Pack in packs.Packs)
                        {
                            ListViewItem LvItem = new ListViewItem(Pack.Name, Pack.Name)
                            {
                                Font = new Font("Thaoma", 16, FontStyle.Bold)
                            };
                            Invoke(new Action(() =>
                            {
                                lst_packs_images.Images.Add(Pack.Name, L.GetPackIcon(Pack));
                                LstPacks.Items.Add(LvItem);
                            }));
                        }
                    }
                }
                else
                {
                    L.LoadInstalledPacks();
                    MCPacksInstalled Packs = L.GetInstalledPacks();
                    if (Packs.packs != null)
                    {
                        foreach (MCPacksInstalledPack Pack in Packs.packs)
                        {
                            ListViewItem LvItem = new ListViewItem(Pack.Name, Pack.Name)
                            {
                                Font = new Font("Thaoma", 16, FontStyle.Bold)
                            };
                            Invoke(new Action(() =>
                            {
                                if (L.GetPackIconOffline(Pack) != null)
                                {
                                    lst_packs_images.Images.Add(Pack.Name, L.GetPackIconOffline(Pack));
                                }
                                LstPacks.Items.Add(LvItem);
                            }));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Invoke(new Action(() =>
                {
                    MessageBox.Show(this, ex.Message.ToString(), "Verbindungsfehler zu Minestar!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
            }
            worker.ReportProgress(75);

            // Load installed Packs
            L.LoadInstalledPacks();

            // end worker
            worker.ReportProgress(100);
            System.Threading.Thread.Sleep(500);
        }