private static BaseRegistryValue ParseValue(DiffingToken token, RegistryKey parent = null) { BaseRegistryValue value; // TODO value = new RegistryString { IsVisible = true, Name = token.Token[1], Value = token.Token[2] }; //switch (valueToken.Type) //{ // case RegistryValueType.REG_SZ: // value = new RegistryString // { // Name = valueToken.Name, // Value = valueToken.Value // }; // break; // case RegistryValueType.REG_DWORD: // value = new RegistryDWORD // { // Name = valueToken.Name, // Value = valueToken.Value // }; // break; // default: // value = new RegistryString // { // Name = valueToken.Name // }; // break; //} value.IsInA = token.IsInA; value.IsInB = token.IsInB; value.HasDifference = !value.IsInB || !value.IsInA; if (value.HasDifference && parent != null) { parent.HasDifference = true; } return(value); }
private static async Task <int> ParseKeyAsync(DiffingToken token, DiffingToken[] tokens, int startIndex, RegistryKey key, IProgress <ProgressIncrement> progress, RegistryKey parent = null) { bool ShouldContinue(int index) { return(index < tokens.Length && tokens[index].Token[0].StartsWith(token.Token[0])); } key.Path = token.Token[0]; key.Name = token.Token[0].Split('\\').Last(); key.HasDifference = !key.IsInB || !key.IsInA; if (key.HasDifference && parent != null) { parent.HasDifference = true; } for (; ShouldContinue(startIndex); startIndex++) { var nextToken = tokens[startIndex]; // Registry key. if (nextToken.Token.Length == 1) { var nextKey = new RegistryKey { IsInA = nextToken.IsInA, IsInB = nextToken.IsInB }; startIndex = await ParseKeyAsync(nextToken, tokens, startIndex + 1, nextKey, progress, key); if (key.HasDifference && parent != null) { parent.HasDifference = true; } key.Keys.Add(nextKey); } // Registry value. else if (nextToken.Token.Length == 3) { key.Values.Add(ParseValue(nextToken, key)); if (key.HasDifference && parent != null) { parent.HasDifference = true; } } if (startIndex + 1 % 3726 == 0) { var progressIncrement = new ProgressIncrement { Current = startIndex + 1, Message = $"Building view... ({startIndex + 1} of {tokens.Length})", Total = tokens.Length }; await Task.Run(() => progress?.Report(progressIncrement)); } } return(--startIndex); }