-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMiscUtil.cs
66 lines (59 loc) · 1.91 KB
/
MiscUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace Meadow.CoverageReport
{
public static class MiscUtil
{
public static string GetFileUrl(string filePath)
{
filePath = Path.GetFullPath(filePath);
var uri = new Uri("file:///" + filePath);
var str = uri.AbsoluteUri;
return str;
}
public static void OpenBrowser(string filePath)
{
var url = GetFileUrl(filePath);
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&", StringComparison.Ordinal);
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
}
/// <summary>
/// Creates or empties out a directory
/// </summary>
public static void ResetDirectory(string dir)
{
// Clear directory if exists.
// The thread sleeps are for a bug with directory actions not being fully blocking.
if (Directory.Exists(dir))
{
Directory.Delete(dir, true);
while (Directory.Exists(dir))
{
Thread.Sleep(1);
}
}
Directory.CreateDirectory(dir);
while (!Directory.Exists(dir))
{
Thread.Sleep(1);
}
}
}
}