big file support
[pandora-libraries.git] / lib / pnd_desktop.c
index 3fffa36..5420116 100644 (file)
@@ -16,7 +16,7 @@
 
 unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t *p ) {
   char filename [ FILENAME_MAX ];
-  char buffer [ 1024 ];
+  char buffer [ 4096 ];
   FILE *f;
 
   // specification
@@ -131,6 +131,11 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
   }
 #endif
 
+  // association requests
+  if ( p -> associationitem1_filetype ) {
+    fprintf ( f, "MimeType=%s\n", p -> associationitem1_filetype );
+  }
+
   if ( p -> exec ) {
     char *nohup;
 
@@ -157,7 +162,7 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
       strncat ( buffer, p -> startdir, 1020 );
     }
 
-    // args
+    // args (regular args, for pnd_run.sh to handle)
     if ( p -> execargs ) {
       char argbuf [ 1024 ];
       snprintf ( argbuf, 1000, " -a \"%s\"", p -> execargs );
@@ -175,6 +180,13 @@ unsigned char pnd_emit_dotdesktop ( char *targetpath, char *pndrun, pnd_disco_t
       strncat ( buffer, " -x ", 1020 );
     }
 
+    // args (dashdash -- args, that the shell can screw with before pnd_run.sh gets them)
+    if ( p -> exec_dashdash_args ) {
+      char argbuf [ 4096 ];
+      snprintf ( argbuf, 4096, " -- %s", p -> exec_dashdash_args );
+      strncat ( buffer, argbuf, 4096 );
+    }
+
     // newline
     strncat ( buffer, "\n", 1020 );
 
@@ -401,7 +413,7 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
 
   // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
   if ( ( p -> object_type == pnd_object_type_pnd ) &&
-       ( ! p -> pnd_icon_pos ) )
+       ( ! p -> pnd_icon_pos64 ) )
   {
     return ( 0 ); // discover code didn't find it, so FAIL
   }
@@ -425,7 +437,7 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
     return ( 0 );
   }
 
-  unsigned int len;
+  off_t len;
 
   target = fopen ( buffer, "wb" );
 
@@ -435,15 +447,19 @@ unsigned char pnd_emit_icon ( char *targetpath, pnd_disco_t *p ) {
     return ( 0 );
   }
 
-  fseek ( pnd, 0, SEEK_END );
-  len = ftell ( pnd );
-  //fseek ( pnd, 0, SEEK_SET );
+  fseeko ( pnd, 0, SEEK_END );
+  len = ftello ( pnd );
 
-  fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
+  fseeko ( pnd, p -> pnd_icon_pos64, SEEK_SET );
 
-  len -= p -> pnd_icon_pos;
+  len -= p -> pnd_icon_pos64;
 
-  pnd_log ( PND_LOG_DEFAULT, "    Emit icon, length: %u\n", len );
+  if ( len <= 0 ) {
+    fclose ( pnd );
+    return ( 0 );
+  }
+
+  pnd_log ( PND_LOG_DEFAULT, "    Emit icon, length: %u\n", (int)len );
 
   while ( len ) {
 
@@ -520,8 +536,10 @@ int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsi
   #define MAPCAT(field)                                            \
     if ( ( t = d -> field ) ) {                             \
       match = pnd_map_dotdesktop_category ( c, t );         \
-      strncat ( target_buffer, match ? match : t, len );    \
-      strncat ( target_buffer, ";", len );                  \
+      if ( ( !match ) || ( strcasecmp ( match, "NoCategory" ) ) ) {    \
+       strncat ( target_buffer, match ? match : t, len );  \
+       strncat ( target_buffer, ";", len );                \
+      }                                                     \
     }
 
   MAPCAT(main_category);
@@ -704,7 +722,7 @@ unsigned char *pnd_emit_icon_to_buffer ( pnd_disco_t *p, unsigned int *r_buflen
 
   // prelim .. if a pnd file, and no offset found, discovery code didn't locate icon.. so bail.
   if ( ( p -> object_type == pnd_object_type_pnd ) &&
-       ( ! p -> pnd_icon_pos ) )
+       ( ! p -> pnd_icon_pos64 ) )
   {
     return ( NULL ); // discover code didn't find it, so FAIL
   }
@@ -725,15 +743,19 @@ unsigned char *pnd_emit_icon_to_buffer ( pnd_disco_t *p, unsigned int *r_buflen
   }
 
   // determine length of file, then adjust by icon position to find begin of icon
-  unsigned int len;
+  off_t len;
+
+  fseeko ( pnd, 0, SEEK_END );
+  len = ftello ( pnd );
 
-  fseek ( pnd, 0, SEEK_END );
-  len = ftell ( pnd );
-  //fseek ( pnd, 0, SEEK_SET );
+  fseeko ( pnd, p -> pnd_icon_pos64, SEEK_SET );
 
-  fseek ( pnd, p -> pnd_icon_pos, SEEK_SET );
+  len -= p -> pnd_icon_pos64;
 
-  len -= p -> pnd_icon_pos;
+  if ( len <= 0 ) {
+    fclose ( pnd );
+    return ( NULL );
+  }
 
   // create target buffer
   target = malloc ( len );
@@ -996,7 +1018,7 @@ pnd_disco_t *pnd_parse_dotdesktop ( char *ddpath, unsigned int flags ) {
       return ( NULL );
     } else {
       char hack [ 100 ];
-      snprintf ( hack, 100, "inode-%lu", statbuf.st_ino );
+      snprintf ( hack, 100, "inode-%lu", (long)statbuf.st_ino );
       p -> unique_id = strdup ( hack );
     }
   }