banshee r3181 - in trunk/musicbrainz-sharp/src/MusicBrainz: . MusicBrainz



Author: scottp
Date: Sat Feb  9 07:21:08 2008
New Revision: 3181
URL: http://svn.gnome.org/viewvc/banshee?rev=3181&view=rev

Log:
* src/MusicBrainz/MusicBrainz/DiscLinux.cs: Improvements to the linux
  discid implimentation. Still doesn't work, but getting closer.

Modified:
   trunk/musicbrainz-sharp/src/MusicBrainz/ChangeLog
   trunk/musicbrainz-sharp/src/MusicBrainz/MusicBrainz/DiscLinux.cs

Modified: trunk/musicbrainz-sharp/src/MusicBrainz/MusicBrainz/DiscLinux.cs
==============================================================================
--- trunk/musicbrainz-sharp/src/MusicBrainz/MusicBrainz/DiscLinux.cs	(original)
+++ trunk/musicbrainz-sharp/src/MusicBrainz/MusicBrainz/DiscLinux.cs	Sat Feb  9 07:21:08 2008
@@ -52,22 +52,31 @@
             return get_entry(fd, CDROMREADTOCENTRY, ref entry);
         }
         
+        [StructLayout(LayoutKind.Sequential)]
         struct cdrom_tochdr
         {
             public byte cdth_trk0; // start track
             public byte cdth_trk1; // end track
         }
         
+        [StructLayout(LayoutKind.Explicit)]
         struct cdrom_tocentry
         {
+            [FieldOffset(0)]
             public byte cdte_track;
+            [FieldOffset(1)]
             public byte cdte_adr;
+            [FieldOffset(1)]
             public byte cdte_ctrl;
+            [FieldOffset(2)]
             public byte cdte_format;
+            [FieldOffset(3)]
             public cdrom_addr cdte_addr;
+            [FieldOffset(7)]
             public byte cdte_datamode;
         }
         
+        [StructLayout(LayoutKind.Sequential)]
         struct cdrom_multisession
         {
             public cdrom_addr addr;
@@ -82,6 +91,7 @@
             [FieldOffset(0)] public int lba;
         }
         
+        [StructLayout(LayoutKind.Sequential)]
         struct cdrom_msf0
         {
             public byte minute;
@@ -143,31 +153,31 @@
         internal DiscLinux(string device)
         {
             int fd = open(device, O_RDONLY | O_NONBLOCK);
-
+            
             if(fd < 0)
                 throw new Exception(String.Format("Cannot open device '{0}'", device));
             
-            if(ReadTocHeader(fd) < 0) {
-                close(fd);
-                throw new Exception("Cannot read table of contents");
-            }
-            
-            if(LastTrack == 0) {
+            try {
+                if(ReadTocHeader(fd) < 0) {
+                    throw new Exception("Cannot read table of contents");
+                }
+                
+                if(LastTrack == 0) {
+                    throw new Exception("This disc has no tracks");
+                }
+                
+                ulong lba = 0;
+                ReadLeadout(fd, ref lba);
+                TrackOffsets[0] = (int)lba + 150;
+                
+                for(byte i = FirstTrack; i <= LastTrack; i++) {
+                    ReadTocEntry(fd, i, ref lba);
+                    TrackOffsets[i] = (int)lba + 150;
+                }
+            } finally {
                 close(fd);
-                throw new Exception("This disc has no tracks");
-            }
-            
-            ulong lba = 0;
-            ReadLeadout(fd, ref lba);
-            TrackOffsets[0] = (int)lba + 150;
-            
-            for(byte i = FirstTrack; i <= LastTrack; i++) {
-                ReadTocEntry(fd, i, ref lba);
-                TrackOffsets[i] = (int)lba + 150;
             }
             
-            close(fd);
-            
             Init();
         }
     }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]