@@ -51,7 +51,7 @@ public IEnumerable<Status> Export()
5151 // Find a file name which allows us to export without name conflicts.
5252 private int FileNameNum ( IReadOnlyList < ExportCommand > cmdToExport , string nameBase )
5353 {
54- const int maxAttemptCount = 10000 ;
54+ const int maxAttemptCount = 1000 ;
5555 for ( int i = 1 ; i <= maxAttemptCount ; i ++ )
5656 {
5757 if ( cmdToExport . All ( c => ! FileExist ( nameBase , c , i ) ) ) return i ;
@@ -62,10 +62,10 @@ private int FileNameNum(IReadOnlyList<ExportCommand> cmdToExport, string nameBas
6262
6363 private Status Export ( string nameBase , ExportCommand c , int i )
6464 {
65- var fileName = GetFileFullPath ( nameBase , c , i ) ;
66-
6765 try
6866 {
67+ var fileName = GetFileFullPath ( nameBase , c , i ) ;
68+
6969 // Although the file name has been checked to have no conflict, if the user choose
7070 // to export multiple files to the same folder, the file names can still collide.
7171 var newName = File . Exists ( fileName )
@@ -94,10 +94,14 @@ private static string GenerateFileName(string nameBase, ExportCommand c)
9494
9595 private bool FileExist ( string nameBase , ExportCommand cmd , int n )
9696 {
97- var filePath = GetFileFullPath ( nameBase , cmd , n ) ;
98- return File . Exists ( filePath ) ;
97+ return DefaultIfThrows ( ( ) =>
98+ {
99+ var filePath = GetFileFullPath ( nameBase , cmd , n ) ;
100+ return File . Exists ( filePath ) ;
101+ } , false ) ;
99102 }
100103
104+ /// Returned path may be null or not exist.
101105 private string ExportDirectory ( ExportCommand c ) =>
102106 Providers . Types . ExportDirectory ( c . DefaultSimulator , c , options ( ) ) ;
103107
@@ -109,6 +113,7 @@ private void TryCreateDirectories(IEnumerable<ExportCommand> enabledCommands)
109113 }
110114 }
111115
116+ // May throw exception. Returned path may not exist.
112117 private string GetFileFullPath ( string nameBase , ExportCommand cmd , int n )
113118 {
114119 var fileName = nameBase + n . ToString ( ) . PadLeft ( 2 , '0' ) + cmd . Extension ;
0 commit comments