Exemple #1
0
        //load SQLProduct from meta
        public SQLProduct(string filePath)
        {
            SQLProduct p = (SQLProduct)OutputProcessor.DeserializeFromXML <SQLProduct>(filePath);

            this.msiPackages = p.msiPackages;
            this.mspPackages = p.mspPackages;

            if (p != null)
            {
                //    Controller.gSQLProduct.InitOrAddHashSet(this);
            }
        }
        public static void LoadSQLProductFromSetupSrc()
        {
            LastSQLSetupSource = SQLSetupSource;
            //  string path = @"D:\SETUP Media\2016";
            //  path = @"\\sqlbuilds\Released\SQLServer2016\RTM\13.0.1601.5\release\editions\SQLFull_CHS";
            UpdateProgress("Scanning MSI/MSP packages from:" + SQLSetupSource, true);
            //   SQLProduct sql2016 = new SQLProduct("SQL2016", SQLSetupSource);
            //  sqlProducts.Add(sql2016);

            string folder = Utility.CleanFileName(SQLSetupSource);

            if (folder.Length > 20)
            {
                folder = folder.Substring(0, 10) + "..." + folder.Substring(folder.Length - 10);
            }

            string name = "Cached_" + folder + System.DateTime.Now.ToString("_yyyy-MM-dd_HH_mm_ss");

            SQLProduct sql = new SQLProduct(name, SQLSetupSource);


            try
            {
                //Save it temp folder so that we can copy it to data folder.
                string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                //string path2 = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
                path = Path.Combine(path, "Cache");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                sumFromSetupSrc = new SQLProductSum(name, SQLSetupSource, "By SQLMsiMspScan.");
                sumFromSetupSrc.InitOrAddHashSet(sql);
                string file    = Path.Combine(path, name + ".sum.xml");
                string content = OutputProcessor.DataContractSerializeToXML <SQLProductSum>(sumFromSetupSrc);
                File.WriteAllText(file, content);
            }
            catch (Exception ex)
            {
                Logger.LogError(ex.Message);
            }
        }
        public void InitOrAddHashSet(SQLProduct me)
        {
            Logger.LogMsg("InitOrAddHashSet started.");
            int ignore = 0;
            int cnt    = 0;

            foreach (MsiPackage pkg in me.msiPackages)
            {
                //If closing
                if (Controller.shouldAbort)
                {
                    return;
                }


                cnt++;

                try
                {
                    //Ignore Visual Studio related things?

                    if (string.IsNullOrEmpty(pkg.ProductName))
                    {
                        ignore++;
                        Controller.UpdateProgress("[Ignore]" + pkg.PackageName + " because product name is empty", true);
                        continue;
                    }

                    /*
                     * if ((pkg.ProductName.ToLower().Contains("visual studio")
                     || pkg.ProductName.ToLower().Contains("visualstudio")))
                     ||{
                     || ignore++;
                     || Controller.UpdateProgress("[Ignore]" + pkg.PackageName + " " + pkg.ProductName, true);
                     || continue;
                     ||}
                     */
                    //I want to ignore those redist packages

                    if (pkg.FullPath.ToLower().Contains("redist"))
                    {
                        ignore++;
                        Controller.UpdateProgress("[Ignore]" + pkg.FullPath, true);
                        continue;
                    }


                    Controller.UpdateProgress("Analyzing meta data for (" + cnt + ") " + pkg.PackageName, false);

                    if (!String.IsNullOrEmpty(pkg.ProductCode) && !productCodes.Contains(pkg.ProductCode))
                    {
                        string compressedPd = Utility.ConvertGUID2CompressedRegistryStyle(pkg.ProductCode);
                        productCodes.Add(pkg.ProductCode);
                        compressedProductCodes.Add(compressedPd);
                        if (!productCodeToName.ContainsKey(compressedPd))
                        {
                            productCodeToName.Add(compressedPd, pkg.ProductName);
                        }
                    }

                    if (pkg.TransformProductCodes != null)
                    {
                        foreach (string pc in pkg.TransformProductCodes)
                        {
                            if (!String.IsNullOrEmpty(pc) && !productCodes.Contains(pc))
                            {
                                string compd = Utility.ConvertGUID2CompressedRegistryStyle(pc);
                                productCodes.Add(pc);
                                compressedProductCodes.Add(compd);
                                if (!productCodeToName.ContainsKey(compd))
                                {
                                    productCodeToName.Add(compd, pkg.ProductName);
                                }
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(pkg.PackageName))
                    {
                        string name = Path.GetFileName(pkg.PackageName).ToLower();
                        if (!packageNames.Contains(name))
                        {
                            packageNames.Add(name);
                            if (!packageToName.ContainsKey(name))
                            {
                                packageToName.Add(name, pkg.ProductName);
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(pkg.UpgradeCode))
                    {
                        if (!upgradeCodes.Contains(pkg.UpgradeCode))
                        {
                            string ugrpd = Utility.ConvertGUID2CompressedRegistryStyle(pkg.UpgradeCode);
                            upgradeCodes.Add(pkg.UpgradeCode);
                            compressedUpgradeCodes.Add(ugrpd);
                            if (!upgradeCodeToName.ContainsKey(ugrpd))
                            {
                                upgradeCodeToName.Add(ugrpd, pkg.ProductName);
                            }
                        }
                    }


                    if (!string.IsNullOrEmpty(pkg.PackageCode))
                    {
                        if (!PackageCodes.Contains(pkg.PackageCode))
                        {
                            string pkgcd = Utility.ConvertGUID2CompressedRegistryStyle(pkg.PackageCode);
                            PackageCodes.Add(pkg.UpgradeCode);

                            compressedPackageCodes.Add(pkgcd);
                            if (!packageCodeToName.ContainsKey(pkgcd))
                            {
                                packageCodeToName.Add(pkgcd, pkg.ProductName);
                            }
                        }
                    }

                    foreach (string f in pkg.Files)
                    {
                        if (!files_EXE_DLL.Contains(f) &&
                            (f.ToLower().EndsWith(".dll") || f.ToLower().EndsWith(".exe"))
                            )
                        {
                            files_EXE_DLL.Add(f.ToLower());
                        }
                    }



                    foreach (MsiRegistry mr in pkg.MsiRegistries)
                    {
                        AddKey(mr);
                    }
                }
                catch (Exception ex)
                {
                    Controller.UpdateProgress("[InitOrAddHashSet]" + pkg.PackageName + "\n" + ex.Message, true);
                }
            }//foreach



            //for MSP

            cnt = 0;
            foreach (MspPackage pkg in me.mspPackages)
            {
                //If closing
                if (Controller.shouldAbort)
                {
                    return;
                }

                cnt++;
                Controller.UpdateProgress("Analyzing meta data for (" + cnt + ") " + pkg.PackageName, false);

                try
                {
                    if (string.IsNullOrEmpty(pkg.DisplayName))
                    {
                        ignore++;
                        Controller.UpdateProgress("[Ignore]" + pkg.PackageName + " because DisplayName  is empty", true);
                        continue;
                    }

                    /*
                     * //ignore Visual Studio thing
                     * if ((pkg.DisplayName.ToLower().Contains("visual studio")
                     || pkg.DisplayName.ToLower().Contains("visualstudio")))
                     ||{
                     || Controller.UpdateProgress("[Ignore]" + pkg.PackageName + " " + pkg.DisplayName, true);
                     || continue;
                     ||}
                     */
                    //I want to ignore those redist packages

                    if (pkg.FullPath.ToLower().Contains("redist"))
                    {
                        ignore++;
                        Controller.UpdateProgress("[Ignore]" + pkg.FullPath, true);
                        continue;
                    }


                    if (!string.IsNullOrEmpty(pkg.PackageName))
                    {
                        string name = Path.GetFileName(pkg.PackageName).ToLower();
                        if (!packageNames.Contains(name))
                        {
                            packageNames.Add(name);
                            if (!packageToName.ContainsKey(name))
                            {
                                packageToName.Add(name, pkg.DisplayName);
                            }
                        }
                    }


                    if (!string.IsNullOrEmpty(pkg.PatchCode))
                    {
                        if (!patchCodes.Contains(pkg.PatchCode))
                        {
                            string pcd = Utility.ConvertGUID2CompressedRegistryStyle(pkg.PatchCode);
                            patchCodes.Add(pkg.PatchCode);
                            compressedPatchCodes.Add(pcd);
                            if (!patchCodeToName.ContainsKey(pcd))
                            {
                                patchCodeToName.Add(pcd, pkg.DisplayName);
                            }
                        }
                    }



                    if (!string.IsNullOrEmpty(pkg.TargetProductName))
                    {
                        if (!targetProductNames.Contains(pkg.TargetProductName))
                        {
                            targetProductNames.Add(pkg.TargetProductName);
                            if (!othersToName.ContainsKey(pkg.TargetProductName))
                            {
                                othersToName.Add(pkg.TargetProductName, pkg.DisplayName);
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(pkg.KBArticle))
                    {
                        if (!kbArticles.Contains(pkg.KBArticle.ToLower()))
                        {
                            kbArticles.Add(pkg.KBArticle.ToLower());
                            if (!othersToName.ContainsKey(pkg.KBArticle))
                            {
                                othersToName.Add(pkg.KBArticle.ToLower(), pkg.DisplayName);
                            }
                        }
                    }

                    if (!string.IsNullOrEmpty(pkg.Targets))
                    {
                        if (!targets.Contains(pkg.Targets))
                        {
                            targets.Add(pkg.Targets);
                            if (!othersToName.ContainsKey(pkg.Targets))
                            {
                                othersToName.Add(pkg.Targets, pkg.DisplayName);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Controller.UpdateProgress("[InitOrAddHashSet]" + pkg.PackageName + "\n" + ex.Message, true);
                }
            }//foreach

            // LoadSQLProductFromSetupSrc is called before LoadSQLProductFromMetaData,
            //so below information will tell how many new things got from user speficied folder.

            Controller.UpdateProgress("==============================================", true);
            Controller.UpdateProgress("Source:" + me.source, true);
            Controller.UpdateProgress(me.msiPackages.Count + " MSI packages meta data processed.", true);
            Controller.UpdateProgress(me.mspPackages.Count + " MSP packages meta data processed.", true);
            Controller.UpdateProgress("==============================================", true);
            Controller.UpdateProgress("Cumulative results:", true);
            Controller.UpdateProgress("Unique Packgage Name:" + packageNames.Count, true);
            Controller.UpdateProgress("Ignore Packgages:" + ignore, true);
            Controller.UpdateProgress("Package Codes:" + PackageCodes.Count, true);
            Controller.UpdateProgress("Product Codes:" + productCodes.Count, true);
            Controller.UpdateProgress("Patch Codes:" + patchCodes.Count, true);
            Controller.UpdateProgress("Upgrade Codes:" + upgradeCodes.Count, true);
            Controller.UpdateProgress("EXE/DLL files:" + files_EXE_DLL.Count, true);
            Controller.UpdateProgress("Registries:" + MsiRegistries.Count, true);
            Controller.UpdateProgress("KB Articles:" + kbArticles.Count, true);
            Controller.UpdateProgress("targetProductNames:" + targetProductNames.Count, true);
            Controller.UpdateProgress("targets:" + targets.Count, true);

            Controller.UpdateProgress("==============================================", true);
            Controller.UpdateProgress("");
        }//function