-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor base directory operations to helper class
- Loading branch information
Showing
2 changed files
with
42 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
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Bonsai.Editor | ||
{ | ||
static class Project | ||
{ | ||
internal const string BonsaiExtension = ".bonsai"; | ||
|
||
public static string GetCurrentBaseDirectory() | ||
{ | ||
return GetCurrentBaseDirectory(out _); | ||
} | ||
|
||
public static string GetCurrentBaseDirectory(out bool currentDirectoryRestricted) | ||
{ | ||
var currentDirectory = Path.GetFullPath(Environment.CurrentDirectory).TrimEnd('\\'); | ||
var appDomainBaseDirectory = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory).TrimEnd('\\'); | ||
currentDirectoryRestricted = currentDirectory == appDomainBaseDirectory; | ||
if (!EditorSettings.IsRunningOnMono) | ||
{ | ||
var systemPath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.System)).TrimEnd('\\'); | ||
var systemX86Path = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)).TrimEnd('\\'); | ||
currentDirectoryRestricted |= currentDirectory == systemPath || currentDirectory == systemX86Path; | ||
} | ||
|
||
return !currentDirectoryRestricted | ||
? currentDirectory | ||
: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||
} | ||
|
||
public static string GetWorkflowBaseDirectory(string fileName) | ||
{ | ||
return Path.GetDirectoryName(fileName); | ||
} | ||
} | ||
} |