/// <summary> /// Import exported file. Used by a fileWatcher. /// </summary> /// <param name="filePath"></param> private void ImportExportedAddIfPossible(string filePath) { bool alreadyExists = ExtractExportedFileInExtractor(filePath); bool added = false; bool copyNameToClipboard = Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied && (Properties.Settings.Default.applyNamePatternOnImportIfEmptyName || (!alreadyExists && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures)); Species species = speciesSelector1.SelectedSpecies; if (_extractor.uniqueResults || (alreadyExists && _extractor.validResults)) { AddCreatureToCollection(true, goToLibraryTab: false); SetMessageLabelText($"Successful {(alreadyExists ? "updated" : "added")} {creatureInfoInputExtractor.CreatureName} ({species.name}) of the exported file\n" + filePath, MessageBoxIcon.Information); added = true; } bool topLevels = false; bool newTopLevels = false; // give feedback in overlay string infoText; Color textColor; const int colorSaturation = 200; if (added) { var sb = new StringBuilder(); sb.AppendLine($"{species.name} \"{creatureInfoInputExtractor.CreatureName}\" {(alreadyExists ? "updated in " : "added to")} the library."); if (copyNameToClipboard) { sb.AppendLine("Name copied to clipboard."); } for (int s = 0; s < values.Values.STATS_COUNT; s++) { int statIndex = values.Values.statsDisplayOrder[s]; if (!species.UsesStat(statIndex)) { continue; } sb.Append($"{Utils.StatName(statIndex, true, species.IsGlowSpecies)}: {_statIOs[statIndex].LevelWild} ({_statIOs[statIndex].BreedingValue})"); if (_statIOs[statIndex].TopLevel == StatIOStatus.NewTopLevel) { sb.Append($" {Loc.S("newTopLevel")}"); newTopLevels = true; } else if (_statIOs[statIndex].TopLevel == StatIOStatus.TopLevel) { sb.Append($" {Loc.S("topLevel")}"); topLevels = true; } sb.AppendLine(); } infoText = sb.ToString(); textColor = Color.FromArgb(colorSaturation, 255, colorSaturation); } else { infoText = $"Creature \"{creatureInfoInputExtractor.CreatureName}\" couldn't be extracted uniquely, manual level selection is necessary."; textColor = Color.FromArgb(255, colorSaturation, colorSaturation); } _overlay?.SetInfoText(infoText, textColor); if (added) { if (Properties.Settings.Default.MoveAutoImportedFileToSubFolder) { string importedPath = Path.Combine(Path.GetDirectoryName(filePath), "imported"); if (!FileService.TryCreateDirectory(importedPath, out string errorMessage)) { MessageBox.Show($"Subfolder\n{importedPath}\ncould not be created.\n{errorMessage}", $"{Loc.S("error")} - {Utils.ApplicationNameVersion}", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FileService.TryMoveFile(filePath, Path.Combine(importedPath, Path.GetFileName(filePath))); } else if (Properties.Settings.Default.DeleteAutoImportedFile) { FileService.TryDeleteFile(filePath); } } else if (copyNameToClipboard) { // extraction failed, user might expect the name of the new creature in the clipboard Clipboard.SetText("Automatic extraction was not possible"); } if (Properties.Settings.Default.PlaySoundOnAutoImport) { if (added) { if (newTopLevels) { Utils.BeepSignal(3); } else if (topLevels) { Utils.BeepSignal(2); } else { Utils.BeepSignal(1); } } else { Utils.BeepSignal(0); } } }