Exemple #1
0
        /// <summary>
        /// Compares one snapshot to another and returns the differences
        /// </summary>
        /// <param name="newSnapshot">The snapshot to compare.</param>
        /// <returns>a <see cref="RegistrySnapshot"/> that contains both the added and removed items.</returns>
        public RegistrySnapshot CompareTo(RegistrySnapshot newSnapshot)
        {
            RegistrySnapshot snapshot = new RegistrySnapshot(this.Hive);

            // compare "this" to what is provided, and if what is provided
            // does not have an entry, the consider it deleted.
            foreach (string key in this.Keys)
            {
                if (!newSnapshot.ContainsKey(key))
                {
                    snapshot.Add(key, this[key]);
                    snapshot[key].State = RegistrySnapshotState.Removed;
                }
            }

            // Now compare what was provided to "this" and if entries
            // are missing, then consider then as newly added.
            foreach (string key in newSnapshot.Keys)
            {
                if (!this.ContainsKey(key))
                {
                    snapshot.Add(key, newSnapshot[key]);
                    snapshot[key].State = RegistrySnapshotState.Added;
                }
            }

            return(snapshot);
        }