@@ -27,9 +27,9 @@ public AnalyzerCppcheck()
2727 {
2828 DateTime fileModifiedDate = File . GetLastWriteTime ( file ) ;
2929
30- if ( fileModifiedDate . AddMinutes ( 60 ) < DateTime . Now )
30+ if ( fileModifiedDate . AddMinutes ( 120 ) < DateTime . Now )
3131 {
32- // File hasn't been written to in the last 60 mins , so it must be
32+ // File hasn't been written to in the last 120 minutes , so it must be
3333 // from an earlier instance which didn't exit gracefully.
3434 File . Delete ( file ) ;
3535 }
@@ -40,12 +40,10 @@ public AnalyzerCppcheck()
4040
4141 ~ AnalyzerCppcheck ( )
4242 {
43- // Delete the temp file. Doesn't throw an exception if the file was never
44- // created, so we don't need to worry about that.
45- File . Delete ( tempFileName ) ;
43+ cleanupTempFiles ( ) ;
4644 }
4745
48- private string getCPPCheckArgs ( ConfiguredFiles configuredFiles , bool analysisOnSavedFile , bool multipleProjects , StreamWriter tempFile )
46+ private string getCPPCheckArgs ( ConfiguredFiles configuredFiles , bool analysisOnSavedFile , bool multipleProjects , string tempFileName )
4947 {
5048 Debug . Assert ( _numCores > 0 ) ;
5149 String cppheckargs = Properties . Settings . Default . DefaultArguments ;
@@ -112,10 +110,13 @@ private string getCPPCheckArgs(ConfiguredFiles configuredFiles, bool analysisOnS
112110 }
113111 }
114112
115- foreach ( SourceFile file in filesToAnalyze )
113+ using ( StreamWriter tempFile = new StreamWriter ( tempFileName ) )
116114 {
117- if ( ! matchMasksList ( file . FileName , unitedSuppressionsInfo . SkippedFilesMask ) )
118- tempFile . WriteLine ( file . FilePath ) ;
115+ foreach ( SourceFile file in filesToAnalyze )
116+ {
117+ if ( ! matchMasksList ( file . FileName , unitedSuppressionsInfo . SkippedFilesMask ) )
118+ tempFile . WriteLine ( file . FilePath ) ;
119+ }
119120 }
120121
121122 cppheckargs += " --file-list=\" " + tempFileName + "\" " ;
@@ -209,11 +210,8 @@ public override void analyze(List<ConfiguredFiles> allConfiguredFiles, OutputWin
209210 return ;
210211
211212 List < string > cppheckargs = new List < string > ( ) ;
212- using ( StreamWriter tempFile = new StreamWriter ( tempFileName ) )
213- {
214- foreach ( var configuredFiles in allConfiguredFiles )
215- cppheckargs . Add ( getCPPCheckArgs ( configuredFiles , analysisOnSavedFile , allConfiguredFiles . Count > 1 , tempFile ) ) ;
216- }
213+ foreach ( var configuredFiles in allConfiguredFiles )
214+ cppheckargs . Add ( getCPPCheckArgs ( configuredFiles , analysisOnSavedFile , allConfiguredFiles . Count > 1 , createNewTempFileName ( ) ) ) ;
217215
218216 string analyzerPath = Properties . Settings . Default . CPPcheckPath ;
219217 while ( ! File . Exists ( analyzerPath ) )
@@ -361,17 +359,37 @@ protected override List<Problem> parseOutput(String output)
361359 return result ;
362360 }
363361
364- protected override void analysisFinished ( )
362+ protected override void analysisFinished ( string arguments )
365363 {
366364 if ( _unfinishedProblem != null )
367365 addProblemToToolwindow ( _unfinishedProblem ) ;
368366
369- // Delete the temp file. Doesn't throw an exception if the file was never
370- // created, so we don't need to worry about that.
367+ const string fileListPattern = "--file-list=\" " ;
368+ int filenamePos = arguments . IndexOf ( fileListPattern ) + fileListPattern . Length ;
369+ int filenameLength = arguments . IndexOf ( '\" ' , filenamePos ) - filenamePos ;
370+ string tempFileName = arguments . Substring ( filenamePos , filenameLength ) ;
371+
371372 File . Delete ( tempFileName ) ;
372373 }
374+
375+ private void cleanupTempFiles ( )
376+ {
377+ // Delete the temp files. Doesn't throw an exception if the file was never
378+ // created, so we don't need to worry about that.
379+ foreach ( string name in _tempFileNamesInUse )
380+ File . Delete ( name ) ;
381+
382+ _tempFileNamesInUse . Clear ( ) ;
383+ }
384+
385+ private string createNewTempFileName ( )
386+ {
387+ string name = Path . GetTempPath ( ) + tempFilePrefix + "_" + Path . GetRandomFileName ( ) ;
388+ _tempFileNamesInUse . Add ( name ) ;
389+ return name ;
390+ }
373391
374392 private Problem _unfinishedProblem = null ;
375- private string tempFileName = Path . GetTempPath ( ) + tempFilePrefix + "_" + Path . GetRandomFileName ( ) ;
393+ private List < string > _tempFileNamesInUse = new List < string > ( ) ;
376394 }
377395}
0 commit comments