-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes xunit/xunit#599: VS Runner: UWP/Store apps don't load config
- Loading branch information
1 parent
b34aeaa
commit 642ee28
Showing
2 changed files
with
64 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,49 @@ | ||
using Windows.ApplicationModel; | ||
using Windows.Storage; | ||
|
||
namespace System.IO | ||
{ | ||
internal static class File | ||
static class File | ||
{ | ||
public static bool Exists(string path) | ||
{ | ||
return GetStorageFile(path) != null; | ||
} | ||
|
||
public static Stream OpenRead(string path) | ||
{ | ||
var storageFile = GetStorageFile(path); | ||
if (storageFile == null) | ||
throw new FileNotFoundException("Could not open file for read", path); | ||
|
||
return storageFile.OpenStreamForReadAsync().GetAwaiter().GetResult(); | ||
} | ||
|
||
// Helpers | ||
|
||
static StorageFile GetStorageFile(string path) | ||
{ | ||
if (string.IsNullOrWhiteSpace(path)) | ||
return false; | ||
return null; | ||
|
||
var folder = Package.Current.InstalledLocation; | ||
|
||
if (!path.Contains(folder.Path)) | ||
return false; | ||
if (Path.GetDirectoryName(path) != string.Empty && !path.Contains(folder.Path)) | ||
return null; | ||
|
||
var fileName = Path.GetFileName(path); | ||
var fileAsync = folder.GetFileAsync(fileName); | ||
|
||
try | ||
{ | ||
fileAsync.AsTask().Wait(); | ||
return fileAsync.GetResults() != null; | ||
var fileAsync = folder.GetFileAsync(fileName); | ||
return fileAsync.AsTask().GetAwaiter().GetResult(); | ||
} | ||
catch | ||
{ | ||
// any errors, we juts can't get it | ||
} | ||
catch { } | ||
|
||
return false; | ||
return null; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters