Exemplo n.º 1
0
 public VersaVault()
 {
     notification = new Notification();
     notification.SetMessage("Started VersaVault");
     notification.Opacity = 0;
     notification.Show();
     InitializeComponent();
     Shown += VersaVaultShown;
     Resize += VersaVaultResize;
     LocationChanged += VersaVaultResize;
     SystemEvents.SessionSwitch += SystemEventsSessionSwitch;
     SystemEvents.SessionEnding += SystemEventsSession;
     SystemEvents.SessionEnded += SystemEventsSessionEnded;
 }
Exemplo n.º 2
0
 public static bool CheckVersion(bool forceCheck)
 {
     // first check the last updated date
     _notification = new Notification();
     _notification.SetMessage("Checking for updates");
     try
     {
         if (forceCheck)
         {
             _notification.Show();
             _notification.ShowForm(10);
         }
         if (forceCheck)
         {
             var amazons3 = AWSClientFactory.CreateAmazonS3Client(Utilities.AwsAccessKey, Utilities.AwsSecretKey, new AmazonS3Config { CommunicationProtocol = Protocol.HTTP });
             var listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool_32Bit.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (!string.IsNullOrEmpty(Utilities.MyConfig.InstallerVersionId) && Utilities.MyConfig.InstallerVersionId != s3ObjectVersion.VersionId)
                     {
                         while (Process.GetProcessesByName("VersaVaultSyncTool_32Bit").Length != 0)
                         {
                             Thread.Sleep(1000);
                             Application.DoEvents();
                         }
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe")))
                             File.Delete(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         if (File.Exists(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")))
                         {
                             File.Move(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"),
                                       Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit_old.exe"));
                         }
                         var service = new S3Service { AccessKeyID = Utilities.AwsAccessKey, SecretAccessKey = Utilities.AwsSecretKey };
                         _notification.SetMessage("Started downloading update.");
                         service.GetObjectProgress += ServiceGetObjectProgress;
                         service.GetObject(Utilities.AppRootBucketName, s3ObjectVersion.Key, Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe"));
                         _notification.SetMessage("Updating VersaVault");
                         Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         var startInfo = new ProcessStartInfo(Path.Combine(Path.GetTempPath(), "VersaVaultSyncTool_32Bit.exe")) { Verb = "runas" };
                         Process.Start(startInfo);
                         Application.Exit();
                         return false;
                     }
                     Utilities.MyConfig.InstallerVersionId = s3ObjectVersion.VersionId;
                     Utilities.MyConfig.Save();
                     break;
                 }
             }
             listVersionRequest = new ListVersionsRequest { BucketName = Utilities.AppRootBucketName, Prefix = "VersaVaultSyncTool.exe" };
             foreach (var s3ObjectVersion in amazons3.ListVersions(listVersionRequest).Versions)
             {
                 if (s3ObjectVersion.IsLatest)
                 {
                     if (s3ObjectVersion.VersionId != null && s3ObjectVersion.VersionId != "null")
                     {
                         if (!string.IsNullOrEmpty(Utilities.MyConfig.VersionId) && Utilities.MyConfig.VersionId != s3ObjectVersion.VersionId)
                         {
                             _notification.Dispose();
                             Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                             Utilities.MyConfig.Save();
                             var startInfo = new ProcessStartInfo(Path.Combine(Application.StartupPath, "VersaVaultUpdater.exe"), s3ObjectVersion.VersionId + " " + "update") { Verb = "runas" };
                             Process.Start(startInfo);
                             Application.Exit();
                             return false;
                         }
                         Utilities.MyConfig.VersionId = s3ObjectVersion.VersionId;
                         Utilities.MyConfig.Save();
                         return true;
                     }
                     // enable bucker versioning
                     var setBucketVersioning = new SetBucketVersioningRequest { BucketName = Utilities.AppRootBucketName, VersioningConfig = new S3BucketVersioningConfig { Status = "Enabled" } };
                     amazons3.SetBucketVersioning(setBucketVersioning);
                     break;
                 }
             }
             return true;
         }
     }
     catch (Exception)
     {
     }
     finally
     {
         try
         {
             _notification.Controls["LblStatus"].Text = @"VersaVault is upto date.";
             _notification.HideForm(10);
             _notification.Close();
             _notification.Dispose();
         }
         catch (Exception)
         {
         }
     }
     return true;
 }