Ejemplo n.º 1
0
    private void CheckVersion()
    {
        try
        {
            using (WebClient client = new WebClient())
            {
                string latestVersion = client.DownloadString("http://greenmaw.com/drazil100.php?filename=tracker_version.txt");

                string[] parts = latestVersion.Split(':');
                if (parts[0] == "CurrentTrackerVersion")
                {
                    string checkVersion = ScoreTracker.version;
                    if (ScoreTracker.config.ContainsKey("skip_version") && ScoreTracker.config["skip_version"] != ScoreTracker.version)
                    {
                        try
                        {
                            string[] versionParts = ScoreTracker.config["skip_version"].Split('/');
                            if (versionParts.Length != 3)
                            {
                                throw new System.Exception();
                            }
                            int m = Int32.Parse(versionParts[0]);
                            int d = Int32.Parse(versionParts[1]);
                            int y = Int32.Parse(versionParts[2]);

                            if (m < 1 || m > 12)
                            {
                                throw new System.Exception();
                            }
                            if (d < 1 || d > 31)
                            {
                                throw new System.Exception();
                            }
                            if (y < 1)
                            {
                                throw new System.Exception();
                            }

                            if (ScoreTracker.DateToNumber(ScoreTracker.config["skip_version"]) > ScoreTracker.DateToNumber(ScoreTracker.version))
                            {
                                checkVersion = ScoreTracker.config["skip_version"];
                                Console.WriteLine("Skip Version:" + checkVersion);
                            }
                        }
                        catch (Exception)
                        {
                            ScoreTracker.config.RemoveKey("skip_version");
                        }
                    }
                    if (ScoreTracker.DateToNumber(checkVersion) < ScoreTracker.DateToNumber(parts[1]))
                    {
                        string whatsNew = client.DownloadString("http://greenmaw.com/drazil100.php?filename=tracker_whats_new.txt");
                        ShowUpdateDialog(parts[1], whatsNew);
                    }
                }
                Console.WriteLine(String.Format("This Version: {0}, Version Check: {1}", ScoreTracker.version, parts[1]));
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }