public void SetDataObjectString(DO dotype, object value) { foreach (var pi in ParentDbObject.GetType().GetProperties()) { var attr = (DataObjectAttribute)pi.GetCustomAttributes(typeof(DataObjectAttribute), false) .FirstOrDefault(a => ((DataObjectAttribute)a).Value.Equals(dotype.ToString(), StringComparison.InvariantCultureIgnoreCase)); if (attr == null) { continue; } pi.SetValue(ParentDbObject, value, null); SetAdditionalDataObject(ParentDbObject, pi.Name, value.ToString()); return; } foreach (var pi in ParentDbObject.GetType().GetProperties()) { if (!pi.Name.Equals(dotype.ToString(), StringComparison.InvariantCultureIgnoreCase)) { continue; } pi.SetValue(ParentDbObject, value, null); SetAdditionalDataObject(ParentDbObject, pi.Name, value.ToString()); return; } throw new InvalidOperationException(ParentDbObject.GetType().Name + " does not have a property matching the " + dotype.ToString() + " object type."); }
private void SetAdditionalDataObject(IDbObject Object, string Name, string Value) { if (Name == "Location") { var pi = ParentDbObject.GetType().GetProperty("LocationWindows"); if (pi == null) { return; } if (Value == null) { return; } string val = Value.Replace(':', Path.DirectorySeparatorChar); var dbrdr = (MhbdReader)ParentReader.ParentReader.ParentReader.ParentReader.ParentReader; var db = (iTunesDb)dbrdr.DbObject; int pos = db.FileName.IndexOf(@"\iPod_Control\"); if (pos < 0) { return; } string prefix = db.FileName.Substring(0, pos); string loc = prefix + val; pi.SetValue(Object, loc, null); } }
protected override bool ParseiTunesObject(BinaryReader Reader) { ObjectSize = TotalSize; var dobj = (DataObject)DbObject; dobj.Type = ReadEnum <DO>(Reader); var rdr = CreateDataObjectReader(dobj.Type, this); rdr.ParseDataObject(Reader); if (ParentDbObject is Track) { var track = (Track)ParentDbObject; TrackTypes.Add(dobj.Type); } else if (ParentDbObject is PlayList) { var playList = (PlayList)ParentDbObject; PlayListTypes.Add(dobj.Type); } else if (ParentDbObject is PlayListItem) { var playListItem = (PlayListItem)ParentDbObject; PlayListItemTypes.Add(dobj.Type); } else if (ParentDbObject is AlbumList) { var albumList = (AlbumList)ParentDbObject; AlbumListTypes.Add(dobj.Type); } else if (ParentDbObject is AlbumItem) { var albumItem = (AlbumItem)ParentDbObject; AlbumItemTypes.Add(dobj.Type); } else { throw new Exception($"Unknown mhod parent type {ParentDbObject.GetType()}"); } return(true); }