Code: Select all
;1.0.3.0
EnableExplicit
Global PBEx_MTP
#PBEx_MTP_Type_File = 1
#PBEx_MTP_Type_Directory = 2
#PBEx_MTP_DeviceType_Generic = 0
#PBEx_MTP_DeviceType_Camera = 1
#PBEx_MTP_DeviceType_MediaPlayer = 2
#PBEx_MTP_DeviceType_Phone = 3
#PBEx_MTP_DeviceType_Video = 4
#PBEx_MTP_DeviceType_PersonalInformationManager = 5
#PBEx_MTP_DeviceType_AudioRecorder = 6
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
PBEx_MTP = OpenLibrary(#PB_Any, "PB.Ex_MTP_x86.dll")
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
PBEx_MTP = OpenLibrary(#PB_Any, "PB.Ex_MTP_x64.dll")
CompilerEndIf
If PBEx_MTP
Prototype ExamineMTP(ErrorOutput)
Global ExamineMTP.ExamineMTP = GetFunction(PBEx_MTP, "ExamineMTP")
Prototype NextMTPEntry(ErrorOutput)
Global NextMTPEntry.NextMTPEntry = GetFunction(PBEx_MTP, "NextMTPEntry")
Prototype FinishMTP(ErrorOutput)
Global FinishMTP.FinishMTP = GetFunction(PBEx_MTP, "FinishMTP")
Prototype MTPEntryName(Output, ErrorOutput)
Global MTPEntryName.MTPEntryName = GetFunction(PBEx_MTP, "MTPEntryName")
Prototype OpenMTP(ID, DeviceName.p-Unicode, ErrorOutput)
Global OpenMTP.OpenMTP = GetFunction(PBEx_MTP, "OpenMTP")
Prototype CloseMTP(ID, ErrorOutput)
Global CloseMTP.CloseMTP = GetFunction(PBEx_MTP, "CloseMTP")
Prototype IsMTP(ID, ErrorOutput)
Global IsMTP.IsMTP = GetFunction(PBEx_MTP, "IsMTP")
Prototype ExamineMTPDirectory(ID, ErrorOutput)
Global ExamineMTPDirectory.ExamineMTPDirectory = GetFunction(PBEx_MTP, "ExamineMTPDirectory")
Prototype FinishMTPDirectory(ID, ErrorOutput)
Global FinishMTPDirectory.FinishMTPDirectory = GetFunction(PBEx_MTP, "FinishMTPDirectory")
Prototype NextMTPDirectoryEntry(ID, ErrorOutput)
Global NextMTPDirectoryEntry.NextMTPDirectoryEntry = GetFunction(PBEx_MTP, "NextMTPDirectoryEntry")
Prototype MTPDirectoryEntryName(ID, Output, ErrorOutput)
Global MTPDirectoryEntryName.MTPDirectoryEntryName = GetFunction(PBEx_MTP, "MTPDirectoryEntryName")
Prototype SetMTPDirectory(ID, DirectoryPath.p-Unicode, ErrorOutput)
Global SetMTPDirectory.SetMTPDirectory = GetFunction(PBEx_MTP, "SetMTPDirectory")
Prototype GetMTPDirectory(ID, Output, ErrorOutput)
Global GetMTPDirectory.GetMTPDirectory = GetFunction(PBEx_MTP, "GetMTPDirectory")
Prototype MTPDirectoryEntryType(ID, ErrorOutput)
Global MTPDirectoryEntryType.MTPDirectoryEntryType = GetFunction(PBEx_MTP, "MTPDirectoryEntryType")
Prototype ReceiveMTPFile(ID, RemoteFileName.p-Unicode, FileName.p-Unicode, ErrorOutput)
Global ReceiveMTPFile.ReceiveMTPFile = GetFunction(PBEx_MTP, "ReceiveMTPFile")
Prototype MTPDirectoryEntrySize(ID, ErrorOutput)
Global MTPDirectoryEntrySize.MTPDirectoryEntrySize = GetFunction(PBEx_MTP, "MTPDirectoryEntrySize")
Prototype MTPDirectoryEntryDate(ID, ErrorOutput)
Global MTPDirectoryEntryDate.MTPDirectoryEntryDate = GetFunction(PBEx_MTP, "MTPDirectoryEntryDate")
Prototype GetMTPDescription(ID, Output, ErrorOutput)
Global GetMTPDescription.GetMTPDescription = GetFunction(PBEx_MTP, "GetMTPDescription")
Prototype GetMTPDeviceID(ID, Output, ErrorOutput)
Global GetMTPDeviceID.GetMTPDeviceID = GetFunction(PBEx_MTP, "GetMTPDeviceID")
Prototype GetMTPDeviceType(ID, ErrorOutput)
Global GetMTPDeviceType.GetMTPDeviceType = GetFunction(PBEx_MTP, "GetMTPDeviceType")
Prototype GetMTPFirmwareVersion(ID, Output, ErrorOutput)
Global GetMTPFirmwareVersion.GetMTPFirmwareVersion = GetFunction(PBEx_MTP, "GetMTPFirmwareVersion")
Prototype GetMTPFriendlyName(ID, Output, ErrorOutput)
Global GetMTPFriendlyName.GetMTPFriendlyName = GetFunction(PBEx_MTP, "GetMTPFriendlyName")
Prototype GetMTPManufacturer(ID, Output, ErrorOutput)
Global GetMTPManufacturer.GetMTPManufacturer = GetFunction(PBEx_MTP, "GetMTPManufacturer")
Prototype GetMTPModel(ID, Output, ErrorOutput)
Global GetMTPModel.GetMTPModel = GetFunction(PBEx_MTP, "GetMTPModel")
Prototype GetMTPPnPDeviceID(ID, Output, ErrorOutput)
Global GetMTPPnPDeviceID.GetMTPPnPDeviceID = GetFunction(PBEx_MTP, "GetMTPPnPDeviceID")
Prototype GetMTPSerialNumber(ID, Output, ErrorOutput)
Global GetMTPSerialNumber.GetMTPSerialNumber = GetFunction(PBEx_MTP, "GetMTPSerialNumber")
EndIf
Global Output$ = Space(1024)
Global ErrorOutput$ = Space(128)
Global DeviceName$
;List all devices to determine the device name.
If ExamineMTP(@ErrorOutput$)
While NextMTPEntry(@ErrorOutput$)
MTPEntryName(@Output$, @ErrorOutput$)
DeviceName$ = Output$
Wend
EndIf
;
; ;Get device information
; GetMTPFriendlyName(1, @Output$, @ErrorOutput$)
; Debug "Friendly name: " + Output$
; GetMTPManufacturer(1, @Output$, @ErrorOutput$)
; Debug "Manufacturer: " + Output$
; GetMTPFirmwareVersion(1, @Output$, @ErrorOutput$)
; Debug "Firmware version: " + Output$
; GetMTPPnPDeviceID(1, @Output$, @ErrorOutput$)
; Debug "PnPDeviceID: " + Output$
;
; !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Procedure FileSearch(id, List Files.s(), dir.s)
Protected NewList CurDir.s()
SetMTPDirectory(id, dir, @ErrorOutput$)
If ExamineMTPDirectory(id, @ErrorOutput$)
While NextMTPDirectoryEntry(id, @ErrorOutput$)
MTPDirectoryEntryName(id, @Output$, @ErrorOutput$)
If MTPDirectoryEntryType(id, @ErrorOutput$) = #PBEx_MTP_Type_Directory And AddElement(CurDir())
CurDir() = dir + "\" + Output$
ElseIf MTPDirectoryEntryType(id, @ErrorOutput$) = #PBEx_MTP_Type_File And AddElement(Files())
Files() = dir + "\" + Output$
EndIf
Wend
EndIf
ForEach CurDir()
FileSearch(id, Files(), CurDir())
Next
EndProcedure
Define NewList Files.s()
Define id = 1
If Asc(DeviceName$) And OpenMTP(id, DeviceName$, @ErrorOutput$)
FileSearch(id, Files(), "\Internal Storage\Movies")
CloseMTP(id, @ErrorOutput$)
Else
Debug ErrorOutput$
EndIf
ForEach Files()
Debug Files()
Next
CloseLibrary(PBEx_MTP)