static PDictionary CreateIndex()
        {
            var plist    = new PDictionary();
            var profiles = new PArray();

            if (Directory.Exists(MobileProvision.ProfileDirectory))
            {
                foreach (var fileName in Directory.EnumerateFiles(MobileProvision.ProfileDirectory))
                {
                    if (!fileName.EndsWith(".mobileprovision", StringComparison.Ordinal) && !fileName.EndsWith(".provisionprofile", StringComparison.Ordinal))
                    {
                        continue;
                    }

                    try {
                        var profile = CreateIndexRecord(fileName);
                        profiles.Add(profile);
                    } catch (Exception ex) {
                        LoggingService.LogWarning("Error reading provisioning profile '{0}': {1}", fileName, ex);
                    }
                }

                profiles.Sort(CreationDateComparer);
            }
            else
            {
                Directory.CreateDirectory(MobileProvision.ProfileDirectory);
            }

            plist.Add("Version", new PNumber(IndexVersion));
            plist.Add("LastModified", new PDate(Directory.GetLastWriteTimeUtc(MobileProvision.ProfileDirectory)));
            plist.Add("ProvisioningProfiles", profiles);

            Save(plist);

            return(plist);
        }
示例#2
0
        void Init()
        {
            string currentLocation = IsInstalled ? MmpPath : null;

            IsInstalled = false;
            versions    = null;

            FrameworkDirectory = "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current";
            var envFrameworkDir = Environment.GetEnvironmentVariable("XAMMAC_FRAMEWORK_PATH");

            if (envFrameworkDir != null && Directory.Exists(envFrameworkDir))
            {
                FrameworkDirectory = envFrameworkDir;
            }

            var versionPath = Path.Combine(FrameworkDirectory, "Version");

            if (File.Exists(versionPath))
            {
                Version = ReadVersion(versionPath);
                lastWriteTimes [versionPath] = File.GetLastWriteTimeUtc(versionPath);

                var path = Path.Combine(FrameworkDirectory, "Versions.plist");
                if (File.Exists(path))
                {
                    try {
                        versions = PDictionary.FromFile(path);
                    } catch {
                        LoggingService.LogWarning("Xamarin.Mac installation is corrupt: invalid Versions.plist at {0}.", path);
                    }
                }

                if (versions == null)
                {
                    versions = CreateDefaultVersionsPlist(Version);
                }
            }
            else
            {
                NotInstalled(versionPath, error: false);
                AnalyticsService.ReportSdkVersion("XS.Core.SDK.Mac.Version", string.Empty);
                return;
            }

            var paths = Version >= new MacOSXSdkVersion(1, 9, 0)
                                ? Detect2x()
                                : Detect1x();

            foreach (var path in paths)
            {
                if (!File.Exists(path))
                {
                    NotInstalled(path);
                    return;
                }

                lastWriteTimes [path] = File.GetLastWriteTimeUtc(path);
            }

            IsInstalled = true;
            LoggingService.LogInfo("Found Xamarin.Mac, version {0}.", Version);
            AnalyticsService.ReportSdkVersion("XS.Core.SDK.Mac.Version", Version.ToString());

            if (Changed != null && currentLocation != MmpPath)
            {
                Changed(this, EventArgs.Empty);
            }
        }
        static PDictionary OpenIndex()
        {
            PDictionary plist;

            try {
                plist = PDictionary.FromFile(IndexFileName);

                if (Directory.Exists(MobileProvision.ProfileDirectory))
                {
                    var mtime = Directory.GetLastWriteTimeUtc(MobileProvision.ProfileDirectory);

                    if (VersionChanged(plist, IndexVersion))
                    {
                        plist = CreateIndex();
                    }
                    else if (LastModifiedChanged(plist, mtime))
                    {
                        var    table = new Dictionary <string, PDictionary> ();
                        PArray profiles;

                        if (plist.TryGetValue("ProvisioningProfiles", out profiles))
                        {
                            foreach (var profile in profiles.OfType <PDictionary> ())
                            {
                                PString fileName;

                                if (!profile.TryGetValue("FileName", out fileName))
                                {
                                    continue;
                                }

                                table[fileName.Value] = profile;
                            }
                        }
                        else
                        {
                            plist.Add("ProvisioningProfiles", profiles = new PArray());
                        }

                        foreach (var fileName in Directory.EnumerateFiles(MobileProvision.ProfileDirectory))
                        {
                            if (!fileName.EndsWith(".mobileprovision", StringComparison.Ordinal) && !fileName.EndsWith(".provisionprofile", StringComparison.Ordinal))
                            {
                                continue;
                            }

                            bool        unknown = false;
                            PDictionary profile;

                            if (table.TryGetValue(Path.GetFileName(fileName), out profile))
                            {
                                // remove from our lookup table (any leftover key/valie pairs will be used to determine deleted files)
                                table.Remove(Path.GetFileName(fileName));

                                // check if the file has changed since our last resync
                                mtime = File.GetLastWriteTimeUtc(fileName);

                                if (LastModifiedChanged(profile, mtime))
                                {
                                    // remove the old record
                                    profile.Remove();

                                    // treat this provisioning profile as if it is unknown
                                    unknown = true;
                                }
                            }
                            else
                            {
                                unknown = true;
                            }

                            if (unknown)
                            {
                                // unknown provisioning profile; add it to our ProvisioningProfiles array
                                try {
                                    profile = CreateIndexRecord(fileName);
                                    profiles.Add(profile);
                                } catch (Exception ex) {
                                    LoggingService.LogWarning("Error reading provisioning profile '{0}': {1}", fileName, ex);
                                }
                            }
                        }

                        // remove provisioning profiles which have been deleted from the file system
                        foreach (var record in table)
                        {
                            record.Value.Remove();
                        }

                        plist["LastModified"] = new PDate(Directory.GetLastWriteTimeUtc(MobileProvision.ProfileDirectory));
                        plist["Version"]      = new PNumber(IndexVersion);

                        profiles.Sort(CreationDateComparer);

                        Save(plist);
                    }
                }
                else
                {
                    try {
                        File.Delete(IndexFileName);
                    } catch (Exception ex) {
                        LoggingService.LogWarning("Failed to delete stale index '{0}': {1}", IndexFileName, ex);
                    }

                    plist.Clear();
                }
            } catch {
                plist = CreateIndex();
            }

            return(plist);
        }
示例#4
0
        void Init()
        {
            string currentLocation = IsInstalled ? Path.Combine(BinDir, "mtouch") : null;

            IsInstalled = false;
            versions    = null;

            if (string.IsNullOrEmpty(SdkDir))
            {
                foreach (var loc in DefaultLocations)
                {
                    if (IsInstalled = ValidateSdkLocation(loc, out hasUsrSubdir))
                    {
                        SdkDir = loc;
                        break;
                    }
                }
            }
            else
            {
                IsInstalled = ValidateSdkLocation(SdkDir, out hasUsrSubdir);
            }

            string mtouch = null;

            if (IsInstalled)
            {
                mtouch         = Path.Combine(BinDir, "mtouch");
                lastMTExeWrite = File.GetLastWriteTime(mtouch);
                Version        = ReadVersion();

                // Note: We require 10.4 for the bundled mlaunch (and Versions.plist, although we have a handy fallback if that file is missing)
                if (Version.CompareTo(IPhoneSdkVersion.V10_4) >= 0)
                {
                    LoggingService.LogInfo("Found Xamarin.iOS, version {0}.", Version);

                    var path = Path.Combine(SdkDir, "Versions.plist");
                    if (File.Exists(path))
                    {
                        try {
                            versions = PDictionary.FromFile(path);
                        } catch {
                            LoggingService.LogWarning("Xamarin.iOS installation is corrupt: invalid Versions.plist.");
                        }
                    }

                    if (versions == null)
                    {
                        versions = CreateDefaultVersionsPlist();
                    }
                }
                else
                {
                    LoggingService.LogInfo("Found unsupported Xamarin.iOS, version {0}.", Version);
                    Version     = new IPhoneSdkVersion();
                    versions    = new PDictionary();
                    IsInstalled = false;
                }

                AnalyticsService.ReportContextProperty("XS.Core.SDK.iOS.Version", Version.ToString());
            }
            else
            {
                lastMTExeWrite = DateTime.MinValue;
                Version        = new IPhoneSdkVersion();
                versions       = new PDictionary();

                LoggingService.LogInfo("Xamarin.iOS not installed. Can't find mtouch.");

                AnalyticsService.ReportContextProperty("XS.Core.SDK.iOS.Version", string.Empty);
            }

            if (Changed != null && currentLocation != mtouch)
            {
                Changed(this, EventArgs.Empty);
            }
        }
示例#5
0
        /// <summary>
        /// All installed provisioning profiles, sorted by newest first.
        /// </summary>
        public static IList <MobileProvision> GetAllInstalledProvisions(MobileProvisionPlatform platform, bool includeExpired)
        {
            if (!Directory.Exists(ProfileDirectory))
            {
                return(new MobileProvision[0]);
            }

            var    uuids = new Dictionary <string, MobileProvision> ();
            var    list  = new List <MobileProvision> ();
            var    now   = DateTime.Now;
            string pattern;

            switch (platform)
            {
            case MobileProvisionPlatform.MacOS:
                pattern = "*.provisionprofile";
                break;

            case MobileProvisionPlatform.tvOS:
            case MobileProvisionPlatform.iOS:
                pattern = "*.mobileprovision";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(platform));
            }

            foreach (var file in Directory.EnumerateFiles(ProfileDirectory, pattern))
            {
                try {
                    var data = File.ReadAllBytes(file);

                    var m = new MobileProvision();
                    m.Load(PDictionary.FromBinaryXml(data));
                    m.Data = data;

                    if (includeExpired || m.ExpirationDate > now)
                    {
                        if (uuids.ContainsKey(m.Uuid))
                        {
                            // we always want the most recently created/updated provision
                            if (m.CreationDate > uuids[m.Uuid].CreationDate)
                            {
                                int index = list.IndexOf(uuids[m.Uuid]);
                                uuids[m.Uuid] = m;
                                list[index]   = m;
                            }
                        }
                        else
                        {
                            uuids.Add(m.Uuid, m);
                            list.Add(m);
                        }
                    }
                } catch (Exception ex) {
                    LoggingService.LogWarning("Error reading " + platform + " provision file '" + file + "'", ex);
                }
            }

            //newest first
            list.Sort((x, y) => y.CreationDate.CompareTo(x.CreationDate));

            return(list);
        }
        public static MobileProvisionIndex OpenIndex(string profilesDir, string indexName)
        {
            MobileProvisionIndex index;

            try {
                index = Load(indexName);

                if (Directory.Exists(profilesDir))
                {
                    var mtime = Directory.GetLastWriteTimeUtc(profilesDir);

                    if (index.Version != IndexVersion)
                    {
                        index = CreateIndex(profilesDir, indexName);
                    }
                    else if (index.LastModified < mtime)
                    {
                        var table = new Dictionary <string, ProvisioningProfile> ();

                        foreach (var profile in index.ProvisioningProfiles)
                        {
                            table[profile.FileName] = profile;
                        }

                        foreach (var fileName in Directory.EnumerateFiles(profilesDir))
                        {
                            if (!fileName.EndsWith(".mobileprovision", StringComparison.Ordinal) && !fileName.EndsWith(".provisionprofile", StringComparison.Ordinal))
                            {
                                continue;
                            }

                            ProvisioningProfile profile;
                            bool unknown = false;

                            if (table.TryGetValue(Path.GetFileName(fileName), out profile))
                            {
                                // remove from our lookup table (any leftover key/valie pairs will be used to determine deleted files)
                                table.Remove(Path.GetFileName(fileName));

                                // check if the file has changed since our last resync
                                mtime = File.GetLastWriteTimeUtc(fileName);

                                if (profile.LastModified < mtime)
                                {
                                    // remove the old record
                                    index.ProvisioningProfiles.Remove(profile);

                                    // treat this provisioning profile as if it is unknown
                                    unknown = true;
                                }
                            }
                            else
                            {
                                unknown = true;
                            }

                            if (unknown)
                            {
                                // unknown provisioning profile; add it to our ProvisioningProfiles array
                                try {
                                    profile = ProvisioningProfile.Load(fileName);
                                    index.ProvisioningProfiles.Add(profile);
                                } catch (Exception ex) {
                                    LoggingService.LogWarning("Error reading provisioning profile '{0}': {1}", fileName, ex);
                                }
                            }
                        }

                        // remove provisioning profiles which have been deleted from the file system
                        foreach (var item in table)
                        {
                            index.ProvisioningProfiles.Remove(item.Value);
                        }

                        index.LastModified = Directory.GetLastWriteTimeUtc(profilesDir);
                        index.Version      = IndexVersion;

                        index.ProvisioningProfiles.Sort(CreationDateComparer);

                        index.Save(indexName);
                    }
                }
                else
                {
                    try {
                        File.Delete(indexName);
                    } catch (Exception ex) {
                        LoggingService.LogWarning("Failed to delete stale index '{0}': {1}", indexName, ex);
                    }

                    index.ProvisioningProfiles.Clear();
                }
            } catch {
                index = CreateIndex(profilesDir, indexName);
            }

            return(index);
        }
示例#7
0
        void Init()
        {
            string currentLocation = IsInstalled ? Path.Combine(BinDir, "mtouch") : null;

            IsInstalled = false;
            versions    = null;

            if (string.IsNullOrEmpty(SdkDir))
            {
                foreach (var loc in DefaultLocations)
                {
                    if (IsInstalled = ValidateSdkLocation(loc, out hasUsrSubdir))
                    {
                        SdkDir = loc;
                        break;
                    }
                }
            }
            else
            {
                IsInstalled = ValidateSdkLocation(SdkDir, out hasUsrSubdir);
            }

            string mtouch = null;

            if (IsInstalled)
            {
                mtouch         = Path.Combine(BinDir, "mtouch");
                lastMTExeWrite = File.GetLastWriteTimeUtc(mtouch);
                Version        = ReadVersion();

                if (Version.CompareTo(requiredXI) >= 0)
                {
                    LoggingService.LogInfo("Found Xamarin.iOS, version {0}.", Version);

                    var path = Path.Combine(SdkDir, "Versions.plist");
                    if (File.Exists(path))
                    {
                        try {
                            versions = PDictionary.FromFile(path);
                        } catch {
                            LoggingService.LogWarning("Xamarin.iOS installation is corrupt: invalid Versions.plist at {0}.", path);
                        }
                    }

                    if (versions == null)
                    {
                        versions = CreateDefaultVersionsPlist();
                    }
                }
                else
                {
                    SdkNotInstalledReason = string.Format("Found unsupported Xamarin.iOS, version {0}.\nYou need Xamarin.iOS {1} or above.", Version, requiredXI.ToString());
                    LoggingService.LogWarning(SdkNotInstalledReason);
                    Version     = new IPhoneSdkVersion();
                    versions    = new PDictionary();
                    IsInstalled = false;
                }

                AnalyticsService.ReportSdkVersion("XS.Core.SDK.iOS.Version", Version.ToString());
            }
            else
            {
                lastMTExeWrite = DateTime.MinValue;
                Version        = new IPhoneSdkVersion();
                versions       = new PDictionary();

                SdkNotInstalledReason = string.Format("Xamarin.iOS not installed.\nCan't find mtouch or the Version file at {0}.", SdkDir);
                LoggingService.LogInfo(SdkNotInstalledReason);

                AnalyticsService.ReportSdkVersion("XS.Core.SDK.iOS.Version", string.Empty);
            }

            if (Changed != null && currentLocation != mtouch)
            {
                Changed(this, EventArgs.Empty);
            }
        }