diff --git a/Intersect.Editor/Forms/FrmUploadToServer.Designer.cs b/Intersect.Editor/Forms/FrmUploadToServer.Designer.cs index 0a915d9f0d..2189fa43d4 100644 --- a/Intersect.Editor/Forms/FrmUploadToServer.Designer.cs +++ b/Intersect.Editor/Forms/FrmUploadToServer.Designer.cs @@ -36,9 +36,6 @@ private void InitializeComponent() this.lblUploadType = new DarkUI.Controls.DarkLabel(); this.rbClientAssets = new DarkUI.Controls.DarkRadioButton(); this.rbEditorAssets = new DarkUI.Controls.DarkRadioButton(); - this.lblDirectory = new DarkUI.Controls.DarkLabel(); - this.txtDirectory = new DarkUI.Controls.DarkTextBox(); - this.btnBrowse = new DarkUI.Controls.DarkButton(); this.btnUpload = new DarkUI.Controls.DarkButton(); this.btnClose = new DarkUI.Controls.DarkButton(); this.progressBar = new System.Windows.Forms.ProgressBar(); @@ -113,40 +110,9 @@ private void InitializeComponent() this.rbEditorAssets.TabIndex = 1; this.rbEditorAssets.Text = "Editor Assets"; // - // lblDirectory - // - this.lblDirectory.AutoSize = true; - this.lblDirectory.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.lblDirectory.Location = new System.Drawing.Point(12, 153); - this.lblDirectory.Name = "lblDirectory"; - this.lblDirectory.Size = new System.Drawing.Size(92, 13); - this.lblDirectory.TabIndex = 4; - this.lblDirectory.Text = "Source Directory:"; - // - // txtDirectory - // - this.txtDirectory.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(69)))), ((int)(((byte)(73)))), ((int)(((byte)(74))))); - this.txtDirectory.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.txtDirectory.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.txtDirectory.Location = new System.Drawing.Point(15, 169); - this.txtDirectory.Name = "txtDirectory"; - this.txtDirectory.ReadOnly = true; - this.txtDirectory.Size = new System.Drawing.Size(357, 20); - this.txtDirectory.TabIndex = 5; - // - // btnBrowse - // - this.btnBrowse.Location = new System.Drawing.Point(378, 167); - this.btnBrowse.Name = "btnBrowse"; - this.btnBrowse.Padding = new System.Windows.Forms.Padding(5); - this.btnBrowse.Size = new System.Drawing.Size(94, 23); - this.btnBrowse.TabIndex = 6; - this.btnBrowse.Text = "Browse..."; - this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click); - // // progressBar // - this.progressBar.Location = new System.Drawing.Point(15, 205); + this.progressBar.Location = new System.Drawing.Point(15, 155); this.progressBar.Name = "progressBar"; this.progressBar.Size = new System.Drawing.Size(457, 23); this.progressBar.TabIndex = 7; @@ -155,7 +121,7 @@ private void InitializeComponent() // this.lblStatus.AutoSize = true; this.lblStatus.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220))))); - this.lblStatus.Location = new System.Drawing.Point(12, 237); + this.lblStatus.Location = new System.Drawing.Point(12, 187); this.lblStatus.Name = "lblStatus"; this.lblStatus.Size = new System.Drawing.Size(0, 13); this.lblStatus.TabIndex = 8; @@ -172,7 +138,7 @@ private void InitializeComponent() // // btnLogin // - this.btnLogin.Location = new System.Drawing.Point(206, 290); + this.btnLogin.Location = new System.Drawing.Point(206, 240); this.btnLogin.Name = "btnLogin"; this.btnLogin.Padding = new System.Windows.Forms.Padding(5); this.btnLogin.Size = new System.Drawing.Size(85, 28); @@ -184,7 +150,7 @@ private void InitializeComponent() // btnUpload // this.btnUpload.Enabled = false; - this.btnUpload.Location = new System.Drawing.Point(297, 290); + this.btnUpload.Location = new System.Drawing.Point(297, 240); this.btnUpload.Name = "btnUpload"; this.btnUpload.Padding = new System.Windows.Forms.Padding(5); this.btnUpload.Size = new System.Drawing.Size(85, 28); @@ -195,7 +161,7 @@ private void InitializeComponent() // btnClose // this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btnClose.Location = new System.Drawing.Point(388, 290); + this.btnClose.Location = new System.Drawing.Point(388, 240); this.btnClose.Name = "btnClose"; this.btnClose.Padding = new System.Windows.Forms.Padding(5); this.btnClose.Size = new System.Drawing.Size(84, 28); @@ -207,16 +173,13 @@ private void InitializeComponent() // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(484, 350); + this.ClientSize = new System.Drawing.Size(484, 300); this.Controls.Add(this.btnTestUrl); this.Controls.Add(this.btnLogin); this.Controls.Add(this.btnClose); this.Controls.Add(this.btnUpload); this.Controls.Add(this.lblStatus); this.Controls.Add(this.progressBar); - this.Controls.Add(this.btnBrowse); - this.Controls.Add(this.txtDirectory); - this.Controls.Add(this.lblDirectory); this.Controls.Add(this.grpUploadType); this.Controls.Add(this.lblUploadType); this.Controls.Add(this.txtServerUrl); @@ -240,9 +203,6 @@ private void InitializeComponent() private DarkLabel lblUploadType; private DarkRadioButton rbClientAssets; private DarkRadioButton rbEditorAssets; - private DarkLabel lblDirectory; - private DarkTextBox txtDirectory; - private DarkButton btnBrowse; private DarkButton btnUpload; private new DarkButton btnClose; private System.Windows.Forms.ProgressBar progressBar; diff --git a/Intersect.Editor/Forms/FrmUploadToServer.cs b/Intersect.Editor/Forms/FrmUploadToServer.cs index 976ddc1bf1..0b54bb6359 100644 --- a/Intersect.Editor/Forms/FrmUploadToServer.cs +++ b/Intersect.Editor/Forms/FrmUploadToServer.cs @@ -8,6 +8,7 @@ using System.Net.Http.Headers; using System.Security.Cryptography; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using DarkUI.Forms; @@ -31,6 +32,8 @@ public FrmUploadToServer() { InitializeComponent(); Icon = Program.Icon; + // Automatically set directory to Editor's current directory + _selectedDirectory = Environment.CurrentDirectory; LoadSettings(); FormClosing += FrmUploadToServer_FormClosing; } @@ -58,14 +61,6 @@ private void LoadSettings() rbEditorAssets.Checked = savedType == "editor"; rbClientAssets.Checked = !rbEditorAssets.Checked; - var savedDirectory = Preferences.LoadPreference("upload_lastDirectory"); - if (!string.IsNullOrWhiteSpace(savedDirectory) && Directory.Exists(savedDirectory)) - { - _selectedDirectory = savedDirectory; - txtDirectory.Text = savedDirectory; - // Don't enable upload here - let UpdateAuthenticationStatus handle it - } - var rawTokenResponse = Preferences.LoadPreference(nameof(TokenResponse)); if (!string.IsNullOrWhiteSpace(rawTokenResponse)) { @@ -95,14 +90,12 @@ private void UpdateAuthenticationStatus() { lblStatus.Text = "✓ Authenticated - Ready to upload"; btnLogin.Text = "Re-Login"; - // Only enable upload if we have authentication AND a directory selected - btnUpload.Enabled = !string.IsNullOrWhiteSpace(_selectedDirectory) && Directory.Exists(_selectedDirectory); + btnUpload.Enabled = true; } else { lblStatus.Text = "⚠ Not authenticated - Please click the Login button below to authenticate"; btnLogin.Text = "Login"; - // Disable upload when not authenticated btnUpload.Enabled = false; } @@ -310,34 +303,6 @@ private void SaveSettings() { Preferences.SavePreference("upload_serverUrl", txtServerUrl.Text); Preferences.SavePreference("upload_type", rbEditorAssets.Checked ? "editor" : "client"); - - if (!string.IsNullOrWhiteSpace(_selectedDirectory)) - { - Preferences.SavePreference("upload_lastDirectory", _selectedDirectory); - } - } - - private void btnBrowse_Click(object sender, EventArgs e) - { - using var folderDialog = new FolderBrowserDialog - { - Description = Strings.UploadToServer.SourceDirectoryPrompt, - ShowNewFolderButton = false - }; - - var lastDir = Preferences.LoadPreference("upload_lastDirectory"); - if (!string.IsNullOrWhiteSpace(lastDir) && Directory.Exists(lastDir)) - { - folderDialog.SelectedPath = lastDir; - } - - if (folderDialog.ShowDialog() == DialogResult.OK) - { - _selectedDirectory = folderDialog.SelectedPath; - txtDirectory.Text = _selectedDirectory; - // Only enable upload if authenticated - btnUpload.Enabled = _tokenResponse != null && !IsTokenExpired(_tokenResponse); - } } private async void btnUpload_Click(object sender, EventArgs e) @@ -366,22 +331,21 @@ private async void btnUpload_Click(object sender, EventArgs e) return; } - if (string.IsNullOrWhiteSpace(_selectedDirectory) || - !Directory.Exists(_selectedDirectory)) + SaveSettings(); + + // Check if we should package assets before uploading + var packageUpdateAssets = Preferences.LoadPreference("PackageUpdateAssets"); + if (!string.IsNullOrWhiteSpace(packageUpdateAssets) && + Convert.ToBoolean(packageUpdateAssets, CultureInfo.InvariantCulture)) { - DarkMessageBox.ShowError( - Strings.UploadToServer.InvalidDirectory, - Strings.UploadToServer.Title, - DarkDialogButton.Ok, - Icon - ); - return; + Globals.PackingProgressForm = new FrmProgress(); + Globals.PackingProgressForm.SetTitle(Strings.AssetPacking.title); + var assetThread = new Thread(() => frmMain.packAssets(_selectedDirectory, this)); + assetThread.Start(); + _ = Globals.PackingProgressForm.ShowDialog(); } - SaveSettings(); - btnUpload.Enabled = false; - btnBrowse.Enabled = false; txtServerUrl.Enabled = false; rbClientAssets.Enabled = false; rbEditorAssets.Enabled = false; @@ -406,7 +370,6 @@ private async void btnUpload_Click(object sender, EventArgs e) finally { btnUpload.Enabled = true; - btnBrowse.Enabled = true; txtServerUrl.Enabled = true; rbClientAssets.Enabled = true; rbEditorAssets.Enabled = true; diff --git a/Intersect.Editor/Forms/frmMain.cs b/Intersect.Editor/Forms/frmMain.cs index 9d1f051e84..a6d5ade189 100644 --- a/Intersect.Editor/Forms/frmMain.cs +++ b/Intersect.Editor/Forms/frmMain.cs @@ -1774,7 +1774,7 @@ private void packClientTexturesToolStripMenuItem_Click(object sender, EventArgs } - private void packAssets(string rootDirectory) + public static void packAssets(string rootDirectory, Form parentForm = null) { //TODO: Make packing heuristic that the texture packer class should use configurable. var preferenceMusicPackSize = Preferences.LoadPreference("MusicPackSize"); @@ -1784,7 +1784,7 @@ private void packAssets(string rootDirectory) if (!int.TryParse(preferenceMusicPackSize, out var musicPackSize)) { _ = MessageBox.Show( - this, + parentForm, Strings.Errors.UnableToParseInvalidIntegerFormat.ToString(preferenceMusicPackSize), Strings.Errors.InvalidInputXCaption.ToString(Strings.Options.MusicPackSize), MessageBoxButtons.OK, @@ -1796,7 +1796,7 @@ private void packAssets(string rootDirectory) if (!int.TryParse(preferenceSoundPackSize, out var soundPackSize)) { _ = MessageBox.Show( - this, + parentForm, Strings.Errors.UnableToParseInvalidIntegerFormat.ToString(preferenceSoundPackSize), Strings.Errors.InvalidInputXCaption.ToString(Strings.Options.SoundPackSize), MessageBoxButtons.OK, @@ -1808,7 +1808,7 @@ private void packAssets(string rootDirectory) if (!int.TryParse(preferenceTexturePackSize, out var texturePackSize)) { _ = MessageBox.Show( - this, + parentForm, Strings.Errors.UnableToParseInvalidIntegerFormat.ToString(preferenceTexturePackSize), Strings.Errors.InvalidInputXCaption.ToString(Strings.Options.TextureSize), MessageBoxButtons.OK, @@ -2097,7 +2097,7 @@ private void PackageUpdate() { Globals.PackingProgressForm = new FrmProgress(); Globals.PackingProgressForm.SetTitle(Strings.AssetPacking.title); - var assetThread = new Thread(() => packAssets(sourceDirectory)); + var assetThread = new Thread(() => packAssets(sourceDirectory, this)); assetThread.Start(); _ = Globals.PackingProgressForm.ShowDialog(); }