@@ -115,7 +115,7 @@ public string CodeUrl
115
115
116
116
set
117
117
{
118
- #if DEBUG
118
+ #if ! REMOTE_DOCS
119
119
_codeUrl = value ;
120
120
#else
121
121
var regex = new Regex ( "^https://github.com/windows-toolkit/WindowsCommunityToolkit/(tree|blob)/(?<branch>.+?)/(?<path>.*)" ) ;
@@ -221,12 +221,13 @@ public async Task<string> GetDocumentationAsync()
221
221
if ( docMatch . Success )
222
222
{
223
223
filepath = docMatch . Groups [ "file" ] . Value ;
224
- filename = Path . GetFileName ( RemoteDocumentationPath ) ;
224
+ filename = Path . GetFileName ( filepath ) ;
225
+
225
226
RemoteDocumentationPath = Path . GetDirectoryName ( filepath ) ;
226
- LocalDocumentationFilePath = $ "ms-appx:///docs/{ RemoteDocumentationPath } /";
227
+ LocalDocumentationFilePath = $ "ms-appx:///docs/{ filepath } /";
227
228
}
228
229
229
- #if ! DEBUG // use the docs repo in release mode
230
+ #if REMOTE_DOCS // use the docs repo in release mode
230
231
string modifiedDocumentationUrl = $ "{ _docsOnlineRoot } live/docs/{ filepath } ";
231
232
232
233
// Read from Cache if available.
@@ -285,6 +286,11 @@ public async Task<string> GetDocumentationAsync()
285
286
return _cachedDocumentation ;
286
287
}
287
288
289
+ public Uri GetOnlineResourcePath ( string relativePath )
290
+ {
291
+ return new Uri ( $ "{ _docsOnlineRoot } live/docs/{ RemoteDocumentationPath } /{ relativePath } ") ;
292
+ }
293
+
288
294
/// <summary>
289
295
/// Gets the image data from a Uri, with Caching.
290
296
/// </summary>
@@ -301,45 +307,61 @@ async Task<Stream> CopyStream(HttpContent source)
301
307
}
302
308
303
309
IRandomAccessStream imageStream = null ;
304
- var localPath = $ "{ uri . Host } /{ uri . LocalPath } ";
310
+ var localPath = $ "{ uri . Host } /{ uri . LocalPath } ". Replace ( "//" , "/" ) ;
311
+
312
+ if ( localPath . StartsWith ( _docsOnlineRoot . Substring ( 8 ) ) )
313
+ {
314
+ // If we're looking for docs we should look in our local area first.
315
+ localPath = localPath . Substring ( _docsOnlineRoot . Length - 3 ) ; // want to chop "live/" but missing https:// as well.
316
+ }
305
317
306
- // Cache only in Release
307
- #if ! DEBUG
318
+ // Try cache only in Release (using remote docs)
319
+ #if REMOTE_DOCS
308
320
try
309
321
{
310
322
imageStream = await StreamHelper . GetLocalCacheFileStreamAsync ( localPath , Windows . Storage . FileAccessMode . Read ) ;
311
323
}
312
324
catch
313
325
{
314
326
}
315
- #endif
316
327
317
328
if ( imageStream == null )
318
329
{
319
330
try
320
331
{
332
+ // Our docs don't reference any external images, this should only be for getting latest image from repo.
321
333
using ( var response = await client . GetAsync ( uri ) )
322
334
{
323
335
if ( response . IsSuccessStatusCode )
324
336
{
325
337
var imageCopy = await CopyStream ( response . Content ) ;
326
338
imageStream = imageCopy . AsRandomAccessStream ( ) ;
327
339
328
- // Cache only in Release
329
- #if ! DEBUG
330
340
// Takes a second copy of the image stream, so that is can save the image data to cache.
331
341
using ( var saveStream = await CopyStream ( response . Content ) )
332
342
{
333
343
await SaveImageToCache ( localPath , saveStream ) ;
334
344
}
335
- #endif
336
345
}
337
346
}
338
347
}
339
348
catch
340
349
{
341
350
}
342
351
}
352
+ #endif
353
+
354
+ // If we don't have internet, then try to see if we have a packaged copy
355
+ if ( imageStream == null )
356
+ {
357
+ try
358
+ {
359
+ imageStream = await StreamHelper . GetPackagedFileStreamAsync ( localPath ) ;
360
+ }
361
+ catch
362
+ {
363
+ }
364
+ }
343
365
344
366
return imageStream ;
345
367
}
0 commit comments