예제 #1
0
        //check new data on PGL
        public int checkUpdate()
        {
            newTables  = new ArrayList();
            fetchTasks = new ArrayList();
            for (int i = 0; i < GlobalConstants.GENERATION.Count; i++)
            {
                int[] blankTable = { 1, 1, 1, 1, 1, 1 };
                Fetch fetch      = new Fetch(i);
                if (fetch.serverStatus == -1)
                {
                    return(-2);
                }
                if (fetch.serverStatus == 0)
                {
                    return(-1);
                }
                if (fetch.mostUpdated.Equals(GlobalConstants.MOSTRECENTFILES[i].ToString()))
                {
                    int           tableCount = 0;
                    AccessHandler ah         = new AccessHandler(GlobalConstants.MOSTRECENTFILES[i].ToString());
                    string[]      rankTables = ah.showAllTables();
                    foreach (string rankTable in rankTables)
                    {
                        blankTable[rankTable[10] - '0'] = 0;
                        tableCount++;
                    }
                    if (tableCount < 6)
                    {
                        newTables.Add(blankTable);
                        fetchTasks.Add(fetch);
                        if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString()))
                        {
                            defaultHasNew = true;
                        }
                    }
                }
                else
                {
                    newTables.Add(blankTable);
                    fetchTasks.Add(fetch);
                    if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString()))
                    {
                        defaultHasNew = true;
                    }
                }
            }
            if (fetchTasks.Count == 0)
            {
                return(0);
            }


            return(1);
        }
예제 #2
0
        public UpdateData(bool autoCheck)
        {
            InitializeComponent();

            if (GlobalConstants.dpiX == 120)
            {
                foreach (Control ct in this.Controls)
                {
                    ct.Font = new System.Drawing.Font(ct.Font.FontFamily, (float)(ct.Font.Size / 1.25), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                }
            }


            valid                = false;
            defaultHasNew        = false;
            radioButton2.Enabled = false;
            radioButton2.Visible = false;

            int  checkRes = checkUpdate();
            bool gitValid = checkGit();

            //fail to connect to PGL
            if (checkRes == -2)
            {
                radioButton1.Enabled = false;
                radioButton1.Visible = false;
                radioButton1.Checked = false;
                if (!gitValid)
                {
                    if (!autoCheck)
                    {
                        SelfDesignedMsg sdm = new SelfDesignedMsg("Sorry~ 无法连接PGL服务器, 可能这货在维护...", false);
                        sdm.ShowDialog();
                    }
                    return;
                }
            }

            //no return for PGL http post
            else if (checkRes == -1)
            {
                radioButton1.Enabled = false;
                radioButton1.Visible = false;
                radioButton1.Checked = false;
                if (!gitValid)
                {
                    if (!autoCheck)
                    {
                        SelfDesignedMsg sdm = new SelfDesignedMsg("刚刚进入新赛季,PGL服务器上暂时还找不到新的数据~", false);
                        sdm.ShowDialog();
                    }
                    return;
                }
            }

            //no new data
            else if (checkRes == 0)
            {
                if (!autoCheck)
                {
                    SelfDesignedMsg sdm = new SelfDesignedMsg("您已拥有最新各项榜单啦~", false);
                    sdm.ShowDialog();
                }
                return;
            }

            //initialize a new thread
            valid       = true;
            errorExists = false;
            bkWorker.WorkerReportsProgress      = true;
            bkWorker.WorkerSupportsCancellation = true;
            bkWorker.DoWork             += new DoWorkEventHandler(startUpdate);
            bkWorker.ProgressChanged    += new ProgressChangedEventHandler(updateProgress);
            bkWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(completeWork);

            //get user's selection for new data
            treeView1.CheckBoxes = true;
            if (checkRes > 0 && (!gitValid))
            {
                for (int i = 0; i < fetchTasks.Count; i++)
                {
                    TreeNode tn = new TreeNode();
                    tn.Text = ((Fetch)fetchTasks[i]).generation + "-" + ((Fetch)fetchTasks[i]).curSeasonName + "-" + ((Fetch)fetchTasks[i]).updateTime.Split('-')[0];
                    if (((int[])newTables[i])[0] == 1)
                    {
                        tn.Nodes.Add("All Matches");
                    }
                    if (((int[])newTables[i])[1] == 1)
                    {
                        tn.Nodes.Add("Single");
                    }
                    if (((int[])newTables[i])[2] == 1)
                    {
                        tn.Nodes.Add("Double");
                    }
                    if (((int[])newTables[i])[3] == 1)
                    {
                        tn.Nodes.Add("Triple");
                    }
                    if (((int[])newTables[i])[4] == 1)
                    {
                        tn.Nodes.Add("Rotation");
                    }
                    if (((int[])newTables[i])[5] == 1)
                    {
                        tn.Nodes.Add("Special");
                    }
                    treeView1.Nodes.Add(tn);
                }
            }
            else
            {
                gitTasks = new ArrayList();
                newTables.Clear();
                for (int i = 0; i < GlobalConstants.GENERATION.Count; i++)
                {
                    int[] blankTable = { 1, 1, 1, 1, 1, 1 };

                    if (gitVersions[i].ToString().Equals(""))
                    {
                        int           tableCount = 0;
                        AccessHandler ah         = new AccessHandler(GlobalConstants.MOSTRECENTFILES[i].ToString());
                        string[]      rankTables = ah.showAllTables();
                        foreach (string rankTable in rankTables)
                        {
                            blankTable[rankTable[10] - '0'] = 0;
                            tableCount++;
                        }
                        if (tableCount < 6)
                        {
                            newTables.Add(blankTable);
                            gitTasks.Add(GlobalConstants.MOSTRECENTFILES[i].ToString());
                            if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString()))
                            {
                                defaultHasNew = true;
                            }
                        }
                    }
                    else
                    {
                        newTables.Add(blankTable);
                        gitTasks.Add(gitVersions[i].ToString());
                        if (GlobalConstants.DEFAULTGENERATION.Equals(i.ToString()))
                        {
                            defaultHasNew = true;
                        }
                    }
                }

                if (gitTasks.Count == 0)
                {
                    valid = false;
                    if (!autoCheck)
                    {
                        SelfDesignedMsg sdm = new SelfDesignedMsg("您已拥有最新各项榜单啦~", false);
                        sdm.ShowDialog();
                    }
                    return;
                }


                for (int i = 0; i < gitTasks.Count; i++)
                {
                    TreeNode tn        = new TreeNode();
                    string[] nameParts = gitTasks[i].ToString().Split('/');
                    tn.Text = nameParts[1] + "-" + nameParts[2].Split('-')[1] + "-" + nameParts[2].Split('-')[2];
                    if (((int[])newTables[i])[0] == 1)
                    {
                        tn.Nodes.Add("All Matches");
                    }
                    if (((int[])newTables[i])[1] == 1)
                    {
                        tn.Nodes.Add("Single");
                    }
                    if (((int[])newTables[i])[2] == 1)
                    {
                        tn.Nodes.Add("Double");
                    }
                    if (((int[])newTables[i])[3] == 1)
                    {
                        tn.Nodes.Add("Triple");
                    }
                    if (((int[])newTables[i])[4] == 1)
                    {
                        tn.Nodes.Add("Rotation");
                    }
                    if (((int[])newTables[i])[5] == 1)
                    {
                        tn.Nodes.Add("Special");
                    }
                    treeView1.Nodes.Add(tn);
                }
            }
        }