UnityGame/Library/PackageCache/com.unity.collab-proxy/Editor/PlasticSCM/UVCPackageVersion.cs
2024-10-27 10:53:47 +03:00

66 lines
1.9 KiB
C#

using System;
using System.Linq;
using Codice.LogWrapper;
using Unity.PlasticSCM.Editor.UI;
using PackageManager = UnityEditor.PackageManager;
namespace Unity.PlasticSCM.Editor
{
internal static class UVCPackageVersion
{
internal static string Value { get; private set; }
internal static void AsyncGetVersion()
{
AsyncFindPackage(
UVCS_PACKAGE_NAME,
PackageManager.Client.List(true),
OnFindPackageCompleted);
}
static void OnFindPackageCompleted(
PackageManager.PackageInfo packageInfo)
{
if (packageInfo == null)
return;
Value = packageInfo.version;
mLog.DebugFormat("OnFindPackageCompleted - Package version: {0}", Value);
}
static void AsyncFindPackage(
string packageName,
PackageManager.Requests.ListRequest listRequest,
Action<PackageManager.PackageInfo> onCompleted)
{
EditorDispatcher.Dispatch(delegate
{
if (!listRequest.IsCompleted)
{
AsyncFindPackage(
packageName, listRequest,
onCompleted);
return;
}
if (listRequest.Status == PackageManager.StatusCode.Success &&
listRequest.Result != null)
{
PackageManager.PackageInfo packageInfo =
listRequest.Result.FirstOrDefault(
package => package.name == packageName);
onCompleted(packageInfo);
}
});
}
const string UVCS_PACKAGE_NAME = "com.unity.collab-proxy";
static readonly ILog mLog = PlasticApp.GetLogger("UVCPackageVersion");
}
}