FindWorkspace.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.IO;
  2. using Codice.Client.Common;
  3. using Codice.CM.Common;
  4. using PlasticGui;
  5. namespace Unity.PlasticSCM.Editor
  6. {
  7. internal static class FindWorkspace
  8. {
  9. internal static string PathForApplicationPath(string path)
  10. {
  11. try
  12. {
  13. return FindWorkspacePath(
  14. path, ClientConfig.Get().GetWkConfigDir());
  15. }
  16. catch (NotConfiguredClientException)
  17. {
  18. return null;
  19. }
  20. }
  21. internal static WorkspaceInfo InfoForApplicationPath(
  22. string path, IPlasticAPI plasticApi)
  23. {
  24. string wkPath = PathForApplicationPath(path);
  25. if (string.IsNullOrEmpty(wkPath))
  26. return null;
  27. return plasticApi.GetWorkspaceFromPath(wkPath);
  28. }
  29. static string FindWorkspacePath(string path, string wkConfigDir)
  30. {
  31. while (!string.IsNullOrEmpty(path))
  32. {
  33. if (Directory.Exists(Path.Combine(path, wkConfigDir)))
  34. return path;
  35. path = Path.GetDirectoryName(path);
  36. }
  37. return null;
  38. }
  39. }
  40. }