コード例 #1
0
ファイル: UpdateService.cs プロジェクト: worm929/RiotControl
 public void CheckForUpdate()
 {
     try
     {
         WebClient client = new WebClient();
         List <ApplicationVersion> versions = new List <ApplicationVersion>();
         string index   = client.DownloadString(Configuration.UpdateURL);
         Regex  pattern = new Regex(Configuration.ReleasePattern);
         foreach (Match match in pattern.Matches(index))
         {
             string             filename       = match.Value;
             string             revisionString = match.Groups[1].Value;
             int                revision       = Convert.ToInt32(revisionString);
             ApplicationVersion version        = new ApplicationVersion(filename, revision);
             versions.Add(version);
         }
         if (versions.Count == 0)
         {
             WriteLine("No versions of this application are being offered by the update server - this should never happen.");
             return;
         }
         //Sort the archives by revision to easily determine the newest one
         versions.Sort();
         NewestVersion = versions[0];
         int newestRevision = NewestVersion.Revision;
         if (CurrentRevision < newestRevision || Configuration.ForceUpdate)
         {
             WriteLine("The current version of this software (r{0}) is outdated. The newest version available is r{1}.", CurrentRevision, newestRevision);
             if (UpdateHandler != null)
             {
                 UpdateHandler.UpdateDetected(CurrentRevision, NewestVersion);
             }
             else
             {
                 DownloadUpdate(false);
             }
         }
         else if (CurrentRevision == newestRevision)
         {
             WriteLine("This software is up to date.");
         }
         else
         {
             WriteLine("The current version (r{0}) is newer than the most recent version of this software available (r{1}).", CurrentRevision, newestRevision);
         }
     }
     catch (ArgumentException exception)
     {
         WriteLine("Invalid update release pattern specified: {0}", exception.Message);
     }
     catch (WebException exception)
     {
         WriteLine("Unable to determine the latest version of this software: {0}", exception.Message);
     }
 }