Пример #1
0
        //load processed data from PreData folder
        public static SQLProductSum LoadSQLProductFromMetaData()
        {
            SQLProductSum sum  = null;
            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, "MetaData");
            if (!Directory.Exists(path))
            {
                Logger.LogMsg("[LoadSQLProductFromMetaData]Data folder doesn't exist:" + path);
                return(null);
            }

            UpdateProgress("Loading MSI/MSP meta data from:" + path + ", may take minutes...", true);

            List <string> xmlFiles = Utility.GetFilesFromFolder(path, new string[] { "*.xml" });
            SQLProductSum totalSum = new SQLProductSum("All-Pre-Sum", "Pre-MetaData", "Merge All sum in predata folder into one");

            foreach (string f in xmlFiles)
            {
                try
                {
                    UpdateProgress("Reading MSI/MSP meta data from pre-processed data:" + Path.GetFileName(f) + ", may take minutes...", true);
                    sum = OutputProcessor.DataContractDeSerializeToXML <SQLProductSum>(f);
                    totalSum.AddProductSum(sum);
                }
                catch (Exception ex)
                {
                    Logger.LogError("[LoadSQLProductFromMetaData]:" + ex.Message);
                }
            }

            return(totalSum);
        }
Пример #2
0
        public void AddProductSum(SQLProductSum newsum)
        {
            this.source      = this.source + "|" + newsum.source;
            this.name        = this.name + "|" + newsum.name;
            this.description = this.description + "|" + newsum.description;

            packageNames.UnionWith(newsum.packageNames);
            productCodes.UnionWith(newsum.productCodes);
            compressedProductCodes.UnionWith(newsum.compressedProductCodes);
            upgradeCodes.UnionWith(newsum.upgradeCodes);
            compressedUpgradeCodes.UnionWith(newsum.compressedUpgradeCodes);
            PackageCodes.UnionWith(newsum.PackageCodes);
            compressedPackageCodes.UnionWith(newsum.compressedPackageCodes);
            patchCodes.UnionWith(newsum.patchCodes);
            compressedPatchCodes.UnionWith(newsum.compressedPatchCodes);
            kbArticles.UnionWith(newsum.kbArticles);
            targetProductNames.UnionWith(newsum.targetProductNames);
            targets.UnionWith(newsum.targets);
            files_EXE_DLL.UnionWith(newsum.files_EXE_DLL);

            MsiRegistries = MsiRegistries.Concat(newsum.MsiRegistries).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);

            productCodeToName = productCodeToName.Union(newsum.productCodeToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
            patchCodeToName   = patchCodeToName.Union(newsum.patchCodeToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
            packageToName     = packageToName.Union(newsum.packageToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
            packageCodeToName = packageCodeToName.Union(newsum.packageCodeToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
            upgradeCodeToName = upgradeCodeToName.Union(newsum.upgradeCodeToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
            othersToName      = othersToName.Union(newsum.othersToName).GroupBy(e => e.Key).ToDictionary(g => g.Key, g => g.First().Value);
        }
Пример #3
0
        }//function

        public void AddProductSumFromFile(string f)
        {
            try
            {
                Logger.LogMsg("AddProductSumFromFile:" + f);
                SQLProductSum sum = OutputProcessor.DataContractDeSerializeToXML <SQLProductSum>(f);
                this.AddProductSum(sum);
            }
            catch (Exception ex)
            {
                Logger.LogError("[AddProductSumFromFile]:" + ex.Message);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public static void ScanSQLRegistry()
        {
            UpdateProgress("Scan starts...", true);

            // var m=LoadSQLProductFromPreData();
            //  m.name = "SQL2008-2017RTM_AllLang";
            //  m.source = "";
            //  m.SaveData("SQL2008-2017RTM_AllLang", @"c:\temp\SQL2008-SQL2017_AllLang.sum.xml");

            ////  LoadSQLProductFromSetupSrc();


            if (sumSQLProduct != null)
            {
                sumSQLProduct.Reset();
            }

            //  SQLProduct sql = new SQLProduct("SQL2012", @"D:\SETUP Media\2016\2016 SQLFull_ENU");
            // SQLProduct sql = new SQLProduct("SQL2012", @"\\shlabprod01\Products\Applications\Server\SQL\SQL Server 2012\SQLFULL");
            //    string data = OutputProcessor.SerializeToXML<SQLProduct>(sql);

            /*
             * string f = @"c:\temp\SQL2016RTM_ENU.xml";
             * //  File.WriteAllText(f, data);
             * SQLProduct sql0 = new SQLProduct(f);
             * sqlProducts.Add(sql0);
             */

            Thread sourceTD = null;

            if (SQLSetupSource != "")
            {
                sourceTD = new Thread(new ThreadStart(LoadSQLProductFromSetupSrc));
                sourceTD.Start();
            }


            //start thread to load registry keys first.
            regHives.Clear();
            normalThreads = LoadRegHives();

            //and also load big Items
            bigThreads = LoadBigItems();

            //Load pre-processed data;
            sumSQLProduct = LoadSQLProductFromMetaData();

            if (!string.IsNullOrEmpty(cachedMetaDataFile))
            {
                sumSQLProduct.AddProductSumFromFile(cachedMetaDataFile);
            }

            if (sourceTD != null)
            {
                sourceTD.Join();
            }


            //Time to merge it.
            if (sumFromSetupSrc != null)
            {
                sumSQLProduct.AddProductSum(sumFromSetupSrc);
            }

            ////Now need to add products to gProduct
            //foreach (SQLProduct sql in Controller.products)
            //{
            //    sumSQLProduct.InitOrAddHashSet(sql);
            //}
            //Time to get SQL related keys
            sqlRegKeys.Clear();

            //wait for all thread loading is completed.
            foreach (Thread th in normalThreads)
            {
                th.Join();
            }

            //If closing
            if (Controller.shouldAbort)
            {
                return;
            }


            Analysis.KnownKeys.Add();
            Analysis.Installer.Add();

            Analysis.Services.Add();
            Analysis.Uninstall.Add();//need to call after Installer.Add because it will reference data geot from installer.Add function
            Analysis.COMClass.Add();

            Analysis.FromMSI.Add();
            //Now generate nodes for treeview

            Logger.LogMsg("Total found SQL related keys:" + sqlRegKeys.Count);
            GenerateRegNodes();

            Logger.LogMsg("UpdateNodeTextWithNodeCount started.");
            RegNode.UpdateNodeTextWithNodeCount(Controller.rootNode);
            Logger.LogMsg("UpdateNodeTextWithNodeCount done.");


            UpdateProgress("Scan done.", true);
            DoneCallBack();
        }