2 using System.Globalization;
3 using System.Collections.Generic;
13 public static string GroupName(PackageSource origin)
15 var group = PackageGroupOrigins.Packages.ToString();
16 if (origin == PackageSource.BuiltIn)
17 group = PackageGroupOrigins.BuiltInPackages.ToString();
22 protected static IEnumerable<PackageInfo> FromUpmPackageInfo(PackageManager.PackageInfo info,
bool isCurrent=
true)
24 var packages =
new List<PackageInfo>();
25 var displayName = info.displayName;
26 if (
string.IsNullOrEmpty(displayName))
28 displayName = info.name.Replace(
"com.unity.modules.",
"");
29 displayName = displayName.Replace(
"com.unity.",
"");
30 displayName =
new CultureInfo(
"en-US").TextInfo.ToTitleCase(displayName);
33 string author = info.author.name;
34 if (
string.IsNullOrEmpty(info.author.name) && info.name.StartsWith(
"com.unity."))
35 author =
"Unity Technologies Inc.";
37 var lastCompatible = info.versions.latestCompatible;
38 var versions =
new List<string>();
39 versions.AddRange(info.versions.compatible);
40 if (versions.FindIndex(version => version == info.version) == -1)
42 versions.Add(info.version);
44 versions.Sort((left, right) =>
46 if (left ==
null || right ==
null)
return 0;
54 if (!
string.IsNullOrEmpty(lastCompatible))
57 string.IsNullOrEmpty(lastCompatible) ? (
SemVersion)
null : lastCompatible;
58 if (packageVersion !=
null &&
string.IsNullOrEmpty(packageVersion.
Prerelease) &&
60 lastCompatible = info.version;
64 if (packageVersion !=
null &&
string.IsNullOrEmpty(packageVersion.
Prerelease))
65 lastCompatible = info.version;
69 foreach(var version
in versions)
71 var isVersionCurrent = version == info.version && isCurrent;
72 var isBuiltIn = info.source == PackageSource.BuiltIn;
74 var state = (isBuiltIn || info.version == lastCompatible || !isCurrent ) ? PackageState.UpToDate : PackageState.Outdated;
77 if (info.versions.all.Length <= 0)
78 state = PackageState.UpToDate;
80 if (info.errors.Length > 0)
81 state = PackageState.Error;
86 DisplayName = displayName,
87 PackageId = version == info.version ? info.packageId :
null,
89 Description = info.description,
90 Category = info.category,
91 IsCurrent = isVersionCurrent,
92 IsLatest = version == lastCompatible,
93 IsVerified = isVerified,
94 Errors = info.errors.ToList(),
95 Group = GroupName(info.source),
97 Origin = isBuiltIn || isVersionCurrent ? info.source : PackageSource.Registry,
102 packages.Add(packageInfo);
108 public static event Action<UpmBaseOperation> OnOperationStart = delegate { };
110 public event Action<Error> OnOperationError = delegate { };
111 public event Action OnOperationFinalized = delegate { };
113 public Error ForceError {
get;
set; }
114 public Error Error {
get;
protected set; }
116 public bool IsCompleted {
get;
private set; }
118 protected abstract Request CreateRequest();
121 protected Request CurrentRequest;
124 protected abstract void ProcessData();
126 protected void Start()
129 OnOperationStart(
this);
133 if (TryForcedError())
136 EditorApplication.update += Progress;
140 private void Progress()
146 if (CurrentRequest ==
null)
148 CurrentRequest = CreateRequest();
153 if (TryForcedError())
156 if (CurrentRequest.IsCompleted)
158 if (CurrentRequest.Status == StatusCode.Success)
160 else if (CurrentRequest.Status >= StatusCode.Failure)
161 OnError(CurrentRequest.Error);
163 Debug.LogError(
"Unsupported progress state " + CurrentRequest.Status);
167 private void OnError(Error error)
173 var message =
"Cannot perform upm operation.";
175 message =
"Cannot perform upm operation: " + Error.message +
" [" + Error.errorCode +
"]";
177 Debug.LogError(message);
179 OnOperationError(Error);
181 catch (Exception exception)
183 Debug.LogError(
"Package Manager Window had an error while reporting an error in an operation: " + exception);
189 private void OnDone()
195 catch (Exception error)
197 Debug.LogError(
"Package Manager Window had an error while completing an operation: " + error);
203 private void FinalizeOperation()
205 EditorApplication.update -= Progress;
206 OnOperationFinalized();
212 EditorApplication.update -= Progress;
213 OnOperationError = delegate { };
214 OnOperationFinalized = delegate { };
218 private bool TryForcedError()
220 if (ForceError !=
null)
A semantic version implementation. Conforms to v2.0.0 of http://semver.org/
int CompareByPrecedence(SemVersion other)
Compares to semantic versions by precedence. This does the same as a Equals, but ignores the build in...
static SemVersion Parse(string version, bool strict=false)
Parses the specified string to a semantic version.
string Prerelease
Gets the pre-release version.