Skip to content

Commit

Permalink
Fixed Open Config Folder
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzemlin committed Mar 5, 2020
1 parent 9a66670 commit 5dba67b
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/MenuScripts/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public void DefaultOptions()

public void OpenConfigFolder()
{
EditorUtility.RevealInFinder($"{Application.persistentDataPath}/Config/");
OpenInFileBrowser.Open($"{Application.persistentDataPath}/Config/");
}

public void FillOptionFields()
Expand Down
105 changes: 105 additions & 0 deletions Assets/Scripts/OpenInFileBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// 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;
}
}

[UnityEditor.MenuItem("Window/Test OpenInFileBrowser")]
public static void Test()
{
Open(UnityEngine.Application.dataPath);
}

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);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/OpenInFileBrowser.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5dba67b

Please sign in to comment.