Skip to content

Commit

Permalink
collection files can be dropped to open them.
Browse files Browse the repository at this point in the history
  • Loading branch information
cadaei committed Dec 24, 2019
1 parent 2208f4b commit d3f5572
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
8 changes: 3 additions & 5 deletions ARKBreedingStats/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions ARKBreedingStats/Form1.collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
72 changes: 40 additions & 32 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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", ",");

Expand Down Expand Up @@ -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;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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]);
}
}

/// <summary>
/// Performs an optical character recognition on either the specified image or a screenshot of the game and extracts the stat-values.
/// </summary>
Expand Down Expand Up @@ -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;
}

/// <summary>
/// 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.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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)
Expand Down

0 comments on commit d3f5572

Please sign in to comment.