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); 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); }