Ejemplo n.º 1
0
        /// <summary>
        /// Sees if the file exists
        /// </summary>
        /// <remarks>Always use this to check for files in the scanners!</remarks>
        /// <param name="filePath">The filename (including path)</param>
        /// <returns>
        /// True if it exists or if the path should be skipped. Otherwise, false if the file path is empty or doesnt exist
        /// </returns>
        public static bool FileExists(string filePath)
        {
            if (string.IsNullOrEmpty(filePath))
            {
                return(false);
            }

            string strFileName = string.Copy(filePath.Trim().ToLower());

            // Remove quotes
            strFileName = UnqouteSpaces(strFileName);

            // Remove environment variables
            strFileName = Environment.ExpandEnvironmentVariables(strFileName);

            // Check for illegal characters
            if (FindAnyIllegalChars(strFileName))
            {
                return(false);
            }

            // Check Drive Type
            VDTReturn ret = ValidDriveType(strFileName);

            if (ret == VDTReturn.InvalidDrive)
            {
                return(false);
            }
            else if (ret == VDTReturn.SkipCheck)
            {
                return(true);
            }

            // See if it is on exclude list
            if (ScanDlg.IsOnIgnoreList(strFileName))
            {
                return(true);
            }

            // Now see if file exists
            if (File.Exists(strFileName))
            {
                return(true);
            }

            if (PathFileExists(strFileName))
            {
                return(true);
            }

            if (SearchPath(strFileName))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sees if the directory exists
        /// </summary>
        /// <remarks>Always use this to check for directories in the scanners!</remarks>
        /// <param name="dirPath">The directory</param>
        /// <returns>True if it exists or if the path should be skipped. Otherwise, false if the file path is empty or doesnt exist</returns>
        public static bool DirExists(string dirPath)
        {
            if (string.IsNullOrEmpty(dirPath))
            {
                return(false);
            }

            string strDirectory = string.Copy(dirPath.Trim().ToLower());

            // Remove quotes
            strDirectory = UnqouteSpaces(strDirectory);

            // Expand environment variables
            strDirectory = Environment.ExpandEnvironmentVariables(strDirectory);

            // Check drive type
            VDTReturn ret = ValidDriveType(strDirectory);

            if (ret == VDTReturn.InvalidDrive)
            {
                return(false);
            }
            else if (ret == VDTReturn.SkipCheck)
            {
                return(true);
            }

            // Check for illegal chars
            if (FindAnyIllegalChars(strDirectory))
            {
                return(false);
            }

            // See if it is on the exclude list
            if (ScanDlg.IsOnIgnoreList(strDirectory))
            {
                return(true);
            }

            // Remove filename.ext and trailing backslash from path
            StringBuilder sb = new StringBuilder(strDirectory);

            if (PathRemoveFileSpec(sb))
            {
                if (Directory.Exists(sb.ToString()))
                {
                    return(true);
                }
            }

            if (Directory.Exists(strDirectory))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Begins scanning the registry
        /// </summary>
        private void ScanRegistry()
        {
            // Clear old results
            this.treeModel.Nodes.Clear();

            // Get number of sections to scan
            int nSectionCount = 0;

            foreach (TreeNode tn in this.treeView1.TopNode.Nodes)
            {
                if (tn.Checked)
                {
                    nSectionCount++;
                }
            }

            if (nSectionCount == 0)
            {
                MessageBox.Show(this, Properties.Resources.mainSelectSections, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Read start time of scan
            DateTime dtStart = DateTime.Now;

            // Create new logger instance + write header
            Main._logger = new Logger(Path.GetTempFileName());

            // Open Scan dialog
            ScanDlg      frmScanBox = new ScanDlg(nSectionCount);
            DialogResult dlgResult  = frmScanBox.ShowDialog(this);

            // See if there are any bad registry keys
            if (ScanDlg.arrBadRegistryKeys.Count > 0)
            {
                // Load bad registry keys
                foreach (BadRegistryKey p in ScanDlg.arrBadRegistryKeys)
                {
                    this.treeModel.Nodes.Add(p);
                }

                // Expand all and Resize columns
                this.treeViewAdvResults.ExpandAll();
                this.treeViewAdvResults.AutoSizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);

                // Show notify box and set status text
                ResourceManager rm = new ResourceManager(this.GetType());
                if (dlgResult == DialogResult.OK)
                {
                    this.notifyIcon1.ShowBalloonTip(6000, Application.ProductName, Properties.Resources.mainScanningFinished, ToolTipIcon.Info);
                    this.toolStripStatusLabel1.Text = Properties.Resources.mainScanningFinished;
                    this.toolStripStatusLabel1.Tag  = "mainScanningFinished";
                }
                else
                {
                    this.notifyIcon1.ShowBalloonTip(6000, Application.ProductName, Properties.Resources.mainScanningAborted, ToolTipIcon.Info);
                    this.toolStripStatusLabel1.Text = Properties.Resources.mainScanningAborted;
                    this.toolStripStatusLabel1.Tag  = "mainScanningAborted";
                }

                // Copy to directory and display log file
                Main.Logger.DisplayLogFile((Properties.Settings.Default.bOptionsAutoRepair && dlgResult == DialogResult.OK));

                // Enable menu items
                this.fixToolStripMenuItem.Enabled = true;
                this.toolStripButtonFix.Enabled   = true;

                // Send usage data to Little Software Stats
                Watcher.EventPeriod("Functions", "Scan Registry", (int)DateTime.Now.Subtract(dtStart).TotalSeconds, (dlgResult == DialogResult.OK));

                // If power user option selected, Automatically fix problems
                if (Properties.Settings.Default.bOptionsAutoRepair && dlgResult == DialogResult.OK)
                {
                    this.FixProblems();
                }
            }
        }