diff --git a/ARKBreedingStats/Form1.collection.cs b/ARKBreedingStats/Form1.collection.cs
index cc2bb4bf..87201cd7 100644
--- a/ARKBreedingStats/Form1.collection.cs
+++ b/ARKBreedingStats/Form1.collection.cs
@@ -793,11 +793,12 @@ private void OpenRecentlyUsedFile(object sender, EventArgs e)
///
/// Imports creature from file created by the export gun mod.
- /// Returns true if the last imported creature already exists in the library.
+ /// Returns already existing Creature or null if it's a new creature.
///
- private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, out Creature lastAddedCreature)
+ private Creature ImportExportGunFiles(string[] filePaths, out bool creatureAdded, out Creature lastAddedCreature, out bool copiedNameToClipboard)
{
creatureAdded = false;
+ copiedNameToClipboard = false;
var newCreatures = new List();
var importedCounter = 0;
@@ -807,8 +808,10 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
string serverMultipliersHash = null;
bool? multipliersImportSuccessful = null;
string serverImportResult = null;
- bool creatureAlreadyExists = false;
+ Creature alreadyExistingCreature = null;
var gameSettingBefore = _creatureCollection.Game;
+ Species lastSpecies = null;
+ Creature[] creaturesOfSpecies = null;
foreach (var filePath in filePaths)
{
@@ -818,6 +821,10 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
newCreatures.Add(c);
importedCounter++;
lastCreatureFilePath = filePath;
+
+ IsCreatureAlreadyInLibrary(c.guid, c.ArkId, out alreadyExistingCreature);
+ copiedNameToClipboard = SetNameOfImportedCreature(c, lastSpecies == c.Species ? creaturesOfSpecies : null, out creaturesOfSpecies, alreadyExistingCreature);
+ lastSpecies = c.Species;
}
else if (lastError != null)
{
@@ -861,7 +868,6 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
lastAddedCreature = newCreatures.LastOrDefault();
if (lastAddedCreature != null)
{
- creatureAlreadyExists = IsCreatureAlreadyInLibrary(lastAddedCreature.guid, lastAddedCreature.ArkId, out _);
creatureAdded = true;
}
@@ -887,7 +893,7 @@ private bool ImportExportGunFiles(string[] filePaths, out bool creatureAdded, ou
SelectCreatureInLibrary(lastAddedCreature);
}
- return creatureAlreadyExists;
+ return alreadyExistingCreature;
}
///
diff --git a/ARKBreedingStats/Form1.cs b/ARKBreedingStats/Form1.cs
index 684f2f67..adfb17e7 100644
--- a/ARKBreedingStats/Form1.cs
+++ b/ARKBreedingStats/Form1.cs
@@ -3357,7 +3357,7 @@ private void ProcessDroppedFiles(string[] files)
OpenCompressedFile(filePath, true);
return;
case ".ini" when files.Length == 1:
- ExtractExportedFileInExtractor(filePath);
+ ExtractExportedFileInExtractor(filePath, out _);
break;
case ".ini":
ShowExportedCreatureListControl();
@@ -3365,7 +3365,7 @@ private void ProcessDroppedFiles(string[] files)
break;
case ".sav":
case ".json":
- ImportExportGunFiles(files, out _, out _);
+ ImportExportGunFiles(files, out _, out _, out _);
break;
case ".asb":
case ".xml":
diff --git a/ARKBreedingStats/Form1.extractor.cs b/ARKBreedingStats/Form1.extractor.cs
index efc2db3a..d978780c 100644
--- a/ARKBreedingStats/Form1.extractor.cs
+++ b/ARKBreedingStats/Form1.extractor.cs
@@ -867,9 +867,10 @@ private void CopyExtractionToClipboard()
/// Returns true if the creature already exists in the library.
/// Returns null if file couldn't be loaded.
///
- private bool? ExtractExportedFileInExtractor(string exportFilePath)
+ private bool? ExtractExportedFileInExtractor(string exportFilePath, out bool nameCopiedToClipboard)
{
CreatureValues cv = null;
+ nameCopiedToClipboard = false;
// if the file is blocked, try it again
const int waitingTimeBase = 200;
@@ -917,7 +918,7 @@ private void CopyExtractionToClipboard()
&& LoadModValuesOfCollection(_creatureCollection, true, true)
&& oldModHash != _creatureCollection.modListHash)
{
- return ExtractExportedFileInExtractor(exportFilePath);
+ return ExtractExportedFileInExtractor(exportFilePath, out nameCopiedToClipboard);
}
return false;
@@ -926,7 +927,7 @@ private void CopyExtractionToClipboard()
tabControlMain.SelectedTab = tabPageExtractor;
bool creatureAlreadyExists = ExtractValuesInExtractor(cv, exportFilePath, true);
- GenerateCreatureNameAndCopyNameToClipboardIfSet(creatureAlreadyExists);
+ nameCopiedToClipboard= GenerateCreatureNameAndCopyNameToClipboardIfSet(creatureAlreadyExists);
return creatureAlreadyExists;
}
@@ -935,7 +936,7 @@ private void CopyExtractionToClipboard()
/// Copies the creature name to the clipboard if the conditions according to the user settings are fulfilled.
///
///
- private void GenerateCreatureNameAndCopyNameToClipboardIfSet(bool creatureAlreadyExists)
+ private bool GenerateCreatureNameAndCopyNameToClipboardIfSet(bool creatureAlreadyExists)
{
if (Properties.Settings.Default.applyNamePatternOnAutoImportAlways
|| (Properties.Settings.Default.applyNamePatternOnImportIfEmptyName
@@ -945,13 +946,10 @@ private void GenerateCreatureNameAndCopyNameToClipboardIfSet(bool creatureAlread
)
{
CreatureInfoInput_CreatureDataRequested(creatureInfoInputExtractor, false, false, false, 0);
- if (Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied)
- {
- Clipboard.SetText(string.IsNullOrEmpty(creatureInfoInputExtractor.CreatureName)
- ? ""
- : creatureInfoInputExtractor.CreatureName);
- }
+ return CopyCreatureNameToClipboardOnImportIfSetting(creatureInfoInputExtractor.CreatureName);
}
+
+ return false;
}
///
@@ -974,7 +972,6 @@ private void ExtractExportedFileInExtractor(importExported.ExportedCreatureContr
creatureInfoInputExtractor.CreatureOwner += _exportedCreatureList.ownerSuffix;
}
-
///
/// Sets the values of a creature to the extractor and extracts its levels.
/// It returns true if the creature is already present in the library.
diff --git a/ARKBreedingStats/Form1.importExported.cs b/ARKBreedingStats/Form1.importExported.cs
index 76ec1ab5..406ac141 100644
--- a/ARKBreedingStats/Form1.importExported.cs
+++ b/ARKBreedingStats/Form1.importExported.cs
@@ -121,7 +121,7 @@ private void ImportLastExportedCreature()
firstExportFolder.FolderPath = lastExportFile.DirectoryName;
exportFolders[0] = firstExportFolder.ToString();
- ExtractExportedFileInExtractor(lastExportFile.FullName);
+ ExtractExportedFileInExtractor(lastExportFile.FullName, out _);
}
return;
}
@@ -132,7 +132,7 @@ private void ImportLastExportedCreature()
{
case ".ini":
// ini files need to be processed by the extractor
- ExtractExportedFileInExtractor(newestExportFile);
+ ExtractExportedFileInExtractor(newestExportFile, out _);
return;
case ".sav":
case ".json":
@@ -195,7 +195,7 @@ private Creature ImportExportedAddIfPossible(string filePath)
switch (Path.GetExtension(filePath))
{
case ".ini":
- var loadResult = ExtractExportedFileInExtractor(filePath);
+ var loadResult = ExtractExportedFileInExtractor(filePath, out copiedNameToClipboard);
if (loadResult == null) return null;
alreadyExists = loadResult.Value;
@@ -210,40 +210,13 @@ private Creature ImportExportedAddIfPossible(string filePath)
SetMessageLabelText($"Successful {(alreadyExists ? "updated" : "added")} {creature.name} ({species.name}) of the exported file\r\n" + filePath, MessageBoxIcon.Information, filePath);
addedToLibrary = true;
}
-
- copiedNameToClipboard = Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied
- && (Properties.Settings.Default.applyNamePatternOnAutoImportAlways
- || Properties.Settings.Default.applyNamePatternOnImportIfEmptyName
- || (!alreadyExists && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures)
- );
break;
case ".sav":
case ".json":
- alreadyExists = ImportExportGunFiles(new[] { filePath }, out addedToLibrary, out creature);
+ var alreadyExistingCreature = ImportExportGunFiles(new[] { filePath }, out addedToLibrary, out creature, out copiedNameToClipboard);
+ alreadyExists = alreadyExistingCreature != null;
if (!addedToLibrary || creature == null) return null;
uniqueExtraction = true;
-
- if (Properties.Settings.Default.applyNamePatternOnAutoImportAlways
- || (Properties.Settings.Default.applyNamePatternOnImportIfEmptyName
- && string.IsNullOrEmpty(creature.name))
- || (!alreadyExists
- && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures)
- )
- {
- creaturesOfSpecies = _creatureCollection.creatures.Where(c => c.Species == creature.Species).ToArray();
- creature.name = NamePattern.GenerateCreatureName(creature, creaturesOfSpecies,
- _topLevels.TryGetValue(creature.Species, out var topLevels) ? topLevels : null,
- _lowestLevels.TryGetValue(creature.Species, out var lowestLevels) ? lowestLevels : null,
- _customReplacingNamingPattern, false, 0);
-
- if (Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied)
- {
- Clipboard.SetText(string.IsNullOrEmpty(creature.name)
- ? ""
- : creature.name);
- copiedNameToClipboard = true;
- }
- }
break;
default: return null;
}
@@ -343,6 +316,59 @@ private Creature ImportExportedAddIfPossible(string filePath)
return addedToLibrary ? creature : null;
}
+ ///
+ /// Sets the name of an imported creature and copies it to the clipboard depending on the user settings.
+ ///
+ /// True if name was copied to clipboard
+ private bool SetNameOfImportedCreature(Creature creature, Creature[] creaturesOfSpeciesIn, out Creature[] creaturesOfSpecies, Creature alreadyExistingCreature)
+ {
+ creaturesOfSpecies = creaturesOfSpeciesIn;
+ if (ApplyNamingPattern(creature, alreadyExistingCreature))
+ {
+ // don't overwrite existing ASB creature name with empty ingame name
+ if (!string.IsNullOrEmpty(alreadyExistingCreature?.name) && string.IsNullOrEmpty(creature.name))
+ {
+ creature.name = alreadyExistingCreature.name;
+ }
+ else
+ {
+ if (creaturesOfSpecies == null)
+ creaturesOfSpecies = _creatureCollection.creatures.Where(c => c.Species == creature.Species)
+ .ToArray();
+ creature.name = NamePattern.GenerateCreatureName(creature, creaturesOfSpecies,
+ _topLevels.TryGetValue(creature.Species, out var topLevels) ? topLevels : null,
+ _lowestLevels.TryGetValue(creature.Species, out var lowestLevels) ? lowestLevels : null,
+ _customReplacingNamingPattern, false, 0);
+ }
+
+ return CopyCreatureNameToClipboardOnImportIfSetting(creature.name);
+ }
+
+ return false;
+ }
+
+ ///
+ /// Returns true if the naming pattern should be applied according to the settings.
+ ///
+ private bool ApplyNamingPattern(Creature creature, Creature alreadyExistingCreature) =>
+ Properties.Settings.Default.applyNamePatternOnAutoImportAlways
+ || (Properties.Settings.Default.applyNamePatternOnImportIfEmptyName
+ && string.IsNullOrEmpty(creature.name))
+ || (alreadyExistingCreature == null
+ && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures);
+
+ ///
+ /// Copies name to clipboard if the according setting is enabled. Returns true if copied.
+ ///
+ private bool CopyCreatureNameToClipboardOnImportIfSetting(string creatureName)
+ {
+ if (!Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied) return false;
+ Clipboard.SetText(string.IsNullOrEmpty(creatureName)
+ ? ""
+ : creatureName);
+ return true;
+ }
+
///
/// Give feedback in overlay for imported creature.
///