private static NPath TryGetFile(ResourceType resourceType, string resource, IEnvironment environment) { /* * This function attempts to get files embedded in the callers assembly. * Unity.VersionControl.Git which tends to contain logos * Git.Api which tends to contain application resources * * Each file's name is their physical path in the project. * * When running tests, we assume the tests are looking for application resources, and default to returning Git.Api * * First check for the resource in the calling assembly. * If the resource cannot be found, fallback to looking in Git.Api's assembly. * If the resource is still not found, it attempts to find it in the file system */ (string type, string os) = ParseResourceType(resourceType, environment); var stream = TryGetResource(resourceType, type, os, resource); if (stream != null) { var target = NPath.GetTempFilename(); return(target.WriteAllBytes(stream.ToByteArray())); } NPath possiblePath = environment.ExtensionInstallPath.Combine(type, os, resource); if (possiblePath.FileExists()) { return(possiblePath); } var basePath = resourceType == ResourceType.Icon ? "Unity.VersionControl.Git" : "Git.Api"; possiblePath = environment.ExtensionInstallPath.Parent.Combine(basePath, type, os, resource); if (possiblePath.FileExists()) { return(possiblePath); } return(NPath.Default); }
public void RunCommandLineWindow(NPath workingDirectory) { var startInfo = new ProcessStartInfo { RedirectStandardInput = false, RedirectStandardOutput = false, RedirectStandardError = false, UseShellExecute = false, CreateNoWindow = false }; if (environment.IsWindows) { startInfo.FileName = "cmd"; gitEnvironment.Configure(startInfo, workingDirectory); } else if (environment.IsMac) { // we need to create a temp bash script to set up the environment properly, because // osx terminal app doesn't inherit the PATH env var and there's no way to pass it in var envVarFile = NPath.GetTempFilename(); startInfo.FileName = "open"; startInfo.Arguments = $"-a Terminal {envVarFile}"; gitEnvironment.Configure(startInfo, workingDirectory); var envVars = startInfo.EnvironmentVariables; var scriptContents = new[] { $"cd \"{envVars["GHU_WORKINGDIR"]}\"", $"PATH=\"{envVars["GHU_FULLPATH"]}\" /bin/bash" }; environment.FileSystem.WriteAllLines(envVarFile, scriptContents); Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions) 493); // -rwxr-xr-x mode (0755) } else { startInfo.FileName = "sh"; gitEnvironment.Configure(startInfo, workingDirectory); } Process.Start(startInfo); }