@@ -33,6 +33,7 @@ private class Library
3333 public string id ;
3434 public ProcessingState state ;
3535 public LibraryLoader customLoader ;
36+ public PackageInfo loadingResult ;
3637 }
3738
3839 private enum ProcessingState
@@ -77,39 +78,38 @@ public void Initialize(ScriptingEngine engine)
7778 Engine = engine ;
7879 }
7980
80- public void Resolve ( SourceCode module , string libraryName , IBslProcess process )
81+ public PackageInfo Resolve ( SourceCode module , string libraryName , IBslProcess process )
8182 {
8283 bool quoted = PrepareQuoted ( ref libraryName ) ;
83- bool loaded ;
84- if ( quoted )
85- loaded = LoadByRelativePath ( module , libraryName , process ) ;
86- else
87- loaded = LoadByName ( libraryName , process ) ;
8884
89- if ( ! loaded )
90- throw new CompilerException ( String . Format ( "Библиотека не найдена: '{0}'" , libraryName ) ) ;
85+ var lib = quoted ?
86+ LoadByRelativePath ( module , libraryName , process ) :
87+ LoadByName ( libraryName , process ) ;
88+
89+ if ( lib == null )
90+ throw new CompilerException ( $ "Библиотека не найдена: '{ libraryName } '") ;
91+
92+ return lib ;
9193 }
9294
93- private bool LoadByName ( string libraryName , IBslProcess process )
95+ private PackageInfo LoadByName ( string libraryName , IBslProcess process )
9496 {
9597 foreach ( var path in SearchDirectories )
9698 {
9799 if ( ! Directory . Exists ( path ) )
98100 continue ;
99101
100102 var libraryPath = Path . Combine ( path , libraryName ) ;
101- if ( LoadByPath ( libraryPath , process ) )
102- return true ;
103+ var loadAttempt = LoadByPath ( libraryPath , process ) ;
104+ if ( loadAttempt != null )
105+ return loadAttempt ;
103106 }
104107
105108 var rootPath = Path . Combine ( LibraryRoot , libraryName ) ;
106- if ( LoadByPath ( rootPath , process ) )
107- return true ;
108-
109- return false ;
109+ return LoadByPath ( rootPath , process ) ;
110110 }
111111
112- private bool LoadByRelativePath ( SourceCode module , string libraryPath , IBslProcess process )
112+ private PackageInfo LoadByRelativePath ( SourceCode module , string libraryPath , IBslProcess process )
113113 {
114114 string realPath ;
115115
@@ -197,17 +197,14 @@ private bool PrepareQuoted(ref string value)
197197 return quoted ;
198198 }
199199
200- private bool LoadByPath ( string libraryPath , IBslProcess process )
200+ private PackageInfo LoadByPath ( string libraryPath , IBslProcess process )
201201 {
202- if ( Directory . Exists ( libraryPath ) )
203- {
204- return LoadLibraryInternal ( libraryPath , process ) ;
205- }
206-
207- return false ;
202+ return Directory . Exists ( libraryPath ) ?
203+ LoadLibraryInternal ( libraryPath , process ) :
204+ null ;
208205 }
209206
210- private bool LoadLibraryInternal ( string libraryPath , IBslProcess process )
207+ private PackageInfo LoadLibraryInternal ( string libraryPath , IBslProcess process )
211208 {
212209 var id = GetLibraryId ( libraryPath ) ;
213210 var existedLib = _libs . FirstOrDefault ( x => x . id == id ) ;
@@ -222,41 +219,42 @@ private bool LoadLibraryInternal(string libraryPath, IBslProcess process)
222219 $ "Error loading library { id } . Circular dependencies found.\n ") + libStack ) ;
223220 }
224221
225- return true ;
222+ return existedLib . loadingResult ;
226223 }
227224
228225 var newLib = new Library ( ) { id = id , state = ProcessingState . Discovered } ;
229- bool hasFiles ;
230226 int newLibIndex = _libs . Count ;
231227
232228 var customLoaderFile = Path . Combine ( libraryPath , PREDEFINED_LOADER_FILE ) ;
233229 if ( File . Exists ( customLoaderFile ) )
234230 newLib . customLoader = LibraryLoader . Create ( Engine , customLoaderFile , process ) ;
235231
232+ PackageInfo package ;
236233 try
237234 {
238235 _libs . Add ( newLib ) ;
239- hasFiles = ProcessLibrary ( newLib , process ) ;
236+ package = ProcessLibrary ( newLib , process ) ;
240237 newLib . state = ProcessingState . Processed ;
238+ newLib . loadingResult = package ;
241239 }
242240 catch ( Exception )
243241 {
244242 _libs . RemoveAt ( newLibIndex ) ;
245243 throw ;
246244 }
247245
248- return hasFiles ;
246+ return package ;
249247 }
250248
251- private bool ProcessLibrary ( Library lib , IBslProcess process )
249+ private PackageInfo ProcessLibrary ( Library lib , IBslProcess process )
252250 {
253251 LibraryLoader loader ;
254252 if ( lib . customLoader != null )
255253 loader = lib . customLoader ;
256254 else
257255 loader = GetDefaultLoader ( process ) ;
258256
259- return loader . ProcessLibrary ( lib . id , process ) != default ;
257+ return loader . ProcessLibrary ( lib . id , process ) ;
260258 }
261259
262260 private static string ListToStringStack ( IEnumerable < Library > libs , string stopToken )
@@ -285,4 +283,4 @@ private static bool PathHasInvalidChars(string path)
285283 return ( ! string . IsNullOrEmpty ( path ) && path . IndexOfAny ( Path . GetInvalidPathChars ( ) ) >= 0 ) ;
286284 }
287285 }
288- }
286+ }
0 commit comments