-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOpenInFileBrowser.cs
More file actions
77 lines (62 loc) · 2.22 KB
/
OpenInFileBrowser.cs
File metadata and controls
77 lines (62 loc) · 2.22 KB
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
67
68
69
70
71
72
73
74
75
76
77
// from http://wiki.unity3d.com/index.php/OpenInFileBrowser
public static class OpenInFileBrowser {
public static bool IsInMacOS {
get {
return UnityEngine.SystemInfo.operatingSystem.IndexOf("Mac OS") != -1;
}
}
public static bool IsInWinOS {
get {
return UnityEngine.SystemInfo.operatingSystem.IndexOf("Windows") != -1;
}
}
public static void OpenInMac(string path) {
bool openInsidesOfFolder = false;
// try mac
string macPath = path.Replace("\\", "/"); // mac finder doesn't like backward slashes
if (System.IO.Directory.Exists(macPath)) { // if path requested is a folder, automatically open insides of that folder
openInsidesOfFolder = true;
}
if (!macPath.StartsWith("\"")) {
macPath = "\"" + macPath;
}
if (!macPath.EndsWith("\"")) {
macPath = macPath + "\"";
}
string arguments = (openInsidesOfFolder? "" : "-R ") + macPath;
try {
System.Diagnostics.Process.Start("open", arguments);
} catch (System.ComponentModel.Win32Exception e) {
// tried to open mac finder in windows
// just silently skip error
// we currently have no platform define for the current OS we are in, so we resort to this
e.HelpLink = ""; // do anything with this variable to silence warning about not using it
}
}
public static void OpenInWin(string path) {
bool openInsidesOfFolder = false;
// try windows
string winPath = path.Replace("/", "\\"); // windows explorer doesn't like forward slashes
if (System.IO.Directory.Exists(winPath)) { // if path requested is a folder, automatically open insides of that folder
openInsidesOfFolder = true;
}
try {
System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder? "/root," : "/select,") + winPath);
} catch (System.ComponentModel.Win32Exception e) {
// tried to open win explorer in mac
// just silently skip error
// we currently have no platform define for the current OS we are in, so we resort to this
e.HelpLink = ""; // do anything with this variable to silence warning about not using it
}
}
public static void Open(string path) {
if (IsInWinOS) {
OpenInWin(path);
} else if (IsInMacOS) {
OpenInMac(path);
} else { // couldn't determine OS
OpenInWin(path);
OpenInMac(path);
}
}
}