/// <summary>Removes a game box from this library without updating the file.</summary> /// <param name="gameBoxReference">A game box reference.</param> private void removeReference(IGameBoxReference gameBoxReference) { List <GameBoxReference> referenceList; if (gameBoxes.TryGetValue(gameBoxReference.Name.ToUpper(), out referenceList)) { for (int i = 0; i < referenceList.Count; ++i) { if (GameBoxReference.HashAreIdentical(referenceList[i].Hash, gameBoxReference.Hash)) { referenceList.RemoveAt(i); break; } } } }
/// <summary>Adds a game box reference to this library.</summary> /// <param name="gameBoxReference">A game box reference.</param> public void AddReference(IGameBoxReference gameBoxReference) { Debug.Assert(gameBoxReference.Name != null); if (gameBoxReference != defaultGameBox) { string name = gameBoxReference.Name.ToUpper(); List <GameBoxReference> referenceList; if (!gameBoxes.TryGetValue(name, out referenceList)) { referenceList = new List <GameBoxReference>(1); gameBoxes.Add(name, referenceList); } else { foreach (GameBoxReference reference in referenceList) { if (GameBoxReference.HashAreIdentical(reference.Hash, gameBoxReference.Hash)) { // update file path? if (reference.FileName != gameBoxReference.FileName) { removeReference(reference); break; } else { return; } } } } // remove other references pointing to the same file path (at most one normally) foreach (IGameBoxReference otherReference in GameBoxes) { if (otherReference.FileName == gameBoxReference.FileName) { removeReference(otherReference); break; } } referenceList.Add((GameBoxReference)gameBoxReference); updateLibraryFile(); } }
/// <summary>Looks for a game box file in the library.</summary> /// <param name="hash">Hash value of the game box.</param> /// <returns>A game box reference, or null if not found.</returns> public IGameBoxReference FindGameBox(byte[] hash) { Debug.Assert(hash != null); if (GameBoxReference.HashAreIdentical(hash, defaultGameBox.Hash)) { return(defaultGameBox); } else { foreach (List <GameBoxReference> referenceList in gameBoxes.Values) { foreach (GameBoxReference reference in referenceList) { if (GameBoxReference.HashAreIdentical(hash, reference.Hash)) { return(reference); } } } return(null); } }