int main (int argc, char **argv) { LIBMTP_mtpdevice_t *device; LIBMTP_playlist_t *playlists; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); LIBMTP_Init(); device = LIBMTP_Get_First_Device(); if (device == NULL) { printf("No devices.\n"); exit (0); } // Get playlist listing. playlists = LIBMTP_Get_Playlist_List(device); if (playlists == NULL) { printf("No playlists.\n"); } else { LIBMTP_playlist_t *pl, *tmp; pl = playlists; while (pl != NULL) { dump_plinfo(device, pl); tmp = pl; pl = pl->next; LIBMTP_destroy_playlist_t(tmp); } } LIBMTP_Release_Device(device); printf("OK.\n"); exit (0); }
static void free_device (void) { #if DEBUG if(mtp_initialised) g_print("\n\n !!!CAUTION!!! \n\n" "Cleaning up MTP upload plugin, please wait!!!...\n" "This will block until the pending tracks are uploaded,\n" "then it will gracefully close your device\n\n" "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n" "Waiting for the MTP mutex to unlock...\n"); #endif if(!mutex) return; g_mutex_lock(mutex); if(mtp_device!= NULL) { LIBMTP_Release_Device(mtp_device); mtp_device = NULL; mtp_initialised = FALSE; #if 0 gtk_widget_hide(mtp_submenu_item_free); #endif } g_mutex_unlock(mutex); return; }
int main(int argc, char const *argv[]) { LIBMTP_Init(); printf("Searching for device...\n"); LIBMTP_mtpdevice_t* device = LIBMTP_Get_First_Device(); if (!device) { printf("Oops, no devices!\n"); return 1; } /* Warning! This id is just for test! Remove it and put your value */ const int id = 10494; int r = 0; LIBMTP_BeginEditObject(device, id); char s[64] = "The quick brown fox jumps over lazy dog\n"; printf("Calling for LIBMTP_SendPartialObject...\n"); r = LIBMTP_SendPartialObject(device, id, 0, (unsigned char *)s, strlen(s)); if (r < 0) { printf("Oops, an error!\n"); goto cleanup; } else printf("LIBMTP_SendPartialObject done successfully!\n"); LIBMTP_EndEditObject(device, id); cleanup: LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); LIBMTP_Release_Device(device); return r < 0 ? -1 : 0; }
/** * Get the first (as in "first in the list of") connected Vita MTP device. * @return a device pointer. NULL if error, no connected device, or no connected Vita * @see LIBMTP_Get_Connected_Devices() */ LIBMTP_mtpdevice_t *LIBVitaMTP_Get_First_Vita(void){ LIBMTP_mtpdevice_t *first_device = NULL; LIBMTP_raw_device_t *devices; int numdevs; int i; LIBMTP_error_number_t ret; ret = LIBMTP_Detect_Raw_Devices(&devices, &numdevs); if (ret != LIBMTP_ERROR_NONE){ return NULL; } if (devices == NULL || numdevs == 0){ return NULL; } for (i = 0; i < numdevs; i++){ if(devices[i].device_entry.vendor_id == VITA_VID && devices[i].device_entry.product_id == VITA_PID){ first_device = LIBMTP_Open_Raw_Device(&devices[i]); break; } LIBMTP_Release_Device(first_device); } free(devices); return first_device; // NULL if no vita }
void MTPDevice::disconnect() { if (!m_device) return; LIBMTP_Release_Device(m_device); m_device = nullptr; logmsg("Disconnected.\n"); }
int main (int argc, char **argv) { int do_delete = 0; int opt; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); while ( (opt = getopt(argc, argv, "d")) != -1 ) { switch (opt) { case 'd': do_delete = 1; break; default: break; } } if(do_delete == 0) { printf("This is a dummy run. No folders will be deleted.\n"); printf("To delete folders, use the '-d' option.\n"); } LIBMTP_mtpdevice_t *device; LIBMTP_folder_t *folders; LIBMTP_file_t *files; LIBMTP_Init(); device = LIBMTP_Get_First_Device(); if (device == NULL) { printf("No devices.\n"); exit (0); } files = LIBMTP_Get_Filelisting_With_Callback(device,NULL,NULL); folders = LIBMTP_Get_Folder_List(device); if(folders == NULL) { printf("No folders found\n"); } else { prune_empty_folders(device,files,folders,do_delete); } LIBMTP_destroy_folder_t(folders); LIBMTP_destroy_file_t(files); LIBMTP_Release_Device(device); printf("OK.\n"); exit (0); }
/***************************************************************************** * Everything else *****************************************************************************/ static int AddDevice( services_discovery_t *p_sd, LIBMTP_raw_device_t *p_raw_device ) { char *psz_name = NULL; LIBMTP_mtpdevice_t *p_device; LIBMTP_track_t *p_track, *p_tmp; if( ( p_device = LIBMTP_Open_Raw_Device( p_raw_device ) ) != NULL ) { if( !( psz_name = LIBMTP_Get_Friendlyname( p_device ) ) ) if( !( psz_name = LIBMTP_Get_Modelname( p_device ) ) ) if( !( psz_name = strdup( N_( "MTP Device" ) ) ) ) return VLC_ENOMEM; msg_Info( p_sd, "Found device: %s", psz_name ); p_sd->p_sys->i_bus = p_raw_device->bus_location; p_sd->p_sys->i_dev = p_raw_device->devnum; p_sd->p_sys->i_product_id = p_raw_device->device_entry.product_id; if( ( p_track = LIBMTP_Get_Tracklisting_With_Callback( p_device, CountTracks, p_sd ) ) == NULL ) { msg_Warn( p_sd, "No tracks on the device" ); } else { if( !( p_sd->p_sys->pp_items = calloc( p_sd->p_sys->i_tracks_num, sizeof( input_item_t * ) ) ) ) { free( psz_name ); return VLC_ENOMEM; } p_sd->p_sys->i_count = 0; while( p_track != NULL ) { msg_Dbg( p_sd, "Track found: %s - %s", p_track->artist, p_track->title ); AddTrack( p_sd, p_track ); p_tmp = p_track; p_track = p_track->next; LIBMTP_destroy_track_t( p_tmp ); } } p_sd->p_sys->psz_name = psz_name; LIBMTP_Release_Device( p_device ); return VLC_SUCCESS; } else { msg_Info( p_sd, "The device seems to be mounted, unmount it first" ); return VLC_EGENERIC; } }
int main (int argc, char **argv) { LIBMTP_mtpdevice_t *device; int ret; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); LIBMTP_Init(); device = LIBMTP_Get_First_Device(); if (device == NULL) { printf("No devices.\n"); return 0; } printf("I will now format your device. This means that\n"); printf("all content (and licenses) will be lost forever.\n"); printf("you will not be able to undo this operation.\n"); printf("Continue? (y/n)\n"); if (prompt() == 0) { // This will just format the first storage. ret = LIBMTP_Format_Storage(device, device->storage); } else { printf("Aborted.\n"); ret = 0; } if ( ret != 0 ) { printf("Failed to format device.\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); LIBMTP_Release_Device(device); return 1; } LIBMTP_Release_Device(device); printf("OK.\n"); return 0; }
static void rb_mtp_source_finalize (GObject *object) { RBMtpSourcePrivate *priv = MTP_SOURCE_GET_PRIVATE (object); g_hash_table_destroy (priv->entry_map); g_hash_table_destroy (priv->album_map); g_hash_table_destroy (priv->artwork_request_map); g_free (priv->udi); LIBMTP_Release_Device (priv->device); G_OBJECT_CLASS (rb_mtp_source_parent_class)->finalize (object); }
// Device.__init__() {{{ static void Device_dealloc(Device* self) { if (self->device != NULL) { Py_BEGIN_ALLOW_THREADS; LIBMTP_Release_Device(self->device); Py_END_ALLOW_THREADS; } self->device = NULL; Py_XDECREF(self->ids); self->ids = NULL; Py_XDECREF(self->friendly_name); self->friendly_name = NULL; Py_XDECREF(self->manufacturer_name); self->manufacturer_name = NULL; Py_XDECREF(self->model_name); self->model_name = NULL; Py_XDECREF(self->serial_number); self->serial_number = NULL; Py_XDECREF(self->device_version); self->device_version = NULL; self->ob_type->tp_free((PyObject*)self); }
void mtp_cleanup(void) { if (plugin_active) { aud_plugin_menu_remove (AUD_MENU_MAIN, mtp_press); aud_plugin_menu_remove (AUD_MENU_MAIN, free_device); #if DEBUG if(mtp_initialised) { g_print("\n\n !!!CAUTION!!! \n\n" "Cleaning up MTP upload plugin, please wait!!!...\n" "This will block until the pending tracks are uploaded,\n" "then it will gracefully close your device\n\n" "!!! FORCING SHUTDOWN NOW MAY CAUSE DAMAGE TO YOUR DEVICE !!!\n\n\n" "Waiting for the MTP mutex to unlock...\n"); exiting=TRUE; } #endif if(mutex) g_mutex_lock(mutex); if(mtp_device!= NULL) { LIBMTP_Release_Device(mtp_device); mtp_device = NULL; } g_mutex_unlock(mutex); #if DEBUG if(mtp_initialised) g_print("The MTP mutex has been unlocked\n"); #endif g_mutex_free (mutex); mutex = NULL; plugin_active = FALSE; #if DEBUG if(mtp_initialised) g_print("MTP upload plugin has been cleaned up successfully\n"); #endif } }
static void impl_finalize (GObject *object) { RBMtpThread *thread = RB_MTP_THREAD (object); RBMtpThreadTask *task; rb_debug ("joining MTP worker thread"); task = create_task (CLOSE_DEVICE); queue_task (thread, task); g_thread_join (thread->thread); rb_debug ("MTP worker thread exited"); g_async_queue_unref (thread->queue); g_hash_table_destroy (thread->albums); if (thread->device != NULL) { LIBMTP_Release_Device (thread->device); } G_OBJECT_CLASS (rb_mtp_thread_parent_class)->finalize (object); }
int main (int argc, char **argv) { LIBMTP_raw_device_t *rawdevices; int numrawdevices; int i; LIBMTP_Init(); printf("Attempting to connect device(s)\n"); switch (LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices)) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: printf("mtp-folders: no devices found\n"); return 0; case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n"); return 1; case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n"); return 1; /* Unknown general errors - This should never execute */ case LIBMTP_ERROR_GENERAL: default: fprintf(stderr, "mtp-folders: Unknown error, please report " "this to the libmtp developers\n"); return 1; /* Successfully connected at least one device, so continue */ case LIBMTP_ERROR_NONE: printf("mtp-folders: Successfully connected\n"); } /* iterate through connected MTP devices */ for (i = 0; i < numrawdevices; i++) { LIBMTP_mtpdevice_t *device; LIBMTP_devicestorage_t *storage; char *friendlyname; int ret; device = LIBMTP_Open_Raw_Device(&rawdevices[i]); if (device == NULL) { fprintf(stderr, "Unable to open raw device %d\n", i); continue; } /* Echo the friendly name so we know which device we are working with */ friendlyname = LIBMTP_Get_Friendlyname(device); if (friendlyname == NULL) { printf("Friendly name: (NULL)\n"); } else { printf("Friendly name: %s\n", friendlyname); free(friendlyname); } LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); /* Get all storages for this device */ ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED); if (ret != 0) { perror("LIBMTP_Get_Storage()\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); continue; } /* Loop over storages, dump folder for each one */ for (storage = device->storage; storage != 0; storage = storage->next) { LIBMTP_folder_t *folders; printf("Storage: %s\n", storage->StorageDescription); folders = LIBMTP_Get_Folder_List_For_Storage(device, storage->id); if (folders == NULL) { fprintf(stdout, "No folders found\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } else { dump_folder_list(folders,0); } LIBMTP_destroy_folder_t(folders); } LIBMTP_Release_Device(device); } free(rawdevices); printf("OK.\n"); return 0; }
int main (int argc, char **argv) { LIBMTP_raw_device_t * rawdevices; int numrawdevices; LIBMTP_error_number_t err; int i; int opt; extern int optind; extern char *optarg; while ((opt = getopt(argc, argv, "d")) != -1 ) { switch (opt) { case 'd': LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); break; } } argc -= optind; argv += optind; LIBMTP_Init(); fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); fprintf(stdout, "Listing raw device(s)\n"); err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); switch(err) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stdout, " No raw devices found.\n"); return 0; case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "Detect: There has been an error connecting. Exiting\n"); return 1; case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n"); return 1; case LIBMTP_ERROR_NONE: { int i; fprintf(stdout, " Found %d device(s):\n", numrawdevices); for (i = 0; i < numrawdevices; i++) { if (rawdevices[i].device_entry.vendor != NULL || rawdevices[i].device_entry.product != NULL) { fprintf(stdout, " %s: %s (%04x:%04x) @ bus %d, dev %d\n", rawdevices[i].device_entry.vendor, rawdevices[i].device_entry.product, rawdevices[i].device_entry.vendor_id, rawdevices[i].device_entry.product_id, rawdevices[i].bus_location, rawdevices[i].devnum); } else { fprintf(stdout, " %04x:%04x @ bus %d, dev %d\n", rawdevices[i].device_entry.vendor_id, rawdevices[i].device_entry.product_id, rawdevices[i].bus_location, rawdevices[i].devnum); } } } break; case LIBMTP_ERROR_GENERAL: default: fprintf(stderr, "Unknown connection error.\n"); return 1; } /* Iterate over connected MTP devices */ fprintf(stdout, "Attempting to connect device(s)\n"); for (i = 0; i < numrawdevices; i++) { LIBMTP_mtpdevice_t *device; LIBMTP_devicestorage_t *storage; char *friendlyname; char *syncpartner; char *sectime; char *devcert; uint16_t *filetypes; uint16_t filetypes_len; uint8_t maxbattlevel; uint8_t currbattlevel; int ret; device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); if (device == NULL) { fprintf(stderr, "Unable to open raw device %d\n", i); continue; } LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); LIBMTP_Dump_Device_Info(device); printf("MTP-specific device properties:\n"); // The friendly name friendlyname = LIBMTP_Get_Friendlyname(device); if (friendlyname == NULL) { fprintf(stdout, " Friendly name: (NULL)\n"); } else { fprintf(stdout, " Friendly name: %s\n", friendlyname); free(friendlyname); } syncpartner = LIBMTP_Get_Syncpartner(device); if (syncpartner == NULL) { fprintf(stdout, " Synchronization partner: (NULL)\n"); } else { fprintf(stdout, " Synchronization partner: %s\n", syncpartner); free(syncpartner); } // Some battery info ret = LIBMTP_Get_Batterylevel(device, &maxbattlevel, &currbattlevel); if (ret == 0) { fprintf(stdout, " Battery level %d of %d (%d%%)\n",currbattlevel, maxbattlevel, (int) ((float) currbattlevel/ (float) maxbattlevel * 100.0)); } else { // Silently ignore. Some devices does not support getting the // battery level. LIBMTP_Clear_Errorstack(device); } ret = LIBMTP_Get_Supported_Filetypes(device, &filetypes, &filetypes_len); if (ret == 0) { uint16_t i; printf("libmtp supported (playable) filetypes:\n"); for (i = 0; i < filetypes_len; i++) { fprintf(stdout, " %s\n", LIBMTP_Get_Filetype_Description(filetypes[i])); } } else { LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } // Secure time XML fragment ret = LIBMTP_Get_Secure_Time(device, §ime); if (ret == 0 && sectime != NULL) { fprintf(stdout, "\nSecure Time:\n%s\n", sectime); free(sectime); } else { // Silently ignore - there may be devices not supporting secure time. LIBMTP_Clear_Errorstack(device); } // Device certificate XML fragment if (rawdevices[i].device_entry.vendor_id == 0x041e) { /* * This code is currently disabled except for vendors we * know does support it: all devices say that * they support getting a device certificate but a lot of * them obviously doesn't, instead they crash when you try * to obtain it. */ ret = LIBMTP_Get_Device_Certificate(device, &devcert); if (ret == 0 && devcert != NULL) { fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert); free(devcert); } else { fprintf(stdout, "Unable to acquire device certificate, perhaps this device " "does not support this\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } } /* Try to get Media player device info XML file... */ /* Loop over storages */ for (storage = device->storage; storage != 0; storage = storage->next) { LIBMTP_file_t *files; /* Get file listing for the root directory, no other dirs */ files = LIBMTP_Get_Files_And_Folders(device, storage->id, 0); if (files != NULL) { LIBMTP_file_t *file, *tmp; file = files; while (file != NULL) { if (!strcmp(file->filename, "WMPInfo.xml") || !strcmp(file->filename, "WMPinfo.xml") || !strcmp(file->filename, "default-capabilities.xml")) { if (file->item_id != 0) { /* Dump this file */ FILE *xmltmp = tmpfile(); int tmpfiledescriptor = fileno(xmltmp); if (tmpfiledescriptor != -1) { int ret = LIBMTP_Get_Track_To_File_Descriptor(device, file->item_id, tmpfiledescriptor, NULL, NULL); if (ret == 0) { uint8_t *buf = NULL; uint32_t readbytes; buf = malloc(XML_BUFSIZE); if (buf == NULL) { printf("Could not allocate %08x bytes...\n", XML_BUFSIZE); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); free(rawdevices); return 1; } lseek(tmpfiledescriptor, 0, SEEK_SET); readbytes = read(tmpfiledescriptor, (void*) buf, XML_BUFSIZE); if (readbytes >= 2 && readbytes < XML_BUFSIZE) { fprintf(stdout, "\n%s file contents:\n", file->filename); dump_xml_fragment(buf, readbytes); } else { perror("Unable to read file"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } free(buf); } else { LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } fclose(xmltmp); } } } tmp = file; file = file->next; LIBMTP_destroy_file_t(tmp); } } } LIBMTP_Release_Device(device); } /* End For Loop */ free(rawdevices); printf("OK.\n"); return 0; }
int main (int argc, char **argv) { int opt; extern int optind; extern char *optarg; LIBMTP_mtpdevice_t *device = NULL; int fd; uint32_t id = 0; uint64_t filesize; uint8_t *imagedata = NULL; char *path = NULL; char *rest; struct stat statbuff; int ret; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); while ( (opt = getopt(argc, argv, "hi:")) != -1 ) { switch (opt) { case 'h': usage(); case 'i': id = strtoul(optarg, &rest, 0); break; default: usage(); } } argc -= optind; argv += optind; if ( argc != 1 ) { printf("You need to pass a filename.\n"); usage(); } path = argv[0]; if ( stat(path, &statbuff) == -1 ) { fprintf(stderr, "%s: ", path); perror("stat"); exit(1); } filesize = (uint64_t) statbuff.st_size; imagedata = malloc(filesize * sizeof(uint16_t)); #ifdef __WIN32__ if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { #else if ( (fd = open(path, O_RDONLY)) == -1) { #endif printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); return 1; } else { read(fd, imagedata, filesize); close(fd); } LIBMTP_Init(); device = LIBMTP_Get_First_Device(); if (device == NULL) { printf("No devices.\n"); return 0; } LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t(); int i; thumb->data = malloc(sizeof(uint16_t) * filesize); for (i = 0; i < filesize; i++) { thumb->data[i] = imagedata[i]; } thumb->size = filesize; thumb->filetype = LIBMTP_FILETYPE_JPEG; ret = LIBMTP_Send_Representative_Sample(device,id,thumb); if (ret != 0) { printf("Couldn't send thumbnail\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } free(imagedata); LIBMTP_destroy_filesampledata_t(thumb); LIBMTP_Release_Device(device); printf("OK.\n"); return 0; }
int main (int argc, char **argv) { LIBMTP_raw_device_t * rawdevices; int numrawdevices; LIBMTP_error_number_t err; int i; int opt; extern int optind; extern char *optarg; while ((opt = getopt(argc, argv, "d")) != -1 ) { switch (opt) { case 'd': LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); break; } } argc -= optind; argv += optind; LIBMTP_Init(); err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); switch(err) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stdout, " No raw devices found.\n"); return 0; case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "Detect: There has been an error connecting. Exiting\n"); return 1; case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n"); return 1; case LIBMTP_ERROR_NONE: break; case LIBMTP_ERROR_GENERAL: default: fprintf(stderr, "Unknown connection error.\n"); return 1; } /* Iterate over connected MTP devices */ fprintf(stdout, "Attempting to connect device(s)\n"); for (i = 0; i < numrawdevices; i++) { LIBMTP_mtpdevice_t *device; LIBMTP_devicestorage_t *storage; char *friendlyname; int ret; device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); if (device == NULL) { fprintf(stderr, "Unable to open raw device %d\n", i); continue; } LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); friendlyname = LIBMTP_Get_Friendlyname(device); if (friendlyname == NULL) { printf("Device: (NULL)\n"); } else { printf("Device: %s\n", friendlyname); free(friendlyname); } /* Get all storages for this device */ ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED); if (ret != 0) { perror("LIBMTP_Get_Storage()"); goto bailout; } /* Loop over storages */ for (storage = device->storage; storage != 0; storage = storage->next) { fprintf(stdout, "Storage: %s\n", storage->StorageDescription); recursive_file_tree(device, storage, 0, 0); } bailout: LIBMTP_Release_Device(device); } /* End For Loop */ free(rawdevices); printf("OK.\n"); return 0; }
int main(int argc, char **argv) { int mainret = 0; if (argc < 2) { fprintf(stderr, "usage: %s [-d] mountpoint\n", argv[0]); exit(1); } char *mount_point = argv[1]; argc -= 1; argv += 1; // LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); LIBMTP_Init(); LIBMTP_error_number_t mtperr; LIBMTP_raw_device_t *rawdevs; int nrawdev; mtperr = LIBMTP_Detect_Raw_Devices(&rawdevs, &nrawdev); switch (mtperr) { case LIBMTP_ERROR_NO_DEVICE_ATTACHED: fprintf(stderr, "no raw devices\n"); exit(0); case LIBMTP_ERROR_CONNECTING: fprintf(stderr, "ERROR connecting\n"); exit(1); case LIBMTP_ERROR_MEMORY_ALLOCATION: fprintf(stderr, "ERROR memory allocation\n"); exit(1); case LIBMTP_ERROR_NONE: break; default: fprintf(stderr, "ERROR unknown\n"); exit(1); } printf("%d raw devices:\n", nrawdev); int i; for (i = 0; i < nrawdev; ++i) { printf(" device #%d: %s: %s (%04X:%04X) @ bus %d, dev %d\n", i, rawdevs[i].device_entry.vendor, rawdevs[i].device_entry.product, rawdevs[i].device_entry.vendor_id, rawdevs[i].device_entry.product_id, rawdevs[i].bus_location, rawdevs[i].devnum); } mtpfuse_t ctx; memset(&ctx, 0, sizeof(ctx)); printf("opening raw device #0...\n"); ctx.dev = LIBMTP_Open_Raw_Device_Uncached(&rawdevs[0]); if (!ctx.dev) { fprintf(stderr, "ERROR opening raw device #0\n"); exit(1); } LIBMTP_Dump_Errorstack(ctx.dev); LIBMTP_Clear_Errorstack(ctx.dev); char *name = LIBMTP_Get_Friendlyname(ctx.dev); printf("opened raw device %s.\n", name); int ret = LIBMTP_Get_Storage(ctx.dev, LIBMTP_STORAGE_SORTBY_NOTSORTED); if (ret != 0) { fprintf(stderr, "ERROR get %s's storage:\n", name); LIBMTP_Dump_Errorstack(ctx.dev); mainret = 1; goto done; } printf("device's storage:\n"); LIBMTP_devicestorage_t *storage; for (storage = ctx.dev->storage, i = 0; storage; storage = storage->next, ++i) { printf(" storage #%d: %d - %s\n", i, storage->id, storage->StorageDescription); } if (i <= 0) { fprintf(stderr, "there is no storage that is usable.\n"); mainret = 1; goto done; } mainret = fuse_main(argc, argv, &mtpfuse_ops, &ctx); done: LIBMTP_Release_Device(ctx.dev); return mainret; }
int main (int argc, char **argv) { int opt; extern int optind; extern char *optarg; LIBMTP_mtpdevice_t *device = NULL; int idcount = 0; uint32_t *ids = NULL; uint32_t *tmp = NULL; char *playlistname = NULL; char *rest; uint32_t storageid = 0; uint32_t parentid = 0; fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); while ( (opt = getopt(argc, argv, "hn:i:s:p:")) != -1 ) { switch (opt) { case 'h': usage(); case 'i': idcount++; if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) { printf("realloc failed\n"); return 1; } ids = tmp; ids[(idcount-1)] = strtoul(optarg, &rest, 0); break; case 'n': playlistname = strdup(optarg); break; case 's': storageid = (uint32_t) strtoul(optarg, NULL, 0); break; case 'p': parentid = (uint32_t) strtoul(optarg, NULL, 0); break; default: usage(); } } argc -= optind; argv += optind; if ( playlistname == NULL) { printf("You need to supply a playlist name.\n"); usage(); } if (idcount == 0) { printf("You need to supply one or more track IDs\n"); usage(); } LIBMTP_Init(); device = LIBMTP_Get_First_Device(); if (device == NULL) { printf("No devices.\n"); return 0; } LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t(); playlist->name = playlistname; playlist->no_tracks = idcount; playlist->tracks = ids; playlist->parent_id = parentid; playlist->storage_id = storageid; int ret = LIBMTP_Create_New_Playlist(device,playlist); if (ret != 0) { printf("Couldn't create playlist object\n"); LIBMTP_Dump_Errorstack(device); LIBMTP_Clear_Errorstack(device); } else { printf("Created new playlist: %u\n", playlist->playlist_id); } LIBMTP_Release_Device(device); printf("OK.\n"); return 0; }