diff --git a/Packages/com.coffee.upm-git-extension/Editor/Commands/get-available-versions.js b/Packages/com.coffee.upm-git-extension/Editor/Commands/get-available-versions.js index ee94893..f11193e 100755 --- a/Packages/com.coffee.upm-git-extension/Editor/Commands/get-available-versions.js +++ b/Packages/com.coffee.upm-git-extension/Editor/Commands/get-available-versions.js @@ -57,7 +57,7 @@ const parseRef = text => { const p = JSON.parse(fs.readFileSync("package.json", "utf8")); // Check package name. - if (packageName != "*" && p.name != packageName) { + if (packageName != "all" && p.name != packageName) { console.error( `error: '${p.name}' is not target package '${packageName}'.` ); diff --git a/Packages/com.coffee.upm-git-extension/Editor/Scripts/AvailableVersions.cs b/Packages/com.coffee.upm-git-extension/Editor/Scripts/AvailableVersions.cs index a9132c4..291e568 100644 --- a/Packages/com.coffee.upm-git-extension/Editor/Scripts/AvailableVersions.cs +++ b/Packages/com.coffee.upm-git-extension/Editor/Scripts/AvailableVersions.cs @@ -6,6 +6,7 @@ using System.IO; using System.Linq; using System.Diagnostics; +using System.Text; // using UnityEditor.PackageManager.UI.InternalBridge; // using Debug = UnityEditor.PackageManager.UI.InternalBridge.Debug; @@ -13,7 +14,7 @@ namespace Coffee.PackageManager.UI { [Serializable] - public class AvailableVersion : IEquatable, ISerializationCallbackReceiver + public class AvailableVersion : IEquatable { public string packageName = ""; public string version = ""; @@ -38,15 +39,6 @@ public override int GetHashCode() + repoUrl.GetHashCode() + refName.GetHashCode(); } - - public void OnBeforeSerialize() - { - } - - public void OnAfterDeserialize() - { - repoUrl = PackageUtils.GetRepoUrl(repoUrl); - } } public class AvailableVersions : ScriptableSingleton @@ -65,14 +57,15 @@ public class ResultInfo public AvailableVersion[] versions; } + [MenuItem("UpmGitExtensions/Clear Cached Versions")] public static void ClearAll() { + Debug.Log(kHeader, "Clear cached versions"); instance.versions = new AvailableVersion[0]; } public static void Clear(string packageName = null, string repoUrl = null) { - repoUrl = string.IsNullOrEmpty(repoUrl) ? repoUrl : PackageUtils.GetRepoUrl(repoUrl); instance.versions = instance.versions .Where(x => string.IsNullOrEmpty(packageName) || x.packageName != packageName) .Where(x => string.IsNullOrEmpty(repoUrl) || x.repoUrl != repoUrl) @@ -81,12 +74,22 @@ public static void Clear(string packageName = null, string repoUrl = null) public static IEnumerable GetVersions(string packageName = null, string repoUrl = null) { - repoUrl = string.IsNullOrEmpty(repoUrl) ? repoUrl : PackageUtils.GetRepoUrl(repoUrl); return instance.versions .Where(x => string.IsNullOrEmpty(packageName) || x.packageName == packageName) .Where(x => string.IsNullOrEmpty(repoUrl) || x.repoUrl == repoUrl); } + [MenuItem("UpmGitExtensions/Dump Cached Versions")] + public static void Dump() + { + var sb = new StringBuilder("[AvailableVersions] Dump:\n"); + foreach(var v in instance.versions.OrderBy(x=>x.packageName).ThenBy(x=>x.version)) + { + sb.AppendLine(JsonUtility.ToJson(v)); + } + Debug.Log(kHeader, sb); + } + public static void AddVersions(IEnumerable add) { if (add == null || !add.Any()) @@ -104,7 +107,7 @@ public static void AddVersions(IEnumerable add) } } - public static void UpdateAvailableVersions(string packageName = "*", string repoUrl = "", EventHandler callback = null) + public static void UpdateAvailableVersions(string packageName = "all", string repoUrl = "", Action callback = null) { var unity = Application.unityVersion; #if UNITY_EDITOR_WIN @@ -119,7 +122,12 @@ public static void UpdateAvailableVersions(string packageName = "*", string repo Arguments = string.Format("\"{0}\" {1} {2} {3}", kGetVersionsJs, packageName, repoUrl, unity) }; Debug.Log(kHeader, "{0} {1}", psi.FileName, psi.Arguments); - new UnityEditor.Utils.Program(psi).Start(callback); + + var p = new UnityEditor.Utils.Program(psi); + if (callback != null) + p.Start((_, __) => callback(p._process.ExitCode == 0)); + else + p.Start(); } static void OnResultCreated(object o, FileSystemEventArgs e) diff --git a/Packages/com.coffee.upm-git-extension/Editor/Scripts/UI/InstallPackageWindow.cs b/Packages/com.coffee.upm-git-extension/Editor/Scripts/UI/InstallPackageWindow.cs index 078c808..05b0d72 100644 --- a/Packages/com.coffee.upm-git-extension/Editor/Scripts/UI/InstallPackageWindow.cs +++ b/Packages/com.coffee.upm-git-extension/Editor/Scripts/UI/InstallPackageWindow.cs @@ -33,7 +33,6 @@ public static bool IsResourceReady() //################################ public InstallPackageWindow() { - UIUtils.SetElementDisplay(this, false); VisualTreeAsset asset = EditorGUIUtility.Load(TemplatePath) as VisualTreeAsset; #if UNITY_2019_1_OR_NEWER @@ -82,13 +81,12 @@ public InstallPackageWindow() // Controll container closeButton.clickable.clicked += onClick_Close; - SetPhase(Phase.InputRepoUrl); + onClick_Close(); } public void Open() { UIUtils.SetElementDisplay(this, true); - SetPhase(Phase.InputRepoUrl); } //################################ @@ -105,81 +103,74 @@ public void Open() readonly Button versionSelectButton; readonly Label packageNameLabel; readonly TextField repoUrlText; - // IEnumerable versions = new string[0]; IEnumerable versions = new AvailableVersion[0]; - string refName = ""; + AvailableVersion currentVersion = null; - enum Phase + void EnableVersionContainer(bool flag) { - InputRepoUrl, - FindVersions, - SelectVersion, - FindPackage, - InstallPackage, + versionContainer.SetEnabled(flag); + versionSelectButton.SetEnabled(flag); + versionSelectButton.text = "-- Select package version --"; } - void SetPhase(Phase phase) + void EnablePackageContainer(bool flag, string name = "") { - bool canFindVersions = Phase.FindVersions <= phase; - repoUrlText.value = canFindVersions ? repoUrlText.value : ""; - findVersionsButton.SetEnabled(canFindVersions); - if (phase == Phase.FindVersions) - repoUrlText.Focus(); - - bool canSelectVersion = Phase.SelectVersion <= phase; - versionContainer.SetEnabled(canSelectVersion); - versionSelectButton.SetEnabled(canSelectVersion); - versionSelectButton.text = canSelectVersion ? versionSelectButton.text : "-- Select package version --"; - if (canSelectVersion) - { - findVersionsError.visible = false; - } - - bool canInstallPackage = Phase.InstallPackage <= phase; - packageContainer.SetEnabled(canInstallPackage); - packageNameLabel.text = canInstallPackage ? packageNameLabel.text : ""; - if (canInstallPackage || phase == Phase.InputRepoUrl) - { - findVersionsError.visible = false; - } + packageContainer.SetEnabled(flag); + installPackageButton.SetEnabled(flag); + packageNameLabel.text = name; } void onClick_Close() { UIUtils.SetElementDisplay(this, false); + + repoUrlText.value = ""; + findVersionsButton.SetEnabled(false); + + EnableVersionContainer(false); + EnablePackageContainer(false); } void onChange_RepoUrl(string url) { - SetPhase(string.IsNullOrEmpty(url) ? Phase.InputRepoUrl : Phase.FindVersions); + var valid = !string.IsNullOrEmpty(url); + findVersionsButton.SetEnabled(valid); + + EnableVersionContainer(false); + EnablePackageContainer(false); + + findVersionsError.visible = false; + currentVersion = null; } void onClick_FindVersions() { - SetPhase(Phase.FindVersions); root.SetEnabled(false); - AvailableVersions.Clear(repoUrl: repoUrlText.value); - AvailableVersions.UpdateAvailableVersions(repoUrl: repoUrlText.value, callback: (s, e)=>{ + EnableVersionContainer(false); + + var repoUrl = GetRepoUrl(repoUrlText.value); + AvailableVersions.Clear(repoUrl: repoUrl); + AvailableVersions.UpdateAvailableVersions(repoUrl: repoUrl, callback: success => + { root.SetEnabled(true); + EnableVersionContainer(success); + findVersionsError.visible = !success; }); - SetPhase(Phase.SelectVersion); } void onClick_SelectVersions() { var menu = new GenericMenu(); - var currentRefName = versionSelectButton.text; - GenericMenu.MenuFunction2 callback = (v) => { var version = v as AvailableVersion; + currentVersion = version; versionSelectButton.text = version.refNameText; - packageNameLabel.text = version.packageName; - refName = version.refName; - SetPhase(Phase.InstallPackage); + EnablePackageContainer(true, version.packageName); }; - foreach (var version in AvailableVersions.GetVersions(repoUrl: repoUrlText.value).OrderByDescending(v => v.version)) + var repoUrl = GetRepoUrl(repoUrlText.value); + foreach (var version in AvailableVersions.GetVersions(repoUrl: repoUrl).OrderByDescending(v => v.version)) { var text = version.refNameText; menu.AddItem(new GUIContent(text), versionSelectButton.text == text, callback, version); @@ -190,7 +181,7 @@ void onClick_SelectVersions() void onClick_InstallPackage() { - PackageUtils.InstallPackage(packageNameLabel.text, GetRepoUrl(repoUrlText.value), refName); + PackageUtils.InstallPackage(currentVersion.packageName, currentVersion.repoUrl, currentVersion.refName); onClick_Close(); }