diff --git a/EVEData/Anom.cs b/EVEData/Anom.cs index 3b4ff693..90d1a09b 100644 --- a/EVEData/Anom.cs +++ b/EVEData/Anom.cs @@ -81,8 +81,8 @@ public enum SignatureType public string Type { get; set; } /// - /// To String + /// Convert to string, keeping the in-game format so that the string can be imported back into SMT /// - public override string ToString() => Signature + " " + Type + " " + Name; + public override string ToString() => Signature + "\t" + "Cosmic Signature" + "\t" + Type + "\t" + Name + "\t\t"; } } \ No newline at end of file diff --git a/EVEData/AnomData.cs b/EVEData/AnomData.cs index c6a86193..6ed65f85 100644 --- a/EVEData/AnomData.cs +++ b/EVEData/AnomData.cs @@ -40,82 +40,64 @@ public AnomData() /// Update the AnomData from the string (usually the clipboard) /// /// raw Anom strings - public void UpdateFromPaste(string pastedText) + /// HashSet of anom IDs present in the dictionary but missing from the pasted text + public HashSet UpdateFromPaste(string pastedText) { - bool validPaste = false; - List itemsToKeep = new List(); + HashSet signaturesPresent = new HashSet(); + string[] pastelines = pastedText.Split('\n'); foreach (string line in pastelines) { // split on tabs string[] words = line.Split('\t'); - if (words.Length == 6) - { - // only care about "Cosmic Signature" - if (CosmicSignatureTags.Contains(words[1])) - { - validPaste = true; - - string sigID = words[0]; - string sigType = words[2]; - string sigName = words[3]; - - if (string.IsNullOrEmpty(sigType)) - { - sigType = "Unknown"; - } - - itemsToKeep.Add(sigID); - - // valid sig - if (Anoms.ContainsKey(sigID)) - { - // updating an existing one - Anom an = Anoms[sigID]; - if (an.Type == "Unknown") - { - an.Type = sigType; - } - - if (!string.IsNullOrEmpty(sigName)) - { - an.Name = sigName; - } - } - else - { - Anom an = new Anom(); - an.Signature = sigID; - an.Type = sigType; - - if (!string.IsNullOrEmpty(sigName)) - { - an.Name = sigName; - } - - Anoms.Add(sigID, an); - } - } - } - } - // if we had a valid paste dump any items we didnt reference, brute force scan and remove.. come back to this later.. - if (validPaste) - { - List toRemove = new List(); - foreach (string an in Anoms.Keys.ToList()) + if (words.Length != 6) + continue; + + // only care about "Cosmic Signature" + if (!CosmicSignatureTags.Contains(words[1])) + continue; + + string sigID = words[0]; + string sigType = words[2]; + string sigName = words[3]; + + if (string.IsNullOrEmpty(sigType)) + sigType = "Unknown"; + + signaturesPresent.Add(sigID); + + if (Anoms.ContainsKey(sigID)) { - if (!itemsToKeep.Contains(an)) - { - toRemove.Add(an); - } - } + // update an existing signature + Anom an = Anoms[sigID]; - foreach (string s in toRemove) + if (an.Type == "Unknown") + an.Type = sigType; + + if (!string.IsNullOrEmpty(sigName)) + an.Name = sigName; + } + else { - Anoms.Remove(s); + // add a new signature + Anom an = new Anom(); + an.Signature = sigID; + an.Type = sigType; + + if (!string.IsNullOrEmpty(sigName)) + an.Name = sigName; + + Anoms.Add(sigID, an); } } + + // find existing signatures that are missing from the paste + var signaturesMissing = Anoms.Where(kvp => !signaturesPresent.Contains(kvp.Value.Signature)) + .Select(kvp => kvp.Key) + .ToHashSet(); + + return signaturesMissing; } } } \ No newline at end of file diff --git a/SMT/MainWindow.xaml b/SMT/MainWindow.xaml index fa140a8e..162209b7 100644 --- a/SMT/MainWindow.xaml +++ b/SMT/MainWindow.xaml @@ -20,6 +20,7 @@ + @@ -114,43 +115,68 @@ - + - + - + + -