Skip to content
This repository was archived by the owner on Aug 9, 2025. It is now read-only.

Commit b5b2fc1

Browse files
committed
Code cleanup
1 parent a5b1556 commit b5b2fc1

File tree

1 file changed

+49
-53
lines changed

1 file changed

+49
-53
lines changed

CPPCheckPlugin/CPPCheckPluginPackage.cs

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,12 @@ private static async Task<SourceFile> createSourceFileAsync(ProjectItem item)
708708
// Do the file-level first in case it disables inheritance. Include files don't have file-level config.
709709
if (implementsInterface(fileConfig.Tool, "Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool"))
710710
{
711+
VCCLCompilerTool vcTool = (VCCLCompilerTool)fileConfig.Tool;
711712
sourceForAnalysis = new SourceFile(item.FileNames[1], projectDirectory, projectName, toolSetName);
712-
includePaths = fileConfig.Tool.FullIncludePath.Split(';');
713-
714-
// Other details may be gathered from the file, project or any inherited property sheets.
715-
recursiveAddToolDetails(sourceForAnalysis, vcconfig, fileConfig.Tool, null, ref bInheritDefs, ref bInheritUndefs);
713+
includePaths = vcTool.FullIncludePath.Split(';');
714+
string macros = vcTool.PreprocessorDefinitions;
715+
// Other details may be gathered from the file, project or any inherited property sheets.
716+
recursiveAddToolDetails(sourceForAnalysis, vcconfig, vcTool, null, ref bInheritDefs, ref bInheritUndefs);
716717
}
717718

718719
// Now get the full include path
@@ -762,23 +763,31 @@ private async void scanProgressUpdated(int filesScanned)
762763
await JoinableTaskFactory.SwitchToMainThreadAsync();
763764

764765
EnvDTE.StatusBar statusBar = _dte.StatusBar;
765-
if (statusBar != null)
766+
if (statusBar == null)
767+
return;
768+
769+
try
766770
{
767-
try
771+
if (filesScanned >= 0)
768772
{
769-
if (filesScanned >= 0)
770-
{
771-
string label = "cppcheck scanning for files (" + filesScanned + ")";
772-
773-
statusBar.Text = label;
774-
}
775-
else
776-
{
777-
statusBar.Clear();
778-
}
773+
string label = "cppcheck scanning for files (" + filesScanned + ")";
774+
statusBar.Text = label;
775+
}
776+
else
777+
{
778+
statusBar.Clear();
779779
}
780-
catch (Exception ex) { }
781780
}
781+
catch (Exception) {}
782+
}
783+
784+
private async void updateStatusBarProgress(bool inProgress, string label, int currentPercentage)
785+
{
786+
await JoinableTaskFactory.SwitchToMainThreadAsync();
787+
try
788+
{
789+
_dte.StatusBar.Progress(inProgress, label, currentPercentage, 100);
790+
} catch (Exception) {}
782791
}
783792

784793
private async void checkProgressUpdated(object sender, ICodeAnalyzer.ProgressEvenArgs e)
@@ -789,47 +798,34 @@ private async void checkProgressUpdated(object sender, ICodeAnalyzer.ProgressEve
789798

790799
await JoinableTaskFactory.SwitchToMainThreadAsync();
791800

792-
EnvDTE.StatusBar statusBar = _dte.StatusBar;
793-
if (statusBar != null)
801+
string label = "";
802+
if (progress < 100)
794803
{
795-
string label = "";
796-
if (progress < 100)
797-
{
798-
if (e.FilesChecked == 0 || e.TotalFilesNumber == 0)
799-
label = "cppcheck analysis in progress...";
800-
else
801-
label = "cppcheck analysis in progress (" + (completedFileCount + e.FilesChecked) + " out of " + (completedFileCount + e.TotalFilesNumber) + " files checked)";
802-
803-
lastAnalyzerTotalFiles = e.TotalFilesNumber;
804-
805-
statusBar.Progress(true, label, progress, 100);
806-
}
804+
if (e.FilesChecked == 0 || e.TotalFilesNumber == 0)
805+
label = "cppcheck analysis in progress...";
807806
else
808-
{
809-
label = "cppcheck analysis completed";
810-
completedFileCount += lastAnalyzerTotalFiles;
811-
lastAnalyzerTotalFiles = 0;
807+
label = "cppcheck analysis in progress (" + (completedFileCount + e.FilesChecked) + " out of " + (completedFileCount + e.TotalFilesNumber) + " files checked)";
812808

813-
try
814-
{
815-
// This raises an exception during shutdown.
816-
statusBar.Progress(true, label, progress, 100);
817-
}
818-
catch (Exception) { }
809+
lastAnalyzerTotalFiles = e.TotalFilesNumber;
819810

820-
_ = System.Threading.Tasks.Task.Run(async delegate
821-
{
822-
await System.Threading.Tasks.Task.Delay(5000);
823-
await JoinableTaskFactory.SwitchToMainThreadAsync();
824-
try
825-
{
826-
statusBar.Progress(false, label, 100, 100);
827-
}
828-
catch (Exception) { }
829-
});
811+
updateStatusBarProgress(true, label, progress);
812+
}
813+
else
814+
{
815+
label = "cppcheck analysis completed";
816+
completedFileCount += lastAnalyzerTotalFiles;
817+
lastAnalyzerTotalFiles = 0;
818+
819+
updateStatusBarProgress(true, label, Math.Max(progress, 100));
830820

831-
setMenuState(false);
832-
}
821+
_ = System.Threading.Tasks.Task.Run(async delegate
822+
{
823+
await System.Threading.Tasks.Task.Delay(5000);
824+
await JoinableTaskFactory.SwitchToMainThreadAsync();
825+
updateStatusBarProgress(false, label, 100);
826+
});
827+
828+
setMenuState(false);
833829
}
834830
}
835831

0 commit comments

Comments
 (0)