├── CHANGELOG.md ├── CHANGELOG.md.meta ├── Documentation~ └── halodi-unity-package-registry-manager-screenshot.png ├── Editor.meta ├── Editor ├── Halodi.PackageRegistryManager.Editor.asmdef ├── Halodi.PackageRegistryManager.Editor.asmdef.meta ├── Halodi.meta ├── Halodi │ ├── PackageRegistry.meta │ └── PackageRegistry │ │ ├── Core.meta │ │ ├── Core │ │ ├── CredentialManager.cs │ │ ├── CredentialManager.cs.meta │ │ ├── RegistryManager.cs │ │ ├── RegistryManager.cs.meta │ │ ├── ScopedRegistry.cs │ │ ├── ScopedRegistry.cs.meta │ │ ├── UpgradePackagesManager.cs │ │ └── UpgradePackagesManager.cs.meta │ │ ├── NPM.meta │ │ ├── NPM │ │ ├── NPMLogin.cs │ │ ├── NPMLogin.cs.meta │ │ ├── NPMPublish.cs │ │ ├── NPMPublish.cs.meta │ │ ├── NPMResponse.cs │ │ ├── NPMResponse.cs.meta │ │ ├── PackageTarball.cs │ │ ├── PackageTarball.cs.meta │ │ ├── PublicationManifest.cs │ │ ├── PublicationManifest.cs.meta │ │ ├── WebExceptionParser.cs │ │ └── WebExceptionParser.cs.meta │ │ ├── UI.meta │ │ └── UI │ │ ├── BulkAddPackages.cs │ │ ├── BulkAddPackages.cs.meta │ │ ├── CredentialEditorView.cs │ │ ├── CredentialEditorView.cs.meta │ │ ├── CredentialManagerView.cs │ │ ├── CredentialManagerView.cs.meta │ │ ├── GetTokenView.cs │ │ ├── GetTokenView.cs.meta │ │ ├── InstallPackageCreator.cs │ │ ├── InstallPackageCreator.cs.meta │ │ ├── RegistryManagerView.cs │ │ ├── RegistryManagerView.cs.meta │ │ ├── ScopedRegistryEditorView.cs │ │ ├── ScopedRegistryEditorView.cs.meta │ │ ├── SettingsProvider.cs │ │ ├── SettingsProvider.cs.meta │ │ ├── UpgradePackagesView.cs │ │ └── UpgradePackagesView.cs.meta ├── ThirdParty.meta └── ThirdParty │ ├── LICENSE.Tomlyn.md │ ├── LICENSE.Tomlyn.md.meta │ ├── README.md │ ├── README.md.meta │ ├── Tomlyn.dll │ ├── Tomlyn.dll.meta │ ├── Unity-SemVer.meta │ └── Unity-SemVer │ ├── Artees.UnitySemVer.asmdef │ ├── Artees.UnitySemVer.asmdef.meta │ ├── CloudBuildManifest.cs │ ├── CloudBuildManifest.cs.meta │ ├── LICENSE │ ├── LICENSE.meta │ ├── README.md │ ├── README.md.meta │ ├── SemVer.cs │ ├── SemVer.cs.meta │ ├── SemVerAttribute.cs │ ├── SemVerAttribute.cs.meta │ ├── SemVerAutoBuild.cs │ ├── SemVerAutoBuild.cs.meta │ ├── SemVerComparer.cs │ ├── SemVerComparer.cs.meta │ ├── SemVerConverter.cs │ ├── SemVerConverter.cs.meta │ ├── SemVerErrorMessage.cs │ ├── SemVerErrorMessage.cs.meta │ ├── SemVerValidationResult.cs │ ├── SemVerValidationResult.cs.meta │ ├── SemVerValidator.cs │ └── SemVerValidator.cs.meta ├── LICENSE.md ├── LICENSE.md.meta ├── README.md ├── README.md.meta ├── Tests.meta ├── Tests ├── Editor.meta └── Editor │ ├── AssemblyInfo.cs │ ├── AssemblyInfo.cs.meta │ ├── Halodi.PackageRegistryManager.Tests.asmdef │ └── Halodi.PackageRegistryManager.Tests.asmdef.meta ├── package.json └── package.json.meta /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # ChangeLog 2 | 3 | 4 | ## 0.0.1 - 2020-05-11 5 | - Package created -------------------------------------------------------------------------------- /CHANGELOG.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3e6d9b2004fec8de1adc49c18ba1bdcb 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Documentation~/halodi-unity-package-registry-manager-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1x-technologies/halodi-unity-package-registry-manager/a496ca337ee0c1dc4b3461ec5b1fbbdb66e5467c/Documentation~/halodi-unity-package-registry-manager-screenshot.png -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f77bd7bac843b45d851f83be3888f20 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi.PackageRegistryManager.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Halodi.PackageRegistryManager.Editor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "Artees.SemanticVersioning" 6 | ], 7 | "includePlatforms": [ 8 | "Editor" 9 | ], 10 | "excludePlatforms": [], 11 | "allowUnsafeCode": false, 12 | "overrideReferences": true, 13 | "precompiledReferences": [ 14 | "Newtonsoft.Json.dll", 15 | "Unity.SharpZipLib.dll", 16 | "Tomlyn.dll" 17 | ], 18 | "autoReferenced": false, 19 | "defineConstraints": [], 20 | "versionDefines": [], 21 | "noEngineReferences": false 22 | } -------------------------------------------------------------------------------- /Editor/Halodi.PackageRegistryManager.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 69fe18a9ea685ee439ed87927dfee5c7 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/Halodi.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 089bef75d43e1ee5888d3be1e71e7ac4 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e0dc91072aad56afa8bf4204ca72e442 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4cf3f1318b46e144cbe43e9daf69c5b5 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/CredentialManager.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using Tomlyn; 7 | using Tomlyn.Model; 8 | using Tomlyn.Syntax; 9 | using UnityEngine; 10 | 11 | namespace Halodi.PackageRegistry.Core 12 | { 13 | public class NPMCredential 14 | { 15 | public string url; 16 | public string token; 17 | public bool alwaysAuth; 18 | } 19 | 20 | public class CredentialManager 21 | { 22 | private string upmconfigFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".upmconfig.toml"); 23 | private List credentials = new List(); 24 | 25 | public List CredentialSet 26 | { 27 | get 28 | { 29 | return credentials; 30 | } 31 | } 32 | 33 | public String[] Registries 34 | { 35 | get 36 | { 37 | String[] urls = new String[credentials.Count]; 38 | int index = 0; 39 | foreach (NPMCredential cred in CredentialSet) 40 | { 41 | urls[index] = cred.url; 42 | ++index; 43 | } 44 | return urls; 45 | } 46 | } 47 | 48 | public CredentialManager() 49 | { 50 | if (File.Exists(upmconfigFile)) 51 | { 52 | var upmconfig = Toml.Parse(File.ReadAllText(upmconfigFile)); 53 | if (upmconfig.HasErrors) 54 | { 55 | Debug.LogError("Cannot load upmconfig, invalid format"); 56 | return; 57 | } 58 | 59 | TomlTable table = upmconfig.ToModel(); 60 | 61 | if(table != null && table.ContainsKey("npmAuth")) 62 | { 63 | TomlTable auth = (TomlTable)table["npmAuth"]; 64 | if (auth != null) 65 | { 66 | foreach (var registry in auth) 67 | { 68 | NPMCredential cred = new NPMCredential(); 69 | cred.url = registry.Key; 70 | TomlTable value = (TomlTable)registry.Value; 71 | cred.token = (string)value["token"]; 72 | cred.alwaysAuth = (bool)value["alwaysAuth"]; 73 | 74 | credentials.Add(cred); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | 81 | public void Write() 82 | { 83 | var doc = new DocumentSyntax(); 84 | 85 | foreach (var credential in credentials) 86 | { 87 | if (string.IsNullOrEmpty(credential.token)) 88 | { 89 | credential.token = ""; 90 | } 91 | 92 | doc.Tables.Add(new TableSyntax(new KeySyntax("npmAuth", credential.url)) 93 | { 94 | Items = 95 | { 96 | {"token", credential.token}, 97 | {"alwaysAuth", credential.alwaysAuth} 98 | } 99 | }); 100 | 101 | } 102 | 103 | 104 | File.WriteAllText(upmconfigFile, doc.ToString()); 105 | } 106 | 107 | public bool HasRegistry(string url) 108 | { 109 | return credentials.Any(x => x.url.Equals(url, StringComparison.Ordinal)); 110 | } 111 | 112 | public NPMCredential GetCredential(string url) 113 | { 114 | return credentials.FirstOrDefault(x => x.url?.Equals(url, StringComparison.Ordinal) ?? false); 115 | } 116 | 117 | public void SetCredential(string url, bool alwaysAuth, string token) 118 | { 119 | if (HasRegistry(url)) 120 | { 121 | var cred = GetCredential(url); 122 | cred.url = url; 123 | cred.alwaysAuth = alwaysAuth; 124 | cred.token = token; 125 | } 126 | else 127 | { 128 | NPMCredential newCred = new NPMCredential(); 129 | newCred.url = url; 130 | newCred.alwaysAuth = alwaysAuth; 131 | newCred.token = token; 132 | 133 | credentials.Add(newCred); 134 | } 135 | } 136 | 137 | public void RemoveCredential(string url) 138 | { 139 | if (HasRegistry(url)) 140 | { 141 | credentials.RemoveAll(x => x.url.Equals(url, StringComparison.Ordinal)); 142 | } 143 | } 144 | } 145 | 146 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/CredentialManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d007b6fca56974d8f856529be2d2130a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/RegistryManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using Newtonsoft.Json.Linq; 5 | using UnityEditor; 6 | using UnityEngine; 7 | 8 | namespace Halodi.PackageRegistry.Core 9 | { 10 | public class RegistryManager 11 | { 12 | private string manifest = Path.Combine(Application.dataPath, "..", "Packages", "manifest.json"); 13 | 14 | public List registries 15 | { 16 | get; private set; 17 | } 18 | 19 | public CredentialManager credentialManager 20 | { 21 | get; 22 | private set; 23 | } 24 | 25 | public RegistryManager() 26 | { 27 | this.credentialManager = new CredentialManager(); 28 | this.registries = new List(); 29 | 30 | JObject manifestJSON = JObject.Parse(File.ReadAllText(manifest)); 31 | 32 | JArray Jregistries = (JArray)manifestJSON["scopedRegistries"]; 33 | if (Jregistries != null) 34 | { 35 | foreach (var JRegistry in Jregistries) 36 | { 37 | registries.Add(LoadRegistry((JObject)JRegistry)); 38 | } 39 | } 40 | else 41 | { 42 | Debug.Log("No scoped registries set"); 43 | } 44 | } 45 | 46 | private ScopedRegistry LoadRegistry(JObject Jregistry) 47 | { 48 | ScopedRegistry registry = new ScopedRegistry(); 49 | registry.name = (string)Jregistry["name"]; 50 | registry.url = (string)Jregistry["url"]; 51 | 52 | List scopes = new List(); 53 | foreach (var scope in (JArray)Jregistry["scopes"]) 54 | { 55 | scopes.Add((string)scope); 56 | } 57 | registry.scopes = new List(scopes); 58 | 59 | if (credentialManager.HasRegistry(registry.url)) 60 | { 61 | NPMCredential credential = credentialManager.GetCredential(registry.url); 62 | registry.auth = credential.alwaysAuth; 63 | registry.token = credential.token; 64 | } 65 | 66 | return registry; 67 | } 68 | 69 | private void UpdateScope(ScopedRegistry registry, JToken registryElement) { 70 | JArray scopes = new JArray(); 71 | foreach (var scope in registry.scopes) 72 | { 73 | scopes.Add(scope); 74 | } 75 | registryElement["scopes"] = scopes; 76 | } 77 | 78 | private JToken GetOrCreateScopedRegistry(ScopedRegistry registry, JObject manifestJSON) 79 | { 80 | JArray Jregistries = (JArray)manifestJSON["scopedRegistries"]; 81 | if (Jregistries == null) 82 | { 83 | Jregistries = new JArray(); 84 | manifestJSON["scopedRegistries"] = Jregistries; 85 | } 86 | 87 | foreach (var JRegistryElement in Jregistries) 88 | { 89 | if (JRegistryElement["name"] != null && JRegistryElement["url"] != null && 90 | String.Equals(JRegistryElement["name"].Value(), registry.name, StringComparison.Ordinal) && 91 | String.Equals(JRegistryElement["url" ].Value(), registry.url, StringComparison.Ordinal)) 92 | { 93 | UpdateScope(registry, JRegistryElement); 94 | return JRegistryElement; 95 | } 96 | } 97 | 98 | JObject JRegistry = new JObject(); 99 | JRegistry["name"] = registry.name; 100 | JRegistry["url"] = registry.url; 101 | UpdateScope(registry, JRegistry); 102 | Jregistries.Add(JRegistry); 103 | 104 | return JRegistry; 105 | } 106 | 107 | public void Remove(ScopedRegistry registry) 108 | { 109 | JObject manifestJSON = JObject.Parse(File.ReadAllText(manifest)); 110 | JArray Jregistries = (JArray)manifestJSON["scopedRegistries"]; 111 | 112 | foreach (var JRegistryElement in Jregistries) 113 | { 114 | if (JRegistryElement["name"] != null && JRegistryElement["url"] != null && 115 | JRegistryElement["name"].Value().Equals(registry.name, StringComparison.Ordinal) && 116 | JRegistryElement["url" ].Value().Equals(registry.url, StringComparison.Ordinal)) 117 | { 118 | JRegistryElement.Remove(); 119 | break; 120 | } 121 | } 122 | 123 | write(manifestJSON); 124 | } 125 | 126 | public void Save(ScopedRegistry registry) 127 | { 128 | JObject manifestJSON = JObject.Parse(File.ReadAllText(manifest)); 129 | 130 | JToken manifestRegistry = GetOrCreateScopedRegistry(registry, manifestJSON); 131 | 132 | if(!string.IsNullOrEmpty(registry.token)) 133 | { 134 | credentialManager.SetCredential(registry.url, registry.auth, registry.token); 135 | } 136 | else 137 | { 138 | credentialManager.RemoveCredential(registry.url); 139 | } 140 | 141 | write(manifestJSON); 142 | 143 | credentialManager.Write(); 144 | } 145 | 146 | private void write(JObject manifestJSON) 147 | { 148 | File.WriteAllText(manifest, manifestJSON.ToString()); 149 | AssetDatabase.Refresh(); 150 | } 151 | } 152 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/RegistryManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed727f03f93e90392bda8e4663336ae2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/ScopedRegistry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Halodi.PackageRegistry.Core 6 | { 7 | [System.Serializable] 8 | public class ScopedRegistry 9 | { 10 | public string name; 11 | public string url; 12 | public List scopes = new List(); 13 | 14 | public bool auth; 15 | 16 | public string token; 17 | 18 | public override string ToString() 19 | { 20 | return JsonUtility.ToJson(this, true); 21 | } 22 | 23 | public bool isValidCredential() 24 | { 25 | 26 | if( string.IsNullOrEmpty(url) || !Uri.IsWellFormedUriString(url, UriKind.Absolute)) 27 | { 28 | return false; 29 | } 30 | 31 | 32 | if(auth) 33 | { 34 | if(string.IsNullOrEmpty(token)) 35 | { 36 | return false; 37 | } 38 | } 39 | 40 | return true; 41 | } 42 | 43 | public bool isValid() 44 | { 45 | if(string.IsNullOrEmpty(name)) 46 | { 47 | return false; 48 | } 49 | 50 | if(scopes.Count < 1) 51 | { 52 | return false; 53 | } 54 | 55 | scopes.RemoveAll(string.IsNullOrEmpty); 56 | 57 | foreach(string scope in scopes) 58 | { 59 | if(Uri.CheckHostName(scope) != UriHostNameType.Dns) 60 | { 61 | Debug.LogWarning("Invalid scope " + scope); 62 | return false; 63 | } 64 | } 65 | 66 | 67 | return isValidCredential(); 68 | 69 | 70 | } 71 | } 72 | 73 | 74 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/ScopedRegistry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: be826e7a3923f2b79b58b8a5d923ba54 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/UpgradePackagesManager.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using UnityEditor.PackageManager.Requests; 4 | using UnityEditor.PackageManager; 5 | using System.Threading; 6 | using System.Collections.Generic; 7 | using Artees.UnitySemVer; 8 | using System; 9 | 10 | namespace Halodi.PackageRegistry.Core 11 | { 12 | public class UpgradePackagesManager 13 | { 14 | 15 | public class PackageUpgradeState 16 | { 17 | public PackageUpgradeState(UnityEditor.PackageManager.PackageInfo info) 18 | { 19 | this.info = info; 20 | previewAvailable = false; 21 | stableAvailable = false; 22 | verifiedAvailable = false; 23 | hasVerified = false; 24 | stableVersion = SemVer.Parse(info.version); 25 | previewVersion = SemVer.Parse(info.version); 26 | 27 | 28 | 29 | try 30 | { 31 | current = SemVer.Parse(info.version); 32 | } 33 | catch 34 | { 35 | Debug.LogError("Cannot parse version for package " + info.displayName + ": " + info.version); 36 | } 37 | 38 | if (info.source == PackageSource.Git) 39 | { 40 | 41 | previewAvailable = true; 42 | preview = info.packageId; 43 | 44 | stableAvailable = true; 45 | stable = info.packageId; 46 | } 47 | else if (info.source == PackageSource.Registry) 48 | { 49 | 50 | string[] compatible = info.versions.compatible; 51 | 52 | foreach (string ver in compatible) 53 | { 54 | try 55 | { 56 | SemVer version = SemVer.Parse(ver); 57 | 58 | if (string.IsNullOrWhiteSpace(version.preRelease)) 59 | { 60 | if (version > stableVersion) 61 | { 62 | stableVersion = version; 63 | stableAvailable = true; 64 | stable = info.name + "@" + ver; 65 | } 66 | } 67 | else 68 | { 69 | // This is a pre-release 70 | if (version > previewVersion) 71 | { 72 | previewVersion = version; 73 | previewAvailable = true; 74 | preview = info.name + "@" + ver; 75 | } 76 | 77 | } 78 | } 79 | catch 80 | { 81 | Debug.LogError("Invalid version for package " + info.displayName + ": " + ver); 82 | } 83 | } 84 | 85 | #if UNITY_2022_2_OR_NEWER 86 | string verified = info.versions.recommended; 87 | #else 88 | string verified = info.versions.verified; 89 | #endif 90 | 91 | hasVerified = !String.IsNullOrWhiteSpace(verified); 92 | 93 | if(hasVerified) 94 | { 95 | try 96 | { 97 | verifiedVersion = SemVer.Parse(verified); 98 | if(verifiedVersion > current) 99 | { 100 | verifiedAvailable = verifiedVersion > current; 101 | verified = info.name + "@" + verified; 102 | } 103 | 104 | } 105 | catch 106 | { 107 | Debug.LogError("Cannot parse version for package " + info.displayName + ": " + verified); 108 | } 109 | } 110 | } 111 | } 112 | 113 | internal string GetCurrentVersion() 114 | { 115 | return info.packageId; 116 | } 117 | 118 | public UnityEditor.PackageManager.PackageInfo info; 119 | 120 | private SemVer current; 121 | 122 | private bool previewAvailable; 123 | private SemVer previewVersion; 124 | 125 | private string preview; 126 | 127 | private bool stableAvailable; 128 | private SemVer stableVersion; 129 | 130 | private string stable; 131 | 132 | private bool hasVerified; 133 | private bool verifiedAvailable; 134 | private SemVer verifiedVersion; 135 | private string verified; 136 | 137 | public bool HasNewVersion(bool showPreviewVersion, bool useVerified) 138 | { 139 | if(useVerified && hasVerified) 140 | { 141 | return verifiedAvailable; 142 | } 143 | else if (showPreviewVersion) 144 | { 145 | return previewAvailable || stableAvailable; 146 | 147 | } 148 | else 149 | { 150 | return stableAvailable; 151 | } 152 | } 153 | 154 | public string GetNewestVersion(bool showPreviewVersion, bool useVerified) 155 | { 156 | if(useVerified && hasVerified) 157 | { 158 | if(verifiedAvailable) 159 | { 160 | return verified; 161 | } 162 | } 163 | else if (showPreviewVersion) 164 | { 165 | if (previewAvailable) 166 | { 167 | if (!stableAvailable || previewVersion > stableVersion) 168 | { 169 | return preview; 170 | } 171 | } 172 | } 173 | if (stableAvailable) 174 | { 175 | if (stableAvailable) 176 | { 177 | return stable; 178 | } 179 | } 180 | 181 | return null; 182 | } 183 | } 184 | 185 | public List UpgradeablePackages = new List(); 186 | 187 | private ListRequest request; 188 | 189 | public bool packagesLoaded = false; 190 | 191 | public UpgradePackagesManager() 192 | { 193 | #if UNITY_2019_1_OR_NEWER 194 | request = Client.List(false, false); 195 | #else 196 | request = Client.List(); 197 | #endif 198 | } 199 | 200 | public void Update() 201 | { 202 | if (!packagesLoaded && request.IsCompleted) 203 | { 204 | if (request.Status == StatusCode.Success) 205 | { 206 | PackageCollection collection = request.Result; 207 | foreach (UnityEditor.PackageManager.PackageInfo info in collection) 208 | { 209 | UpgradeablePackages.Add(new PackageUpgradeState(info)); 210 | } 211 | } 212 | else 213 | { 214 | Debug.LogError("Cannot query package manager for packages"); 215 | } 216 | 217 | packagesLoaded = true; 218 | } 219 | } 220 | 221 | 222 | public bool UpgradePackage(String packageWithVersion, ref string error) 223 | { 224 | AddRequest request = UnityEditor.PackageManager.Client.Add(packageWithVersion); 225 | 226 | while (!request.IsCompleted) 227 | { 228 | Thread.Sleep(100); 229 | } 230 | 231 | if (request.Status == StatusCode.Success) 232 | { 233 | return true; 234 | } 235 | else 236 | { 237 | error = request.Error.message; 238 | return false; 239 | } 240 | 241 | 242 | } 243 | 244 | 245 | } 246 | } 247 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/Core/UpgradePackagesManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 62211760241e94052a18720a8ae0a8ff 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2bdc72b5107d76fc9b0eefd914b165d1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMLogin.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using System.IO; 4 | using System.Net; 5 | using System.Text; 6 | using UnityEngine; 7 | using Random = System.Random; 8 | 9 | namespace Halodi.PackageRegistry.NPM 10 | { 11 | [System.Serializable] 12 | internal class NPMLoginRequest 13 | { 14 | public string name; 15 | public string password; 16 | } 17 | 18 | 19 | public class ExpectContinueAware : System.Net.WebClient 20 | { 21 | protected override System.Net.WebRequest GetWebRequest(Uri address) 22 | { 23 | System.Net.WebRequest request = base.GetWebRequest(address); 24 | if (request is System.Net.HttpWebRequest) 25 | { 26 | var hwr = request as System.Net.HttpWebRequest; 27 | hwr.ServicePoint.Expect100Continue = false; 28 | hwr.AllowAutoRedirect = false; 29 | } 30 | return request; 31 | } 32 | } 33 | 34 | 35 | public class NPMLogin 36 | { 37 | internal static string UrlCombine(string start, string more) 38 | { 39 | if (string.IsNullOrEmpty(start)) 40 | { 41 | return more; 42 | } 43 | else if (string.IsNullOrEmpty(more)) 44 | { 45 | return start; 46 | } 47 | 48 | return start.TrimEnd('/') + "/" + more.TrimStart('/'); 49 | } 50 | 51 | public static string GetBintrayToken(string user, string apiKey) 52 | { 53 | return Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + apiKey)); 54 | } 55 | 56 | public static NPMResponse GetLoginToken(string url, string user, string password) 57 | { 58 | using (var client = new WebClient()) 59 | { 60 | string loginUri = UrlCombine(url, "/-/user/org.couchdb.user:" + user); 61 | client.Headers.Add(HttpRequestHeader.Accept, "application/json"); 62 | client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); 63 | client.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + password))); 64 | 65 | NPMLoginRequest request = new NPMLoginRequest(); 66 | request.name = user; 67 | request.password = password; 68 | 69 | string requestString = JsonUtility.ToJson(request); 70 | 71 | try 72 | { 73 | string responseString = client.UploadString(loginUri, WebRequestMethods.Http.Put, requestString); 74 | NPMResponse response = JsonUtility.FromJson(responseString); 75 | return response; 76 | } 77 | catch (WebException e) 78 | { 79 | NPMResponse response = new NPMResponse(); 80 | response.error = WebExceptionParser.ParseWebException(e); 81 | return response; 82 | 83 | } 84 | } 85 | } 86 | 87 | 88 | 89 | 90 | } 91 | 92 | } 93 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMLogin.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b48148742aea9c373b5a101a0794ff57 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMPublish.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using Halodi.PackageRegistry.Core; 6 | using UnityEngine; 7 | 8 | namespace Halodi.PackageRegistry.NPM 9 | { 10 | public class NPMPublish 11 | { 12 | public static void Publish(string packageFolder, string registry) 13 | { 14 | CredentialManager manager = new CredentialManager(); 15 | if (!manager.HasRegistry(registry)) 16 | { 17 | throw new System.IO.IOException("Credentials not set for registry " + registry); 18 | } 19 | 20 | string token = manager.GetCredential(registry).token; 21 | 22 | PublicationManifest manifest = new PublicationManifest(packageFolder, registry); ; 23 | 24 | 25 | 26 | 27 | using (var client = new ExpectContinueAware()) 28 | { 29 | string upload = NPMLogin.UrlCombine(registry, manifest.name); 30 | 31 | 32 | client.Encoding = Encoding.UTF8; 33 | client.Headers.Add(HttpRequestHeader.Accept, "application/json"); 34 | client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); 35 | client.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + token); 36 | 37 | 38 | // Headers set by the NPM client, but not by us. Option to try with compatibility issues. 39 | 40 | // client.Headers.Add("npm-in-ci", "false"); 41 | // client.Headers.Add("npm-scope", ""); 42 | // client.Headers.Add(HttpRequestHeader.UserAgent, "npm/6.14.4 node/v12.16.2 linux x64"); 43 | // var random = new Random(); 44 | // string a = String.Format("{0:X8}", random.Next(0x10000000, int.MaxValue)).ToLower(); 45 | // string b = String.Format("{0:X8}", random.Next(0x10000000, int.MaxValue)).ToLower(); 46 | 47 | // client.Headers.Add("npm-session", a + b); 48 | // client.Headers.Add("referer", "publish"); 49 | 50 | 51 | try 52 | { 53 | string responseString = client.UploadString(upload, WebRequestMethods.Http.Put, manifest.Request); 54 | 55 | try 56 | { 57 | NPMResponse response = JsonUtility.FromJson(responseString); 58 | if (!response.success && string.IsNullOrEmpty(response.ok)) 59 | { 60 | throw new System.IO.IOException(responseString); 61 | } 62 | } 63 | catch (Exception) 64 | { 65 | throw new System.IO.IOException(responseString); 66 | } 67 | 68 | 69 | } 70 | catch (WebException e) 71 | { 72 | throw new System.IO.IOException(WebExceptionParser.ParseWebException(e)); 73 | } 74 | } 75 | 76 | } 77 | 78 | 79 | } 80 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMPublish.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4c14ed213814c5c26835ad084ee31ef0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Halodi.PackageRegistry.NPM 2 | { 3 | [System.Serializable] 4 | public class NPMResponse 5 | { 6 | public string error; 7 | public string ok; 8 | public string token; 9 | 10 | public bool success; 11 | 12 | public string reason; 13 | } 14 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/NPMResponse.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1686b71fd1b8d8ad91a35d5a7994008 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/PackageTarball.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System.IO; 3 | using Unity.SharpZipLib.GZip; 4 | using Unity.SharpZipLib.Tar; 5 | 6 | namespace Halodi.PackageRegistry.NPM 7 | { 8 | 9 | /// 10 | /// Tool to create tarballs for packages. 11 | /// UnityEditor.PackageManager.Client.Pack() creates a broken tarball that gets rejected by bintray. 12 | /// 13 | public class PackageTarball 14 | { 15 | public static string Create(string packageFolder, string outputFolder) 16 | { 17 | JObject manifest = PublicationManifest.LoadManifest(packageFolder); 18 | 19 | string packageName = manifest["name"] + "-" + manifest["version"] + ".tgz"; 20 | 21 | Directory.CreateDirectory(outputFolder); 22 | 23 | string outputFile = Path.Combine(outputFolder, packageName); 24 | 25 | 26 | Stream outStream = File.Create(outputFile); 27 | Stream gzoStream = new GZipOutputStream(outStream); 28 | TarArchive tarArchive = TarArchive.CreateOutputTarArchive(gzoStream); 29 | 30 | AddDirectoryFilesToTar(tarArchive, packageFolder, true, "packages/"); 31 | tarArchive.Close(); 32 | gzoStream.Close(); 33 | outStream.Close(); 34 | 35 | return outputFile; 36 | } 37 | 38 | 39 | 40 | private static string AppendDirectorySeparatorChar(string path) 41 | { 42 | // Append a slash only if the path is a directory and does not have a slash. 43 | if (Directory.Exists(path) && 44 | !path.EndsWith(Path.DirectorySeparatorChar.ToString())) 45 | { 46 | return path + Path.DirectorySeparatorChar; 47 | } 48 | 49 | return path; 50 | } 51 | 52 | 53 | 54 | private static void AddDirectoryFilesToTar(TarArchive tarArchive, string sourceDirectory, bool recurse, string directoryName) 55 | { 56 | // Optionally, write an entry for the directory itself. 57 | // Specify false for recursion here if we will add the directory's files individually. 58 | TarEntry tarEntry = TarEntry.CreateEntryFromFile(sourceDirectory); 59 | tarEntry.Name = directoryName; 60 | tarArchive.WriteEntry(tarEntry, false); 61 | 62 | // Write each file to the tar. 63 | string[] filenames = Directory.GetFiles(sourceDirectory); 64 | foreach (string filename in filenames) 65 | { 66 | TarEntry fileEntry = TarEntry.CreateEntryFromFile(filename); 67 | fileEntry.Name = directoryName + Path.GetFileName(filename); 68 | tarArchive.WriteEntry(fileEntry, true); 69 | } 70 | 71 | if (recurse) 72 | { 73 | string[] directories = Directory.GetDirectories(sourceDirectory); 74 | foreach (string directory in directories) 75 | { 76 | string dirname = new DirectoryInfo(directory).Name; 77 | if (dirname == ".git") 78 | { 79 | continue; 80 | } 81 | string newDirectory = directoryName + dirname + "/"; 82 | AddDirectoryFilesToTar(tarArchive, directory, recurse, newDirectory); 83 | } 84 | } 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/PackageTarball.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 65eda3cbab9699e01aee646d705bf241 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/PublicationManifest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Security.Cryptography; 4 | using System.Threading; 5 | using Newtonsoft.Json.Linq; 6 | using UnityEditor; 7 | using UnityEditor.PackageManager; 8 | using UnityEditor.PackageManager.Requests; 9 | using UnityEngine; 10 | using System.Linq; 11 | using Newtonsoft.Json; 12 | using System.Text.RegularExpressions; 13 | using Halodi.PackageRegistry.Core; 14 | 15 | namespace Halodi.PackageRegistry.NPM 16 | { 17 | /// 18 | /// Helper class to create the JSON data to upload to the package server 19 | /// 20 | internal class PublicationManifest 21 | { 22 | private JObject j = new JObject(); 23 | 24 | public string name 25 | { 26 | get; private set; 27 | } 28 | 29 | private string base64Data; 30 | private long size; 31 | private string sha512; 32 | private string sha1; 33 | 34 | public string Request 35 | { 36 | get 37 | { 38 | return j.ToString(Formatting.None); 39 | } 40 | } 41 | 42 | internal static JObject LoadManifest(string packageFolder) 43 | { 44 | string manifestPath = Path.Combine(packageFolder, "package.json"); 45 | 46 | if (!File.Exists(manifestPath)) 47 | { 48 | throw new System.IO.IOException("Invalid package folder. Cannot find package.json in " + packageFolder); 49 | } 50 | 51 | JObject manifest = JObject.Parse(File.ReadAllText(manifestPath)); 52 | 53 | if (manifest["name"] == null) 54 | { 55 | throw new System.IO.IOException("Package name not set"); 56 | } 57 | 58 | if (manifest["version"] == null) 59 | { 60 | throw new System.IO.IOException("Package version not set"); 61 | } 62 | 63 | if (manifest["description"] == null) 64 | { 65 | throw new System.IO.IOException("Package description not set"); 66 | } 67 | 68 | return manifest; 69 | } 70 | 71 | 72 | 73 | internal PublicationManifest(string packageFolder, string registry) 74 | { 75 | 76 | CreateTarball(packageFolder); 77 | 78 | JObject manifest = LoadManifest(packageFolder); 79 | 80 | name = manifest["name"].ToString(); 81 | string version = manifest["version"].ToString(); 82 | string description = manifest["description"].ToString(); 83 | 84 | string tarballName = name + "-" + version + ".tgz"; 85 | string tarballPath = name + "/-/" + tarballName; 86 | 87 | 88 | string tarballUri = NPMLogin.UrlCombine(registry, tarballPath); 89 | tarballUri = Regex.Replace(tarballUri, @"^https:\/\/", "http://"); 90 | 91 | 92 | string readmeFile = GetReadmeFilename(packageFolder); 93 | string readme = null; 94 | if(readmeFile != null) 95 | { 96 | readme = GetReadme(readmeFile); 97 | } 98 | 99 | 100 | 101 | 102 | j["_id"] = name; 103 | j["name"] = name; 104 | j["description"] = description; 105 | 106 | 107 | 108 | j["dist-tags"] = new JObject(); 109 | j["dist-tags"]["latest"] = version; 110 | 111 | 112 | j["versions"] = new JObject(); 113 | j["versions"][version] = manifest; 114 | 115 | if (!string.IsNullOrEmpty(readmeFile)) 116 | { 117 | j["versions"][version]["readme"] = readme; 118 | j["versions"][version]["readmeFilename"] = readmeFile; 119 | } 120 | 121 | j["versions"][version]["_id"] = name + "@" + version; 122 | 123 | 124 | // Extra options set by the NPM client. Will not set here as they do not seem neccessary. 125 | 126 | // j["versions"][version]["_npmUser"] = new JObject(); 127 | // j["versions"][version]["_npmUser"]["name"] = ""; 128 | // j["versions"][version]["_npmUser"]["email"] = ""; 129 | // j["versions"][version]["_npmVersion"] = "6.14.4"; 130 | // j["versions"][version]["_nodeVersion"] = "12.16.2"; 131 | 132 | j["versions"][version]["dist"] = new JObject(); 133 | j["versions"][version]["dist"]["integrity"] = sha512; 134 | j["versions"][version]["dist"]["shasum"] = sha1; 135 | j["versions"][version]["dist"]["tarball"] = tarballUri.ToString(); 136 | 137 | if (!string.IsNullOrEmpty(readme)) 138 | { 139 | j["readme"] = readme; 140 | } 141 | 142 | j["_attachments"] = new JObject(); 143 | j["_attachments"][tarballName] = new JObject(); 144 | j["_attachments"][tarballName]["content_type"] = "application/octet-stream"; 145 | j["_attachments"][tarballName]["length"] = new JValue(size); 146 | j["_attachments"][tarballName]["data"] = base64Data; 147 | 148 | } 149 | 150 | private string GetReadmeFilename(string packageFolder) 151 | { 152 | foreach (var path in Directory.EnumerateFiles(packageFolder)) 153 | { 154 | string file = Path.GetFileName(path); 155 | if (file.Equals("readme.md", StringComparison.InvariantCultureIgnoreCase) || 156 | file.Equals("readme.txt", StringComparison.InvariantCultureIgnoreCase) || 157 | file.Equals("readme", StringComparison.InvariantCultureIgnoreCase)) 158 | { 159 | return path; 160 | } 161 | } 162 | return null; 163 | } 164 | 165 | private string GetReadme(string readmeFile) 166 | { 167 | return File.ReadAllText(readmeFile); 168 | } 169 | 170 | private string SHA512(byte[] data) 171 | { 172 | var sha = new SHA512Managed(); 173 | byte[] checksum = sha.ComputeHash(data); 174 | return "sha512-" + Convert.ToBase64String(checksum); 175 | } 176 | private string SHA1(byte[] data) 177 | { 178 | var sha = new SHA1Managed(); 179 | byte[] checksum = sha.ComputeHash(data); 180 | return BitConverter.ToString(checksum).Replace("-", string.Empty).ToLower(); 181 | } 182 | 183 | 184 | 185 | public void CreateTarball(string packageFolder) 186 | { 187 | string folder = FileUtil.GetUniqueTempPathInProject(); 188 | string file = PackageTarball.Create(packageFolder, folder); 189 | 190 | Byte[] bytes = File.ReadAllBytes(file); 191 | base64Data = Convert.ToBase64String(bytes); 192 | size = bytes.Length; 193 | 194 | sha1 = SHA1(bytes); 195 | sha512 = SHA512(bytes); 196 | 197 | File.Delete(file); 198 | Directory.Delete(folder); 199 | 200 | } 201 | 202 | 203 | } 204 | } 205 | 206 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/PublicationManifest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0c6809e15491b0062ad2e9c9aa05a72a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/WebExceptionParser.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Halodi.PackageRegistry.NPM 4 | { 5 | public class WebExceptionParser 6 | { 7 | public static string ParseWebException(WebException e) 8 | { 9 | if (e.Status == WebExceptionStatus.ProtocolError) 10 | { 11 | HttpWebResponse response = (HttpWebResponse)e.Response; 12 | 13 | switch (response.StatusCode) 14 | { 15 | case HttpStatusCode.Unauthorized: 16 | return response.StatusCode + ": Invalid credentials."; 17 | case HttpStatusCode.BadRequest: 18 | case HttpStatusCode.Conflict: 19 | return response.StatusCode + ": Check if version already exists on server."; 20 | default: 21 | return response.StatusCode + ": Unknown error. Try again."; 22 | 23 | } 24 | 25 | } 26 | else 27 | { 28 | if (e.InnerException != null) 29 | { 30 | return e.InnerException.Message; 31 | } 32 | else 33 | { 34 | return e.Message; 35 | } 36 | } 37 | 38 | 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/NPM/WebExceptionParser.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 38840c461d1475a36bb61118358e2b51 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a67360ebdc1e6d247b183859bd4be8a1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/BulkAddPackages.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Threading; 4 | using UnityEditor; 5 | using UnityEditor.PackageManager; 6 | using UnityEditor.PackageManager.Requests; 7 | using UnityEngine; 8 | 9 | namespace Halodi.PackageRegistry.UI 10 | { 11 | public class BulkAddPackages : EditorWindow 12 | { 13 | private string PackageList = ""; 14 | 15 | [MenuItem("Packages/Add packages (bulk)", false, 22)] 16 | internal static void ManageRegistries() 17 | { 18 | EditorWindow.GetWindow(true, "Add packages", true); 19 | } 20 | 21 | void OnEnable() 22 | { 23 | PackageList = ""; 24 | minSize = new Vector2(640, 320); 25 | } 26 | void OnGUI() 27 | { 28 | EditorGUILayout.LabelField("Add Packages", EditorStyles.whiteLargeLabel); 29 | EditorGUILayout.Separator(); 30 | 31 | PackageList = EditorGUILayout.TextArea(PackageList, GUILayout.Height(200)); 32 | 33 | EditorGUILayout.LabelField("Add multiple packages. Place each package on a newline."); 34 | EditorGUILayout.LabelField("Format:."); 35 | EditorGUILayout.LabelField("\tLatest version of package: com.halodi.halodi-unity-package-registry-manager"); 36 | EditorGUILayout.LabelField("\tSpecific version: com.halodi.halodi-unity-package-registry-manager@0.1.0"); 37 | 38 | 39 | 40 | EditorGUILayout.BeginHorizontal(); 41 | if (GUILayout.Button("Add packages")) 42 | { 43 | AddPackages(); 44 | CloseWindow(); 45 | } 46 | 47 | if (GUILayout.Button("Close")) 48 | { 49 | CloseWindow(); 50 | } 51 | 52 | EditorGUILayout.EndHorizontal(); 53 | 54 | } 55 | 56 | private void AddPackages() 57 | { 58 | string result = ""; 59 | 60 | bool hasPackages = false; 61 | 62 | using (StringReader reader = new StringReader(PackageList)) 63 | { 64 | string line = string.Empty; 65 | while ( (line = reader.ReadLine()) != null) 66 | { 67 | if(!string.IsNullOrEmpty(line)) 68 | { 69 | AddRequest request = UnityEditor.PackageManager.Client.Add(line); 70 | 71 | while(!request.IsCompleted) 72 | { 73 | Thread.Sleep(100); 74 | } 75 | 76 | if(request.Status == StatusCode.Success) 77 | { 78 | result += "Imported: " + line + Environment.NewLine; 79 | } 80 | else 81 | { 82 | result += "Cannot import " + line + ": " + request.Error.message + Environment.NewLine; 83 | } 84 | hasPackages = true; 85 | } 86 | } 87 | } 88 | 89 | if(hasPackages) 90 | { 91 | EditorUtility.DisplayDialog("Added packages", "Packages added:" + Environment.NewLine + Environment.NewLine + result, "OK"); 92 | } 93 | else 94 | { 95 | EditorUtility.DisplayDialog("No packages entered", "No packages entered.", "OK"); 96 | } 97 | } 98 | 99 | private void CloseWindow() 100 | { 101 | Close(); 102 | GUIUtility.ExitGUI(); 103 | } 104 | 105 | } 106 | 107 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/BulkAddPackages.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 392cfa6b2194898f5a5328604b1e4814 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/CredentialEditorView.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using Halodi.PackageRegistry.Core; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | namespace Halodi.PackageRegistry.UI 8 | { 9 | class CredentialEditorView : EditorWindow 10 | { 11 | private bool initialized = false; 12 | 13 | private CredentialManager credentialManager; 14 | 15 | private bool createNew; 16 | 17 | private ScopedRegistry registry; 18 | 19 | private int tokenMethod; 20 | 21 | 22 | void OnEnable() 23 | { 24 | tokenMethod = 0; 25 | minSize = new Vector2(480, 320); 26 | } 27 | 28 | void OnDisable() 29 | { 30 | initialized = false; 31 | } 32 | 33 | public void CreateNew(CredentialManager credentialManager) 34 | { 35 | this.credentialManager = credentialManager; 36 | this.createNew = true; 37 | this.registry = new ScopedRegistry(); 38 | this.initialized = true; 39 | } 40 | 41 | public void Edit(NPMCredential credential, CredentialManager credentialManager) 42 | { 43 | this.credentialManager = credentialManager; 44 | this.registry = new ScopedRegistry(); 45 | this.registry.url = credential.url; 46 | this.registry.auth = credential.alwaysAuth; 47 | this.registry.token = credential.token; 48 | 49 | this.createNew = false; 50 | this.initialized = true; 51 | } 52 | 53 | void OnGUI() 54 | { 55 | if (initialized) 56 | { 57 | if (createNew) 58 | { 59 | EditorGUILayout.LabelField("Add credential", EditorStyles.whiteLargeLabel); 60 | 61 | registry.url = EditorGUILayout.TextField("Registry URL", registry.url); 62 | } 63 | else 64 | { 65 | EditorGUILayout.LabelField("Edit credential", EditorStyles.whiteLargeLabel); 66 | EditorGUILayout.LabelField("Registry URL: " + registry.url); 67 | } 68 | 69 | if(string.IsNullOrEmpty(registry.url)) 70 | { 71 | EditorGUILayout.HelpBox("Enter the registry URL you want to add authentication for.", MessageType.Warning); 72 | } 73 | 74 | registry.auth = EditorGUILayout.Toggle("Always auth", registry.auth); 75 | registry.token = EditorGUILayout.TextField("Token", registry.token); 76 | 77 | EditorGUILayout.Space(); 78 | 79 | EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(registry.url)); 80 | tokenMethod = GetTokenView.CreateGUI(tokenMethod, registry); 81 | 82 | if (!string.IsNullOrEmpty(registry.url) && string.IsNullOrEmpty(registry.token)) 83 | { 84 | EditorGUILayout.HelpBox("Select an authentication method and click on \"Get token\"", MessageType.Warning); 85 | } 86 | 87 | EditorGUI.BeginDisabledGroup(string.IsNullOrEmpty(registry.token)); 88 | 89 | EditorGUILayout.Space(); 90 | EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true)); 91 | EditorGUILayout.EndVertical(); 92 | 93 | EditorGUILayout.HelpBox("Restart Unity to reload credentials after saving.", MessageType.Info); 94 | EditorGUILayout.BeginHorizontal(); 95 | if (createNew) 96 | { 97 | if (GUILayout.Button("Add")) 98 | { 99 | Save(); 100 | } 101 | } 102 | else 103 | { 104 | if (GUILayout.Button("Save")) 105 | { 106 | Save(); 107 | } 108 | } 109 | 110 | EditorGUI.EndDisabledGroup(); 111 | EditorGUI.EndDisabledGroup(); 112 | 113 | if (GUILayout.Button("Cancel")) 114 | { 115 | Close(); 116 | GUIUtility.ExitGUI(); 117 | } 118 | EditorGUILayout.EndHorizontal(); 119 | } 120 | } 121 | 122 | private void Save() 123 | { 124 | if (registry.isValidCredential() && !string.IsNullOrEmpty(registry.token)) 125 | { 126 | credentialManager.SetCredential(registry.url, registry.auth, registry.token); 127 | credentialManager.Write(); 128 | 129 | // TODO figure out in which cases/Editor versions a restart is actually required, 130 | // and where a Client.Resolve() call or PackMan reload is sufficient 131 | if (EditorUtility.DisplayDialog("Unity Editor restart might be required", "The Unity editor might need to be restarted for this change to take effect.", "Restart Now", "Cancel")) 132 | { 133 | EditorApplication.OpenProject(Environment.CurrentDirectory); 134 | } 135 | 136 | Close(); 137 | GUIUtility.ExitGUI(); 138 | } 139 | else 140 | { 141 | EditorUtility.DisplayDialog("Invalid", "Invalid settings for credential.", "Ok"); 142 | } 143 | } 144 | 145 | 146 | 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/CredentialEditorView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aed147722dfd212f18ab415b2ced4be3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/CredentialManagerView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Halodi.PackageRegistry.Core; 5 | using UnityEditor; 6 | using UnityEditorInternal; 7 | using UnityEngine; 8 | 9 | namespace Halodi.PackageRegistry.UI 10 | { 11 | public class CredentialManagerView : EditorWindow 12 | { 13 | 14 | private ReorderableList drawer; 15 | 16 | void OnEnable() 17 | { 18 | drawer = GetCredentialList(new CredentialManager()); 19 | minSize = new Vector2(640, 320); 20 | } 21 | 22 | void OnGUI() 23 | { 24 | drawer.DoLayoutList(); 25 | } 26 | 27 | internal static ReorderableList GetCredentialList(CredentialManager credentialManager) 28 | { 29 | ReorderableList credentialList = null; 30 | credentialList = new ReorderableList(credentialManager.CredentialSet, typeof(NPMCredential), false, true, true, true) 31 | { 32 | drawHeaderCallback = rect => 33 | { 34 | GUI.Label(rect, "User Credentials on this computer"); 35 | }, 36 | drawElementCallback = (rect, index, active, focused) => 37 | { 38 | var credential = credentialList.list[index] as NPMCredential; 39 | if (credential == null) return; 40 | 41 | rect.width -= 60; 42 | EditorGUI.LabelField(rect, credential.url); 43 | 44 | rect.x += rect.width; 45 | rect.width = 60; 46 | if (GUI.Button(rect, "Edit")) 47 | { 48 | CredentialEditorView credentialEditor = EditorWindow.GetWindow(true, "Edit credential", true); 49 | credentialEditor.Edit(credential, credentialManager); 50 | } 51 | }, 52 | onAddCallback = reorderableList => 53 | { 54 | CredentialEditorView credentialEditor = EditorWindow.GetWindow(true, "Add credential", true); 55 | credentialEditor.CreateNew(credentialManager); 56 | }, 57 | onRemoveCallback = reorderableList => 58 | { 59 | var credential = credentialList.list[credentialList.index] as NPMCredential; 60 | 61 | credentialManager.RemoveCredential(credential.url); 62 | credentialManager.Write(); 63 | } 64 | }; 65 | return credentialList; 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/CredentialManagerView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6f1896f0b6cdab862b835b3498da53bd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/GetTokenView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Halodi.PackageRegistry.Core; 3 | using Halodi.PackageRegistry.NPM; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | namespace Halodi.PackageRegistry.UI 8 | { 9 | internal class TokenMethod : GUIContent 10 | { 11 | internal delegate bool GetToken(ScopedRegistry registry, string username, string password); 12 | internal string usernameName; 13 | internal string passwordName; 14 | internal GetToken action; 15 | 16 | public TokenMethod(string name, string usernameName, string passwordName, GetToken action) : base(name) 17 | { 18 | this.usernameName = usernameName; 19 | this.passwordName = passwordName; 20 | this.action = action; 21 | } 22 | } 23 | 24 | internal class GetTokenView : EditorWindow 25 | { 26 | private static TokenMethod[] methods = { 27 | new TokenMethod("npm login", "Registry username", "Registry password", GetNPMLoginToken), 28 | new TokenMethod("bintray", "Bintray username", "Bintray API key", GetBintrayToken), 29 | // TODO adjust TokenMethod to allow for opening GitHub token URL: https://github.com/settings/tokens/new 30 | }; 31 | 32 | 33 | private string username; 34 | private string password; 35 | 36 | private bool initialized = false; 37 | 38 | private TokenMethod tokenMethod; 39 | 40 | private ScopedRegistry registry; 41 | 42 | 43 | void OnEnable() 44 | { 45 | error = null; 46 | } 47 | 48 | void OnDisable() 49 | { 50 | initialized = false; 51 | } 52 | 53 | private void SetRegistry(TokenMethod tokenMethod, ScopedRegistry registry) 54 | { 55 | this.tokenMethod = tokenMethod; 56 | this.registry = registry; 57 | this.initialized = true; 58 | } 59 | 60 | void OnGUI() 61 | { 62 | if (initialized) 63 | { 64 | EditorGUILayout.LabelField(tokenMethod, EditorStyles.whiteLargeLabel); 65 | username = EditorGUILayout.TextField(tokenMethod.usernameName, username); 66 | password = EditorGUILayout.PasswordField(tokenMethod.passwordName, password); 67 | 68 | if (GUILayout.Button("Login")) 69 | { 70 | if(tokenMethod.action(registry, username, password)) 71 | { 72 | CloseWindow(); 73 | } 74 | } 75 | 76 | if (GUILayout.Button("Close")) 77 | { 78 | CloseWindow(); 79 | } 80 | 81 | if (!string.IsNullOrEmpty(error)) 82 | { 83 | EditorGUILayout.HelpBox(error, MessageType.Error); 84 | } 85 | } 86 | } 87 | 88 | private static void CreateWindow(TokenMethod method, ScopedRegistry registry) 89 | { 90 | GetTokenView getTokenView = EditorWindow.GetWindow(true, "Get token", true); 91 | getTokenView.SetRegistry(method, registry); 92 | } 93 | 94 | private static string error = null; 95 | 96 | private static bool GetNPMLoginToken(ScopedRegistry registry, string username, string password) 97 | { 98 | NPMResponse response = NPMLogin.GetLoginToken(registry.url, username, password); 99 | 100 | if (string.IsNullOrEmpty(response.ok)) 101 | { 102 | // EditorUtility.DisplayDialog("Cannot get token", response.error, "Ok"); 103 | error = "Cannot get token: " + response.error; 104 | return false; 105 | } 106 | else 107 | { 108 | registry.token = response.token; 109 | return true; 110 | } 111 | } 112 | 113 | private static bool GetBintrayToken(ScopedRegistry registry, string username, string password) 114 | { 115 | registry.token = NPMLogin.GetBintrayToken(username, password); 116 | return !string.IsNullOrEmpty(registry.token); 117 | } 118 | 119 | 120 | private void CloseWindow() 121 | { 122 | error = null; 123 | foreach (var view in Resources.FindObjectsOfTypeAll()) 124 | { 125 | view.Repaint(); 126 | } 127 | Close(); 128 | GUIUtility.ExitGUI(); 129 | } 130 | 131 | 132 | internal static int CreateGUI(int selectedIndex, ScopedRegistry registry) 133 | { 134 | EditorGUILayout.LabelField("Generate token", EditorStyles.whiteLargeLabel); 135 | EditorGUILayout.BeginHorizontal(); 136 | selectedIndex = EditorGUILayout.Popup(new GUIContent("Method"), selectedIndex, methods); 137 | 138 | if(GUILayout.Button("Login & get auth token")) 139 | { 140 | CreateWindow(methods[selectedIndex], registry); 141 | } 142 | 143 | EditorGUILayout.EndHorizontal(); 144 | 145 | return selectedIndex; 146 | } 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/GetTokenView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c114ccf58900f5e5ab2f67306c0f40c2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/InstallPackageCreator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Halodi.PackageRegistry.Core; 4 | using UnityEditor; 5 | using UnityEngine; 6 | 7 | namespace Halodi.PackageRegistry.UI 8 | { 9 | internal class InstallPackageCreatorView : EditorWindow 10 | { 11 | [MenuItem("Packages/Install Halodi Package Creator", false, 41)] 12 | internal static void ManageRegistries() 13 | { 14 | UnityEditor.PackageManager.Client.Add("com.halodi.halodi-unity-package-creator"); 15 | } 16 | 17 | 18 | } 19 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/InstallPackageCreator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7c16af11ea1aab931a6cc447c7b7bd7d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/RegistryManagerView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using Halodi.PackageRegistry.Core; 5 | using UnityEditor; 6 | using UnityEditorInternal; 7 | using UnityEngine; 8 | 9 | namespace Halodi.PackageRegistry.UI 10 | { 11 | public class RegistryManagerView : EditorWindow 12 | { 13 | [MenuItem("Packages/Manage scoped registries", false, 21)] 14 | internal static void ManageRegistries() 15 | { 16 | SettingsService.OpenProjectSettings("Project/Package Manager/Credentials"); 17 | } 18 | 19 | private ReorderableList drawer; 20 | 21 | void OnEnable() 22 | { 23 | drawer = GetRegistryList(new RegistryManager()); 24 | minSize = new Vector2(640, 320); 25 | } 26 | 27 | void OnGUI() 28 | { 29 | EditorGUILayout.LabelField("Scoped registries", EditorStyles.whiteLargeLabel); 30 | drawer.DoLayoutList(); 31 | } 32 | 33 | internal static ReorderableList GetRegistryList(RegistryManager registryManager) 34 | { 35 | ReorderableList registryList = null; 36 | registryList = new ReorderableList(registryManager.registries, typeof(ScopedRegistry), false, true, true, true) 37 | { 38 | drawHeaderCallback = rect => 39 | { 40 | GUI.Label(rect, "Scoped Registries in this project"); 41 | }, 42 | elementHeight = 70, 43 | drawElementCallback = (rect, index, active, focused) => 44 | { 45 | var registry = registryList.list[index] as ScopedRegistry; 46 | if (registry == null) return; 47 | bool registryHasAuth = !string.IsNullOrEmpty(registry.token) && registry.isValidCredential(); 48 | 49 | var rect2 = rect; 50 | rect.width -= 60; 51 | rect.height = 20; 52 | GUI.Label(rect, registry.name + " (" + registry.scopes.Count + " scopes)", EditorStyles.boldLabel); 53 | rect.y += 20; 54 | GUI.Label(rect, registry.url); 55 | rect.y += 20; 56 | EditorGUI.BeginDisabledGroup(true); 57 | GUI.Toggle(rect, registryHasAuth, "Has Credentials"); 58 | EditorGUI.EndDisabledGroup(); 59 | 60 | rect2.x = rect2.xMax - 60; 61 | rect2.height = 20; 62 | rect2.width = 60; 63 | rect2.y += 5; 64 | if (GUI.Button(rect2, "Edit")) 65 | { 66 | ScopedRegistryEditorView registryEditor = EditorWindow.GetWindow(true, "Edit registry", true); 67 | registryEditor.Edit(registry, registryManager); 68 | } 69 | }, 70 | onAddCallback = list => 71 | { 72 | ScopedRegistryEditorView registryEditor = EditorWindow.GetWindow(true, "Add registry", true); 73 | registryEditor.CreateNew(registryManager); 74 | }, 75 | onRemoveCallback = list => 76 | { 77 | Debug.Log("index to remove: " + list.index); 78 | var entry = list.list[list.index] as ScopedRegistry; 79 | registryManager.Remove(entry); 80 | } 81 | }; 82 | return registryList; 83 | } 84 | } 85 | 86 | 87 | 88 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/RegistryManagerView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bb92217c830c75c4baccac1d1455d6a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/ScopedRegistryEditorView.cs: -------------------------------------------------------------------------------- 1 | 2 | using System; 3 | using Halodi.PackageRegistry.Core; 4 | using UnityEditor; 5 | using UnityEditorInternal; 6 | using UnityEngine; 7 | 8 | namespace Halodi.PackageRegistry.UI 9 | { 10 | class ScopedRegistryEditorView : EditorWindow 11 | { 12 | private bool initialized = false; 13 | 14 | private RegistryManager controller; 15 | 16 | private bool createNew; 17 | 18 | private ScopedRegistry registry; 19 | 20 | private int tokenMethod; 21 | void OnEnable() 22 | { 23 | tokenMethod = 0; 24 | 25 | minSize = new Vector2(480, 320); 26 | } 27 | 28 | void OnDisable() 29 | { 30 | initialized = false; 31 | } 32 | 33 | public void CreateNew(RegistryManager controller) 34 | { 35 | this.controller = controller; 36 | this.createNew = true; 37 | this.registry = new ScopedRegistry(); 38 | this.initialized = true; 39 | } 40 | 41 | public void Edit(ScopedRegistry registry, RegistryManager controller) 42 | { 43 | this.controller = controller; 44 | this.registry = registry; 45 | this.createNew = false; 46 | this.initialized = true; 47 | } 48 | 49 | 50 | private ReorderableList scopeList = null; 51 | void OnGUI() 52 | { 53 | if (initialized) 54 | { 55 | EditorGUILayout.Space(); 56 | if (createNew) 57 | { 58 | EditorGUILayout.LabelField("Add scoped registry ", EditorStyles.whiteLargeLabel); 59 | registry.name = EditorGUILayout.TextField("Name", registry.name); 60 | 61 | EditorGUI.BeginChangeCheck(); 62 | registry.url = EditorGUILayout.TextField("URL", registry.url); 63 | if (EditorGUI.EndChangeCheck()) 64 | { 65 | UpdateCredential(); 66 | } 67 | } 68 | else 69 | { 70 | EditorGUILayout.LabelField("Edit scoped registry", EditorStyles.whiteLargeLabel); 71 | EditorGUILayout.LabelField("Name", registry.name); 72 | EditorGUILayout.LabelField("URL", registry.url); 73 | } 74 | 75 | if (scopeList == null) 76 | { 77 | scopeList = new ReorderableList(registry.scopes, typeof(string), true, false, true, true) 78 | { 79 | drawElementCallback = (rect, index, active, focused) => 80 | { 81 | registry.scopes[index] = EditorGUI.TextField(rect, registry.scopes[index]); 82 | }, 83 | onAddCallback = list => 84 | { 85 | registry.scopes.Add(""); 86 | } 87 | }; 88 | } 89 | 90 | EditorGUILayout.BeginHorizontal(); 91 | EditorGUILayout.PrefixLabel("Package Scopes"); 92 | EditorGUILayout.BeginVertical(); 93 | scopeList.DoLayoutList(); 94 | EditorGUILayout.EndVertical(); 95 | EditorGUILayout.EndHorizontal(); 96 | 97 | EditorGUILayout.Space(); 98 | EditorGUILayout.LabelField("Authentication / Credentials", EditorStyles.whiteLargeLabel); 99 | 100 | registry.auth = EditorGUILayout.Toggle("Always auth", registry.auth); 101 | registry.token = EditorGUILayout.TextField("Token", registry.token); 102 | 103 | EditorGUILayout.Space(); 104 | 105 | tokenMethod = GetTokenView.CreateGUI(tokenMethod, registry); 106 | 107 | EditorGUILayout.Space(); 108 | EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true)); 109 | EditorGUILayout.EndVertical(); 110 | 111 | EditorGUILayout.HelpBox("Restart Unity to reload credentials after saving.", MessageType.Info); 112 | EditorGUILayout.BeginHorizontal(); 113 | if (createNew) 114 | { 115 | if (GUILayout.Button("Add")) 116 | { 117 | Add(); 118 | } 119 | } 120 | else 121 | { 122 | if (GUILayout.Button("Save")) 123 | { 124 | Save(); 125 | } 126 | } 127 | 128 | if (GUILayout.Button("Cancel")) 129 | { 130 | Close(); 131 | GUIUtility.ExitGUI(); 132 | } 133 | EditorGUILayout.EndHorizontal(); 134 | } 135 | } 136 | 137 | private void Save() 138 | { 139 | if (registry.isValid()) 140 | { 141 | controller.Save(registry); 142 | Close(); 143 | GUIUtility.ExitGUI(); 144 | } 145 | else 146 | { 147 | EditorUtility.DisplayDialog("Invalid", "Invalid settings for registry.", "Ok"); 148 | } 149 | } 150 | 151 | private void Add() 152 | { 153 | if (registry.isValid()) 154 | { 155 | controller.Save(registry); 156 | Close(); 157 | GUIUtility.ExitGUI(); 158 | } 159 | else 160 | { 161 | EditorUtility.DisplayDialog("Invalid", "Invalid settings for registry.", "Ok"); 162 | } 163 | 164 | } 165 | 166 | private void UpdateCredential() 167 | { 168 | if (controller.credentialManager.HasRegistry(registry.url)) 169 | { 170 | NPMCredential cred = controller.credentialManager.GetCredential(registry.url); 171 | registry.auth = cred.alwaysAuth; 172 | registry.token = cred.token; 173 | } 174 | } 175 | 176 | 177 | 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/ScopedRegistryEditorView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fa2f00a8426714b1a94a89df408ce1c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/SettingsProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Halodi.PackageRegistry.Core; 4 | using UnityEditor; 5 | using UnityEditor.PackageManager; 6 | using UnityEditor.SceneManagement; 7 | using UnityEditorInternal; 8 | using UnityEngine; 9 | 10 | namespace Halodi.PackageRegistry.UI 11 | { 12 | static class CredentialManagerSettingsProvider 13 | { 14 | [SettingsProvider] 15 | public static SettingsProvider CreateMyCustomSettingsProvider() 16 | { 17 | RegistryManager registryManager; 18 | ReorderableList credentialDrawer = null; 19 | ReorderableList registryDrawer = null; 20 | 21 | var provider = new SettingsProvider("Project/Package Manager/Credentials", SettingsScope.Project) 22 | { 23 | label = "Credentials", 24 | activateHandler = (str, v) => 25 | { 26 | registryManager = new RegistryManager(); 27 | registryDrawer = RegistryManagerView.GetRegistryList(registryManager); 28 | credentialDrawer = CredentialManagerView.GetCredentialList(registryManager.credentialManager); 29 | }, 30 | guiHandler = (searchContext) => 31 | { 32 | ThirdPartyInfo(); 33 | 34 | EditorGUILayout.Space(); 35 | registryDrawer.DoLayoutList(); 36 | 37 | EditorGUILayout.Space(); 38 | credentialDrawer.DoLayoutList(); 39 | }, 40 | footerBarGuiHandler = () => 41 | { 42 | EditorGUILayout.BeginHorizontal(); 43 | #if UNITY_2020_1_OR_NEWER 44 | if (GUILayout.Button("Reload Packages")) 45 | { 46 | // call internal PackageManagerWindow.ResetPackageDatabase(); 47 | var packageManagerWindow = typeof(Client).Assembly.GetType("UnityEditor.PackageManager.UI.PackageManagerWindow"); 48 | if (packageManagerWindow != null) 49 | packageManagerWindow.GetMethod("ResetPackageDatabase")?.Invoke(packageManagerWindow, new object[] { }); 50 | 51 | Client.Resolve(); 52 | } 53 | #endif 54 | if (GUILayout.Button("Restart Editor")) 55 | { 56 | if(EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) 57 | EditorApplication.OpenProject(Environment.CurrentDirectory); 58 | } 59 | 60 | EditorGUILayout.EndHorizontal(); 61 | }, 62 | // Populate the search keywords to enable smart search filtering and label highlighting 63 | keywords = new HashSet(new[] { "UPM", "NPM", "Credentials", "Packages", "Authentication", "Scoped Registry" }) 64 | }; 65 | 66 | return provider; 67 | } 68 | 69 | private static class Styles 70 | { 71 | public static readonly GUIStyle linkLabel; 72 | 73 | static Styles() 74 | { 75 | #if UNITY_2019_2_OR_NEWER 76 | linkLabel = new GUIStyle(EditorStyles.linkLabel); 77 | #else 78 | linkLabel = new GUIStyle(EditorStyles.miniLabel); 79 | #endif 80 | linkLabel.fontSize = EditorStyles.miniLabel.fontSize; 81 | linkLabel.wordWrap = true; 82 | } 83 | } 84 | 85 | private static void ThirdPartyInfo() 86 | { 87 | EditorGUILayout.HelpBox("Packages on scoped registries are provided by third parties.\n", MessageType.Info); 88 | var lastRect = GUILayoutUtility.GetLastRect(); 89 | lastRect.xMin = lastRect.xMax - 60; 90 | lastRect.yMin = lastRect.yMax - 20; 91 | if (GUI.Button(lastRect, "Read more", Styles.linkLabel)) 92 | Application.OpenURL("https://docs.unity3d.com/Documentation/Manual/upm-scoped.html"); 93 | EditorGUIUtility.AddCursorRect(lastRect, MouseCursor.Link); 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/SettingsProvider.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef531c9865ba9df44a7b77c821d7bf81 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/UpgradePackagesView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Halodi.PackageRegistry.Core; 4 | using UnityEditor; 5 | using UnityEngine; 6 | using static Halodi.PackageRegistry.Core.UpgradePackagesManager; 7 | 8 | namespace Halodi.PackageRegistry.UI 9 | { 10 | internal class UpgradePackagesView : EditorWindow 11 | { 12 | [MenuItem("Packages/Upgrade Packages", false, 23)] 13 | internal static void ManageRegistries() 14 | { 15 | EditorWindow.GetWindow(true, "Upgrade packages", true); 16 | } 17 | 18 | private UpgradePackagesManager manager; 19 | 20 | private bool upgradeAll; 21 | 22 | private bool showPreviewPackages = false; 23 | 24 | private bool useVerified = true; 25 | private Dictionary upgradeList = new Dictionary(); 26 | 27 | void OnEnable() 28 | { 29 | manager = new UpgradePackagesManager(); 30 | 31 | minSize = new Vector2(640, 320); 32 | upgradeAll = false; 33 | } 34 | 35 | void OnDisable() 36 | { 37 | manager = null; 38 | } 39 | 40 | private Vector2 scrollPos; 41 | 42 | private void Package(PackageUpgradeState info) 43 | { 44 | 45 | if(info.HasNewVersion(showPreviewPackages, useVerified)) 46 | { 47 | 48 | GUIStyle boxStyle = new GUIStyle(); 49 | boxStyle.padding = new RectOffset(10, 10, 0, 0); 50 | 51 | EditorGUILayout.BeginHorizontal(boxStyle); 52 | 53 | 54 | EditorGUI.BeginChangeCheck(); 55 | 56 | bool upgrade = false; 57 | if (upgradeList.ContainsKey(info)) 58 | { 59 | upgrade = upgradeList[info]; 60 | } 61 | 62 | upgrade = EditorGUILayout.BeginToggleGroup(info.GetCurrentVersion(), upgrade); 63 | if (EditorGUI.EndChangeCheck()) 64 | { 65 | if (!upgrade) 66 | { 67 | upgradeAll = false; 68 | } 69 | } 70 | 71 | upgradeList[info] = upgrade; 72 | 73 | EditorGUILayout.EndToggleGroup(); 74 | 75 | 76 | EditorGUILayout.LabelField(info.GetNewestVersion(showPreviewPackages, useVerified)); 77 | 78 | EditorGUILayout.EndHorizontal(); 79 | } 80 | } 81 | 82 | void OnGUI() 83 | { 84 | if (manager != null) 85 | { 86 | manager.Update(); 87 | 88 | EditorGUILayout.LabelField("Upgrade packages", EditorStyles.whiteLargeLabel); 89 | 90 | showPreviewPackages = EditorGUILayout.ToggleLeft("Show Preview Packages", showPreviewPackages); 91 | 92 | useVerified = EditorGUILayout.ToggleLeft("Prefer verified packages", useVerified); 93 | 94 | if (manager.packagesLoaded) 95 | { 96 | 97 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos); 98 | 99 | 100 | 101 | 102 | foreach (var info in manager.UpgradeablePackages) 103 | { 104 | Package(info); 105 | } 106 | 107 | EditorGUILayout.EndScrollView(); 108 | 109 | 110 | EditorGUI.BeginChangeCheck(); 111 | upgradeAll = EditorGUILayout.ToggleLeft("Upgrade all packages", upgradeAll); 112 | if (EditorGUI.EndChangeCheck()) 113 | { 114 | foreach (var info in manager.UpgradeablePackages) 115 | { 116 | upgradeList[info] = upgradeAll; 117 | } 118 | } 119 | 120 | EditorGUILayout.BeginHorizontal(); 121 | if (GUILayout.Button("Upgrade")) 122 | { 123 | Upgrade(); 124 | CloseWindow(); 125 | } 126 | 127 | if (GUILayout.Button("Close")) 128 | { 129 | CloseWindow(); 130 | } 131 | 132 | EditorGUILayout.EndHorizontal(); 133 | } 134 | else 135 | { 136 | EditorGUILayout.LabelField("Loading packages...", EditorStyles.whiteLargeLabel); 137 | } 138 | 139 | 140 | 141 | } 142 | } 143 | 144 | private void Upgrade() 145 | { 146 | 147 | if (manager != null) 148 | { 149 | 150 | EditorUtility.DisplayProgressBar("Upgrading packages", "Starting", 0); 151 | 152 | string output = ""; 153 | bool failures = false; 154 | try 155 | { 156 | foreach (var info in manager.UpgradeablePackages) 157 | { 158 | if(upgradeList.ContainsKey(info)) 159 | { 160 | if(upgradeList[info]) 161 | { 162 | EditorUtility.DisplayProgressBar("Upgrading packages", "Upgrading " + info.info.displayName, 0.5f); 163 | 164 | string error = ""; 165 | if (manager.UpgradePackage(info.GetNewestVersion(showPreviewPackages, useVerified), ref error)) 166 | { 167 | output += "[Success] Upgraded " + info.info.displayName + Environment.NewLine; 168 | } 169 | else 170 | { 171 | output += "[Error] Failed upgrade of" + info.info.displayName + " with error: " + error + Environment.NewLine; 172 | failures = true; 173 | } 174 | } 175 | } 176 | 177 | } 178 | 179 | 180 | } 181 | finally 182 | { 183 | EditorUtility.ClearProgressBar(); 184 | } 185 | 186 | 187 | string message; 188 | if (failures) 189 | { 190 | message = "Upgraded with errors." + Environment.NewLine + output; 191 | } 192 | else 193 | { 194 | message = "Upgraded all packages. " + Environment.NewLine + output; 195 | } 196 | EditorUtility.DisplayDialog("Upgrade finished", message, "OK"); 197 | 198 | } 199 | } 200 | 201 | 202 | private void CloseWindow() 203 | { 204 | Close(); 205 | GUIUtility.ExitGUI(); 206 | } 207 | 208 | } 209 | } -------------------------------------------------------------------------------- /Editor/Halodi/PackageRegistry/UI/UpgradePackagesView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f38c8e7a61df01009d0a1d9a8cd169e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ab3ad5cc6e9818cd498b049fe12c0c47 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ThirdParty/LICENSE.Tomlyn.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019, Alexandre Mutel 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification 5 | , are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /Editor/ThirdParty/LICENSE.Tomlyn.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 475ab608e6dbf99409204c1b770d6562 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ThirdParty/README.md: -------------------------------------------------------------------------------- 1 | # Third party libraries 2 | 3 | To avoid conflicts between packages all third party managed DLL's are prefixed with "860BB79D", which is the CRC32 hash of "com.halodi.halodi-unity-package-creator". 4 | 5 | Due to the 260 character limit on windows paths, we avoid prefixing the DLL names with "com.halodi.halodi-unity-package-reigstry-manager" 6 | 7 | 8 | ## NewtonSoft JSON 9 | 10 | https://www.newtonsoft.com/json 11 | License: MIT (see LICENSE.Newtonsoft.Json) 12 | 13 | ## SharpZipLib 14 | 15 | https://github.com/icsharpcode/SharpZipLib 16 | License: MIT 17 | 18 | ## Tomlyn 19 | 20 | https://github.com/xoofx/Tomlyn 21 | License: BSD-2-Clause (see LICENSE.Tomlyn) 22 | -------------------------------------------------------------------------------- /Editor/ThirdParty/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0006809df3aab01ef9e2bb535d02ebd9 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Tomlyn.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/1x-technologies/halodi-unity-package-registry-manager/a496ca337ee0c1dc4b3461ec5b1fbbdb66e5467c/Editor/ThirdParty/Tomlyn.dll -------------------------------------------------------------------------------- /Editor/ThirdParty/Tomlyn.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe280739c6633ac4682879c184af804f 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 1 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | Any: 16 | second: 17 | enabled: 0 18 | settings: {} 19 | - first: 20 | Editor: Editor 21 | second: 22 | enabled: 1 23 | settings: 24 | DefaultValueInitialized: true 25 | - first: 26 | Windows Store Apps: WindowsStoreApps 27 | second: 28 | enabled: 0 29 | settings: 30 | CPU: AnyCPU 31 | userData: 32 | assetBundleName: 33 | assetBundleVariant: 34 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 701bc2a7cddabf3a4885c944fc034394 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/Artees.UnitySemVer.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Artees.SemanticVersioning", 3 | "references": [], 4 | "includePlatforms": [], 5 | "excludePlatforms": [], 6 | "allowUnsafeCode": false, 7 | "overrideReferences": true, 8 | "precompiledReferences": [], 9 | "autoReferenced": true, 10 | "defineConstraints": [], 11 | "versionDefines": [], 12 | "noEngineReferences": false 13 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/Artees.UnitySemVer.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 807287499d1ce5fd6a509eb37593f7da 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/CloudBuildManifest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Artees.UnitySemVer 5 | { 6 | /// 7 | /// A parsed Unity Cloud Build manifest. 8 | /// 9 | internal class CloudBuildManifest 10 | { 11 | private static CloudBuildManifest _instance; 12 | 13 | public static CloudBuildManifest Instance => _instance ?? (_instance = new CloudBuildManifest()); 14 | 15 | /// 16 | /// Returns true if the manifest has been successfully loaded. 17 | /// 18 | public readonly bool IsLoaded; 19 | 20 | /// 21 | /// The Unity Cloud Build “build number” corresponding to this build. 22 | /// 23 | public readonly int BuildNumber; 24 | 25 | private CloudBuildManifest() 26 | { 27 | var manifestAsset = Resources.Load("UnityCloudBuildManifest.json"); 28 | if (manifestAsset == null) return; 29 | var manifest = manifestAsset.text; 30 | IsLoaded = true; 31 | const string key = "\"buildNumber\""; 32 | const StringComparison comparison = StringComparison.Ordinal; 33 | var keyStart = manifest.IndexOf(key, comparison); 34 | var valueStart = manifest.IndexOf("\"", keyStart + key.Length, comparison) + 1; 35 | var valueEnd = manifest.IndexOf("\"", valueStart, comparison); 36 | var buildNumber = manifest.Substring(valueStart, valueEnd - valueStart); 37 | int.TryParse(buildNumber, out BuildNumber); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/CloudBuildManifest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3827c13e6b66fbeaa8fa6d86711b6ab2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Artees 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a5b2e83aa2757a0e8adc6834aff5a52 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/README.md: -------------------------------------------------------------------------------- 1 | # Unity SemVer 2 | [![openupm](https://img.shields.io/npm/v/games.artees.semver?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/games.artees.semver/) 3 | 4 | A convenient way to edit and compare version numbers according to the [Semantic Versioning 2.0.0](https://semver.org/) specification. Also includes a property drawer for Unity. 5 | 6 | ![Property drawer](https://github.com/Artees/Unity-SemVer/raw/master/SemVerDrawer.png) 7 | 8 | # Installation 9 | Install the package **games.artees.semver** using [my package registry](https://artees.games/upm). 10 | Or install via the [OpenUPM registry](https://openupm.com/packages/games.artees.semver/). 11 | 12 | # Usage 13 | Use the `Artees.UnitySemVer.SemVer` class or apply the `Artees.UnitySemVer.SemVerAttribute` attribute to a string field. 14 | ``` 15 | public SemVer version = new SemVer {major = 1, minor = 2, patch = 3}; 16 | [SemVer] public string versionString = "1.2.3"; 17 | ``` 18 | 19 | Parsing: 20 | ``` 21 | var version = SemVer.Parse("2.0.0-rc.1+build.123"); 22 | ``` 23 | 24 | Comparing: 25 | ``` 26 | Debug.Log("2.1.0" > version); 27 | ``` 28 | 29 | Validating: 30 | ``` 31 | var result = version.Validate(); 32 | version = result.Corrected; 33 | foreach (var message in result.Errors) 34 | { 35 | Debug.LogWarning(message); 36 | } 37 | ``` 38 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 21d9cfaa2380b79739f0f756280752f3 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Artees.UnitySemVer 5 | { 6 | /// 7 | /// A semantic version based on the Semantic Versioning 2.0.0 specification. 8 | /// 9 | [Serializable] 10 | public class SemVer : IComparable, IEquatable 11 | { 12 | public const char IdentifiersSeparator = '.'; 13 | public const char PreReleasePrefix = '-'; 14 | public const char BuildPrefix = '+'; 15 | 16 | public static bool operator ==(SemVer left, SemVer right) 17 | { 18 | return Equals(left, right); 19 | } 20 | 21 | public static bool operator !=(SemVer left, SemVer right) 22 | { 23 | return !Equals(left, right); 24 | } 25 | 26 | public static bool operator >(SemVer left, SemVer right) 27 | { 28 | return left.CompareTo(right) > 0; 29 | } 30 | 31 | public static bool operator <(SemVer left, SemVer right) 32 | { 33 | return left.CompareTo(right) < 0; 34 | } 35 | 36 | public static bool operator >=(SemVer left, SemVer right) 37 | { 38 | return left.CompareTo(right) >= 0; 39 | } 40 | 41 | public static bool operator <=(SemVer left, SemVer right) 42 | { 43 | return left.CompareTo(right) <= 0; 44 | } 45 | 46 | public static implicit operator string(SemVer s) 47 | { 48 | return s.ToString(); 49 | } 50 | 51 | public static implicit operator SemVer(string s) 52 | { 53 | return Parse(s); 54 | } 55 | 56 | public static SemVer Parse(string semVer) 57 | { 58 | return SemVerConverter.FromString(semVer); 59 | } 60 | 61 | /// 62 | /// Major version X (X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced 63 | /// to the public API. It MAY include minor and patch level changes. Patch and minor version MUST be reset to 0 64 | /// when major version is incremented. 65 | /// 66 | /// 67 | public uint major; 68 | 69 | /// 70 | /// Minor version Y (x.Y.z | x > 0) MUST be incremented if new, backwards compatible functionality is 71 | /// introduced to the public API. It MUST be incremented if any public API functionality is marked as 72 | /// deprecated. It MAY be incremented if substantial new functionality or improvements are introduced within 73 | /// the private code. It MAY include patch level changes. Patch version MUST be reset to 0 when minor version 74 | /// is incremented. 75 | /// 76 | /// 77 | public uint minor; 78 | 79 | /// 80 | /// Patch version Z (x.y.Z | x > 0) MUST be incremented if only backwards compatible bug fixes are introduced. 81 | /// 82 | public uint patch; 83 | 84 | /// 85 | /// A pre-release version indicates that the version is unstable and might not satisfy the intended 86 | /// compatibility requirements as denoted by its associated normal version. 87 | /// 88 | /// 1.0.0-alpha, 1.0.0-alpha.1, 1.0.0-0.3.7, 1.0.0-x.7.z.92 89 | public string preRelease; 90 | 91 | /// 92 | /// Set the build metadata automatically 93 | /// 94 | /// 95 | public SemVerAutoBuild.Type autoBuild; 96 | 97 | [SerializeField] private string build = string.Empty; 98 | 99 | /// 100 | /// Build metadata MUST be ignored when determining version precedence. Thus two versions that differ only in 101 | /// the build metadata, have the same precedence. 102 | /// 103 | /// 1.0.0-alpha+001, 1.0.0+20130313144700, 1.0.0-beta+exp.sha.5114f85 104 | public string Build 105 | { 106 | get => SemVerAutoBuild.Instances[autoBuild].Get(build); 107 | set => build = SemVerAutoBuild.Instances[autoBuild].Set(value); 108 | } 109 | 110 | /// 111 | /// The base part of the version number (Major.Minor.Patch). 112 | /// 113 | /// 1.9.0 114 | /// Major.Minor.Patch 115 | public string Core => $"{major}.{minor}.{patch}"; 116 | 117 | /// 118 | /// An internal version number. This number is used only to determine whether one version is more recent than 119 | /// another, with higher numbers indicating more recent versions. 120 | /// 121 | /// 122 | /// Major * 10000 + Minor * 100 + Patch 123 | public int AndroidBundleVersionCode 124 | { 125 | get 126 | { 127 | var clampedPatch = ClampAndroidBundleVersionCode(patch, "Patch"); 128 | var clampedMinor = ClampAndroidBundleVersionCode(minor, "Minor"); 129 | return (int) (major * 10000 + clampedMinor * 100 + clampedPatch); 130 | } 131 | } 132 | 133 | private static uint ClampAndroidBundleVersionCode(uint value, string name) 134 | { 135 | uint clamped; 136 | const uint max = 100; 137 | if (value >= max) 138 | { 139 | clamped = max - 1; 140 | Debug.LogWarning(name + " should be less than " + max); 141 | } 142 | else 143 | { 144 | clamped = value; 145 | } 146 | 147 | return clamped; 148 | } 149 | 150 | public SemVer() 151 | { 152 | minor = 1; 153 | preRelease = string.Empty; 154 | autoBuild = SemVerAutoBuild.Type.Manual; 155 | } 156 | 157 | /// 158 | /// Increment the major version, reset the patch and the minor version to 0. 159 | /// 160 | public void IncrementMajor() 161 | { 162 | major++; 163 | minor = patch = 0; 164 | } 165 | 166 | /// 167 | /// Increment the minor version, reset the patch version to 0. 168 | /// 169 | public void IncrementMinor() 170 | { 171 | minor++; 172 | patch = 0; 173 | } 174 | 175 | /// 176 | /// Increment the patch version. 177 | /// 178 | public void IncrementPatch() 179 | { 180 | patch++; 181 | } 182 | 183 | /// 184 | /// Check if this semantic version meets the Semantic Versioning 2.0.0 185 | /// specification. 186 | /// 187 | /// The result of validation and automatically corrected version number. 188 | public SemVerValidationResult Validate() 189 | { 190 | return new SemVerValidator().Validate(this); 191 | } 192 | 193 | /// 194 | /// Creates a copy of this semantic version. 195 | /// 196 | public SemVer Clone() 197 | { 198 | return new SemVer 199 | { 200 | major = major, 201 | minor = minor, 202 | patch = patch, 203 | preRelease = preRelease, 204 | Build = Build, 205 | autoBuild = autoBuild, 206 | }; 207 | } 208 | 209 | public int CompareTo(SemVer other) 210 | { 211 | return new SemVerComparer().Compare(this, other); 212 | } 213 | 214 | public bool Equals(SemVer other) 215 | { 216 | if (ReferenceEquals(null, other)) return false; 217 | if (ReferenceEquals(this, other)) return true; 218 | return CompareTo(other) == 0; 219 | } 220 | 221 | public override bool Equals(object obj) 222 | { 223 | if (ReferenceEquals(null, obj)) return false; 224 | if (ReferenceEquals(this, obj)) return true; 225 | return obj.GetType() == GetType() && Equals((SemVer) obj); 226 | } 227 | 228 | public override int GetHashCode() 229 | { 230 | throw new NotImplementedException(); 231 | } 232 | 233 | public override string ToString() 234 | { 235 | return SemVerConverter.ToString(this); 236 | } 237 | } 238 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 61d25493bd7efc0be91154722ca4f557 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerAttribute.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | namespace Artees.UnitySemVer 4 | { 5 | /// 6 | /// Indicates that a string is a semantic version. It looks like in the Unity's Inspector. 7 | /// 8 | public class SemVerAttribute : PropertyAttribute 9 | { 10 | 11 | } 12 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a865e2b2f8f01fe74a15283aac262bdb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerAutoBuild.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | 4 | namespace Artees.UnitySemVer 5 | { 6 | /// 7 | /// Sets the build metadata automatically 8 | /// 9 | /// 10 | public abstract class SemVerAutoBuild 11 | { 12 | /// 13 | /// implementations 14 | /// 15 | public enum Type 16 | { 17 | /// 18 | /// Disables automatic build metadata 19 | /// 20 | Manual, 21 | 22 | /// 23 | /// Sets the build metadata to the 24 | /// Unity Cloud Build 25 | /// “build number” 26 | /// 27 | /// 28 | CloudBuildNumber 29 | } 30 | 31 | public static readonly IReadOnlyDictionary Instances = 32 | new Dictionary 33 | { 34 | {Type.Manual, new ManualBuild()}, 35 | {Type.CloudBuildNumber, new CloudBuildNumberBuild()} 36 | }; 37 | 38 | internal abstract string Get(string build); 39 | 40 | internal abstract string Set(string build); 41 | 42 | private class ManualBuild : SemVerAutoBuild 43 | { 44 | internal override string Get(string build) 45 | { 46 | return build; 47 | } 48 | 49 | internal override string Set(string build) 50 | { 51 | return build; 52 | } 53 | } 54 | 55 | private class CloudBuildNumberBuild : ReadOnly 56 | { 57 | internal override string Get(string build) 58 | { 59 | return CloudBuildManifest.Instance.IsLoaded 60 | ? CloudBuildManifest.Instance.BuildNumber.ToString() 61 | : string.Empty; 62 | } 63 | } 64 | 65 | public abstract class ReadOnly : SemVerAutoBuild 66 | { 67 | internal sealed override string Set(string build) 68 | { 69 | Debug.LogWarning("The build metadata is read-only"); 70 | return build; 71 | } 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerAutoBuild.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7da255b3007599433a91930f1a658967 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerComparer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Artees.UnitySemVer 6 | { 7 | internal class SemVerComparer : IComparer 8 | { 9 | public int Compare(SemVer x, SemVer y) 10 | { 11 | if (ReferenceEquals(x, y)) return 0; 12 | if (ReferenceEquals(null, y)) return 1; 13 | if (ReferenceEquals(x, null)) return -1; 14 | var majorComparison = x.major.CompareTo(y.major); 15 | if (majorComparison != 0) return majorComparison; 16 | var minorComparison = x.minor.CompareTo(y.minor); 17 | if (minorComparison != 0) return minorComparison; 18 | var patchComparison = x.patch.CompareTo(y.patch); 19 | return patchComparison != 0 ? patchComparison : ComparePreReleaseVersions(x, y); 20 | } 21 | 22 | private static int ComparePreReleaseVersions(SemVer x, SemVer y) 23 | { 24 | if (IsPreRelease(x)) 25 | { 26 | if (!IsPreRelease(y)) return -1; 27 | } 28 | else 29 | { 30 | return IsPreRelease(y) ? 1 : 0; 31 | } 32 | 33 | var xIdentifiers = x.preRelease.Split(SemVer.IdentifiersSeparator); 34 | var yIdentifiers = y.preRelease.Split(SemVer.IdentifiersSeparator); 35 | var length = Mathf.Min(xIdentifiers.Length, yIdentifiers.Length); 36 | for (var i = 0; i < length; i++) 37 | { 38 | var xIdentifier = xIdentifiers[i]; 39 | var yIdentifier = yIdentifiers[i]; 40 | if (Equals(xIdentifier, yIdentifier)) continue; 41 | return ComparePreReleaseIdentifiers(xIdentifier, yIdentifier); 42 | } 43 | 44 | return xIdentifiers.Length.CompareTo(yIdentifiers.Length); 45 | } 46 | 47 | private static bool IsPreRelease(SemVer semVer) 48 | { 49 | return !string.IsNullOrEmpty(semVer.preRelease); 50 | } 51 | 52 | private static int ComparePreReleaseIdentifiers(string xIdentifier, string yIdentifier) 53 | { 54 | var isXNumber = int.TryParse(xIdentifier, out var xNumber); 55 | var isYNumber = int.TryParse(yIdentifier, out var yNumber); 56 | if (!isXNumber) 57 | { 58 | const StringComparison comparison = StringComparison.Ordinal; 59 | return isYNumber ? 1 : string.Compare(xIdentifier, yIdentifier, comparison); 60 | } 61 | 62 | if (isYNumber) 63 | { 64 | return xNumber.CompareTo(yNumber); 65 | } 66 | 67 | return -1; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerComparer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e4f2656aa63c5aae9f0e95a538481a2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Artees.UnitySemVer 2 | { 3 | internal static class SemVerConverter 4 | { 5 | public static SemVer FromString(string semVerString) 6 | { 7 | var strings = semVerString.Split(SemVer.IdentifiersSeparator, SemVer.PreReleasePrefix, SemVer.BuildPrefix); 8 | var preReleaseStart = semVerString.IndexOf(SemVer.PreReleasePrefix); 9 | var buildIndex = semVerString.IndexOf(SemVer.BuildPrefix); 10 | var preReleaseEnd = buildIndex >= 0 ? buildIndex : semVerString.Length; 11 | var preRelease = preReleaseStart >= 0 12 | ? semVerString.Substring(preReleaseStart + 1, preReleaseEnd - preReleaseStart - 1) 13 | : string.Empty; 14 | var build = buildIndex >= 0 ? semVerString.Substring(buildIndex + 1) : string.Empty; 15 | uint major = 0; 16 | if (strings.Length > 0) uint.TryParse(strings[0], out major); 17 | uint minor = 1; 18 | if (strings.Length > 1) uint.TryParse(strings[1], out minor); 19 | uint patch = 0; 20 | if (strings.Length > 2) uint.TryParse(strings[2], out patch); 21 | var semVer = new SemVer 22 | { 23 | major = major, 24 | minor = minor, 25 | patch = patch, 26 | preRelease = preRelease, 27 | Build = build 28 | }; 29 | return semVer; 30 | } 31 | 32 | public static string ToString(SemVer semVer) 33 | { 34 | var preRelease = 35 | string.IsNullOrEmpty(semVer.preRelease) 36 | ? string.Empty 37 | : $"{SemVer.PreReleasePrefix}{semVer.preRelease}"; 38 | var build = 39 | string.IsNullOrEmpty(semVer.Build) 40 | ? string.Empty 41 | : $"{SemVer.BuildPrefix}{semVer.Build}"; 42 | return string.Format("{1}{0}{2}{0}{3}{4}{5}", 43 | SemVer.IdentifiersSeparator, 44 | semVer.major, 45 | semVer.minor, 46 | semVer.patch, 47 | preRelease, 48 | build); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0f9e174e68f0a02129374b3ac91fe3d8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerErrorMessage.cs: -------------------------------------------------------------------------------- 1 | namespace Artees.UnitySemVer 2 | { 3 | public static class SemVerErrorMessage 4 | { 5 | public const string Empty = "Pre-release and build identifiers must not be empty"; 6 | 7 | public const string Invalid = 8 | "Pre-release and build identifiers must comprise only ASCII alphanumerics and hyphen"; 9 | 10 | public const string LeadingZero = "Numeric pre-release identifiers must not include leading zeroes"; 11 | } 12 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerErrorMessage.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2a7bb66e6d2ef54aca93374afae8bbed 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerValidationResult.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.ObjectModel; 2 | 3 | namespace Artees.UnitySemVer 4 | { 5 | /// 6 | /// Information returned about a checked semantic version. 7 | /// 8 | /// 9 | public class SemVerValidationResult 10 | { 11 | /// 12 | /// Error messages. This collection is empty if the version is valid. 13 | /// 14 | public readonly ReadOnlyCollection Errors; 15 | 16 | /// 17 | /// Automatically corrected semantic version. 18 | /// 19 | public readonly SemVer Corrected; 20 | 21 | /// 22 | /// Does the version meet the Semantic Versioning 2.0.0 specification? 23 | /// 24 | public bool IsValid => Errors.Count == 0; 25 | 26 | internal SemVerValidationResult(ReadOnlyCollection errors, SemVer corrected) 27 | { 28 | Errors = errors; 29 | Corrected = corrected; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerValidationResult.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 52627243f647c2e3bbda3a99bc93f30c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerValidator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text.RegularExpressions; 5 | 6 | namespace Artees.UnitySemVer 7 | { 8 | internal class SemVerValidator 9 | { 10 | private List _errors; 11 | private SemVer _corrected; 12 | 13 | public SemVerValidationResult Validate(SemVer semVer) 14 | { 15 | _errors = new List(); 16 | _corrected = semVer.Clone(); 17 | ValidatePreRelease(semVer); 18 | ValidateBuild(semVer); 19 | return new SemVerValidationResult(_errors.AsReadOnly(), _corrected.Clone()); 20 | } 21 | 22 | private void ValidatePreRelease(SemVer semVer) 23 | { 24 | var identifiers = ValidateIdentifiers(semVer.preRelease); 25 | identifiers = ValidateLeadingZeroes(identifiers); 26 | var joined = JoinIdentifiers(identifiers); 27 | _corrected.preRelease = joined; 28 | } 29 | 30 | private void ValidateBuild(SemVer semVer) 31 | { 32 | if (SemVerAutoBuild.Instances[semVer.autoBuild] is SemVerAutoBuild.ReadOnly) return; 33 | var identifiers = ValidateIdentifiers(semVer.Build); 34 | var joined = JoinIdentifiers(identifiers); 35 | _corrected.Build = joined; 36 | } 37 | 38 | private string[] ValidateIdentifiers(string identifiers) 39 | { 40 | if (string.IsNullOrEmpty(identifiers)) return new string[0]; 41 | var separators = new[] {SemVer.IdentifiersSeparator}; 42 | var strings = identifiers.Split(separators, StringSplitOptions.RemoveEmptyEntries); 43 | if (strings.Length < identifiers.Count(c => c == SemVer.IdentifiersSeparator) + 1) 44 | { 45 | _errors.Add(SemVerErrorMessage.Empty); 46 | } 47 | 48 | for (var i = 0; i < strings.Length; i++) 49 | { 50 | var raw = strings[i]; 51 | var corrected = Regex.Replace(raw, "[^0-9A-Za-z-]", "-"); 52 | if (string.Equals(raw, corrected)) continue; 53 | _errors.Add(SemVerErrorMessage.Invalid); 54 | strings[i] = corrected; 55 | } 56 | 57 | return strings; 58 | } 59 | 60 | private string[] ValidateLeadingZeroes(IList identifiers) 61 | { 62 | var length = identifiers.Count; 63 | var corrected = new string[length]; 64 | for (var i = 0; i < length; i++) 65 | { 66 | var identifier = identifiers[i]; 67 | var isNumeric = int.TryParse(identifier, out var numericIdentifier); 68 | if (isNumeric && identifier.StartsWith("0") && identifier.Length > 1) 69 | { 70 | corrected[i] = numericIdentifier.ToString(); 71 | _errors.Add(SemVerErrorMessage.LeadingZero); 72 | } 73 | else 74 | { 75 | corrected[i] = identifier; 76 | } 77 | } 78 | 79 | return corrected; 80 | } 81 | 82 | private static string JoinIdentifiers(string[] identifiers) 83 | { 84 | return string.Join(SemVer.IdentifiersSeparator.ToString(), identifiers); 85 | } 86 | } 87 | } -------------------------------------------------------------------------------- /Editor/ThirdParty/Unity-SemVer/SemVerValidator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e9342dc023a6f090be08b41d4c907d2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /LICENSE.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5924639ebe9748b8e86a3e462ddd84fe 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Halodi Unity Package Registry Manager 2 | 3 | This package provides a simple UI to edit scoped registries and set credentials. 4 | 5 | To manage package creation and publication, take a look at [Halodi Unity Package Creator ](https://github.com/Halodi/halodi-unity-package-creator). 6 | 7 | ![Screenshot of main functionality](Documentation~/halodi-unity-package-registry-manager-screenshot.png) 8 | 9 | ## License 10 | 11 | Apache 2.0 12 | 13 | ## Installation 14 | 15 | In Unity, go to Window -> Package Manager. 16 | 17 | Add package from git url (press the + in the top left of the Window). Use the repository URL for this package: 18 | 19 | ``` 20 | https://github.com/Halodi/halodi-unity-package-registry-manager.git 21 | ``` 22 | 23 | ## Usage 24 | 25 | After installation a new menu "Packages" will appear. 26 | 27 | ### Manage credentials 28 | 29 | Under "Manage credential" you can add, edit and remove credentials in ~/.upmconfig.toml. 30 | 31 | Each registry logs in using a token. If your NPM provider provides a token directly, enter it here. If your provider requires a login, select the method and press "Get Token". Enter required information and press "Login". A token will be requested from the registry. The login information will not get saved. 32 | 33 | To always authenticate, set "Always auth" to true; 34 | 35 | After setting the registry credentials, it is advised to restart Unity to reload the package manager. 36 | 37 | #### Notes for specific providers 38 | 39 | **Github**: Create a [Personal access token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line), make sure to select "read:packages" for adding packages to a project and "write:packages" if you want to publish packages. Copy the personal access token directly in the "Token" field (ignore Generate Token). 40 | 41 | **Bintray**: In Generate Token, select "bintray" as method and press "Get token". Enter your credentials. Note: Your credentials are not checked here, the token is calculated from your credentials. 42 | 43 | **Verdaccio**: In Generate Token, select "npm login" as method and press "Get token". Enter your credentials. 44 | 45 | ### Manage scoped registries 46 | 47 | Using "Manage scoped registries" you can add, edit and remove scoped registries from the projects package manifest.json. 48 | 49 | In the same dialog, you can set the credentials for scoped registries. If no token is set, the credentials will be removed from the credential database. For more information, see "Manage credentials". 50 | 51 | Note: The authentication settings are saved per-computer, not per project. If you have multiple projects with the same scoped registry, the authentication parameters will be shared. 52 | 53 | ### Add Packages (Bulk) 54 | 55 | Utility to add a list of packages. 56 | 57 | Utility could include 58 | 59 | - Sharing a list of packages to be bulk imported a project by copy-pasting 60 | - Adding packages when the registry does not support listing all packages 61 | 62 | Note: The Editor will freeze while downloading the packages. This is expected. A popup with the imported packages will appear when done. 63 | 64 | 65 | ## Library functions 66 | 67 | This library provides basic NPM functionality in [Halodi.PackageRegistry.NPM](Editor/Halodi/PackageRegistry/NPM.cs). The following functions are implemented 68 | 69 | 70 | ### NPM.GetLoginToken(string url, string user, string password) 71 | 72 | Same as "npm login --registry [url]". Returns a NPMResponse struct. 73 | 74 | If succesfull, NPMResponse.ok will be set and NPMResponse.token will contain the token. 75 | If a fault happend, NPMREsponse.error will be set to the error. 76 | 77 | ### NPM.Publish(string packageFolder, string registry) 78 | 79 | Same as "npm publish --registry [registry]" executed in "packageFolder". 80 | 81 | The publish functionality uses the credentials set in "~/.upmconfig.toml" to publish to the registry. Use "Manage registries" to set the credentials. 82 | 83 | The package tarball is created using SharpZipLib, to avoid compatibility issues with PackageManager.Client.Pack() in Unity. 84 | 85 | Throws a System.IO.IOException if an error occurs. 86 | 87 | ## Bugs and feature requests 88 | 89 | Please open a ticket on Github. Pull requests are encouraged. 90 | 91 | ## Maintainer 92 | 93 | [Jesper](jesper@halodi.com) 94 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 851de30f36983cf75b87f89edfac329a 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Tests.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb4cfc2933fda19ed95027bf0df94ac1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d26e9d0d897f2ff3cb41c5d4d4c8985e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Tests/Editor/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyTitle("com.halodi.halodi-unity-package-registry-manager.Editor.Tests")] -------------------------------------------------------------------------------- /Tests/Editor/AssemblyInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6e0e426895d792d2ca7bc29a9b7e67f2 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Tests/Editor/Halodi.PackageRegistryManager.Tests.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Halodi.PackageRegistryManager.Tests", 3 | "references": [ 4 | "UnityEngine.TestRunner", 5 | "UnityEditor.TestRunner", 6 | "Halodi.PackageRegistryManager.Editor" 7 | ], 8 | "includePlatforms": [ 9 | "Editor" 10 | ], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": false, 13 | "overrideReferences": true, 14 | "precompiledReferences": [ 15 | "nunit.framework.dll" 16 | ], 17 | "autoReferenced": false, 18 | "defineConstraints": [ 19 | "UNITY_INCLUDE_TESTS" 20 | ], 21 | "versionDefines": [], 22 | "noEngineReferences": false 23 | } -------------------------------------------------------------------------------- /Tests/Editor/Halodi.PackageRegistryManager.Tests.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f56fe7affb0989254a398cff4738a865 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.halodi.halodi-unity-package-registry-manager", 3 | "version": "1.0.5", 4 | "displayName": "Halodi Package Registry Manager", 5 | "type": "tool", 6 | "samples": [], 7 | "description": "Simple tool to manage scoped registries and NPM credentials.", 8 | "license": "Apache-2.0", 9 | "author": { 10 | "name": "Halodi", 11 | "email": "jesper@halodi.com", 12 | "url": "https://halodi.com" 13 | }, 14 | "dependencies": { 15 | "com.unity.nuget.newtonsoft-json": "3.0.2", 16 | "com.unity.sharp-zip-lib": "1.3.4-preview" 17 | }, 18 | "publishConfig": { 19 | "registry": "" 20 | }, 21 | "repository": { 22 | "type": "git", 23 | "url": "https://github.com/Halodi/halodi-unity-package-registry-manager.git" 24 | } 25 | } -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4480134b80472dc1a847e756ab3917cc 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | --------------------------------------------------------------------------------