From d3f557290a643dd7c4e98d782af92fd6dcf1ef06 Mon Sep 17 00:00:00 2001 From: cadaei Date: Tue, 24 Dec 2019 12:37:45 +0100 Subject: [PATCH] collection files can be dropped to open them. --- ARKBreedingStats/Form1.Designer.cs | 8 ++-- ARKBreedingStats/Form1.collection.cs | 14 +++--- ARKBreedingStats/Form1.cs | 72 +++++++++++++++------------- 3 files changed, 50 insertions(+), 44 deletions(-) diff --git a/ARKBreedingStats/Form1.Designer.cs b/ARKBreedingStats/Form1.Designer.cs index c9606fc4..36978115 100644 --- a/ARKBreedingStats/Form1.Designer.cs +++ b/ARKBreedingStats/Form1.Designer.cs @@ -1582,7 +1582,6 @@ private void InitializeComponent() // // tabPageExtractor // - this.tabPageExtractor.AllowDrop = true; this.tabPageExtractor.AutoScroll = true; this.tabPageExtractor.Controls.Add(this.llOnlineHelpExtractionIssues); this.tabPageExtractor.Controls.Add(this.groupBoxRadarChartExtractor); @@ -1607,8 +1606,6 @@ private void InitializeComponent() this.tabPageExtractor.TabIndex = 0; this.tabPageExtractor.Text = "Extractor"; this.tabPageExtractor.UseVisualStyleBackColor = true; - this.tabPageExtractor.DragDrop += new System.Windows.Forms.DragEventHandler(this.FileDropedOnExtractor); - this.tabPageExtractor.DragEnter += new System.Windows.Forms.DragEventHandler(this.TestEnteredDragData); // // llOnlineHelpExtractionIssues // @@ -1825,8 +1822,6 @@ private void InitializeComponent() this.tabPageLibrary.TabIndex = 2; this.tabPageLibrary.Text = "Library"; this.tabPageLibrary.UseVisualStyleBackColor = true; - this.tabPageLibrary.DragDrop += new System.Windows.Forms.DragEventHandler(this.FileDropedOnExtractor); - this.tabPageLibrary.DragEnter += new System.Windows.Forms.DragEventHandler(this.TestEnteredDragData); // // tableLayoutPanelLibrary // @@ -3218,6 +3213,7 @@ private void InitializeComponent() // Form1 // this.AcceptButton = this.btExtractLevels; + this.AllowDrop = true; this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1232, 841); @@ -3234,6 +3230,8 @@ private void InitializeComponent() this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing); this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed); this.Load += new System.EventHandler(this.Form1_Load); + this.DragDrop += new System.Windows.Forms.DragEventHandler(this.Form1_DragDrop); + this.DragEnter += new System.Windows.Forms.DragEventHandler(this.Form1_DragEnter); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownImprintingBonusTester)).EndInit(); diff --git a/ARKBreedingStats/Form1.collection.cs b/ARKBreedingStats/Form1.collection.cs index 0dfbf5d5..568d6921 100644 --- a/ARKBreedingStats/Form1.collection.cs +++ b/ARKBreedingStats/Form1.collection.cs @@ -19,13 +19,11 @@ public partial class Form1 private void NewCollection() { - if (collectionDirty) - { - if (MessageBox.Show("Your Creature Collection has been modified since it was last saved, " + + if (collectionDirty + && MessageBox.Show("Your Creature Collection has been modified since it was last saved, " + "are you sure you want to discard your changes and create a new Library without saving?", - "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) - return; - } + "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) + return; if (creatureCollection.modIDs?.Count > 0) { @@ -104,7 +102,7 @@ private void LoadCollection(bool add = false) { if (!add && collectionDirty) { - if (MessageBox.Show("Your Creature Collection has been modified since it was last saved, are you sure you want to load without saving first?", "Discard Changes?", MessageBoxButtons.YesNo) == DialogResult.No) + if (MessageBox.Show("Your Creature Collection has been modified since it was last saved, are you sure you want to load without saving first?", "Discard Changes?", MessageBoxButtons.YesNo) != DialogResult.Yes) return; } using (OpenFileDialog dlg = new OpenFileDialog @@ -280,6 +278,8 @@ private bool LoadCollectionFile(string filePath, bool keepCurrentCreatures = fal if (!modFound && MessageBox.Show("The additional-values file in the library you're loading is unknown. You should first get a values-file in the new format for that mod.\n" + "If you're loading the library the conversion of some modded species to the new format may fail and the according creatures have to be imported again later.\n\n" + + $"File:\n{filePath}\n" + + $"unknown mod-file: {modTag}\n\n" + "Do you want to load the library and risk losing creatures?", "Unknown mod-file", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) return false; diff --git a/ARKBreedingStats/Form1.cs b/ARKBreedingStats/Form1.cs index 67cf0f18..02a9cbe4 100644 --- a/ARKBreedingStats/Form1.cs +++ b/ARKBreedingStats/Form1.cs @@ -152,8 +152,6 @@ public Form1() ArkOCR.OCR.setOCRControl(ocrControl1); ocrControl1.updateWhiteThreshold += OcrupdateWhiteThreshold; - ocrControl1.dragEnter += TestEnteredDragData; - ocrControl1.dragDrop += FileDropedOnExtractor; settingsToolStripMenuItem.ShortcutKeyDisplayString = new KeysConverter().ConvertTo(Keys.Control, typeof(string))?.ToString().Replace("None", ","); @@ -2061,36 +2059,6 @@ private void CreateTimer(string name, DateTime time, Creature c, string group) timerList1.AddTimer(name, time, c, group); } - private void TestEnteredDragData(object sender, DragEventArgs e) - { - if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; - } - - /// - /// If a file was dropped onto the extractor, try to extract it as an exported creature, perform an ocr on an image, or if it's a folder, import all included files. - /// - /// - /// - private void FileDropedOnExtractor(object sender, DragEventArgs e) - { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); - if (files.Length > 0) - { - string file = files[0]; - if (File.GetAttributes(file).HasFlag(FileAttributes.Directory)) - { - ShowExportedCreatureListControl(); - exportedCreatureList.loadFilesInFolder(file); - } - else if (file.Substring(file.Length - 4).ToLower() == ".ini") - { - ExtractExportedFileInExtractor(file); - } - else - DoOCR(files[0]); - } - } - /// /// Performs an optical character recognition on either the specified image or a screenshot of the game and extracts the stat-values. /// @@ -3051,6 +3019,46 @@ private void AdminCommandToSetColors() } } + private void Form1_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy; + } + + /// + /// If a file was dropped onto the extractor, try to extract it as an exported creature, perform an ocr on an image, or if it's a folder, import all included files. + /// + /// + /// + private void Form1_DragDrop(object sender, DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files.Length == 0) return; + + string filePath = files[0]; + string ext = Path.GetExtension(filePath).ToLower(); + if (File.GetAttributes(filePath).HasFlag(FileAttributes.Directory)) + { + ShowExportedCreatureListControl(); + exportedCreatureList.loadFilesInFolder(filePath); + } + else if (ext == ".ini") + { + ExtractExportedFileInExtractor(filePath); + } + else if (ext == ".asb") + { + if (!collectionDirty + || MessageBox.Show("Your Creature Collection has been modified since it was last saved, " + + "are you sure you want to discard your changes and load the file without saving first?", + "Discard Changes?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) + { + LoadCollectionFile(filePath); + } + } + else + DoOCR(files[0]); + } + private void ToolStripMenuItemOpenWiki_Click(object sender, EventArgs e) { if (listViewLibrary.SelectedItems.Count > 0)