public myRow(CacheFileStatus status, string nm, string ver, string pn) { Status = status; PackageName = nm; ProductVersion = ver; ProductName = pn; //RowColor = color; }
/// <summary> /// Add row for MSI package /// </summary> /// <param name="p"></param> public myRow(ProductInstallation p) { // if(!string.IsNullOrEmpty(p.ProductName) && ) this.Index = myData.Index++; try { this.ProductVersion = p.ProductVersion.ToString(); if (!string.IsNullOrEmpty(p.AdvertisedPackageCode)) { this.PackageCode = p.AdvertisedPackageCode; } CacheFileStatus stat = CacheFileStatus.Missing; if (!String.IsNullOrEmpty(p.LocalPackage)) { CachedMsiMsp = Path.GetFileName(p.LocalPackage); if (File.Exists(p.LocalPackage)) { try { String ver = MSIHelper.Get(p.LocalPackage, "ProductVersion"); this.CachedMsiMspVersion = ver; string cachedPackageCode = MSIHelper.GetRevisionNumber(p.LocalPackage); if (!string.IsNullOrEmpty(cachedPackageCode) && !string.IsNullOrEmpty(this.PackageCode)) { if (string.Compare(this.PackageCode, cachedPackageCode, StringComparison.Ordinal) != 0) { stat = CacheFileStatus.Mismatched; this.Comment = "Package code doesn't matched. cached file has package code:" + cachedPackageCode + ", but Installer expected:" + this.PackageCode; } } else //if local package exists, but the package code is null, or this.PackageCode is null, set it mismatch { //if both are null, or one is null, set it mismatched if (string.IsNullOrEmpty(cachedPackageCode) || string.IsNullOrEmpty(this.PackageCode)) { stat = CacheFileStatus.Mismatched; this.Comment = "At least one of the package codes is null. cached file has package code:" + cachedPackageCode + ", Installer one:" + this.PackageCode; } } //if (!String.IsNullOrEmpty(this.ProductVersion)) //{ // if (ver != this.ProductVersion) // { // //Cannot set it here, if sp1 applied then production version is sp1 vesion, but cached msi is still RTM version // // stat = CacheFileStatus.Mismatched; // // Comment = p.LocalPackage + ": ProductVersion not matched"; // } //} /* * //Cannot compare product name, sp1/sp2 will change product name... * if (stat != CacheFileStatus.Mismatched) * { * //Cannot compare product name, sp1/sp2 will change product name... * String pn = MSIHelper.Get(p.LocalPackage, "ProductName"); * if (p.ProductName != pn) * { * stat = CacheFileStatus.Mismatched; * Comment = p.LocalPackage + ": ProductName not matched! [" + pn + "] vs [" + p.ProductName + "]"; * } * } */ } catch (Exception ex) { // (any exception) set it to mismatched stat = CacheFileStatus.Mismatched; Comment = ex.Message; Logger.LogError("[Mismatched MSI check failed]" + p.LocalPackage + " \n" + ex.Message); } if (stat != CacheFileStatus.Mismatched) { stat = CacheFileStatus.OK; } } else { stat = CacheFileStatus.Missing; Comment = p.LocalPackage + " doesn't exist."; } } else { stat = CacheFileStatus.Empty; } this.Status = stat; if (p.SourceList != null) { this.PackageName = p.SourceList.PackageName; this.LastUsedSource = p.SourceList.LastUsedSource; } this.InstallDate = p.InstallDate; // this.InstallLocation = p.InstallLocation; this.InstallSource = p.InstallSource; this.IsAdvertised = p.IsAdvertised.ToString(); this.ProductCode = p.ProductCode; this.ProductName = p.ProductName; this.Publisher = p.Publisher; } catch (Exception e) { Logger.LogError("myRow:ProductInstallation:" + e.Message); } }
/// <summary> /// Add row for MSP package /// </summary> /// <param name="p"></param> public myRow(PatchInstallation p) { this.Index = myData.Index++; try { if (!string.IsNullOrEmpty(p.PatchCode)) { this.PatchCode = p.PatchCode; } CacheFileStatus stat = CacheFileStatus.Missing; if (!String.IsNullOrEmpty(p.LocalPackage)) { if (File.Exists(p.LocalPackage)) { try { string cachePatchCode = MSIHelper.GetRevisionNumber(p.LocalPackage); if (!string.IsNullOrEmpty(cachePatchCode) && !string.IsNullOrEmpty(this.PatchCode)) { if (string.Compare(this.PatchCode, cachePatchCode, StringComparison.Ordinal) != 0) { stat = CacheFileStatus.Mismatched; this.Comment = "Patch code doesn't matched. cached file has package code:" + cachePatchCode + ", but Installer expected:" + this.PatchCode; } } else //if local package exists, but the cachePatchCode is null, or this.PatchCode is null, set it mismatch { //if both are null, or one is null, set it mismatched if (string.IsNullOrEmpty(cachePatchCode) || string.IsNullOrEmpty(this.PatchCode)) { stat = CacheFileStatus.Mismatched; this.Comment = "At least one of the patch codes is null. cached file has package code:" + cachePatchCode + ", Installer one:" + this.PatchCode; } } //String ver = MSIHelper.MspGetMetadata(p.LocalPackage, "BaselineVersion"); //if (!String.IsNullOrEmpty(this.ProductVersion)) //{ // if (ver != this.ProductVersion) // { // stat = CacheFileStatus.Mismatched; // Comment = p.LocalPackage + ": BaselineVersion in MSP not matched the ProductVersion in its MSI. If SP applied this could be normal."; // } //} //don't check this. patch code is good enough to check mismatched msp file. /* * if (stat != CacheFileStatus.Mismatched) * { * String pn = MSIHelper.MspGetMetadata(p.LocalPackage, "DisplayName"); * if (p.DisplayName != pn) * { * stat = CacheFileStatus.Mismatched; * Comment = p.LocalPackage + ": DisplayName not matched! Cached file has DisplayName:[" + pn + "] but Installer expected: [" + p.DisplayName + "]"; * } * } */ } catch (Exception ex) { // (any exception) set it to mismatched stat = CacheFileStatus.Mismatched; Comment = ex.Message; Logger.LogError("[Mismatched MSP check failed]" + p.LocalPackage + " \n" + ex.Message); } if (stat != CacheFileStatus.Mismatched) { stat = CacheFileStatus.OK; } } else { stat = CacheFileStatus.Missing; Comment = p.LocalPackage + " doesn't exist"; } } else { stat = CacheFileStatus.Empty; } this.Status = stat; if (p.SourceList != null) { this.PackageName = p.SourceList.PackageName; this.LastUsedSource = p.SourceList.LastUsedSource; } this.InstallDate = p.InstallDate; //patch doesn't have source //this.InstallSource = p.InstallSource; //this.IsAdvertised = p.IsAdvertised.ToString(); this.ProductCode = p.ProductCode; this.ProductName = p.DisplayName; //patch won't have product version // this.ProductVersion = p.ProductVersion.ToString(); // this.Publisher = p.Publisher; this.isPatch = true; if (!String.IsNullOrEmpty(p.LocalPackage)) { CachedMsiMsp = Path.GetFileName(p.LocalPackage); if (File.Exists(p.LocalPackage)) { // CachedMsiMspVersion = MSIHelper.Get(p.LocalPackage, "ProductVersion").ToString(); using (var db = new QDatabase(p.LocalPackage, DatabaseOpenMode.ReadOnly)) { //using try catch since some msp doesn't all this properties try { this.CachedMsiMspVersion = db.ExecuteScalar("SELECT `Value` FROM `MsiPatchMetadata` WHERE `Property` = '{0}'", "PatchVersion") as string; } catch { } try { this.PatchBaselineVersion = db.ExecuteScalar("SELECT `Value` FROM `MsiPatchMetadata` WHERE `Property` = '{0}'", "BaselineVersion") as string; } catch { }; try { this.MoreInfoURL = db.ExecuteScalar("SELECT `Value` FROM `MsiPatchMetadata` WHERE `Property` = '{0}'", "MoreInfoURL") as string; } catch { }; } } } } catch (Exception e) { Logger.LogError("myRow:patch:" + e.Message); } }