/// <summary> /// Checks whether the specified object equals the current one /// (does not take the <see cref="IsDefault"/> property into account). /// </summary> /// <param name="other">Object to compare with.</param> /// <returns>true, if the specified object equals the current one; otherwise false.</returns> public bool Equals(LogWriterConfiguration other) { return(mBaseLevel == other.mBaseLevel && NamePatterns.SequenceEqual(other.NamePatterns) && TagPatterns.SequenceEqual(other.TagPatterns) && Includes.SequenceEqual(other.Includes) && Excludes.SequenceEqual(other.Excludes)); }
/// <summary> /// Import exported file. Used by a fileWatcher. /// </summary> /// <param name="filePath"></param> private void ImportExportedAddIfPossible(string filePath) { var loadResult = ExtractExportedFileInExtractor(filePath); if (!loadResult.HasValue) { return; } bool alreadyExists = loadResult.Value; bool added = false; bool copyNameToClipboard = Properties.Settings.Default.copyNameToClipboardOnImportWhenAutoNameApplied && (Properties.Settings.Default.applyNamePatternOnAutoImportAlways || Properties.Settings.Default.applyNamePatternOnImportIfEmptyName || (!alreadyExists && Properties.Settings.Default.applyNamePatternOnAutoImportForNewCreatures) ); Species species = speciesSelector1.SelectedSpecies; Creature creature = null; if (_extractor.UniqueResults || (alreadyExists && _extractor.ValidResults)) { creature = AddCreatureToCollection(true, goToLibraryTab: Properties.Settings.Default.AutoImportGotoLibraryAfterSuccess); SetMessageLabelText($"Successful {(alreadyExists ? "updated" : "added")} {creature.name} ({species.name}) of the exported file\n" + filePath, MessageBoxIcon.Information, filePath); 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} \"{creature.name}\" {(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.statNames)}: { _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); } if (_overlay != null) { _overlay.SetInfoText(infoText, textColor); if (Properties.Settings.Default.DisplayInheritanceInOverlay && creature != null) { _overlay.SetInheritanceCreatures(creature, creature.Mother, creature.Father); } } if (added) { if (Properties.Settings.Default.DeleteAutoImportedFile) { FileService.TryDeleteFile(filePath); } else if (Properties.Settings.Default.MoveAutoImportedFileToSubFolder || Properties.Settings.Default.AutoImportedExportFileRename) { string newPath = Properties.Settings.Default.MoveAutoImportedFileToSubFolder ? (string.IsNullOrEmpty(Properties.Settings.Default.ImportExportedArchiveFolder) ? Path.Combine(Path.GetDirectoryName(filePath), "imported") : Properties.Settings.Default.ImportExportedArchiveFolder) : Path.GetDirectoryName(filePath); if (Properties.Settings.Default.MoveAutoImportedFileToSubFolder && !FileService.TryCreateDirectory(newPath, out string errorMessage)) { MessageBoxes.ShowMessageBox($"Subfolder\n{newPath}\ncould not be created.\n{errorMessage}"); return; } string namePattern = Properties.Settings.Default.AutoImportedExportFileRenamePattern; string newFileName = Properties.Settings.Default.AutoImportedExportFileRename && !string.IsNullOrWhiteSpace(namePattern) ? NamePatterns.GenerateCreatureName(creature, _creatureCollection.creatures.Where(c => c.Species == speciesSelector1.SelectedSpecies).ToArray(), null, null, _customReplacingNamingPattern, false, -1, false, namePattern) : Path.GetFileName(filePath); string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFileName); string newFileNameExtension = Path.GetExtension(newFileName); string newFilePath = Path.Combine(newPath, newFileName); int fileSuffix = 1; while (File.Exists(newFilePath)) { newFilePath = Path.Combine(newPath, $"{newFileNameWithoutExtension}_{++fileSuffix}{newFileNameExtension}"); } if (FileService.TryMoveFile(filePath, newFilePath)) { _librarySelectionInfoClickPath = newFilePath; } } } 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 (alreadyExists) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Indifferent); } if (newTopLevels) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Great); } else if (topLevels) { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Good); } else { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Success); } } else { SoundFeedback.BeepSignal(SoundFeedback.FeedbackSounds.Failure); } } }