public override CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges) { if (!VerifyIfCorrectTestData(data)) { return CheckResult.NotCheckDone(); } var startMenuData = data as StartMenuData; var path = startMenuData.AllUsers ? GetAllUsersMenuFolder() : Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); // To get the program folder var dirInfo = new DirectoryInfo(path); path = Path.Combine(path, dirInfo.GetDirectories()[0].Name); path = Path.Combine(path, startMenuData.Name + ".lnk"); // Find registry GlobalAssocChangedCounter key that is updated when creating a startmenu var globalAssocChangedCounterKey = @"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\explorer"; if (Environment.Is64BitOperatingSystem) { globalAssocChangedCounterKey = @"HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer"; } var registryChange = registryChanges.FirstOrDefault(x => string.Equals(x.Key, globalAssocChangedCounterKey, StringComparison.InvariantCultureIgnoreCase) && x.ValueName == "GlobalAssocChangedCounter" && x.Type == RegistryChangeType.SetValue); var fileChange = fileChanges.FirstOrDefault(x => x.Path == path); return startMenuData.Exist ? CheckDataIfStartMenuIsExpectedToExist(fileChanges, registryChanges, fileChange, startMenuData, registryChange) : CheckDataIfStartMenuIsExpectedToNotExist(fileChanges, registryChanges, fileChange, startMenuData, registryChange); }
public static void AddTestData(bool expectedToBeInstalled, BaseTestData data, ICollection<BaseTestData> testDataCollection) { if (data == null) { throw new ArgumentNullException("data"); } data.Exist = expectedToBeInstalled && data.Condition; // Avoid double copy if (testDataCollection.Contains(data)) { return; } testDataCollection.Add(data); }
public override CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges) { if (!VerifyIfCorrectTestData(data)) { return CheckResult.NotCheckDone(); } var regData = data as RegistryKeyData; var registryChange = registryChanges.FirstOrDefault(x => x.Key == regData.Key && (x.Type == RegistryChangeType.DeleteKey || x.Type == RegistryChangeType.CreateKey)); if (registryChange == null) { if (regData.Exist && !RegistryTool.RegistryKeyExist(regData.Key)) { return CheckResult.Failure("Registry key:'" + regData.Key + "' is supose to exist"); } if (!regData.Exist && RegistryTool.RegistryKeyExist(regData.Key)) { return CheckResult.Failure("Registry key:'" + regData.Key + "' is not supose to exist"); } return CheckResult.Succeeded(data); } if (registryChange.Type == RegistryChangeType.DeleteKey && regData.Exist) { registryChanges.Remove(registryChange); return CheckResult.Failure("Registry key:'" + regData.Key + "' is supose to exist"); } if (registryChange.Type == RegistryChangeType.CreateKey && !regData.Exist) { registryChanges.Remove(registryChange); return CheckResult.Failure("Registry key:'" + regData.Key + "' is NOT supose to exist"); } registryChanges.Remove(registryChange); return CheckResult.Succeeded(data); }
public CheckResult Check(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges) { if (!VerifyIfCorrectTestData(data)) { return CheckResult.NotCheckDone(); } var result = DoCheck(data, fileChanges, registryChanges); if (!result.Success) { Log.WriteCheckError(result.ErrorMessage, Name, data.ComponentID); } else { Log.WriteCheckInfo(result.InfomrationMessage, Name, data.ComponentID); } return result; }
public override CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges) { if (!VerifyIfCorrectTestData(data)) { return CheckResult.NotCheckDone(); } var dirData = data as DirectoryData; var fileChange = fileChanges.FirstOrDefault(x => x.Path == dirData.Path && x.IsDirectory); if (fileChange == null) { //If directory allready exist it may not be created if (dirData.Exist && !Directory.Exists(dirData.Path)) { return CheckResult.Failure("Directory=" + dirData.Path + " is supose to exist"); } if (!dirData.Exist && Directory.Exists(dirData.Path)) { return CheckResult.Failure("Directory=" + dirData.Path + " is not supose to exist"); } return CheckResult.Succeeded(data); } if (fileChange.Type == FileChangeType.Delete && dirData.Exist) { fileChanges.Remove(fileChange); return CheckResult.Failure("Directory=" + dirData.Path + " is supose to exist"); } if (fileChange.Type != FileChangeType.Delete && !dirData.Exist) { fileChanges.Remove(fileChange); return CheckResult.Failure("Directory=" + dirData.Path + " is not supose to exist"); } fileChanges.Remove(fileChange); return CheckResult.Succeeded(data); }
public static CheckResult Succeeded(BaseTestData data) { return new CheckResult { Success = true, InfomrationMessage = data.ToString()}; }
protected bool VerifyIfCorrectTestData(BaseTestData data) { return string.Compare(CheckerDataTypeLoader.FindDataType(data.GetType()), Name, StringComparison.OrdinalIgnoreCase) == 0; }
public abstract CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges);
protected static void AddCommonData(XElement node, BaseTestData data, ICollection<DataProperty> properties) { if (node == null) { throw new ArgumentNullException("node"); } if (data == null) { throw new ArgumentNullException("data"); } if (properties == null) { throw new ArgumentNullException("properties"); } var neverUninstall = XmlTools.GetNamedAttributeValue(node, "neverUnInstall", string.Empty); data.NeverUninstall = !string.IsNullOrEmpty(neverUninstall) && bool.Parse(neverUninstall); var condition = XmlTools.GetNamedAttributeValue(node, "condition", string.Empty); if (!string.IsNullOrEmpty(condition)) { //// Example condition ([VersionNT] > 600) OR ([VersionNT64] > 600) var conditionBakup = condition; condition = DataPropertyTool.ResolvePropertiesInString(properties, condition); condition = condition.Replace(">", ">"); condition = condition.Replace("<", "<"); condition = condition.Replace(" OR ", " || "); condition = condition.Replace(" AND ", " && "); var evalType = evaluatorAssembly.GetType("Evaluator.Evaluator"); var evaluator = Activator.CreateInstance(evalType); string result; try { result = evalType.InvokeMember("Eval", BindingFlags.InvokeMethod, null, evaluator, new object[] {condition}, CultureInfo.InvariantCulture).ToString(); } catch (TargetInvocationException e) { Log.WriteError(conditionBakup + " resolved to " + condition, "AddCommonData"); Log.WriteError(e, "AddCommonData"); throw new InstallerVerificationLibraryException( "Evaluating condition '" + conditionBakup + "' resolved to '" + condition + "' failed", e); } bool res; if (!bool.TryParse(result, out res)) { throw new InstallerVerificationLibraryException("Could not evaluate condition '" + condition + "' in node '" + node + "'"); } data.Condition = res; } else { data.Condition = true; } }
public override CheckResult DoCheck(BaseTestData data, ICollection<FileChange> fileChanges, ICollection<Registryhange> registryChanges) { if (!VerifyIfCorrectTestData(data)) { return CheckResult.NotCheckDone(); } var regData = data as RegistryValueData; UpdateRegDataIfValueIsShortPath(regData); var registryChange = registryChanges.FirstOrDefault(x => x.Key == regData.Key && x.ValueName == regData.Name && (x.Type == RegistryChangeType.SetValue || x.Type == RegistryChangeType.DeleteValue)); if (registryChange == null) { // In repair scenario MSI will not do any registry change if the correct value is allready there // ValueName = (Default) is the root key and doesn't have any name var value = RegistryTool.RegistryValue(regData.Key, regData.Name == "(Default)" ? "" : regData.Name, null); if (regData.Exist && (value == null || value.ToString() != regData.Data)) { return CheckResult.Failure("Registry key:'" + regData.Key + "' valueName: " + regData.Name + " is supose to exist"); } if (!regData.Exist && value != null) { return CheckResult.Failure("Registry key:'" + regData.Key + "' valueName: " + regData.Name + " is not supose to exist"); } return CheckResult.Succeeded(data); } if (registryChange.Type == RegistryChangeType.DeleteValue && regData.Exist) { registryChanges.Remove(registryChange); return CheckResult.Failure("Registry key:'" + regData.Key + "' valueName: " + regData.Name + " is supose to exist"); } if (registryChange.Type == RegistryChangeType.SetValue && !regData.Exist) { registryChanges.Remove(registryChange); return CheckResult.Failure("Registry key:'" + regData.Key + "' valueName: " + regData.Name + "' is NOT supose to exist"); } if (registryChange.Type == RegistryChangeType.SetValue) { switch (regData.DataCmpMethod) { case RegistryValueData.DataComparisonMethod.Equal: if (string.Compare(registryChange.Value, regData.Data, StringComparison.OrdinalIgnoreCase) == 0) { registryChanges.Remove(registryChange); return CheckResult.Succeeded(data); } break; case RegistryValueData.DataComparisonMethod.Contains: if (registryChange.Value.ToLowerInvariant().Contains(regData.Data.ToLowerInvariant())) { registryChanges.Remove(registryChange); return CheckResult.Succeeded(data); } break; } } else { registryChanges.Remove(registryChange); return CheckResult.Succeeded(data); } registryChanges.Remove(registryChange); return CheckResult.Failure("Registry Key:'" + regData.Key + "' with valueName='" + regData.Name + "' should be '" + regData.Data + "' but it is '" + registryChange.Value + "'"); }