View | Details | Raw Unified | Return to bug 118281
Collapse All | Expand All

(-)src/Device.cs (+6 lines)
Lines 55-60 Link Here
55
            }
55
            }
56
        }
56
        }
57
57
58
        public string ModelString {
59
            get {
60
                return (string)GetProperty ("device-model-string").Val;
61
            }
62
        }
63
58
        public DeviceGeneration Generation {
64
        public DeviceGeneration Generation {
59
            get {
65
            get {
60
                uint rawtype = (uint) GetProperty ("device-generation").Val;
66
                uint rawtype = (uint) GetProperty ("device-generation").Val;
(-)src/DeviceGeneration.cs (-1 / +2 lines)
Lines 6-11 Link Here
6
        First,
6
        First,
7
        Second,
7
        Second,
8
        Third,
8
        Third,
9
        Fourth
9
        Fourth,
10
        Fifth
10
    }
11
    }
11
}
12
}
(-)src/DeviceModel.cs (-1 / +5 lines)
Lines 13-18 Link Here
13
        MiniPink,
13
        MiniPink,
14
        MiniGreen,
14
        MiniGreen,
15
        MiniGold,
15
        MiniGold,
16
        Shuffle
16
        Shuffle,
17
        NanoWhite,
18
        NanoBlack,
19
        VideoWhite,
20
        VideoBlack
17
    }
21
    }
18
}
22
}
(-)src/SongDatabase.cs (-9 / +129 lines)
Lines 187-192 Link Here
187
            return true;
187
            return true;
188
        }
188
        }
189
189
190
        public void RemoveTrack (int id) {
191
            foreach (PlaylistItemRecord item in playlistItems) {
192
                if (item.TrackId == id) {
193
                    playlistItems.Remove (item);
194
                    break;
195
                }
196
            }
197
        }
198
190
        public void AddItem (PlaylistItemRecord rec) {
199
        public void AddItem (PlaylistItemRecord rec) {
191
            InsertItem (-1, rec);
200
            InsertItem (-1, rec);
192
        }
201
        }
Lines 256-277 Link Here
256
            }
265
            }
257
        }
266
        }
258
267
259
        private void CreateLibraryIndices () {
268
        private DetailRecord CreateIndexRecord (TrackListRecord tracks, IndexType type) {
269
            DetailRecord record = new DetailRecord ();
270
            record.Type = DetailType.LibraryIndex;
271
            record.IndexType = type;
272
273
            // blah, this is soooo sleaux
274
            
275
            ArrayList items = (ArrayList) playlistItems.Clone ();
276
            TrackSorter sorter = new TrackSorter (tracks, type);
277
            items.Sort (sorter);
278
279
            ArrayList indices = new ArrayList ();
280
            foreach (PlaylistItemRecord item in items) {
281
                indices.Add (tracks.IndexOf (item.TrackId));
282
            }
283
284
            record.LibraryIndices = (int[]) indices.ToArray (typeof (int));
285
            return record;
286
        }
287
288
        private void CreateLibraryIndices (TrackListRecord tracks) {
289
290
            ArrayList details = new ArrayList ();
291
            
260
            // remove any existing library index records
292
            // remove any existing library index records
261
            foreach (Record rec in (ArrayList) otherDetails.Clone ()) {
293
            foreach (Record rec in (ArrayList) otherDetails) {
262
                DetailRecord detail = rec as DetailRecord;
294
                DetailRecord detail = rec as DetailRecord;
263
                if (detail != null && detail.Type == DetailType.LibraryIndex) {
295
                if (detail != null && detail.Type != DetailType.LibraryIndex) {
264
                    otherDetails.Remove (rec);
296
                    details.Add (rec);
265
                }
297
                }
266
            }
298
            }
267
299
268
            // TODO: actually create the new indices
300
            otherDetails = details;
301
            otherDetails.Add (CreateIndexRecord (tracks, IndexType.Song));
302
            otherDetails.Add (CreateIndexRecord (tracks, IndexType.Album));
303
            otherDetails.Add (CreateIndexRecord (tracks, IndexType.Artist));
304
            otherDetails.Add (CreateIndexRecord (tracks, IndexType.Genre));
305
            otherDetails.Add (CreateIndexRecord (tracks, IndexType.Composer));
269
        }
306
        }
270
        
307
        
271
        public override void Save (DatabaseRecord db, BinaryWriter writer) {
308
        public override void Save (DatabaseRecord db, BinaryWriter writer) {
272
309
273
            if (isLibrary) {
310
            if (isLibrary) {
274
                CreateLibraryIndices ();
311
                CreateLibraryIndices (db[DataSetIndex.Library].TrackList);
275
            }
312
            }
276
            
313
            
277
            MemoryStream stream = new MemoryStream ();
314
            MemoryStream stream = new MemoryStream ();
Lines 308-313 Link Here
308
            writer.Write (new byte[PadLength]);
345
            writer.Write (new byte[PadLength]);
309
            writer.Write (childData, 0, childDataLength);
346
            writer.Write (childData, 0, childDataLength);
310
        }
347
        }
348
349
        private class TrackSorter : IComparer {
350
351
            private TrackListRecord tracks;
352
            private IndexType type;
353
354
            public TrackSorter (TrackListRecord tracks, IndexType type) {
355
                this.tracks = tracks;
356
                this.type = type;
357
            }
358
            
359
            public int Compare (object a, object b) {
360
                TrackRecord trackA = tracks.LookupTrack ((a as PlaylistItemRecord).TrackId);
361
                TrackRecord trackB = tracks.LookupTrack ((b as PlaylistItemRecord).TrackId);
362
363
                if (trackA == null || trackB == null)
364
                    return 0;
365
                
366
                switch (type) {
367
                case IndexType.Song:
368
                    return String.Compare (trackA.GetDetail (DetailType.Title).Value,
369
                                           trackB.GetDetail (DetailType.Title).Value);
370
                case IndexType.Artist:
371
                    return String.Compare (trackA.GetDetail (DetailType.Artist).Value,
372
                                           trackB.GetDetail (DetailType.Artist).Value);
373
                case IndexType.Album:
374
                    return String.Compare (trackA.GetDetail (DetailType.Album).Value,
375
                                           trackB.GetDetail (DetailType.Album).Value);
376
                case IndexType.Genre:
377
                    return String.Compare (trackA.GetDetail (DetailType.Genre).Value,
378
                                           trackB.GetDetail (DetailType.Genre).Value);
379
                case IndexType.Composer:
380
                    return String.Compare (trackA.GetDetail (DetailType.Composer).Value,
381
                                           trackB.GetDetail (DetailType.Composer).Value);
382
                default:
383
                    return 0;
384
                }
385
            }
386
        }
311
    }
387
    }
312
        
388
        
313
389
Lines 814-819 Link Here
814
        public IEnumerator GetEnumerator () {
890
        public IEnumerator GetEnumerator () {
815
            return tracks.GetEnumerator ();
891
            return tracks.GetEnumerator ();
816
        }
892
        }
893
894
        public TrackRecord LookupTrack (int id) {
895
            foreach (TrackRecord record in tracks) {
896
                if (record.Id == id)
897
                    return record;
898
            }
899
900
            return null;
901
        }
902
903
        public int IndexOf (int id) {
904
            for (int i = 0; i < tracks.Count; i++) {
905
                if ((tracks[i] as TrackRecord).Id == id)
906
                    return i;
907
            }
908
909
            return -1;
910
        }
817
        
911
        
818
        public override void Read (DatabaseRecord db, BinaryReader reader) {
912
        public override void Read (DatabaseRecord db, BinaryReader reader) {
819
913
Lines 949-960 Link Here
949
1043
950
    internal class DatabaseRecord : Record {
1044
    internal class DatabaseRecord : Record {
951
1045
1046
        private const int SongIdStart = 1000;
1047
952
        private int unknownOne = 1;
1048
        private int unknownOne = 1;
953
        private int unknownTwo = 2;
1049
        private int unknownTwo = 2;
954
        
1050
        
955
        private ArrayList datasets = new ArrayList ();
1051
        private ArrayList datasets = new ArrayList ();
956
1052
957
        public int Version = 13;
1053
        public int Version = 15;
958
        public long Id;
1054
        public long Id;
959
1055
960
        public DataSetRecord this[DataSetIndex index] {
1056
        public DataSetRecord this[DataSetIndex index] {
Lines 993-999 Link Here
993
            Id = BitConverter.ToInt64 (body, 12);
1089
            Id = BitConverter.ToInt64 (body, 12);
994
            unknownTwo = BitConverter.ToInt32 (body, 20);
1090
            unknownTwo = BitConverter.ToInt32 (body, 20);
995
1091
996
            if (Version > 13)
1092
            if (Version > 15)
997
                throw new DatabaseReadException ("Detected unsupported database version {0}", Version);
1093
                throw new DatabaseReadException ("Detected unsupported database version {0}", Version);
998
            
1094
            
999
            datasets.Clear ();
1095
            datasets.Clear ();
Lines 1009-1015 Link Here
1009
                this[DataSetIndex.PlaylistDuplicate].PlaylistList = this[DataSetIndex.Playlist].PlaylistList;
1105
                this[DataSetIndex.PlaylistDuplicate].PlaylistList = this[DataSetIndex.Playlist].PlaylistList;
1010
        }
1106
        }
1011
1107
1108
        private void ReassignTrackIds () {
1109
            Hashtable oldids = new Hashtable ();
1110
1111
            int id = SongIdStart;
1112
            foreach (TrackRecord track in this[DataSetIndex.Library].TrackList.Tracks) {
1113
                oldids[track.Id] = id;
1114
                track.Id = id++;
1115
            }
1116
1117
            foreach (PlaylistRecord pl in this[DataSetIndex.Playlist].PlaylistList.Playlists) {
1118
                foreach (PlaylistItemRecord item in pl.Items) {
1119
                    if (oldids[item.TrackId] == null)
1120
                        continue;
1121
                    
1122
                    item.TrackId = (int) oldids[item.TrackId];
1123
                }
1124
            }
1125
        }
1126
1012
        public override void Save (DatabaseRecord db, BinaryWriter writer) {
1127
        public override void Save (DatabaseRecord db, BinaryWriter writer) {
1128
1129
            ReassignTrackIds ();
1130
            
1013
            MemoryStream stream = new MemoryStream ();
1131
            MemoryStream stream = new MemoryStream ();
1014
            BinaryWriter childWriter = new BinaryWriter (stream);
1132
            BinaryWriter childWriter = new BinaryWriter (stream);
1015
1133
Lines 1371-1376 Link Here
1371
        internal string GetFilesystemPath (string ipodPath) {
1489
        internal string GetFilesystemPath (string ipodPath) {
1372
            if (ipodPath == null)
1490
            if (ipodPath == null)
1373
                return null;
1491
                return null;
1492
            else if (ipodPath == String.Empty)
1493
                return String.Empty;
1374
            
1494
            
1375
            return device.MountPoint + ipodPath.Replace (":", "/");
1495
            return device.MountPoint + ipodPath.Replace (":", "/");
1376
        }
1496
        }
Lines 1421-1427 Link Here
1421
1541
1422
                    // remove from the song db
1542
                    // remove from the song db
1423
                    dbrec[DataSetIndex.Library].TrackList.Remove (song.Id);
1543
                    dbrec[DataSetIndex.Library].TrackList.Remove (song.Id);
1424
                    dbrec[DataSetIndex.Playlist].Library.RemoveItem (song.Track.Id);
1544
                    dbrec[DataSetIndex.Playlist].Library.RemoveTrack (song.Track.Id);
1425
                    
1545
                    
1426
                    // remove from the "normal" playlists
1546
                    // remove from the "normal" playlists
1427
                    foreach (Playlist list in playlists) {
1547
                    foreach (Playlist list in playlists) {

Return to bug 118281