Esempio n. 1
0
        public void GenerateCleanupScript(TreeNode node)
        {
            //at this moment, the functionality to generate cleanup script for a node (not root) is removed. but the code is here still.

            string[] result = null;
            string   name   = "";

            if (RegNode.IsMeOrParentSQLRoot(node))
            {
                result = GetCleanUpForKey(node.Name);
            }

            else
            {
                //we should export all its child keys which are SQL exclusively owned.



                if (node == Controller.rootNode)
                {
                    result = GetCleanup("");
                }
                else
                {
                    result = GetCleanup(node.Name);
                }
            }
            name = Utility.CleanFileName(node.Name);
            SaveCleanupScript(name, result);
        }
Esempio n. 2
0
        public static void BackgroundTask()
        {
            //Here we start new thread to load Components which is too big to load so i loaded it in background.
            //List<Thread> bigThreads = LoadBigItems();
            foreach (Thread th in bigThreads)
            {
                th.Join();
            }

            //Now start another thread to compare the Component key.
            if (Controller.shouldAbort)
            {
                return;
            }

            Thread thComponents = new Thread(new ThreadStart(Analysis.Installer.Add_HKLM_Components));

            thComponents.Start();
            thComponents.Join();

            if (Controller.shouldAbort)
            {
                return;
            }


            GenerateNodeForBigItems();

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

            DoneBGCallBack();
        }
Esempio n. 3
0
        public static void GenerateRegNodes()
        {
            UpdateProgress("Generating treeview nodes from sqlRegKeys:" + sqlRegKeys.Keys.Count + " keys...", true);

            rootNode.Nodes.Clear();
            RegNode.nodesList.Clear();
            int           cnt  = 0;
            List <string> keys = sqlRegKeys.Keys.OrderBy(p => p).ToList();//sort them to avoid the treeview node sorter.

            foreach (string regkey in keys)
            {
                // HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server
                if (cnt % 500 == 0)
                {
                    Controller.UpdateProgress("Processing " + regkey, false);
                    //If closing
                    if (Controller.shouldAbort)
                    {
                        return;
                    }
                }
                cnt++;

                RegNode.AddKey(rootNode, regkey);
            }
        }
Esempio n. 4
0
        //background task completed.
        public void DoneBGCallBack()
        {
            myform.BeginInvoke((MethodInvoker) delegate
            {
                string msg = "Background task finished, update treeview, may take minutes...";
                Logger.LogMsg(msg);
                lblInfo.Text = msg;
                lblInfo.Refresh();

                //now bigItems load completed. now need to add it to my node.

                foreach (string key in Controller.bigKeys.Keys)
                {
                    TreeNode node = RegNode.FindFromTree(Controller.rootNodeBig, key);
                    if (node != null)
                    {
                        int idx       = key.LastIndexOf("\\");
                        string parent = key.Substring(0, idx);
                        //TreeNode pnode = RegNode.FindFromTree(Controller.rootNode, parent);

                        TreeNode pnode        = RegNode.FindLowestParent(Controller.rootNode, node);
                        TreeNode bigRightNode = RegNode.FindFromTree(Controller.rootNodeBig, pnode.Name);
                        if (pnode != null && bigRightNode != null)
                        {
                            foreach (TreeNode nd in bigRightNode.Nodes)
                            {
                                pnode.Nodes.Add(nd);
                            }
                            RegNode.UpdateParentNodeText(pnode);
                        }
                        else
                        {
                            if (pnode == null)
                            {
                                Logger.LogMsg("pnode is null.");
                            }
                            if (bigRightNode == null)
                            {
                                Logger.LogMsg("bigRightNode is null.");
                            }
                            Logger.LogError("node's parent not found:" + node.Name);
                        }
                    }
                    else
                    {
                        Logger.LogError("node not found for big key:" + key);
                    }
                }

                exportMenu.Enabled = exportToolStripMenuItem.Enabled = true;
                scanRegistryToolStripMenuItem.Enabled = true;
                findToolStripMenuItem.Enabled         = findToolStripMenuItem1.Enabled = true;
                findNextToolStripMenuItem.Enabled     = true;


                Logger.LogMsg("TreeView updated.");
                lblInfo.Text = "";
                MessageBox.Show("Scan Finished.", "Finish", MessageBoxButtons.OK, MessageBoxIcon.Information);
            });
        }
Esempio n. 5
0
        private void Go()
        {
            RegNode.lastFindText = textBox1.Text.Trim();

            if (!string.IsNullOrEmpty(textBox1.Text.Trim()))
            {
                bool isFound = RegNode.Find(textBox1.Text.Trim());
                if (isFound)
                {
                    this.DialogResult = DialogResult.Yes;
                }
                else
                {
                    this.DialogResult = DialogResult.No;
                }
            }
        }
Esempio n. 6
0
        private void propertyGrid_SelectionChanged(object sender, EventArgs e)
        {
            int cnt = propertyGrid.SelectedCells.Count;

            if (cnt == 0)
            {
                return;
            }
            int minCol = 0;
            int minRow = 0;

            minRow = Math.Max(propertyGrid.SelectedCells[0].RowIndex, minRow);
            minCol = Math.Max(propertyGrid.SelectedCells[0].ColumnIndex, minCol);
            for (int i = 1; i < cnt; i++)
            {
                minRow = Math.Min(propertyGrid.SelectedCells[i].RowIndex, minRow);
                minCol = Math.Min(propertyGrid.SelectedCells[i].ColumnIndex, minCol);
            }
            RegNode.SetSelectedInfo(minRow, minCol);
            //   textBox2.Text = minRow + ":" + minCol;
        }
Esempio n. 7
0
        private void SelectNode(TreeNode nd)
        {
            TreeNode node = nd;

            RegNode.treeViewSelectedNode = node;
            textBox1.Text = node.Name;
            textBox2.Text = "";
            SetDataSource(node);

            RegNode.SetSelectedInfo(-1, -1);
            propertyGrid.ClearSelection();

            if (node.Tag != null && ((RegKey)node.Tag).IsSQLRoot)
            {
                if (Controller.sqlRegKeys.ContainsKey(node.Name))
                {
                    Reason r = Controller.sqlRegKeys[node.Name];
                    textBox2.Text = "Reason:" + (String.IsNullOrEmpty(r.comment) ? r.tag : r.comment);
                }
            }
        }
Esempio n. 8
0
        public static void GenerateNodeForBigItems()
        {
            int           cnt  = 0;
            List <string> keys = sqlRegKeys.Keys.OrderBy(p => p).ToList();//sort them to avoid the treeview node sorter.

            foreach (string s in bigKeys.Keys)
            {
                foreach (string regkey in keys)
                {
                    if (regkey.StartsWith(s))
                    {
                        if (cnt % 500 == 0)
                        {
                            Controller.UpdateProgress("Processing " + regkey, false);
                        }
                        cnt++;

                        RegNode.AddKey(rootNodeBig, regkey);
                    }
                }
            }
        }
Esempio n. 9
0
 private void findNextToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(RegNode.lastFindText))
     {
         bool isFound = RegNode.Find(RegNode.lastFindText);
         if (isFound)
         {
             RegNode.findResult.node.TreeView.SelectedNode = RegNode.findResult.node;
             SetSelectedForGrid();
             if (RegNode.findResult.isNodeText)
             {
                 this.regTree.Focus();
             }
             else
             {
                 this.propertyGrid.Focus();
             }
         }
         else
         {
             MessageBox.Show("Key not found!", "Not Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Esempio n. 10
0
        public void SetDataSource(TreeNode node)
        {
            RegNode.SetSelectedInfo(-1, -1);

            if (node.Tag == null)
            {
                propertyGrid.DataSource = null;
                propertyGrid.Rows.Clear();
                return;
            }
            List <RegProperty> lst = ((RegKey)node.Tag).RegProperties;

            if (lst != null)
            {
                BindingList <RegProperty> blst = new BindingList <RegProperty>(lst);
                BindingSource             src  = new BindingSource(blst, null);
                propertyGrid.DataSource = src;
            }
            else
            {
                propertyGrid.DataSource = null;
                propertyGrid.Rows.Clear();
            }
        }
Esempio n. 11
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();
        }