예제 #1
0
        private static void PerformCheck(Object stateInfo)
        {
            try
            {
                ShrewProperties properties = ShrewConfiguration.LoadProperties();

                Version localVersion = Assembly.GetExecutingAssembly().GetName().Version;

                //userID used to track active user count.
                WebRequest   request  = HttpWebRequest.Create(string.Format(VERSION_URL, properties.userId, localVersion.ToString(), getArch()));
                WebResponse  response = request.GetResponse();
                StreamReader rdr      = new StreamReader(response.GetResponseStream());
                char[]       buffer   = new char[response.ContentLength];
                rdr.Read(buffer, 0, (Int32)response.ContentLength);
                Version latestVersion       = new Version(new String(buffer));
                bool    newVersionAvailable = latestVersion.CompareTo(localVersion) > 0;
                if (newVersionAvailable && UpdateAvailable != null)
                {
                    UpdateAvailable(null, new UpdateAvailableArgs(latestVersion));
                }
                properties.lastUpdateCheck = DateTime.UtcNow;
                ShrewConfiguration.SaveProperties(properties);
            }
            catch (Exception)
            {
                //Eat all errors
            }
        }
예제 #2
0
        internal static void SaveProperties(ShrewProperties properties)
        {
            DeleteProperties();
            string serializedProperties = JsonConvert.SerializeObject(properties);

            byte[] encryptedData = ProtectedData.Protect(
                Encoding.UTF8.GetBytes(serializedProperties), null, DataProtectionScope.CurrentUser);
            File.WriteAllBytes(propsFileName, encryptedData);
        }
예제 #3
0
        public static void CheckForUpdate()
        {
            ShrewProperties properties = ShrewConfiguration.LoadProperties();

            if (properties == null)
            {
                properties        = new ShrewProperties();
                properties.userId = Guid.NewGuid();
                ShrewConfiguration.SaveProperties(properties);
            }
            long initalDelay = 0;

            if (properties.lastUpdateCheck != null)
            {
                initalDelay = (long)properties.lastUpdateCheck.AddMilliseconds(UPDATE_CHECK_INTERVAL_MILLIS)
                              .Subtract(DateTime.UtcNow).TotalMilliseconds;
                if (initalDelay < 0)
                {
                    initalDelay = 0;
                }
            }

            updateCheckTimer = new Timer(UpdateChecker.PerformCheck, null, initalDelay, UPDATE_CHECK_INTERVAL_MILLIS);
        }
예제 #4
0
 internal static ShrewProperties LoadProperties()
 {
     if (File.Exists(propsFileName))
     {
         try
         {
             byte[] encryotedData        = File.ReadAllBytes(propsFileName);
             string serializedProperties = Encoding.UTF8.GetString(
                 ProtectedData.Unprotect(
                     encryotedData, null, DataProtectionScope.CurrentUser));
             ShrewProperties properties = JsonConvert.DeserializeObject <ShrewProperties>(serializedProperties);
             return(properties);
         }
         catch (Exception)
         {
             DeleteProperties();
             throw;
         }
     }
     else
     {
         return(null);
     }
 }