|
| 1 | +// Unity C# reference source |
| 2 | +// Copyright (c) Unity Technologies. For terms of use, see |
| 3 | +// https://unity3d.com/legal/licenses/Unity_Reference_Only_License |
| 4 | + |
| 5 | +using System; |
| 6 | +using System.Text.RegularExpressions; |
| 7 | +using System.IO; |
| 8 | +using System.Collections.Generic; |
| 9 | +using System.ComponentModel; |
| 10 | +using System.Diagnostics; |
| 11 | +using System.Linq; |
| 12 | +using System.Text; |
| 13 | +using System.Threading; |
| 14 | +using UnityEditor; |
| 15 | +using Debug = UnityEngine.Debug; |
| 16 | + |
| 17 | +namespace UnityEditor.PlatformSupport |
| 18 | +{ |
| 19 | + internal class iOSEditorPrefKeys |
| 20 | + { |
| 21 | + public readonly static string kDefaultiOSAutomaticallySignBuild = "DefaultiOSAutomaticallySignBuild"; |
| 22 | + public readonly static string kDefaultiOSAutomaticSignTeamId = "DefaultiOSAutomaticSignTeamId"; |
| 23 | + |
| 24 | + public readonly static string kDefaultiOSProvisioningProfileUUID = "DefaultiOSProvisioningProfileUUID"; |
| 25 | + public readonly static string kDefaulttvOSProvisioningProfileUUID = "DefaulttvOSProvisioningProfileUUID"; |
| 26 | + public readonly static string kDefaultiOSProvisioningProfileType = "kDefaultiOSProvisioningProfileType"; |
| 27 | + public readonly static string kDefaulttvOSProvisioningProfileType = "kDefaulttvOSProvisioningProfileType"; |
| 28 | + } |
| 29 | + |
| 30 | + internal class ProvisioningProfile |
| 31 | + { |
| 32 | + private string m_UUID = string.Empty; |
| 33 | + private ProvisioningProfileType m_Type = ProvisioningProfileType.Development; |
| 34 | + |
| 35 | + public string UUID { get { return m_UUID; } set { m_UUID = value; } } |
| 36 | + public ProvisioningProfileType type { get { return m_Type; } set { m_Type = value; } } |
| 37 | + |
| 38 | + // regex patterns used for finding specific parts of data from a provisioning profile |
| 39 | + static readonly string s_PatternUUID = "<key>UUID<\\/key>[\n\t]*<string>((\\w*\\-?){5})"; |
| 40 | + private static readonly string s_PatternDeveloperCertificates = |
| 41 | + "<key>DeveloperCertificates<\\/key>[\n\t]*<array>[\n\t]*<data>([\\w\\/+=\\.\\_]+)<\\/data>"; |
| 42 | + static readonly string s_DistributionPattern = "iPhone Distribution: "; |
| 43 | + |
| 44 | + internal static ProvisioningProfile ParseProvisioningProfileAtPath(string pathToFile) |
| 45 | + { |
| 46 | + ProvisioningProfile profile = new ProvisioningProfile(); |
| 47 | + parseFile(pathToFile, profile); |
| 48 | + return profile; |
| 49 | + } |
| 50 | + |
| 51 | + private ProvisioningProfile() {} |
| 52 | + |
| 53 | + public ProvisioningProfile(string UUID, ProvisioningProfileType type) |
| 54 | + { |
| 55 | + m_UUID = UUID; |
| 56 | + m_Type = type; |
| 57 | + } |
| 58 | + |
| 59 | + internal static void parseFile(string filePath, ProvisioningProfile profile) |
| 60 | + { |
| 61 | + var provisioningFileContents = File.ReadAllText(filePath); |
| 62 | + Match matchUUID = Regex.Match(provisioningFileContents, s_PatternUUID, RegexOptions.Singleline); |
| 63 | + if (matchUUID.Success) |
| 64 | + { |
| 65 | + profile.UUID = matchUUID.Groups[1].Value; |
| 66 | + } |
| 67 | + |
| 68 | + Match matchCertificate = Regex.Match(provisioningFileContents, s_PatternDeveloperCertificates, |
| 69 | + RegexOptions.Singleline); |
| 70 | + if (matchCertificate.Success) |
| 71 | + { |
| 72 | + string value = matchCertificate.Groups[1].Value; |
| 73 | + string decodedCertificate = Encoding.UTF8.GetString(Convert.FromBase64String(value)); |
| 74 | + |
| 75 | + if (decodedCertificate.Contains(s_DistributionPattern)) |
| 76 | + { |
| 77 | + profile.type = ProvisioningProfileType.Distribution; |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + profile.type = ProvisioningProfileType.Development; |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + internal static readonly string[] DefaultProvisioningProfileSearchPaths = new string[] |
| 87 | + { |
| 88 | + "{Home}/Library/MobileDevice/Provisioning Profiles", |
| 89 | + }; |
| 90 | + |
| 91 | + internal static ProvisioningProfile FindLocalProfileByUUID(string UUID, string[] searchPaths = null) |
| 92 | + { |
| 93 | + var localProfilePath = LoadLocalProfiles(searchPaths).FirstOrDefault(p => p.Contains(UUID)); |
| 94 | + |
| 95 | + if (localProfilePath != null && File.Exists(localProfilePath)) |
| 96 | + { |
| 97 | + return ParseProvisioningProfileAtPath(localProfilePath); |
| 98 | + } |
| 99 | + return null; |
| 100 | + } |
| 101 | + |
| 102 | + internal static List<string> LoadLocalProfiles(string[] searchPaths = null) |
| 103 | + { |
| 104 | + if (searchPaths == null) |
| 105 | + searchPaths = DefaultProvisioningProfileSearchPaths; |
| 106 | + |
| 107 | + List<string> localProfiles = new List<string>(); |
| 108 | + foreach (var path in searchPaths) |
| 109 | + { |
| 110 | + var profilesFolder = |
| 111 | + path.Replace("{Home}", Environment.GetFolderPath(Environment.SpecialFolder.Personal)); |
| 112 | + |
| 113 | + if (!Directory.Exists(profilesFolder)) |
| 114 | + continue; |
| 115 | + |
| 116 | + foreach (var file in Directory.GetFiles(profilesFolder)) |
| 117 | + { |
| 118 | + if (Path.GetExtension(file) == ".mobileprovision") |
| 119 | + { |
| 120 | + localProfiles.Add(file); |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + return localProfiles; |
| 125 | + } |
| 126 | + } |
| 127 | +} |
0 commit comments