コード例 #1
0
ファイル: ProjectScanner.cs プロジェクト: ianrmurphy/bigbug
        /**
         * @brief Scans a project location of file and fills the BBCodeBase.
         * @param projectPath is path to a directory or a single file.
         * @param supportedFileExtensions string array of extensions.
         * @param bbCodeBase clears all entries in this object and adds the new entries.
         * @return true if entries are found.
         */
        public static bool Scan(string projectPath, string[] supportedFileExtensions, ref BBCodeBase bbCodeBase)
        {
            // Create an empty BBCode database.
            bbCodeBase = new BBCodeBase();

            // Check if the given is a file or directory.
            if (File.Exists(projectPath))
            {
                // Scan single file.
                ScanSingleFile(projectPath, ref bbCodeBase);
            }
            else
            {
                // Create empty file list.
                string[] fileList = { };

                // Try to get file names under the selected path.
                try
                {
                    fileList = Directory.GetFiles(projectPath, "*.*", SearchOption.AllDirectories);
                }
                catch { };

                // Get the selected path and make sure that its not empty.
                if (fileList.Length > 0)
                {
                    // Iterate all files under the selected path.
                    foreach (string fileName in fileList)
                    {
                        // Check the file extension for allowed extensions.
                        if (File.Exists(fileName) && ((fileList.Length == 1) || supportedFileExtensions.Contains(Path.GetExtension(fileName).TrimStart('.'))))
                        {
                            ScanSingleFile(fileName, ref bbCodeBase);
                        }
                    }
                }
            }

            // Success if descriptors are found.
            return(bbCodeBase.GetCodeCount() > 0);
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: ianrmurphy/bigbug
        /**
         * @brief New Project button event, loads the Recent project path from the settings
         *        and shown folder browser.
         * @param sender
         * @param e
         */
        private void buttonNewProject_Click(object sender, EventArgs e)
        {
            // Load Recent opened folder and set it to the folder browser initial path.
            browserNewProject.SelectedPath = settings.LoadSetting("General.RecentProject");

            // Show browser.
            if (browserNewProject.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Get supported file extensions.
                string   supportedFileExtensionsString = (settings.LoadSetting("User.FileExtensions") != "") ? settings.LoadSetting("User.FileExtensions") : Properties.Resources.supportedFileExtensions;
                string[] supportedFileExtensions       = supportedFileExtensionsString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                // Use ProjectScanner to scan all files.
                if (!ProjectScanner.Scan(browserNewProject.SelectedPath, supportedFileExtensions, ref bbCodeBase))
                {
                    MessageBox.Show("No BBCode Descriptor has been found under the selected path.");
                }

                // Remember the project name including the number of recognized BBCode entries.
                projectName = Path.GetFileName(browserNewProject.SelectedPath) + " #" + bbCodeBase.GetCodeCount();

                // Set visuals for ProjectOpen state.
                SetVisuals(GetVisuals() | VisualStates.ProjectOpen);

                // Save teh successfuly opened project path.
                settings.SaveSetting("General.RecentProject", browserNewProject.SelectedPath);
            }
        }