diff --git a/MyS3.GUI/MainForm.cs b/MyS3.GUI/MainForm.cs index 8eea609..82b4c56 100644 --- a/MyS3.GUI/MainForm.cs +++ b/MyS3.GUI/MainForm.cs @@ -133,11 +133,10 @@ private void TriggerUseMyS3Setups() public void UseMyS3Setups() { - if (!Tools.HasInternet()) return; - // Show or hide instructions and MyS3 tabs noSetupsLabel.Visible = SetupStore.Entries.Count == 0; - mys3Tabs.Visible = SetupStore.Entries.Count > 0; + + if (!Tools.HasInternet()) return; // --- @@ -153,6 +152,7 @@ public void UseMyS3Setups() } mys3Tabs.TabPages.Clear(); myS3s.Clear(); + mys3Tabs.Visible = SetupStore.Entries.Count > 0; // --- diff --git a/MyS3.GUI/MyS3Form.Designer.cs b/MyS3.GUI/MyS3Form.Designer.cs index c8b3152..39f6063 100644 --- a/MyS3.GUI/MyS3Form.Designer.cs +++ b/MyS3.GUI/MyS3Form.Designer.cs @@ -458,7 +458,7 @@ private void InitializeComponent() this.tableLayoutPanel6.ColumnCount = 3; this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 43.51145F)); this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 56.48855F)); - this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 395F)); + this.tableLayoutPanel6.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 397F)); this.tableLayoutPanel6.Controls.Add(this.downloadsListTitleLabel, 2, 1); this.tableLayoutPanel6.Controls.Add(this.downloadSizeLabel, 0, 0); this.tableLayoutPanel6.Controls.Add(this.downloadProgress, 1, 0); @@ -475,10 +475,10 @@ private void InitializeComponent() // // downloadsListTitleLabel // - this.downloadsListTitleLabel.Location = new System.Drawing.Point(169, 25); + this.downloadsListTitleLabel.Location = new System.Drawing.Point(154, 25); this.downloadsListTitleLabel.Name = "downloadsListTitleLabel"; this.downloadsListTitleLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.downloadsListTitleLabel.Size = new System.Drawing.Size(224, 25); + this.downloadsListTitleLabel.Size = new System.Drawing.Size(241, 25); this.downloadsListTitleLabel.TabIndex = 4; this.downloadsListTitleLabel.Text = "S3 objects:"; this.downloadsListTitleLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter; @@ -486,11 +486,11 @@ private void InitializeComponent() // // downloadSizeLabel // - this.downloadSizeLabel.Location = new System.Drawing.Point(482, 5); + this.downloadSizeLabel.Location = new System.Drawing.Point(483, 5); this.downloadSizeLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.downloadSizeLabel.Name = "downloadSizeLabel"; this.downloadSizeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.downloadSizeLabel.Size = new System.Drawing.Size(67, 15); + this.downloadSizeLabel.Size = new System.Drawing.Size(66, 15); this.downloadSizeLabel.TabIndex = 100; this.downloadSizeLabel.Text = "3.2 MB"; this.downloadSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -498,17 +498,17 @@ private void InitializeComponent() // // downloadProgress // - this.downloadProgress.Location = new System.Drawing.Point(396, 0); + this.downloadProgress.Location = new System.Drawing.Point(398, 0); this.downloadProgress.Margin = new System.Windows.Forms.Padding(0); this.downloadProgress.Name = "downloadProgress"; - this.downloadProgress.Size = new System.Drawing.Size(86, 25); + this.downloadProgress.Size = new System.Drawing.Size(85, 25); this.downloadProgress.TabIndex = 100; this.downloadProgress.Value = 100; this.downloadProgress.Visible = false; // // downloadFileLabel // - this.downloadFileLabel.Location = new System.Drawing.Point(29, 5); + this.downloadFileLabel.Location = new System.Drawing.Point(31, 5); this.downloadFileLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.downloadFileLabel.Name = "downloadFileLabel"; this.downloadFileLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; @@ -521,7 +521,7 @@ private void InitializeComponent() // // downloadPercentLabel // - this.downloadPercentLabel.Location = new System.Drawing.Point(410, 25); + this.downloadPercentLabel.Location = new System.Drawing.Point(411, 25); this.downloadPercentLabel.Name = "downloadPercentLabel"; this.downloadPercentLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; this.downloadPercentLabel.Size = new System.Drawing.Size(69, 25); @@ -561,7 +561,7 @@ private void InitializeComponent() this.tableLayoutPanel5.ColumnCount = 3; this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 43.51145F)); this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 56.48855F)); - this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 395F)); + this.tableLayoutPanel5.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 397F)); this.tableLayoutPanel5.Controls.Add(this.uploadsListTitleLabel, 2, 1); this.tableLayoutPanel5.Controls.Add(this.uploadSizeLabel, 0, 0); this.tableLayoutPanel5.Controls.Add(this.uploadProgress, 1, 0); @@ -578,7 +578,7 @@ private void InitializeComponent() // // uploadsListTitleLabel // - this.uploadsListTitleLabel.Location = new System.Drawing.Point(152, 25); + this.uploadsListTitleLabel.Location = new System.Drawing.Point(154, 25); this.uploadsListTitleLabel.Name = "uploadsListTitleLabel"; this.uploadsListTitleLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; this.uploadsListTitleLabel.Size = new System.Drawing.Size(241, 25); @@ -589,11 +589,11 @@ private void InitializeComponent() // // uploadSizeLabel // - this.uploadSizeLabel.Location = new System.Drawing.Point(482, 5); + this.uploadSizeLabel.Location = new System.Drawing.Point(483, 5); this.uploadSizeLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.uploadSizeLabel.Name = "uploadSizeLabel"; this.uploadSizeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.uploadSizeLabel.Size = new System.Drawing.Size(67, 15); + this.uploadSizeLabel.Size = new System.Drawing.Size(66, 15); this.uploadSizeLabel.TabIndex = 100; this.uploadSizeLabel.Text = "3.2 MB"; this.uploadSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -601,17 +601,17 @@ private void InitializeComponent() // // uploadProgress // - this.uploadProgress.Location = new System.Drawing.Point(396, 0); + this.uploadProgress.Location = new System.Drawing.Point(398, 0); this.uploadProgress.Margin = new System.Windows.Forms.Padding(0); this.uploadProgress.Name = "uploadProgress"; - this.uploadProgress.Size = new System.Drawing.Size(86, 25); + this.uploadProgress.Size = new System.Drawing.Size(85, 25); this.uploadProgress.TabIndex = 100; this.uploadProgress.Value = 100; this.uploadProgress.Visible = false; // // uploadFileLabel // - this.uploadFileLabel.Location = new System.Drawing.Point(29, 5); + this.uploadFileLabel.Location = new System.Drawing.Point(31, 5); this.uploadFileLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.uploadFileLabel.Name = "uploadFileLabel"; this.uploadFileLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; @@ -624,7 +624,7 @@ private void InitializeComponent() // // uploadPercentLabel // - this.uploadPercentLabel.Location = new System.Drawing.Point(410, 25); + this.uploadPercentLabel.Location = new System.Drawing.Point(411, 25); this.uploadPercentLabel.Name = "uploadPercentLabel"; this.uploadPercentLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; this.uploadPercentLabel.Size = new System.Drawing.Size(69, 25); @@ -707,7 +707,7 @@ private void InitializeComponent() this.tableLayoutPanel7.ColumnCount = 3; this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 43.51145F)); this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 56.48855F)); - this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 395F)); + this.tableLayoutPanel7.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 397F)); this.tableLayoutPanel7.Controls.Add(this.restoreDownloadsListTitleLabel, 2, 1); this.tableLayoutPanel7.Controls.Add(this.restoreDownloadSizeLabel, 0, 0); this.tableLayoutPanel7.Controls.Add(this.restoreDownloadProgress, 1, 0); @@ -724,7 +724,7 @@ private void InitializeComponent() // // restoreDownloadsListTitleLabel // - this.restoreDownloadsListTitleLabel.Location = new System.Drawing.Point(169, 25); + this.restoreDownloadsListTitleLabel.Location = new System.Drawing.Point(171, 25); this.restoreDownloadsListTitleLabel.Name = "restoreDownloadsListTitleLabel"; this.restoreDownloadsListTitleLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; this.restoreDownloadsListTitleLabel.Size = new System.Drawing.Size(224, 25); @@ -735,11 +735,11 @@ private void InitializeComponent() // // restoreDownloadSizeLabel // - this.restoreDownloadSizeLabel.Location = new System.Drawing.Point(482, 5); + this.restoreDownloadSizeLabel.Location = new System.Drawing.Point(483, 5); this.restoreDownloadSizeLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.restoreDownloadSizeLabel.Name = "restoreDownloadSizeLabel"; this.restoreDownloadSizeLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; - this.restoreDownloadSizeLabel.Size = new System.Drawing.Size(67, 15); + this.restoreDownloadSizeLabel.Size = new System.Drawing.Size(66, 15); this.restoreDownloadSizeLabel.TabIndex = 100; this.restoreDownloadSizeLabel.Text = "3.2 MB"; this.restoreDownloadSizeLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; @@ -747,17 +747,17 @@ private void InitializeComponent() // // restoreDownloadProgress // - this.restoreDownloadProgress.Location = new System.Drawing.Point(396, 0); + this.restoreDownloadProgress.Location = new System.Drawing.Point(398, 0); this.restoreDownloadProgress.Margin = new System.Windows.Forms.Padding(0); this.restoreDownloadProgress.Name = "restoreDownloadProgress"; - this.restoreDownloadProgress.Size = new System.Drawing.Size(86, 25); + this.restoreDownloadProgress.Size = new System.Drawing.Size(85, 25); this.restoreDownloadProgress.TabIndex = 100; this.restoreDownloadProgress.Value = 100; this.restoreDownloadProgress.Visible = false; // // restoreDownloadFileLabel // - this.restoreDownloadFileLabel.Location = new System.Drawing.Point(29, 5); + this.restoreDownloadFileLabel.Location = new System.Drawing.Point(31, 5); this.restoreDownloadFileLabel.Margin = new System.Windows.Forms.Padding(0, 5, 0, 0); this.restoreDownloadFileLabel.Name = "restoreDownloadFileLabel"; this.restoreDownloadFileLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; @@ -770,7 +770,7 @@ private void InitializeComponent() // // restoreDownloadPercentLabel // - this.restoreDownloadPercentLabel.Location = new System.Drawing.Point(410, 25); + this.restoreDownloadPercentLabel.Location = new System.Drawing.Point(411, 25); this.restoreDownloadPercentLabel.Name = "restoreDownloadPercentLabel"; this.restoreDownloadPercentLabel.RightToLeft = System.Windows.Forms.RightToLeft.No; this.restoreDownloadPercentLabel.Size = new System.Drawing.Size(69, 25); diff --git a/MyS3.GUI/MyS3Form.cs b/MyS3.GUI/MyS3Form.cs index f81d41f..561c4d6 100644 --- a/MyS3.GUI/MyS3Form.cs +++ b/MyS3.GUI/MyS3Form.cs @@ -31,6 +31,7 @@ public MyS3Form(int controlNameCounter) { InitializeComponent(); + // Number controls to make unique this.controlNameCounter = controlNameCounter; this.Name += controlNameCounter; foreach (Control control in GetAllControls(this)) @@ -86,6 +87,8 @@ private void ReadyControls() ((ListBox)control).Items.Clear(); } + // Pause buttons + Button pauseDownloadsButton = Controls.Find("pauseDownloadsButton" + controlNameCounter, true).FirstOrDefault() as Button; pauseDownloadsButton.Text = "Pause downloads"; pauseDownloadsButton.Click += (sender, args) => myS3.PauseDownloads(!myS3.DownloadsPaused); @@ -114,7 +117,7 @@ private void StartUpdatingSizeUsedControl() try { // MyS3 file info - long numberOfFiles = myS3.NumberOfFiles; + long numberOfFiles = myS3.NumberOfMyS3Files; long totalFileSize = myS3.GetTotalFileSize(); if (numberOfFiles != -1 && totalFileSize != -1) { @@ -530,7 +533,7 @@ private void UpdateTransferControls() if (control.Name.StartsWith("downloadsTab")) { string tabText = "Downloads"; - if (!myS3.IsComparingFiles && downloadList.Count > 0) tabText += " (" + downloadList.Count + ")"; + if (!myS3.IsComparingS3AndMyS3 && downloadList.Count > 0) tabText += " (" + downloadList.Count + ")"; if (control.Text != tabText) // stop constant flashing control.Text = tabText; @@ -538,7 +541,7 @@ private void UpdateTransferControls() else if (control.Name.StartsWith("uploadsTab")) { string tabText = "Uploads"; - if (!myS3.IsComparingFiles && uploadList.Count > 0) tabText += " (" + uploadList.Count + ")"; + if (!myS3.IsComparingS3AndMyS3 && uploadList.Count > 0) tabText += " (" + uploadList.Count + ")"; if (control.Text != tabText) // stop constant flashing control.Text = tabText; @@ -546,7 +549,7 @@ private void UpdateTransferControls() else if (control.Name.StartsWith("restoresTab")) { string tabText = "Restores"; - if (!myS3.IsComparingFiles && restoreDownloadList.Count > 0) tabText += " (" + restoreDownloadList.Count + ")"; + if (!myS3.IsComparingS3AndMyS3 && restoreDownloadList.Count > 0) tabText += " (" + restoreDownloadList.Count + ")"; if (control.Text != tabText) // stop constant flashing control.Text = tabText; @@ -555,7 +558,7 @@ private void UpdateTransferControls() // Tables - active downloads and uploads and restores else if (control.Name.StartsWith("downloadSpeedLabel")) { - control.Visible = !myS3.IsComparingFiles && namedDownloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedDownloadList.Count > 0; if (namedDownloadList.Count > 0) { @@ -567,7 +570,7 @@ private void UpdateTransferControls() } else if (control.Name.StartsWith("downloadFileLabel")) { - control.Visible = !myS3.IsComparingFiles && namedDownloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedDownloadList.Count > 0; if (namedDownloadList.Count > 0) { @@ -592,26 +595,26 @@ private void UpdateTransferControls() else if (control.Name.StartsWith("downloadProgress")) { ProgressBar progressBar = (ProgressBar)control; - progressBar.Visible = !myS3.IsComparingFiles && namedDownloadList.Count > 0; + progressBar.Visible = !myS3.IsComparingS3AndMyS3 && namedDownloadList.Count > 0; progressBar.Value = (int)Math.Round(myS3.DownloadPercent); } else if (control.Name.StartsWith("downloadSizeLabel")) { - control.Visible = !myS3.IsComparingFiles && namedDownloadList.Count > 0 && myS3.DownloadSize > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedDownloadList.Count > 0 && myS3.DownloadSize > 0; if (namedDownloadList.Count > 0 && myS3.DownloadSize > 0) control.Text = Tools.GetByteSizeAsText((long)myS3.DownloadSize); } else if (control.Name.StartsWith("downloadPercentLabel")) { - control.Visible = !myS3.IsComparingFiles && namedDownloadList.Count > 0 && myS3.DownloadPercent > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedDownloadList.Count > 0 && myS3.DownloadPercent > 0; if (namedDownloadList.Count > 0 && myS3.DownloadPercent > 0) control.Text = Math.Round(myS3.DownloadPercent) + " %"; } else if (control.Name.StartsWith("uploadSpeedLabel")) { - control.Visible = !myS3.IsComparingFiles && uploadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0; if (uploadList.Count > 0) { @@ -623,7 +626,7 @@ private void UpdateTransferControls() } else if (control.Name.StartsWith("uploadFileLabel")) { - control.Visible = !myS3.IsComparingFiles && uploadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0; if (uploadList.Count > 0) { @@ -648,26 +651,26 @@ private void UpdateTransferControls() else if (control.Name.StartsWith("uploadProgress")) { ProgressBar progressBar = (ProgressBar)control; - progressBar.Visible = !myS3.IsComparingFiles && uploadList.Count > 0; + progressBar.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0; progressBar.Value = (int)Math.Round(myS3.UploadPercent); } else if (control.Name.StartsWith("uploadSizeLabel")) { - control.Visible = !myS3.IsComparingFiles && uploadList.Count > 0 && myS3.UploadSize > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0 && myS3.UploadSize > 0; if (uploadList.Count > 0 && myS3.UploadSize > 0) control.Text = Tools.GetByteSizeAsText((long)myS3.UploadSize); } else if (control.Name.StartsWith("uploadPercentLabel")) { - control.Visible = !myS3.IsComparingFiles && uploadList.Count > 0 && myS3.UploadPercent > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0 && myS3.UploadPercent > 0; if (uploadList.Count > 0 && myS3.UploadPercent > 0) control.Text = Math.Round(myS3.UploadPercent) + " %"; } else if (control.Name.StartsWith("restoreDownloadSpeedLabel")) { - control.Visible = !myS3.IsComparingFiles && namedRestoreDownloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedRestoreDownloadList.Count > 0; if (namedRestoreDownloadList.Count > 0) { @@ -679,7 +682,7 @@ private void UpdateTransferControls() } else if (control.Name.StartsWith("restoreDownloadFileLabel")) { - control.Visible = !myS3.IsComparingFiles && namedRestoreDownloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedRestoreDownloadList.Count > 0; if (namedRestoreDownloadList.Count > 0) { @@ -704,19 +707,19 @@ private void UpdateTransferControls() else if (control.Name.StartsWith("restoreDownloadProgress")) { ProgressBar progressBar = (ProgressBar)control; - progressBar.Visible = !myS3.IsComparingFiles && namedRestoreDownloadList.Count > 0; + progressBar.Visible = !myS3.IsComparingS3AndMyS3 && namedRestoreDownloadList.Count > 0; progressBar.Value = (int)Math.Round(myS3.RestoreDownloadPercent); } else if (control.Name.StartsWith("restoreDownloadSizeLabel")) { - control.Visible = !myS3.IsComparingFiles && namedRestoreDownloadList.Count > 0 && myS3.RestoreDownloadSize > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedRestoreDownloadList.Count > 0 && myS3.RestoreDownloadSize > 0; if (restoreDownloadList.Count > 0 && myS3.RestoreDownloadSize > 0) control.Text = Tools.GetByteSizeAsText((long)myS3.RestoreDownloadSize); } else if (control.Name.StartsWith("restoreDownloadPercentLabel")) { - control.Visible = !myS3.IsComparingFiles && namedRestoreDownloadList.Count > 0 && myS3.RestoreDownloadPercent > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && namedRestoreDownloadList.Count > 0 && myS3.RestoreDownloadPercent > 0; if (namedRestoreDownloadList.Count > 0 && myS3.RestoreDownloadPercent > 0) control.Text = Math.Round(myS3.RestoreDownloadPercent) + " %"; @@ -725,7 +728,7 @@ private void UpdateTransferControls() // Lists else if (control.Name.StartsWith("downloadsListTitleLabel")) { - control.Visible = !myS3.IsComparingFiles && downloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && downloadList.Count > 0; } else if (control.Name.StartsWith("downloadsList")) { @@ -743,11 +746,11 @@ private void UpdateTransferControls() } if (listBox.Items.Count == MAX_LIST_LENGTH) listBox.Items.Add("..."); - listBox.Visible = !myS3.IsComparingFiles && downloadList.Count > 0; + listBox.Visible = !myS3.IsComparingS3AndMyS3 && downloadList.Count > 0; } else if (control.Name.StartsWith("uploadsListTitleLabel")) { - control.Visible = !myS3.IsComparingFiles && uploadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0; } else if (control.Name.StartsWith("uploadsList")) { @@ -765,11 +768,11 @@ private void UpdateTransferControls() } if (listBox.Items.Count == MAX_LIST_LENGTH) listBox.Items.Add("..."); - listBox.Visible = !myS3.IsComparingFiles && uploadList.Count > 0; + listBox.Visible = !myS3.IsComparingS3AndMyS3 && uploadList.Count > 0; } else if (control.Name.StartsWith("restoreDownloadsListTitleLabel")) { - control.Visible = !myS3.IsComparingFiles && restoreDownloadList.Count > 0; + control.Visible = !myS3.IsComparingS3AndMyS3 && restoreDownloadList.Count > 0; } else if (control.Name.StartsWith("restoreDownloadsList")) { @@ -787,7 +790,7 @@ private void UpdateTransferControls() } if (listBox.Items.Count == MAX_LIST_LENGTH) listBox.Items.Add("..."); - listBox.Visible = !myS3.IsComparingFiles && restoreDownloadList.Count > 0; + listBox.Visible = !myS3.IsComparingS3AndMyS3 && restoreDownloadList.Count > 0; } // Pausing @@ -820,18 +823,19 @@ private void UpdateTransferControls() control.Text = "Uploads paused"; control.ForeColor = Color.Red; } - else if (myS3.IsIndexingFiles) + else if (myS3.IsIndexingMyS3Files) { - control.Text = "Indexing MyS3's files"; + control.Text = "Indexing MyS3 files (" + myS3.NumberOfMyS3Files + ")"; control.ForeColor = Color.DarkOrange; } - else if (myS3.IsComparingFiles) + else if (myS3.IsIndexingS3Objects) { - if (myS3.ComparisonPercent == 0) - control.Text = "Retrieving S3 object lists"; - else - control.Text = "Comparing S3 and MyS3 (" + myS3.ComparisonPercent + " %)"; - + control.Text = "Indexing S3 objects (" + myS3.NumberOfIndexedS3Objects + " %)"; + control.ForeColor = Color.DarkOrange; + } + else if (myS3.IsComparingS3AndMyS3) + { + control.Text = "Comparing S3 and MyS3 (" + myS3.ComparisonPercent + " %)"; control.ForeColor = Color.DarkOrange; } else if (downloadList.Count > 0 || uploadList.Count > 0) diff --git a/MyS3.GUI/MyS3Form.resx b/MyS3.GUI/MyS3Form.resx index 2640138..691441c 100644 --- a/MyS3.GUI/MyS3Form.resx +++ b/MyS3.GUI/MyS3Form.resx @@ -62,7 +62,7 @@ AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0 ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADi - CAAAAk1TRnQBSQFMAgEBAwEAAWABAgFgAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo + CAAAAk1TRnQBSQFMAgEBAwEAAXABAgFwAQIBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5 AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA diff --git a/MyS3.GUI/MyS3SetupForm.cs b/MyS3.GUI/MyS3SetupForm.cs index 5c62665..6777315 100644 --- a/MyS3.GUI/MyS3SetupForm.cs +++ b/MyS3.GUI/MyS3SetupForm.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using Amazon; +using System.Text; namespace MyS3.GUI { @@ -78,6 +79,7 @@ private void bucketBox_TextChanged(object sender, EventArgs e) bucketBox.BackColor = DEFAULT_CONTROL_BACKGROUND_COLOR; } else if (bucketBox.TextLength >= 3 && bucketBox.TextLength <= 63 && // length + bucketBox.TextLength == Encoding.UTF8.GetByteCount(bucketBox.Text) && // only ASCII ((bucketBox.Text.First() + "").Any(char.IsLower) || (bucketBox.Text.First() + "").Any(char.IsDigit)) && // first char is lower letter or number ((bucketBox.Text.Last() + "").Any(char.IsLower) || (bucketBox.Text.Last() + "").Any(char.IsDigit)) && // last char is lower letter or number !bucketBox.Text.Any(char.IsSymbol) && // no symbols @@ -251,7 +253,7 @@ private void myS3PathLabel_TextChanged(object sender, EventArgs e) private void changeMyS3PathButton_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); - folderBrowser.Description = "Select or create MyS3 folder"; + folderBrowser.Description = "Select or create a folder for MyS3"; folderBrowser.SelectedPath = myS3PathLabel.Text; folderBrowser.ShowNewFolderButton = true; folderBrowser.ShowDialog(); @@ -398,10 +400,11 @@ private void okSetupButton_Click(object sender, EventArgs e) InUseNow = inUseBox.Checked }; - SetupStore.Add(setup); - if (editedSetup.Bucket != setup.Bucket) + if (editedSetup != null && editedSetup.Bucket != setup.Bucket) SetupStore.Remove(editedSetup.Bucket); + SetupStore.Add(setup); + Client.MainForm.CreateEditSetupMenuItems(); Client.MainForm.UseMyS3Setups(); Close(); diff --git a/MyS3/MyS3Runner.cs b/MyS3/MyS3Runner.cs index ea31247..1ea7d44 100644 --- a/MyS3/MyS3Runner.cs +++ b/MyS3/MyS3Runner.cs @@ -242,9 +242,12 @@ public void PauseUploads(bool pause) public void Pause(bool pause) { - PauseDownloads(pause); - PauseUploads(pause); - PauseRestores(pause); + pauseDownloads = pause; + pauseUploads = pause; + pauseRestore = pause; + + string text = pause ? "All MyS3 activity set to pause" : "All MyS3 activity set to continue"; + if (verboseLogFunc != null) verboseLogFunc(text); } public bool restorePaused { get { return pauseRestore; } } @@ -418,8 +421,8 @@ private static string MyS3FilePathToS3ObjectKey(string filePath) // - public bool IsIndexingFiles { get { return isIndexingFiles; } } - private bool isIndexingFiles = true; + public bool IsIndexingMyS3Files { get { return isIndexingMyS3Files; } } + private bool isIndexingMyS3Files = true; private void SaveFileIndex() { @@ -438,12 +441,12 @@ private void SaveFileIndex() Tools.WriteSettingsFile(Bucket + INDEX_FILE_PATH, data); })); } - + private void LoadFileIndex() { ThreadPool.QueueUserWorkItem(new WaitCallback((object callback) => { - isIndexingFiles = true; + isIndexingMyS3Files = true; if (Tools.SettingsFileExists(Bucket + INDEX_FILE_PATH)) { @@ -507,7 +510,7 @@ private void LoadFileIndex() if (stop) break; } - isIndexingFiles = false; + isIndexingMyS3Files = false; // --- @@ -518,7 +521,21 @@ private void LoadFileIndex() // - public int NumberOfFiles { get { return myS3FileIndexDict.Count; } } + public int NumberOfS3Objects { get { return s3ObjectIndexDict.Count; } } + private int numberOfIndexedS3Objects; + + public int NumberOfIndexedS3Objects + { + get + { + if (NumberOfS3Objects > 0) + return (int) Math.Round((numberOfIndexedS3Objects / NumberOfS3Objects) * 100.0); + else + return 0; + } + } + + public int NumberOfMyS3Files { get { return myS3FileIndexDict.Count; } } public long GetTotalFileSize() { @@ -539,22 +556,27 @@ public void TriggerS3AndMyS3Comparison() private bool newS3AndMyS3ComparisonNeeded; private DateTime timeLastActivity; - public bool IsComparingFiles { get { return isComparingFiles; } } - private bool isComparingFiles = false; + // + + public bool IsIndexingS3Objects { get { return isIndexingS3Objects; } } + private bool isIndexingS3Objects = false; + + public bool IsComparingS3AndMyS3 { get { return isComparingS3AndMyS3; } } + private bool isComparingS3AndMyS3 = false; public int ComparisonPercent { get { if (totalNumberOfComparisons > 0) - return (int)Math.Round((numberOfComparisons / totalNumberOfComparisons) * 100); + return (int) Math.Round((numberOfComparisons / totalNumberOfComparisons) * 100); else return 0; } } private double numberOfComparisons; private double totalNumberOfComparisons; - + // --- public void OnChangedFileHandler(string offlineFilePath) // on file creation and change @@ -575,7 +597,7 @@ public void OnChangedFileHandler(string offlineFilePath) // on file creation and lock (removeList) if (removeList.Contains(offlineFilePathInsideMyS3)) return; lock (renameDict) if (renameDict.ContainsKey(offlineFilePathInsideMyS3)) return; lock (renamedDict) if (renamedDict.ContainsKey(offlineFilePathInsideMyS3) && - renamedDict[offlineFilePathInsideMyS3].AddSeconds(3) > DateTime.Now) return; + renamedDict[offlineFilePathInsideMyS3].AddSeconds(5) > DateTime.Now) return; // Index file lock (myS3FileIndexDict) @@ -623,12 +645,13 @@ public void OnRenamedFileHandler(string oldOfflineFilePath, string newOfflineFil // Index file lock (myS3FileIndexDict) + { if (myS3FileIndexDict.ContainsKey(oldOfflineFilePathInsideMyS3)) - { myS3FileIndexDict.Remove(oldOfflineFilePathInsideMyS3); - if (!myS3FileIndexDict.ContainsKey(newOfflineFilePathInsideMyS3)) - myS3FileIndexDict.Add(newOfflineFilePathInsideMyS3, newS3ObjectKey); - } + + if (!myS3FileIndexDict.ContainsKey(newOfflineFilePathInsideMyS3)) + myS3FileIndexDict.Add(newOfflineFilePathInsideMyS3, newS3ObjectKey); + } // Do rename lock (s3ObjectIndexDict) @@ -703,6 +726,8 @@ public void OnTransferProgressHandler(string shownFilePath, long transferredByte { double percentDone = (((double) transferredBytes / (double) totalBytes) * 100); percentDone = Math.Round(percentDone, 2); + if (percentDone > 100) percentDone = 100; + else if (percentDone < 0) percentDone = 0; string typeText = null; switch (transferType) @@ -794,12 +819,13 @@ private void StartComparingS3AndMyS3() lock (renameDict) lock (removeList) { - if (isIndexingFiles || + if (isIndexingMyS3Files || isIndexingS3Objects || isComparingS3AndMyS3 || uploadList.Count != 0 || downloadList.Count != 0 || renameDict.Count != 0 || removeList.Count != 0) timeLastActivity = DateTime.Now; - activityDone = (!isIndexingFiles && + activityDone = ( + !isIndexingMyS3Files && !isIndexingS3Objects && !isComparingS3AndMyS3 && uploadList.Count == 0 && downloadList.Count == 0 && renameDict.Count == 0 && removeList.Count == 0); } @@ -807,7 +833,7 @@ private void StartComparingS3AndMyS3() // --- // Start compare work - if (activityDone && timeLastActivity.AddSeconds(3) < DateTime.Now) // Give S3 a little time to finish last activity + if (activityDone && !pauseDownloads && timeLastActivity.AddSeconds(3) < DateTime.Now) // Give S3 a little time to finish last activity { // S3 and MyS3 comparison also runs on a schedule if bucket is shared if (sharedBucketWithMoreComparisons && @@ -824,10 +850,10 @@ private void StartComparingS3AndMyS3() // --- if (verboseLogFunc != null) - verboseLogFunc("Retrieving S3 object lists for S3 and MyS3 comparisons"); + verboseLogFunc("Indexing S3 objects before S3 and MyS3 comparisons"); - isComparingFiles = true; - numberOfComparisons = 0; + isIndexingS3Objects = true; + numberOfIndexedS3Objects = 0; try { @@ -840,36 +866,55 @@ private void StartComparingS3AndMyS3() // Get list of S3 objects with metadata lock (s3ObjectIndexDict) { - // Get all S3 object info + // Old S3 object info + Dictionary> oldS3ObjectIndexDict = s3ObjectIndexDict.ToDictionary(x => x.Key, x => x.Value); + + // Get newest S3 object info s3ObjectIndexDict = s3.GetCompleteObjectList().ToDictionary( x => x.Key, x => Tuple.Create(x, null) ); - // Get all S3 object custom metadata + // Get newest S3 object custom metadata for (int s = 0; s < s3ObjectIndexDict.Count; s++) { - string s3ObjectKey = s3ObjectIndexDict.Keys.ElementAt(s); + numberOfIndexedS3Objects++; - // Get metadata - GetObjectMetadataResponse s3ObjectMetadataResult = s3.GetMetadata(s3ObjectKey, null).Result; - MetadataCollection s3ObjectMetadata = s3ObjectMetadataResult.Metadata; + string s3ObjectKey = s3ObjectIndexDict.Keys.ElementAt(s); // Update S3 object index S3Object s3ObjectInfo = s3ObjectIndexDict[s3ObjectKey].Item1; - s3ObjectIndexDict[s3ObjectKey] = Tuple.Create(s3ObjectInfo, s3ObjectMetadata); + + // Use old metadata + if (oldS3ObjectIndexDict.ContainsKey(s3ObjectKey) && + oldS3ObjectIndexDict[s3ObjectKey].Item1.LastModified == s3ObjectIndexDict[s3ObjectKey].Item1.LastModified) + { + s3ObjectIndexDict[s3ObjectKey] = Tuple.Create(s3ObjectInfo, oldS3ObjectIndexDict[s3ObjectKey].Item2); + } + + // Get new metadata + else + { + GetObjectMetadataResponse s3ObjectMetadataResult = s3.GetMetadata(s3ObjectKey, null).Result; + MetadataCollection s3ObjectMetadata = s3ObjectMetadataResult.Metadata; + + s3ObjectIndexDict[s3ObjectKey] = Tuple.Create(s3ObjectInfo, s3ObjectMetadata); + } } } + // --- + + isIndexingS3Objects = false; + isComparingS3AndMyS3 = true; + numberOfComparisons = 0; totalNumberOfComparisons = ((removedS3Objects.Count > 0) ? myS3FileIndexDict.Count : 0) + // looping through local files s3ObjectIndexDict.Count + // looping through S3 objects myS3FileIndexDict.Count; // looping through local files, again - // --- - if (verboseLogFunc != null) - verboseLogFunc("Comparing S3 and MyS3 [" + NumberOfFiles + " " + (NumberOfFiles == 1 ? "file" : "files") + + verboseLogFunc("Comparing S3 and MyS3 [" + NumberOfMyS3Files + " " + (NumberOfMyS3Files == 1 ? "file" : "files") + " = " + Tools.GetByteSizeAsText(GetTotalFileSize()) + "]"); // 1. Find files locally that should be removed when already removed in S3 from elsewhere (shared bucket only) @@ -1073,6 +1118,10 @@ private void StartComparingS3AndMyS3() // Give other threads access to locked queues Thread.Sleep(25); } + + // --- + + timeLastCompare = DateTime.Now; } catch (Exception ex) { @@ -1082,9 +1131,8 @@ private void StartComparingS3AndMyS3() errorLogFunc(myS3Path + RELATIVE_LOCAL_MYS3_LOG_DIRECTORY_PATH + "Comparing.log", problem); } - isComparingFiles = false; - - timeLastCompare = DateTime.Now; + isIndexingS3Objects = false; + isComparingS3AndMyS3 = false; } } @@ -1113,7 +1161,7 @@ private void StartUploadWorker() bool haveUploads = false; lock (uploadList) haveUploads = uploadList.Count > 0; - while (!IsComparingFiles && haveUploads && !pauseUploads) + while (!isIndexingMyS3Files && !isIndexingS3Objects && !IsComparingS3AndMyS3 && haveUploads && !pauseUploads) { // Remove old uploads from "log" while (true) @@ -1184,7 +1232,7 @@ private void StartUploadWorker() ); /* - * Never had an issue so disabling decryption testing + * Never had an issue so disabling decryption test * // Decryption test = abort work if it's unsuccessful byte[] decryptedUploadFileData = AesEncryptionWrapper.DecryptForGCM( @@ -1286,6 +1334,7 @@ private void StartUploadWorker() verboseLogFunc("Local file \"" + offlineFilePathInsideMyS3.Replace(@"\", @" \ ").Replace(@"/", @" / ") + "\" uploaded"); // Metadata + Thread.Sleep(25); // Give S3 some extra time before request = could return NotFound exception if not GetObjectMetadataResponse uploadS3ObjectMetadataResult = s3.GetMetadata(s3ObjectKey, null).Result; S3Object uploadS3ObjectInfo = new S3Object() { @@ -1359,7 +1408,7 @@ private void StartDownloadWorker() bool haveDownloads = false; lock (downloadList) haveDownloads = downloadList.Count > 0; - while (!IsComparingFiles && haveDownloads && !pauseDownloads) + while (!isIndexingMyS3Files && !isIndexingS3Objects && !IsComparingS3AndMyS3 && haveDownloads && !pauseDownloads) { // Remove old downloads from "log" while (true) @@ -1601,6 +1650,7 @@ private void StartRenameWorker() s3.RemoveAsync(oldS3ObjectKey, null).Wait(); // Custom metadata + Thread.Sleep(25); // Give S3 some time before request = could return NotFound exception if not GetObjectMetadataResponse renameS3ObjectMetadataResult = s3.GetMetadata(newS3ObjectKey, null).Result; renameS3ObjectMetadataResult.LastModified = renameS3ObjectMetadataResult.LastModified.ToLocalTime(); @@ -1642,7 +1692,12 @@ private void StartRenameWorker() // Aborted so clean up attempt else { + Thread.Sleep(25); // Give S3 some time before request = could return NotFound exception if not s3.RemoveAsync(newS3ObjectKey, null).Wait(); + + if (verboseLogFunc != null) + verboseLogFunc("S3 object rename for \"" + + newOfflineFilePathInsideMyS3.Replace(@"\", @" \ ").Replace(@"/", @" / ") + "\" aborted"); } } catch (Exception ex) @@ -1699,12 +1754,12 @@ private void StartRemoveWorker() if (s3ObjectIndexDict.ContainsKey(s3ObjectKey)) s3ObjectIndexDict.Remove(s3ObjectKey); + removeCounter++; + if (verboseLogFunc != null) lock (removeList) verboseLogFunc("S3 object for local file \"" + offlineFilePathInsideMyS3.Replace(@"\", @" \ ").Replace(@"/", @" / ") + "\" removed [" + removeCounter + "/" + (removeCounter + removeList.Count - 1) + "]"); - - removeCounter++; } catch (Exception ex) { diff --git a/MyS3/S3Wrapper.cs b/MyS3/S3Wrapper.cs index 1d38eef..1ab5095 100644 --- a/MyS3/S3Wrapper.cs +++ b/MyS3/S3Wrapper.cs @@ -308,7 +308,6 @@ public async Task GetMetadata(string s3ObjectPath, st return await client.GetObjectMetadataAsync(request); // Note: GetObjectMetadataResponse does not return local time in LastModified - // All other methods with a LastModified somewhere returns local time } // ---