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

(-)./ChangeLog (+18 lines)
Lines 1-3 Link Here
1
2005-09-15  James Willcox  <snorp@snorp.net>
2
3
	* configure.in: bump to 0.5.5
4
	* src/SongDatabase.cs: reassign the track ids on every save.
5
	Apparently if the ids are not sequential without gaps, the iPod
6
	will not show the songs after the gap.  Also, write out
7
	library index records.
8
	* src/Device.cs: enable write support on v14 databases.
9
10
2005-09-08  Aaron Bockover  <aaron@aaronbock.net>
11
12
	* configure.in: Require libipoddevice 0.3.3
13
	* src/SongDatabase.cs: Throw an unsupported exception if DB version is 
14
	greater than 14
15
	* src/Device.cs: support libipoddevice "device-model-string" property,
16
	bound as Device.ModelString, return false for Device.CanWrite if
17
	SongDatabase.Version is 14 or greater (we can't write that out yet)
18
1
2005-09-07  Aaron Bockover  <aaron@aaronbock.net>
19
2005-09-07  Aaron Bockover  <aaron@aaronbock.net>
2
20
3
	* configure.in: bump to 0.5.4, require libipoddevice 0.3.2
21
	* configure.in: bump to 0.5.4, require libipoddevice 0.3.2
(-)./configure (-10 / +10 lines)
Lines 1365-1371 Link Here
1365
1365
1366
MAJOR_VERSION=0
1366
MAJOR_VERSION=0
1367
MINOR_VERSION=5
1367
MINOR_VERSION=5
1368
MICRO_VERSION=4
1368
MICRO_VERSION=5
1369
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
1369
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
1370
1370
1371
am__api_version="1.9"
1371
am__api_version="1.9"
Lines 1938-1949 Link Here
1938
1938
1939
if test -n "$PKG_CONFIG"; then
1939
if test -n "$PKG_CONFIG"; then
1940
        if test -n "$PKG_CONFIG" && \
1940
        if test -n "$PKG_CONFIG" && \
1941
    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"ipoddevice >= 0.3.2 gtk-sharp-2.0\"") >&5
1941
    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"ipoddevice >= 0.3.3 gtk-sharp-2.0\"") >&5
1942
  ($PKG_CONFIG --exists --print-errors "ipoddevice >= 0.3.2 gtk-sharp-2.0") 2>&5
1942
  ($PKG_CONFIG --exists --print-errors "ipoddevice >= 0.3.3 gtk-sharp-2.0") 2>&5
1943
  ac_status=$?
1943
  ac_status=$?
1944
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
1944
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
1945
  (exit $ac_status); }; then
1945
  (exit $ac_status); }; then
1946
  pkg_cv_IPODDEVICE_CFLAGS=`$PKG_CONFIG --cflags "ipoddevice >= 0.3.2 gtk-sharp-2.0" 2>/dev/null`
1946
  pkg_cv_IPODDEVICE_CFLAGS=`$PKG_CONFIG --cflags "ipoddevice >= 0.3.3 gtk-sharp-2.0" 2>/dev/null`
1947
else
1947
else
1948
  pkg_failed=yes
1948
  pkg_failed=yes
1949
fi
1949
fi
Lines 1952-1963 Link Here
1952
fi
1952
fi
1953
if test -n "$PKG_CONFIG"; then
1953
if test -n "$PKG_CONFIG"; then
1954
        if test -n "$PKG_CONFIG" && \
1954
        if test -n "$PKG_CONFIG" && \
1955
    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"ipoddevice >= 0.3.2 gtk-sharp-2.0\"") >&5
1955
    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"ipoddevice >= 0.3.3 gtk-sharp-2.0\"") >&5
1956
  ($PKG_CONFIG --exists --print-errors "ipoddevice >= 0.3.2 gtk-sharp-2.0") 2>&5
1956
  ($PKG_CONFIG --exists --print-errors "ipoddevice >= 0.3.3 gtk-sharp-2.0") 2>&5
1957
  ac_status=$?
1957
  ac_status=$?
1958
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
1958
  echo "$as_me:$LINENO: \$? = $ac_status" >&5
1959
  (exit $ac_status); }; then
1959
  (exit $ac_status); }; then
1960
  pkg_cv_IPODDEVICE_LIBS=`$PKG_CONFIG --libs "ipoddevice >= 0.3.2 gtk-sharp-2.0" 2>/dev/null`
1960
  pkg_cv_IPODDEVICE_LIBS=`$PKG_CONFIG --libs "ipoddevice >= 0.3.3 gtk-sharp-2.0" 2>/dev/null`
1961
else
1961
else
1962
  pkg_failed=yes
1962
  pkg_failed=yes
1963
fi
1963
fi
Lines 1966-1983 Link Here
1966
fi
1966
fi
1967
1967
1968
if test $pkg_failed = yes; then
1968
if test $pkg_failed = yes; then
1969
	IPODDEVICE_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "ipoddevice >= 0.3.2 gtk-sharp-2.0"`
1969
	IPODDEVICE_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "ipoddevice >= 0.3.3 gtk-sharp-2.0"`
1970
	# Put the nasty error message in config.log where it belongs
1970
	# Put the nasty error message in config.log where it belongs
1971
	echo "$IPODDEVICE_PKG_ERRORS" 1>&5
1971
	echo "$IPODDEVICE_PKG_ERRORS" 1>&5
1972
1972
1973
	{ { echo "$as_me:$LINENO: error: Package requirements (ipoddevice >= 0.3.2 gtk-sharp-2.0) were not met.
1973
	{ { echo "$as_me:$LINENO: error: Package requirements (ipoddevice >= 0.3.3 gtk-sharp-2.0) were not met.
1974
Consider adjusting the PKG_CONFIG_PATH environment variable if you
1974
Consider adjusting the PKG_CONFIG_PATH environment variable if you
1975
installed software in a non-standard prefix.
1975
installed software in a non-standard prefix.
1976
1976
1977
Alternatively you may set the IPODDEVICE_CFLAGS and IPODDEVICE_LIBS environment variables
1977
Alternatively you may set the IPODDEVICE_CFLAGS and IPODDEVICE_LIBS environment variables
1978
to avoid the need to call pkg-config.  See the pkg-config man page for
1978
to avoid the need to call pkg-config.  See the pkg-config man page for
1979
more details." >&5
1979
more details." >&5
1980
echo "$as_me: error: Package requirements (ipoddevice >= 0.3.2 gtk-sharp-2.0) were not met.
1980
echo "$as_me: error: Package requirements (ipoddevice >= 0.3.3 gtk-sharp-2.0) were not met.
1981
Consider adjusting the PKG_CONFIG_PATH environment variable if you
1981
Consider adjusting the PKG_CONFIG_PATH environment variable if you
1982
installed software in a non-standard prefix.
1982
installed software in a non-standard prefix.
1983
1983
(-)./configure.in (-2 / +2 lines)
Lines 3-9 Link Here
3
3
4
MAJOR_VERSION=0
4
MAJOR_VERSION=0
5
MINOR_VERSION=5
5
MINOR_VERSION=5
6
MICRO_VERSION=4
6
MICRO_VERSION=5
7
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
7
VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION
8
                                                                                
8
                                                                                
9
AM_INIT_AUTOMAKE(ipod-sharp, $VERSION)
9
AM_INIT_AUTOMAKE(ipod-sharp, $VERSION)
Lines 18-24 Link Here
18
18
19
AM_MAINTAINER_MODE
19
AM_MAINTAINER_MODE
20
20
21
PKG_CHECK_MODULES(IPODDEVICE, ipoddevice >= 0.3.2 gtk-sharp-2.0)
21
PKG_CHECK_MODULES(IPODDEVICE, ipoddevice >= 0.3.3 gtk-sharp-2.0)
22
22
23
dnl Mono	   
23
dnl Mono	   
24
AC_PATH_PROG(MONO, mono)
24
AC_PATH_PROG(MONO, mono)
(-)./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/DeviceModel.cs (-1 / +3 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
17
    }
19
    }
18
}
20
}
(-)./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 = 14;
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 > 14)
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