9
9
using System . Threading ;
10
10
using System . Threading . Tasks ;
11
11
using Microsoft . Web . LibraryManager . Contracts ;
12
+ using Microsoft . Web . LibraryManager . Helpers ;
12
13
using Microsoft . Web . LibraryManager . LibraryNaming ;
13
14
using Microsoft . Web . LibraryManager . Resources ;
14
15
@@ -73,25 +74,25 @@ public override async Task<OperationResult<LibraryInstallationGoalState>> Instal
73
74
return goalStateResult ;
74
75
}
75
76
76
- foreach ( string file in desiredState . Files )
77
+ foreach ( ( string destFile , string sourceFile ) in goalStateResult . Result . InstalledFiles )
77
78
{
78
79
if ( cancellationToken . IsCancellationRequested )
79
80
{
80
81
return OperationResult < LibraryInstallationGoalState > . FromCancelled ( goalStateResult . Result ) ;
81
82
}
82
83
83
- if ( string . IsNullOrEmpty ( file ) )
84
+ if ( string . IsNullOrEmpty ( destFile ) )
84
85
{
85
- return OperationResult < LibraryInstallationGoalState > . FromError ( PredefinedErrors . CouldNotWriteFile ( file ) ) ;
86
+ return OperationResult < LibraryInstallationGoalState > . FromError ( PredefinedErrors . CouldNotWriteFile ( destFile ) ) ;
86
87
}
87
88
88
- string path = Path . Combine ( desiredState . DestinationPath , file ) ;
89
- var sourceStream = new Func < Stream > ( ( ) => GetStreamAsync ( desiredState , file , cancellationToken ) . Result ) ;
90
- bool writeOk = await HostInteraction . WriteFileAsync ( path , sourceStream , desiredState , cancellationToken ) . ConfigureAwait ( false ) ;
89
+ string libraryName = LibraryNamingScheme . GetLibraryId ( desiredState . Name , desiredState . Version ) ;
90
+ var sourceStream = new Func < Stream > ( ( ) => GetStreamAsync ( sourceFile , libraryName , cancellationToken ) . Result ) ;
91
+ bool writeOk = await HostInteraction . WriteFileAsync ( destFile , sourceStream , desiredState , cancellationToken ) . ConfigureAwait ( false ) ;
91
92
92
93
if ( ! writeOk )
93
94
{
94
- return OperationResult < LibraryInstallationGoalState > . FromError ( PredefinedErrors . CouldNotWriteFile ( file ) ) ;
95
+ return OperationResult < LibraryInstallationGoalState > . FromError ( PredefinedErrors . CouldNotWriteFile ( destFile ) ) ;
95
96
}
96
97
}
97
98
@@ -135,10 +136,8 @@ public override string GetSuggestedDestination(ILibrary library)
135
136
return string . Empty ;
136
137
}
137
138
138
- private async Task < Stream > GetStreamAsync ( ILibraryInstallationState state , string file , CancellationToken cancellationToken )
139
+ private async Task < Stream > GetStreamAsync ( string sourceFile , string libraryName , CancellationToken cancellationToken )
139
140
{
140
- string sourceFile = state . Name ;
141
-
142
141
try
143
142
{
144
143
if ( ! Uri . TryCreate ( sourceFile , UriKind . RelativeOrAbsolute , out Uri url ) )
@@ -154,14 +153,7 @@ private async Task<Stream> GetStreamAsync(ILibraryInstallationState state, strin
154
153
// File
155
154
if ( url . IsFile )
156
155
{
157
- if ( Directory . Exists ( url . OriginalString ) )
158
- {
159
- return await FileHelpers . ReadFileAsStreamAsync ( Path . Combine ( url . OriginalString , file ) , cancellationToken ) . ConfigureAwait ( false ) ;
160
- }
161
- else
162
- {
163
- return await FileHelpers . ReadFileAsStreamAsync ( sourceFile , cancellationToken ) . ConfigureAwait ( false ) ;
164
- }
156
+ return await FileHelpers . ReadFileAsStreamAsync ( sourceFile , cancellationToken ) . ConfigureAwait ( false ) ;
165
157
}
166
158
// Url
167
159
else
@@ -175,7 +167,7 @@ private async Task<Stream> GetStreamAsync(ILibraryInstallationState state, strin
175
167
}
176
168
catch ( Exception )
177
169
{
178
- throw new InvalidLibraryException ( state . Name , state . ProviderId ) ;
170
+ throw new InvalidLibraryException ( libraryName , Id ) ;
179
171
}
180
172
}
181
173
0 commit comments