├── _config.yml ├── qt ├── .gitignore ├── android-file-transfer.png ├── translations │ └── translations.qrc.in ├── android-file-transfer.desktop ├── icons │ ├── dark │ │ ├── go-next.svg │ │ ├── go-previous.svg │ │ ├── folder-new.svg │ │ └── view-refresh.svg │ └── light │ │ ├── go-next.svg │ │ ├── go-previous.svg │ │ ├── folder-new.svg │ │ └── view-refresh.svg ├── android-file-transfer.qrc ├── utils.cpp ├── qtobjectstream.cpp ├── mtpmimedata.cpp ├── mtpmimedata.h ├── devicesdialog.h ├── android-file-transfer.appdata.xml ├── renamedialog.cpp ├── renamedialog.h ├── createdirectorydialog.cpp ├── utils.h ├── createdirectorydialog.h ├── Info.plist.in ├── mtpstoragesmodel.h ├── devicesdialog.ui ├── progressdialog.h ├── renamedialog.ui ├── createdirectorydialog.ui ├── fileuploader.h ├── mtpstoragesmodel.cpp ├── main.cpp ├── progressdialog.ui └── qtobjectstream.h ├── python ├── example │ ├── requirements.txt │ └── menu.py └── CMakeLists.txt ├── screenshot.png ├── cli ├── update.sh ├── Tokens.h ├── Command.cpp ├── arg_lexer.l ├── Tokenizer.h ├── CommandLineStub.cpp ├── CommandLine.h ├── Tokenizer.cpp └── CommandLine.cpp ├── .gitignore ├── osx ├── android-file-transfer.icns ├── android-file-transfer.png └── icns.sh ├── mtp ├── version.cpp.in ├── ptp │ ├── PerceivedDeviceType.values.h │ ├── EventCode.cpp │ ├── OperationCode.cpp │ ├── DataTypeCode.h │ ├── EventCode.values.h │ ├── DataTypeCode.cpp │ ├── DataTypeCode.values.h │ ├── DeviceProperty.cpp │ ├── EventCode.h │ ├── OperationCode.h │ ├── ObjectProperty.h │ ├── DeviceProperty.h │ ├── Response.cpp │ ├── ResponseType.values.h │ ├── Messages.cpp │ ├── DeviceProperty.values.h │ ├── PipePacketer.h │ ├── Container.h │ ├── Device.h │ ├── ObjectId.h │ ├── Response.h │ ├── ObjectFormat.h │ ├── IObjectStream.h │ ├── ObjectProperty.cpp │ └── ObjectFormat.values.h ├── backend │ ├── linux │ │ └── usb │ │ │ ├── linux │ │ │ └── types.h │ │ │ ├── Context.h │ │ │ ├── Interface.cpp │ │ │ ├── Endpoint.h │ │ │ ├── Interface.h │ │ │ ├── Context.cpp │ │ │ ├── Endpoint.cpp │ │ │ ├── DeviceDescriptor.cpp │ │ │ └── Device.h │ ├── haiku │ │ └── usb │ │ │ ├── Context.cpp │ │ │ ├── DeviceDescriptor.cpp │ │ │ ├── Context.h │ │ │ ├── Interface.h │ │ │ ├── Device.cpp │ │ │ └── DeviceDescriptor.h │ ├── libusb │ │ └── usb │ │ │ ├── Interface.cpp │ │ │ ├── call.h │ │ │ ├── Exception.h │ │ │ ├── Exception.cpp │ │ │ ├── Context.h │ │ │ ├── Context.cpp │ │ │ ├── DeviceDescriptor.cpp │ │ │ ├── Interface.h │ │ │ └── DeviceDescriptor.h │ ├── posix │ │ ├── FileHandler.cpp │ │ ├── FileHandler.h │ │ ├── Exception.h │ │ └── Exception.cpp │ └── darwin │ │ └── usb │ │ ├── Exception.h │ │ ├── usb.h │ │ ├── Exception.cpp │ │ ├── Context.h │ │ ├── call.h │ │ ├── DeviceDescriptor.h │ │ ├── Device.h │ │ └── Interface.h ├── scope_guard.h ├── metadata │ ├── Metadata.h │ └── Metadata.cpp ├── ByteArray.cpp ├── version.h ├── ByteArray.h ├── usb │ ├── types.h │ ├── TimeoutException.h │ ├── DeviceNotFoundException.h │ ├── DeviceBusyException.h │ └── BulkPipe.h ├── Token.h ├── Demangle.h ├── mtpz │ └── TrustedApp.h ├── function_invoker.h ├── log.cpp └── make_function.h ├── .editorconfig ├── .github └── .editorconfig ├── pyproject.toml ├── android-file-transfer-linux.json ├── replace-guards.py ├── fuse ├── CMakeLists.txt ├── FuseId.h ├── Exception.h ├── FuseDirectory.h └── FuseEntry.h ├── replace-license.py ├── cmake └── FindReadline.cmake └── FAQ.md /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /qt/.gitignore: -------------------------------------------------------------------------------- 1 | *.cxx_parameters 2 | -------------------------------------------------------------------------------- /python/example/requirements.txt: -------------------------------------------------------------------------------- 1 | InquirerPy ~= 0.3.4 2 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoozle/android-file-transfer-linux/HEAD/screenshot.png -------------------------------------------------------------------------------- /cli/update.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | flex -L -F -o arg_lexer.l.cpp --header-file=arg_lexer.l.h arg_lexer.l 4 | -------------------------------------------------------------------------------- /qt/android-file-transfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoozle/android-file-transfer-linux/HEAD/qt/android-file-transfer.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ninja* 2 | cmake_* 3 | CMakeFiles* 4 | CMakeCache* 5 | nbproject 6 | build 7 | *.user 8 | doc 9 | .vscode 10 | -------------------------------------------------------------------------------- /osx/android-file-transfer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoozle/android-file-transfer-linux/HEAD/osx/android-file-transfer.icns -------------------------------------------------------------------------------- /osx/android-file-transfer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/whoozle/android-file-transfer-linux/HEAD/osx/android-file-transfer.png -------------------------------------------------------------------------------- /qt/translations/translations.qrc.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | ${QM_FILES_XML} 4 | 5 | 6 | -------------------------------------------------------------------------------- /mtp/version.cpp.in: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace mtp 4 | { 5 | std::string GetVersion() 6 | { return std::string("${AFT_VERSION}"); } 7 | } 8 | -------------------------------------------------------------------------------- /mtp/ptp/PerceivedDeviceType.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(GenericMtpDevice, 0) 2 | ENUM_VALUE(DigitalStillCamera, 1) 3 | ENUM_VALUE(MediaPlayer, 2) 4 | ENUM_VALUE(MobilePhone, 3) 5 | ENUM_VALUE(DigitalVideoCamera, 4) 6 | ENUM_VALUE(PDA, 5) 7 | ENUM_VALUE(AudioRecorder, 6) 8 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/linux/types.h: -------------------------------------------------------------------------------- 1 | #ifndef LINUX_TYPES_STUB_H 2 | #define LINUX_TYPES_STUB_H 3 | 4 | #include 5 | 6 | typedef uint8_t __u8; 7 | typedef uint16_t __u16; 8 | typedef uint32_t __u32; 9 | 10 | #define __user 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_style = tab 11 | indent_size = 4 12 | -------------------------------------------------------------------------------- /.github/.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = false 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_style = space 11 | indent_size = 2 12 | -------------------------------------------------------------------------------- /qt/android-file-transfer.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Android File Transfer (MTP) 3 | Comment=Transfer files from/to MTP devices 4 | Exec=android-file-transfer 5 | Icon=android-file-transfer 6 | StartupNotify=false 7 | Terminal=false 8 | Type=Application 9 | Categories=Utility;System;FileTools;Filesystem;Qt; 10 | -------------------------------------------------------------------------------- /qt/icons/dark/go-next.svg: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /mtp/ptp/EventCode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace mtp 5 | { 6 | std::string ToString(EventCode code) 7 | { 8 | switch(code) 9 | { 10 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(EventCode, NAME, VALUE) 11 | # include 12 | ENUM_VALUE_TO_STRING_DEFAULT(OperationCode, code, 4); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /qt/icons/dark/go-previous.svg: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /qt/icons/light/go-next.svg: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /qt/icons/light/go-previous.svg: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /mtp/ptp/OperationCode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace mtp 5 | { 6 | std::string ToString(OperationCode property) 7 | { 8 | switch(property) 9 | { 10 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(OperationCode, NAME, VALUE) 11 | # include 12 | ENUM_VALUE_TO_STRING_DEFAULT(OperationCode, property, 4); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | name = "android-file-transfer-linux" 3 | version = "4.6" 4 | 5 | [build-system] 6 | requires = ["scikit-build-core", "pybind11"] 7 | build-backend = "scikit_build_core.build" 8 | 9 | [tool.scikit-build] 10 | build.targets = ["aftl"] 11 | install.components = ["aftl"] 12 | # Rely only on CMake install. 13 | wheel.packages = [] 14 | 15 | [tool.scikit-build.cmake.define] 16 | BUILD_FUSE = false 17 | BUILD_QT_UI = false 18 | -------------------------------------------------------------------------------- /mtp/scope_guard.h: -------------------------------------------------------------------------------- 1 | #ifndef AFTL_MTP_SCOPE_GUARD_H 2 | #define AFTL_MTP_SCOPE_GUARD_H 3 | 4 | #include 5 | #include 6 | 7 | namespace mtp 8 | { 9 | class scope_guard : Noncopyable 10 | { 11 | using Callback = std::function; 12 | Callback _callback; 13 | 14 | public: 15 | scope_guard(Callback && c): _callback(c) 16 | { } 17 | 18 | ~scope_guard() 19 | { _callback(); } 20 | }; 21 | 22 | } 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | message(STATUS ${CMAKE_CURRENT_SOURCE_DIR}) 2 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}) 3 | include(pybind11Tools) 4 | 5 | pybind11_add_module(aftl aftl.cpp) 6 | target_link_libraries(aftl PRIVATE ${LIB_NAME}) 7 | # Use destination `.` to place `.so` file in `site-packages`, then it can be `import aftl`. 8 | # Set component to only install this target `.so` file. 9 | # See `pyproject.toml`. 10 | install(TARGETS aftl DESTINATION . COMPONENT aftl) 11 | -------------------------------------------------------------------------------- /mtp/ptp/DataTypeCode.h: -------------------------------------------------------------------------------- 1 | #ifndef AFTL_MTP_PTP_DATATYPECODE_H 2 | #define AFTL_MTP_PTP_DATATYPECODE_H 3 | 4 | #include 5 | #include 6 | 7 | namespace mtp 8 | { 9 | enum struct DataTypeCode : u16 10 | { 11 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 12 | # include 13 | #undef ENUM_VALUE 14 | }; 15 | DECLARE_ENUM(DataTypeCode, u16); 16 | 17 | bool IsArray(DataTypeCode type); 18 | std::string ToString(DataTypeCode type); 19 | 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /qt/android-file-transfer.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | android-file-transfer.png 4 | icons/dark/folder-new.svg 5 | icons/dark/go-next.svg 6 | icons/dark/go-previous.svg 7 | icons/dark/view-refresh.svg 8 | icons/light/folder-new.svg 9 | icons/light/go-next.svg 10 | icons/light/go-previous.svg 11 | icons/light/view-refresh.svg 12 | 13 | 14 | -------------------------------------------------------------------------------- /android-file-transfer-linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "io.github.whoozle.android-file-transfer-linux", 3 | 4 | "runtime": "org.kde.Platform", 5 | "runtime-version": "5.10", 6 | 7 | "sdk": "org.kde.Sdk", 8 | 9 | "modules" : [ 10 | { 11 | "name": "android-file-transfer-linux", 12 | "buildsystem": "cmake", 13 | "config-opts": [ "-DCMAKE_BUILD_TYPE=Release" ], 14 | "sources": [{ 15 | "type": "git", 16 | "tag": "v4.6", 17 | "url": "https://github.com/whoozle/android-file-transfer-linux.git" 18 | }] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /osx/icns.sh: -------------------------------------------------------------------------------- 1 | export PROJECT=android-file-transfer 2 | export ICONDIR=./$PROJECT.iconset 3 | export ORIGICON=./android-file-transfer.png 4 | 5 | mkdir $ICONDIR 6 | 7 | # Normal screen icons 8 | for SIZE in 16 32 64 128 256 512; do 9 | sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_${SIZE}x${SIZE}.png ; 10 | done 11 | 12 | # Retina display icons 13 | for SIZE in 32 64 256 512 1024; do 14 | sips -z $SIZE $SIZE $ORIGICON --out $ICONDIR/icon_$(expr $SIZE / 2)x$(expr $SIZE / 2)@2x.png ; 15 | done 16 | 17 | # Make a multi-resolution Icon 18 | iconutil -c icns -o ./$PROJECT.icns $ICONDIR 19 | rm -rf $ICONDIR #it is useless now 20 | -------------------------------------------------------------------------------- /qt/icons/dark/folder-new.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /qt/icons/light/folder-new.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 11 | 12 | 18 | 19 | -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/Context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Context.cpp 3 | * Copyright (C) 2022 pulkomandy 4 | * 5 | * Distributed under terms of the MIT license. 6 | */ 7 | 8 | #include "Context.h" 9 | 10 | namespace mtp { namespace usb 11 | { 12 | Context::Context(int debugLevel) 13 | : BUSBRoster() 14 | { 15 | Start(); 16 | } 17 | 18 | Context::~Context() { 19 | Stop(); 20 | } 21 | 22 | status_t Context::DeviceAdded(BUSBDevice* device) { 23 | _devices.emplace_back(std::make_shared(device)); 24 | 25 | return B_OK; 26 | } 27 | 28 | void Context::DeviceRemoved(BUSBDevice* device) { 29 | // TODO _devices.remove(device); 30 | } 31 | 32 | 33 | } }; 34 | -------------------------------------------------------------------------------- /mtp/ptp/EventCode.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(TransactionCancelled, 0x4001) 2 | ENUM_VALUE(ObjectAdded, 0x4002) 3 | ENUM_VALUE(ObjectRemoved, 0x4003) 4 | ENUM_VALUE(StoreAdded, 0x4004) 5 | ENUM_VALUE(StoreRemoved, 0x4005) 6 | ENUM_VALUE(DevicePropChanged, 0x4006) 7 | ENUM_VALUE(ObjectInfoChanged, 0x4007) 8 | ENUM_VALUE(DeviceInfoChanged, 0x4008) 9 | ENUM_VALUE(RequestObjectTransfer, 0x4009) 10 | ENUM_VALUE(StoreFull, 0x400a) 11 | ENUM_VALUE(DeviceReset, 0x400b) 12 | ENUM_VALUE(StorageInfoChanged, 0x400c) 13 | ENUM_VALUE(CaptureComplete, 0x400d) 14 | ENUM_VALUE(UnreportedStatus, 0x400e) 15 | ENUM_VALUE(ObjectPropChanged, 0xc801) 16 | ENUM_VALUE(ObjectPropDescChanged, 0xc802) 17 | ENUM_VALUE(ObjectReferenceChanged, 0xc803) 18 | -------------------------------------------------------------------------------- /qt/icons/dark/view-refresh.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /qt/icons/light/view-refresh.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /mtp/ptp/DataTypeCode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace mtp 5 | { 6 | std::string ToString(DataTypeCode type) 7 | { 8 | switch(type) 9 | { 10 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(DataTypeCode, NAME, VALUE) 11 | # include 12 | ENUM_VALUE_TO_STRING_DEFAULT(DataTypeCode, type, 4); 13 | } 14 | } 15 | bool IsArray(DataTypeCode type) 16 | { 17 | switch(type) 18 | { 19 | # define CASE(BITS) case DataTypeCode::ArrayInt##BITS : case DataTypeCode::ArrayUint##BITS : 20 | CASE(8) 21 | CASE(16) 22 | CASE(32) 23 | CASE(64) 24 | CASE(128) 25 | return true; 26 | default: 27 | return false; 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /mtp/ptp/DataTypeCode.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(Undefined, 0x0000) 2 | ENUM_VALUE(Int8, 0x0001) 3 | ENUM_VALUE(Uint8, 0x0002) 4 | ENUM_VALUE(Int16, 0x0003) 5 | ENUM_VALUE(Uint16, 0x0004) 6 | ENUM_VALUE(Int32, 0x0005) 7 | ENUM_VALUE(Uint32, 0x0006) 8 | ENUM_VALUE(Int64, 0x0007) 9 | ENUM_VALUE(Uint64, 0x0008) 10 | ENUM_VALUE(Int128, 0x0009) 11 | ENUM_VALUE(Uint128, 0x000a) 12 | ENUM_VALUE(ArrayInt8, 0x4001) 13 | ENUM_VALUE(ArrayUint8, 0x4002) 14 | ENUM_VALUE(ArrayInt16, 0x4003) 15 | ENUM_VALUE(ArrayUint16, 0x4004) 16 | ENUM_VALUE(ArrayInt32, 0x4005) 17 | ENUM_VALUE(ArrayUint32, 0x4006) 18 | ENUM_VALUE(ArrayInt64, 0x4007) 19 | ENUM_VALUE(ArrayUint64, 0x4008) 20 | ENUM_VALUE(ArrayInt128, 0x4009) 21 | ENUM_VALUE(ArrayUint128, 0x400a) 22 | ENUM_VALUE(String, 0xffff) 23 | -------------------------------------------------------------------------------- /mtp/metadata/Metadata.h: -------------------------------------------------------------------------------- 1 | #ifndef AFTL_MTP_METADATA_METADATA_H 2 | #define AFTL_MTP_METADATA_METADATA_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace mtp 10 | { 11 | struct Metadata; 12 | DECLARE_PTR(Metadata); 13 | 14 | struct MetadataPicture 15 | { 16 | std::string Type; 17 | std::string MimeType; 18 | std::string Description; 19 | mtp::ByteArray Data; 20 | }; 21 | 22 | struct Metadata 23 | { 24 | std::string Title; 25 | std::string Artist; 26 | std::string Album; 27 | std::string Genre; 28 | unsigned Year; 29 | unsigned Track; 30 | MetadataPicture Picture; 31 | 32 | static MetadataPtr Read(const std::string & path); 33 | }; 34 | 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /mtp/ptp/DeviceProperty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace mtp 5 | { 6 | std::string ToString(DeviceProperty property) 7 | { 8 | switch(property) 9 | { 10 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(DeviceProperty, NAME, VALUE) 11 | # include 12 | ENUM_VALUE_TO_STRING_DEFAULT(DeviceProperty, property, 4); 13 | # undef ENUM_VALUE 14 | } 15 | } 16 | 17 | std::string ToString(PerceivedDeviceType property) 18 | { 19 | switch(property) 20 | { 21 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(PerceivedDeviceType, NAME, VALUE) 22 | # include 23 | ENUM_VALUE_TO_STRING_DEFAULT(PerceivedDeviceType, property, 8); 24 | # undef ENUM_VALUE 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /qt/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | int GetCoverScore(const QString & str_) 4 | { 5 | QString str = str_.toLower(); 6 | int score = 0; 7 | if (str.contains("0001")) 8 | score += 1001; 9 | else if (str.contains("0000")) 10 | score += 1000; 11 | else if (str.contains("001")) 12 | score += 101; 13 | else if (str.contains("000")) 14 | score += 100; 15 | else if (str.contains("01")) 16 | score += 11; 17 | else if (str.contains("00")) 18 | score += 10; 19 | else if (str.contains("1")) 20 | score += 1; 21 | 22 | if (str.contains("art")) 23 | score += 10000; 24 | if (str.contains("album")) 25 | score += 10000; 26 | if (str.contains("cover")) 27 | score += 20000; 28 | if (str.contains("large")) 29 | score += 20000; 30 | if (str.contains("small")) 31 | score += 10000; 32 | if (str.contains("folder")) 33 | score += 10000; 34 | return score; 35 | } 36 | -------------------------------------------------------------------------------- /qt/qtobjectstream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "qtobjectstream.h" 21 | 22 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Interface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "Interface.h" 21 | 22 | -------------------------------------------------------------------------------- /qt/mtpmimedata.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "mtpmimedata.h" 21 | 22 | MtpMimeData::MtpMimeData() 23 | { 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /mtp/ByteArray.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp 25 | { 26 | } 27 | -------------------------------------------------------------------------------- /mtp/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_VERSION_H 21 | #define AFTL_MTP_VERSION_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | std::string GetVersion(); 28 | } 29 | 30 | #endif -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/DeviceDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * DeviceDescriptor.cpp 3 | * Copyright (C) 2022 pulkomandy 4 | * 5 | * Distributed under terms of the MIT license. 6 | */ 7 | 8 | #include "DeviceDescriptor.h" 9 | 10 | 11 | 12 | namespace mtp { namespace usb 13 | { 14 | DeviceDescriptor::DeviceDescriptor(BUSBDevice* dev) 15 | :_dev(dev) 16 | { 17 | } 18 | 19 | DeviceDescriptor::~DeviceDescriptor() 20 | { 21 | } 22 | 23 | ConfigurationPtr DeviceDescriptor::GetConfiguration(int conf) 24 | { 25 | return std::make_shared(_dev->ConfigurationAt(conf)); 26 | } 27 | 28 | ByteArray DeviceDescriptor::GetDescriptor() const 29 | { 30 | const usb_device_descriptor* descriptor = _dev->Descriptor(); 31 | ByteArray out; 32 | out.reserve(sizeof(usb_device_descriptor)); 33 | memcpy(out.data(), descriptor, sizeof(usb_device_descriptor)); 34 | return out; 35 | } 36 | 37 | DevicePtr DeviceDescriptor::TryOpen(ContextPtr context) 38 | { 39 | if (_dev->InitCheck() != B_OK) 40 | return nullptr; 41 | return std::make_shared(context, _dev); 42 | } 43 | }} 44 | -------------------------------------------------------------------------------- /mtp/backend/posix/FileHandler.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | namespace mtp { namespace posix 25 | { 26 | 27 | FileHandler::~FileHandler() 28 | { close(_fd); } 29 | 30 | }} 31 | -------------------------------------------------------------------------------- /qt/mtpmimedata.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_MTPMIMEDATA_H 21 | #define AFTL_QT_MTPMIMEDATA_H 22 | 23 | 24 | class MtpMimeData : public QMimeData 25 | { 26 | public: 27 | MtpMimeData(); 28 | }; 29 | 30 | #endif // MTPMIMEDATA_H 31 | -------------------------------------------------------------------------------- /cli/Tokens.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_CLI_TOKENS_H 21 | #define AFTL_CLI_TOKENS_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cli 27 | { 28 | typedef std::list Tokens; 29 | } 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /qt/devicesdialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DEVICESDIALOG_H 2 | #define DEVICESDIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Ui { 10 | class DevicesDialog; 11 | } 12 | class QListWidgetItem; 13 | 14 | class DevicesDialog : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | private: 19 | struct Row 20 | { 21 | mtp::usb::DeviceDescriptorPtr Descriptor; 22 | mtp::DevicePtr Device; 23 | std::vector Processes; 24 | }; 25 | 26 | bool _resetDevice; 27 | std::vector _devices; 28 | 29 | public: 30 | explicit DevicesDialog(bool resetDevice, QWidget *parent = nullptr); 31 | ~DevicesDialog(); 32 | 33 | mtp::DevicePtr getDevice(); 34 | 35 | int exec(); 36 | 37 | private slots: 38 | void scan(); 39 | void kill(); 40 | void itemClicked(QListWidgetItem *); 41 | void itemDoubleClicked(QListWidgetItem *); 42 | void updateButtons(); 43 | 44 | private: 45 | Ui::DevicesDialog * ui; 46 | 47 | QPushButton * _buttonScan; 48 | QPushButton * _buttonKill; 49 | }; 50 | 51 | #endif // DEVICESDIALOG_H 52 | -------------------------------------------------------------------------------- /replace-guards.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | #!/usr/bin/env python 4 | 5 | import os 6 | import os.path 7 | import re 8 | 9 | guard_re = re.compile(r'#ifndef\s+(\w+)\n#define\s+(\w+)', re.M | re.S) 10 | base_dir = os.path.dirname(os.path.realpath(__file__)) 11 | clean_re = re.compile(r'[^\w]') 12 | print(base_dir) 13 | 14 | for root, dirs, files in os.walk('.'): 15 | root = os.path.relpath(root, base_dir) 16 | if (root[0] == '.' and len(root) > 1) or root.startswith("build"): 17 | dirs[:] = [] 18 | continue 19 | if root == "mtp/backend/linux/usb/linux": 20 | continue 21 | 22 | for file in files: 23 | name, ext = os.path.splitext(file) 24 | if ext != '.h' or name == "arg_lexer.l" or name.endswith(".values"): 25 | continue 26 | 27 | fname = os.path.join(root, file) 28 | with open(fname) as f: 29 | data = f.read() 30 | 31 | guard = 'AFTL_' + clean_re.sub('_', os.path.relpath(os.path.join(root, file), base_dir)).upper() 32 | 33 | def replace_guard(m): 34 | return "#ifndef %s\n#define %s" %(guard, guard) 35 | 36 | data, n = guard_re.subn(replace_guard, data, count=1) 37 | if n == 0: 38 | print("missing guard in %s" %file) 39 | else: 40 | with open(fname, 'w') as f: 41 | f.write(data) 42 | 43 | -------------------------------------------------------------------------------- /mtp/ByteArray.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BYTEARRAY_H 21 | #define AFTL_MTP_BYTEARRAY_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp 28 | { 29 | using ByteArray = std::vector; //! \typedef ByteArray : vector of bytes 30 | DECLARE_PTR(ByteArray); 31 | } 32 | 33 | #endif /* BYTEARRAY_H */ 34 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/call.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_CALL_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_CALL_H 22 | 23 | #include 24 | 25 | #include 26 | 27 | #define USB_CALL(...) do { int r = (__VA_ARGS__); if (r != 0) throw mtp::usb::Exception(#__VA_ARGS__, r) ; } while(false) 28 | 29 | #endif 30 | 31 | -------------------------------------------------------------------------------- /mtp/usb/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_USB_TYPES_H 21 | #define AFTL_MTP_USB_TYPES_H 22 | 23 | namespace mtp { namespace usb 24 | { 25 | 26 | enum struct EndpointType 27 | { 28 | Control = 0, Isochronous = 1, Bulk = 2, Interrupt = 3 29 | }; 30 | 31 | enum struct EndpointDirection 32 | { 33 | In, Out, Both 34 | }; 35 | 36 | }} 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /mtp/Token.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_TOKEN_H 21 | #define AFTL_MTP_TOKEN_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | //! Token, base class for ref counted objects which hold some resources while they are alive 28 | struct IToken : Noncopyable 29 | { 30 | virtual ~IToken() = default; 31 | }; 32 | DECLARE_PTR(IToken); 33 | } 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /qt/android-file-transfer.appdata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | android-file-transfer 4 | CC0-1.0 5 | LGPL-2.0+ 6 | Android File Transfer 7 | Interactive MTP client with Qt4/Qt5 GUI 8 | 9 |
    10 |
  • Simple Qt UI with progress dialogs.
  • 11 |
  • FUSE wrapper (If you'd prefer mounting your device), 12 | supporting partial read/writes, allowing instant access to your files.
  • 13 |
  • No file size limits.
  • 14 |
  • Automatically renames album cover to make it visible from media player.
  • 15 |
  • No extra dependencies (e.g. libptp/libmtp).
  • 16 |
  • Available as static/shared library.
  • 17 |
  • Simple CLI tool.
  • 18 |
19 |
20 | android-file-transfer.desktop 21 | https://whoozle.github.io/android-file-transfer-linux 22 | vladimir.menshakov@gmail.com 23 | 24 | android-file-transfer.desktop 25 | 26 |
27 | -------------------------------------------------------------------------------- /cli/Command.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | namespace cli 24 | { 25 | 26 | void impl::Completer::Complete(CompletionContext & ctx) 27 | { ctx.Session.CompletePath(ctx.Prefix, ctx.Result); } 28 | 29 | void impl::Completer::Complete(CompletionContext & ctx) 30 | { ctx.Session.CompleteStoragePath(ctx.Prefix, ctx.Result); } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cli/arg_lexer.l: -------------------------------------------------------------------------------- 1 | %option noyywrap nounput 2 | %option reentrant 3 | %option 8bit 4 | %option nounistd 5 | %option batch 6 | %option never-interactive 7 | %option prefix="args_" 8 | 9 | %top { 10 | # include 11 | # define register 12 | } 13 | 14 | %{ 15 | # include 16 | # include 17 | # include 18 | # include 19 | 20 | # define LVAL (yylval_param) 21 | # define PARSER (reinterpret_cast(yyget_extra(yyscanner))) 22 | # define YY_INPUT(buf,result,max_size) result = PARSER->Input(buf, max_size); 23 | 24 | static void yy_fatal_error(const char*, yyscan_t); 25 | void (*hide_warning)(const char*, yyscan_t) = &yy_fatal_error; 26 | 27 | %} 28 | 29 | %x STRING 30 | 31 | %% 32 | 33 | \" { BEGIN(STRING); } 34 | 35 | \\n { PARSER->Write('\n'); } 36 | \\t { PARSER->Write('\t'); } 37 | \\f { PARSER->Write('\f'); } 38 | \\r { PARSER->Write('\r'); } 39 | \\b { PARSER->Write('\b'); } 40 | \\. { PARSER->Write(yytext[1]); } 41 | \" { BEGIN(INITIAL); } 42 | [^\\\"]+ { PARSER->Write(yytext, yyleng); } 43 | 44 | "\\ " { PARSER->Write(' '); } 45 | [[:space:]]+ { PARSER->NextArgument(); } 46 | <*>. { PARSER->Write(yytext[0]); } 47 | %% 48 | -------------------------------------------------------------------------------- /mtp/usb/TimeoutException.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_USB_TIMEOUTEXCEPTION_H 21 | #define AFTL_MTP_USB_TIMEOUTEXCEPTION_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace usb 26 | { 27 | 28 | struct TimeoutException : public std::runtime_error //! Exception throw if USB URB transfer timeout occured 29 | { 30 | TimeoutException(const std::string &msg): std::runtime_error(msg) { } 31 | }; 32 | 33 | }} 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /qt/renamedialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "renamedialog.h" 21 | #include "ui_renamedialog.h" 22 | 23 | RenameDialog::RenameDialog(QString name, QWidget *parent) : 24 | QDialog(parent), 25 | ui(new Ui::RenameDialog) 26 | { 27 | ui->setupUi(this); 28 | ui->lineEdit->setText(name); 29 | } 30 | 31 | QString RenameDialog::name() const 32 | { return ui->lineEdit->text(); } 33 | 34 | RenameDialog::~RenameDialog() 35 | { 36 | delete ui; 37 | } 38 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/Exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_EXCEPTION_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_EXCEPTION_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace usb 26 | { 27 | class Exception : public std::runtime_error 28 | { 29 | public: 30 | Exception(const std::string &what, int retCode) throw(); 31 | static std::string GetErrorMessage(int retCode); 32 | }; 33 | }} 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_EXCEPTION_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_EXCEPTION_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace usb 26 | { 27 | class Exception : public std::runtime_error 28 | { 29 | public: 30 | Exception(const std::string &what, int retCode) throw(); 31 | static std::string GetErrorMessage(int retCode); 32 | }; 33 | }} 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /mtp/Demangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_DEMANGLE_H 21 | #define AFTL_MTP_DEMANGLE_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp 27 | { 28 | //! demangles c++ symbol 29 | inline std::string Demangle(const char *abiName) 30 | { 31 | int status; 32 | char *ret = abi::__cxa_demangle(abiName, 0, 0, &status); 33 | 34 | std::string name(ret); 35 | free(ret); 36 | return name; 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp { namespace usb 25 | { 26 | Exception::Exception(const std::string &what, int returnCode) throw() : std::runtime_error(what + ": " + GetErrorMessage(returnCode)) 27 | { } 28 | 29 | std::string Exception::GetErrorMessage(int returnCode) 30 | { 31 | return libusb_error_name(returnCode); 32 | } 33 | 34 | }} -------------------------------------------------------------------------------- /mtp/ptp/EventCode.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2025 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_EVENTCODE_H 21 | #define AFTL_MTP_PTP_EVENTCODE_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | enum struct EventCode : u16 28 | { 29 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 30 | # include 31 | #undef ENUM_VALUE 32 | }; 33 | DECLARE_ENUM(EventCode, u16); 34 | 35 | std::string ToString(EventCode code); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /qt/renamedialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_RENAMEDIALOG_H 21 | #define AFTL_QT_RENAMEDIALOG_H 22 | 23 | #include 24 | 25 | namespace Ui { 26 | class RenameDialog; 27 | } 28 | 29 | class RenameDialog : public QDialog 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit RenameDialog(QString name, QWidget *parent = 0); 35 | ~RenameDialog(); 36 | 37 | QString name() const; 38 | 39 | private: 40 | Ui::RenameDialog *ui; 41 | }; 42 | 43 | #endif // RENAMEDIALOG_H 44 | -------------------------------------------------------------------------------- /mtp/backend/posix/FileHandler.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_POSIX_FILEHANDLER_H 21 | #define AFTL_MTP_BACKEND_POSIX_FILEHANDLER_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp { namespace posix 27 | { 28 | 29 | class FileHandler : Noncopyable 30 | { 31 | int _fd; 32 | 33 | public: 34 | FileHandler(int fd): _fd(fd) { } 35 | ~FileHandler(); 36 | 37 | int Get() const 38 | { return _fd; } 39 | }; 40 | 41 | }} 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /qt/createdirectorydialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "createdirectorydialog.h" 21 | #include "ui_createdirectorydialog.h" 22 | 23 | CreateDirectoryDialog::CreateDirectoryDialog(QWidget *parent) : 24 | QDialog(parent), 25 | ui(new Ui::CreateDirectoryDialog) 26 | { 27 | ui->setupUi(this); 28 | } 29 | 30 | CreateDirectoryDialog::~CreateDirectoryDialog() 31 | { 32 | delete ui; 33 | } 34 | 35 | QString CreateDirectoryDialog::name() const 36 | { 37 | return ui->lineEdit->text(); 38 | } 39 | -------------------------------------------------------------------------------- /mtp/backend/posix/Exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_POSIX_EXCEPTION_H 21 | #define AFTL_MTP_BACKEND_POSIX_EXCEPTION_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace posix 26 | { 27 | class Exception : public std::runtime_error 28 | { 29 | public: 30 | Exception(const std::string &what) throw(); 31 | Exception(const std::string &what, int retCode) throw(); 32 | static std::string GetErrorMessage(int retCode); 33 | }; 34 | }} 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /mtp/usb/DeviceNotFoundException.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_USB_DEVICENOTFOUNDEXCEPTION_H 21 | #define AFTL_MTP_USB_DEVICENOTFOUNDEXCEPTION_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace usb 26 | { 27 | 28 | struct DeviceNotFoundException : public std::runtime_error //! Exception throw when device was disconnected or was not found 29 | { 30 | DeviceNotFoundException(): std::runtime_error("device was disconnected") { } 31 | }; 32 | 33 | }} 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /qt/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_UTILS_H 21 | #define AFTL_QT_UTILS_H 22 | 23 | #include 24 | #include 25 | 26 | inline QString fromUtf8(const std::string &str) 27 | { 28 | return QString::fromUtf8(str.c_str(), str.size()); 29 | } 30 | 31 | inline std::string toUtf8(const QString &str) 32 | { 33 | QByteArray utf8(str.toUtf8()); 34 | return std::string(utf8.data(), utf8.size()); 35 | } 36 | 37 | int GetCoverScore(const QString &str_); 38 | 39 | #endif // UTILS 40 | 41 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace mtp { namespace usb 26 | { 27 | #if defined (kIOUSBDeviceInterfaceID500) 28 | typedef IOUSBDeviceInterface500 IOUSBDeviceType; 29 | #define DeviceInterfaceID kIOUSBDeviceInterfaceID500 30 | #else 31 | typedef IOUSBDeviceInterface IOUSBDeviceType; 32 | #define DeviceInterfaceID kIOUSBDeviceInterface 33 | #endif 34 | }} -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/Exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp { namespace usb 25 | { 26 | Exception::Exception(const std::string &what, int returnCode) throw() : std::runtime_error(what + ": " + GetErrorMessage(returnCode)) 27 | { } 28 | 29 | std::string Exception::GetErrorMessage(int returnCode) 30 | { 31 | char buf[128]; 32 | snprintf(buf, sizeof(buf), "error 0x%08x", returnCode); 33 | return std::string(buf); 34 | } 35 | 36 | }} -------------------------------------------------------------------------------- /mtp/ptp/OperationCode.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_OPERATIONCODE_H 21 | #define AFTL_MTP_PTP_OPERATIONCODE_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | enum class OperationCode : u16 //! MTP operation code 28 | { 29 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 30 | # include 31 | #undef ENUM_VALUE 32 | }; 33 | 34 | DECLARE_ENUM(OperationCode, u16); 35 | std::string ToString(OperationCode property); 36 | } 37 | 38 | #endif /* OPERATIONCODE_H */ 39 | -------------------------------------------------------------------------------- /qt/createdirectorydialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_CREATEDIRECTORYDIALOG_H 21 | #define AFTL_QT_CREATEDIRECTORYDIALOG_H 22 | 23 | #include 24 | 25 | namespace Ui { 26 | class CreateDirectoryDialog; 27 | } 28 | 29 | class CreateDirectoryDialog : public QDialog 30 | { 31 | Q_OBJECT 32 | 33 | public: 34 | explicit CreateDirectoryDialog(QWidget *parent = 0); 35 | ~CreateDirectoryDialog(); 36 | 37 | QString name() const; 38 | 39 | private: 40 | Ui::CreateDirectoryDialog *ui; 41 | }; 42 | 43 | #endif // CREATEDIRECTORYDIALOG_H 44 | -------------------------------------------------------------------------------- /fuse/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(aft-mtp-mount fuse.cpp) 2 | 3 | target_link_libraries(aft-mtp-mount ${MTP_LIBRARIES} ${FUSE_LDFLAGS} ${CMAKE_THREAD_LIBS_INIT}) 4 | install(TARGETS aft-mtp-mount RUNTIME DESTINATION bin) 5 | 6 | if (BUILD_QT_UI AND (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")) 7 | add_custom_command(TARGET aft-mtp-mount POST_BUILD COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath "@executable_path/../../Frameworks/" $) 8 | add_custom_command(TARGET aft-mtp-mount POST_BUILD COMMAND ${OTOOL_BIN} -L $) 9 | set(AFT_MTP_MOUNT_PATH "${MACOSX_BUNDLE_ROOT_DIR}/Contents/SharedSupport/bin/aft-mtp-mount") 10 | set(MACOSX_BUNDLE_LIBS_INSTALL " 11 | ${MACOSX_BUNDLE_LIBS_INSTALL} 12 | file(INSTALL \"${CMAKE_CURRENT_BINARY_DIR}/aft-mtp-mount\" DESTINATION \"${MACOSX_BUNDLE_ROOT_DIR}/Contents/SharedSupport/bin\") 13 | ") 14 | foreach(DYNLIB ${MACOSX_BUNDLE_LIBS}) 15 | get_filename_component(DYNLIB_NAME "${DYNLIB}" NAME) 16 | set(MACOSX_BUNDLE_LIBS_INSTALL " 17 | ${MACOSX_BUNDLE_LIBS_INSTALL} 18 | message(STATUS \"fuse: fixing ${DYNLIB_NAME}\") 19 | execute_process(COMMAND \"${CMAKE_INSTALL_NAME_TOOL}\" -change \"${DYNLIB}\" \"@executable_path/../../Frameworks/${DYNLIB_NAME}\" \"${AFT_MTP_MOUNT_PATH}\") 20 | ") 21 | endforeach() 22 | 23 | set(MACOSX_BUNDLE_LIBS_INSTALL " 24 | ${MACOSX_BUNDLE_LIBS_INSTALL} 25 | execute_process(COMMAND \"${OTOOL_BIN}\" -L \"${AFT_MTP_MOUNT_PATH}\") 26 | " PARENT_SCOPE) 27 | 28 | endif() 29 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Context.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LINUX_USB_CONTEXT_H 21 | #define AFTL_MTP_BACKEND_LINUX_USB_CONTEXT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | class Context : Noncopyable 31 | { 32 | private: 33 | 34 | public: 35 | typedef std::vector Devices; 36 | 37 | private: 38 | Devices _devices; 39 | 40 | public: 41 | Context(); 42 | ~Context(); 43 | 44 | const Devices & GetDevices() const 45 | { return _devices; } 46 | }; 47 | DECLARE_PTR(Context); 48 | 49 | }} 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/Context.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_CONTEXT_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_CONTEXT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | class Context : Noncopyable 31 | { 32 | public: 33 | typedef std::vector Devices; 34 | 35 | private: 36 | Devices _devices; 37 | 38 | public: 39 | Context(); 40 | ~Context(); 41 | 42 | void Wait(); 43 | 44 | const Devices & GetDevices() const 45 | { return _devices; } 46 | }; 47 | DECLARE_PTR(Context); 48 | 49 | }} 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /mtp/ptp/ObjectProperty.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_OBJECTPROPERTY_H 21 | #define AFTL_MTP_PTP_OBJECTPROPERTY_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mtp 29 | { 30 | 31 | enum struct ObjectProperty : u16 32 | { 33 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 34 | # include 35 | #undef ENUM_VALUE 36 | }; 37 | DECLARE_ENUM(ObjectProperty, u16); 38 | 39 | std::string ToString(ObjectProperty property); 40 | std::string ToString(DataTypeCode type, const ByteArray & value); 41 | 42 | } 43 | 44 | #endif /* OBJECTPROPERTY_H */ 45 | -------------------------------------------------------------------------------- /fuse/FuseId.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_FUSE_FUSEID_H 21 | #define AFTL_FUSE_FUSEID_H 22 | 23 | #include 24 | 25 | namespace mtp { namespace fuse 26 | { 27 | 28 | struct FuseId 29 | { 30 | static const FuseId Root; 31 | 32 | fuse_ino_t Inode; //generation here? 33 | 34 | explicit FuseId(fuse_ino_t inode): Inode(inode) { } 35 | 36 | bool operator == (const FuseId &o) const 37 | { return Inode == o.Inode; } 38 | bool operator != (const FuseId &o) const 39 | { return !((*this) == o); } 40 | bool operator < (const FuseId &o) const 41 | { return Inode < o.Inode; } 42 | }; 43 | 44 | const FuseId FuseId::Root(FUSE_ROOT_ID); 45 | 46 | 47 | }} 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/call.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_CALL_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_CALL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define USB_CALL(...) \ 29 | do { int _r_ = (__VA_ARGS__); \ 30 | switch(_r_) { \ 31 | case kIOReturnSuccess : break; \ 32 | case kIOReturnNoDevice : throw mtp::usb::DeviceNotFoundException(); \ 33 | case kIOReturnExclusiveAccess: throw mtp::usb::DeviceBusyException(); \ 34 | default: throw mtp::usb::Exception(#__VA_ARGS__, _r_) ; \ 35 | } \ 36 | } while(false) 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /qt/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | Android File Transfer for Linux and macOS 9 | CFBundleExecutable 10 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | ${MACOSX_BUNDLE_ICON_FILE} 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleLocalizations 18 | 19 | en 20 | it 21 | ru 22 | 23 | CFBundleName 24 | ${MACOSX_BUNDLE_BUNDLE_NAME} 25 | CFBundlePackageType 26 | APPL 27 | CFBundleShortVersionString 28 | ${MACOSX_BUNDLE_SHORT_VERSION_STRING} 29 | CFBundleVersion 30 | ${MACOSX_BUNDLE_BUNDLE_VERSION} 31 | NSHumanReadableCopyright 32 | ${MACOSX_BUNDLE_COPYRIGHT} 33 | CSResourcesFileMapped 34 | 35 | NSPrincipalClass 36 | NSApplication 37 | NSHighResolutionCapable 38 | True 39 | LSMinimumSystemVersion 40 | 10.12.0 41 | CFBundleSignature 42 | ???? 43 | 44 | 45 | -------------------------------------------------------------------------------- /cli/Tokenizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_CLI_TOKENIZER_H 21 | #define AFTL_CLI_TOKENIZER_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace cli 28 | { 29 | 30 | class Tokenizer 31 | { 32 | public: 33 | const std::string & _text; 34 | Tokens & _tokens; 35 | size_t _inputPosition; 36 | std::stringstream _tempString; 37 | 38 | public: 39 | Tokenizer(const std::string &text, Tokens &tokens); 40 | 41 | void Write(const char *text, size_t size) 42 | { _tempString.write(text, size); } 43 | void Write(const char ch) 44 | { _tempString << ch; } 45 | void NextArgument(); 46 | size_t Input(char *buf, size_t max_size); 47 | }; 48 | } 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /qt/mtpstoragesmodel.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_MTPSTORAGESMODEL_H 21 | #define AFTL_QT_MTPSTORAGESMODEL_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | class MtpStoragesModel : public QAbstractListModel 29 | { 30 | QVector > _storages; 31 | 32 | public: 33 | MtpStoragesModel(QObject *parent = 0); 34 | bool update(const mtp::SessionPtr &session); 35 | 36 | mtp::StorageId getStorageId(int idx) const; 37 | virtual int rowCount(const QModelIndex &parent = QModelIndex()) const; 38 | virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; 39 | }; 40 | 41 | #endif // MTPSTORAGESMODEL_H 42 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Context.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_CONTEXT_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_CONTEXT_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mtp { namespace usb 29 | { 30 | 31 | class Context : Noncopyable 32 | { 33 | private: 34 | libusb_context * _ctx; 35 | 36 | public: 37 | typedef std::vector Devices; 38 | 39 | private: 40 | Devices _devices; 41 | 42 | public: 43 | Context(int debugLevel = 3); 44 | ~Context(); 45 | 46 | void Wait(); 47 | 48 | const Devices & GetDevices() const 49 | { return _devices; } 50 | }; 51 | DECLARE_PTR(Context); 52 | 53 | }} 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /replace-license.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import os.path 5 | import re 6 | 7 | license = """/* 8 | This file is part of Android File Transfer For Linux. 9 | Copyright (C) 2015-2020 Vladimir Menshakov 10 | 11 | This library is free software; you can redistribute it and/or modify it 12 | under the terms of the GNU Lesser General Public License as published by 13 | the Free Software Foundation; either version 2.1 of the License, 14 | or (at your option) any later version. 15 | 16 | This library is distributed in the hope that it will be useful, but 17 | WITHOUT ANY WARRANTY; without even the implied warranty of 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 | Lesser General Public License for more details. 20 | 21 | You should have received a copy of the GNU Lesser General Public License 22 | along with this library; if not, write to the Free Software Foundation, 23 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 | */ 25 | 26 | """ 27 | 28 | license_re = re.compile(r'^/\*.*?\*/\s+', re.M | re.S) 29 | 30 | for root, dirs, files in os.walk('.'): 31 | if root == "./mtp/backend/linux/usb/linux": 32 | continue 33 | 34 | for file in files: 35 | name, ext = os.path.splitext(file) 36 | if ext != '.h' and ext != '.cpp': 37 | continue 38 | if name == "arg_lexer.l": 39 | continue 40 | 41 | fname = os.path.join(root, file) 42 | with open(fname) as f: 43 | data = f.read() 44 | 45 | if license_re.match(data): 46 | data = license_re.sub(license, data, 1) 47 | else: 48 | data = license + data 49 | 50 | with open(fname, 'w') as f: 51 | f.write(data) 52 | -------------------------------------------------------------------------------- /mtp/ptp/DeviceProperty.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_DEVICEPROPERTY_H 21 | #define AFTL_MTP_PTP_DEVICEPROPERTY_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp 27 | { 28 | enum struct PerceivedDeviceType : u32 29 | { 30 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 31 | # include "PerceivedDeviceType.values.h" 32 | #undef ENUM_VALUE 33 | }; 34 | std::string ToString(PerceivedDeviceType property); 35 | 36 | enum struct DeviceProperty : u16 37 | { 38 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 39 | # include "DeviceProperty.values.h" 40 | #undef ENUM_VALUE 41 | }; 42 | DECLARE_ENUM(DeviceProperty, u16); 43 | 44 | std::string ToString(DeviceProperty property); 45 | 46 | } 47 | 48 | #endif /* OBJECTPROPERTY_H */ 49 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Interface.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp { namespace usb 25 | { 26 | 27 | Interface::Interface(int index, const std::string &path): _path(path) 28 | { 29 | _class = Directory::ReadInt(path + "/bInterfaceClass"); 30 | _subclass = Directory::ReadInt(path + "/bInterfaceSubClass"); 31 | _index = Directory::ReadInt(path + "/bInterfaceNumber"); 32 | 33 | Directory dir(path); 34 | while(true) 35 | { 36 | std::string entry = dir.Read(); 37 | if (entry.empty()) 38 | break; 39 | 40 | if (entry.compare(0, 3, "ep_") == 0) 41 | { 42 | EndpointPtr ep = Endpoint::TryOpen(path + "/" + entry); 43 | if (ep) 44 | _endpoints.push_back(ep); 45 | } 46 | } 47 | } 48 | 49 | }} 50 | -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/Context.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_CONTEXT_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_CONTEXT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | class Context : public BUSBRoster, Noncopyable 31 | { 32 | public: 33 | typedef std::vector Devices; 34 | 35 | private: 36 | Devices _devices; 37 | 38 | status_t DeviceAdded(BUSBDevice*) final override; 39 | void DeviceRemoved(BUSBDevice*) final override; 40 | 41 | public: 42 | Context(int debugLevel = 3); 43 | ~Context(); 44 | 45 | void Wait(); 46 | 47 | const Devices & GetDevices() const 48 | { return _devices; } 49 | }; 50 | DECLARE_PTR(Context); 51 | 52 | }} 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp { namespace usb 25 | { 26 | 27 | Context::Context(int debugLevel) 28 | { 29 | USB_CALL(libusb_init(&_ctx)); 30 | libusb_set_debug(_ctx, debugLevel); 31 | libusb_device **devs; 32 | int count = libusb_get_device_list(_ctx, &devs); 33 | if (count < 0) 34 | throw Exception("libusb_get_device_list", count); 35 | 36 | _devices.reserve(count); 37 | for(int i = 0; i < count; ++i) 38 | _devices.push_back(std::make_shared(devs[i])); 39 | libusb_free_device_list(devs, 0); 40 | } 41 | 42 | Context::~Context() 43 | { 44 | libusb_exit(_ctx); 45 | } 46 | 47 | void Context::Wait() 48 | { 49 | USB_CALL(libusb_handle_events(_ctx)); 50 | } 51 | 52 | 53 | }} 54 | -------------------------------------------------------------------------------- /cli/CommandLineStub.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | 22 | #include 23 | 24 | namespace cli 25 | { 26 | CommandLine::CommandLine() 27 | { } 28 | 29 | CommandLine::~CommandLine() 30 | { } 31 | 32 | CommandLine & CommandLine::Get() 33 | { 34 | static CommandLine cmd; 35 | return cmd; 36 | } 37 | 38 | bool CommandLine::ReadLine(const std::string &prompt, std::string &input) 39 | { 40 | fputs(prompt.c_str(), stdout); 41 | fflush(stdout); 42 | return ReadRawLine(input); 43 | } 44 | 45 | bool CommandLine::ReadRawLine(std::string &input) 46 | { 47 | char buf[4096]; 48 | char *r = fgets(buf, sizeof(buf), stdin); 49 | if (r) 50 | input.assign(r); 51 | else 52 | input.clear(); 53 | return r; 54 | } 55 | 56 | std::string CommandLine::GetLineBuffer() const 57 | { return std::string(); } 58 | } 59 | -------------------------------------------------------------------------------- /mtp/usb/DeviceBusyException.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_USB_DEVICEBUSYEXCEPTION_H 21 | #define AFTL_MTP_USB_DEVICEBUSYEXCEPTION_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | struct DeviceBusyException : public std::runtime_error //! Exception thrown when device is busy (claimed by other process) 31 | { 32 | struct ProcessDescriptor 33 | { 34 | int Id; 35 | std::string Name; 36 | }; 37 | 38 | std::vector Processes; 39 | 40 | DeviceBusyException(int fd = -1, const std::string &msg = "Device is already used by another process"); 41 | 42 | void Kill() const; 43 | static void Kill(const ProcessDescriptor & desc); 44 | static void Kill(const std::vector & processes); 45 | }; 46 | 47 | }} 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /mtp/backend/posix/Exception.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp { namespace posix 27 | { 28 | 29 | Exception::Exception(const std::string &what) throw() : std::runtime_error(what + ": " + GetErrorMessage(errno)) 30 | { } 31 | 32 | Exception::Exception(const std::string &what, int returnCode) throw() : std::runtime_error(what + ": " + GetErrorMessage(returnCode)) 33 | { } 34 | 35 | std::string Exception::GetErrorMessage(int returnCode) 36 | { 37 | char buf[1024]; 38 | #if defined(_GNU_SOURCE) && defined(__GLIBC__) 39 | std::string text(strerror_r(returnCode, buf, sizeof(buf))); 40 | #else 41 | int r = strerror_r(returnCode, buf, sizeof(buf)); 42 | std::string text(r == 0? buf: "strerror_r() failed"); 43 | #endif 44 | return text; 45 | } 46 | 47 | }} 48 | -------------------------------------------------------------------------------- /qt/devicesdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | DevicesDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 615 10 | 447 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Qt::Horizontal 24 | 25 | 26 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | buttonBox 36 | accepted() 37 | DevicesDialog 38 | accept() 39 | 40 | 41 | 248 42 | 254 43 | 44 | 45 | 157 46 | 274 47 | 48 | 49 | 50 | 51 | buttonBox 52 | rejected() 53 | DevicesDialog 54 | reject() 55 | 56 | 57 | 316 58 | 260 59 | 60 | 61 | 286 62 | 274 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /cli/CommandLine.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_CLI_COMMANDLINE_H 21 | #define AFTL_CLI_COMMANDLINE_H 22 | 23 | #include 24 | #include 25 | 26 | namespace cli 27 | { 28 | class CommandLine 29 | { 30 | public: 31 | typedef std::function Callback; 32 | 33 | protected: 34 | CommandLine(); 35 | ~CommandLine(); 36 | 37 | private: 38 | static char ** CompletionCallback(const char *text, int start, int end); 39 | static char * CompletionGenerator(const char *text, int state); 40 | 41 | std::string _historyPath; 42 | Callback _callback; 43 | 44 | public: 45 | static CommandLine & Get(); 46 | 47 | bool ReadLine(const std::string &prompt, std::string &input); 48 | bool ReadRawLine(std::string &input); 49 | void SetCallback(const Callback &callback) 50 | { _callback = callback; } 51 | std::string GetLineBuffer() const; 52 | }; 53 | } 54 | 55 | #endif 56 | 57 | -------------------------------------------------------------------------------- /cli/Tokenizer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace cli 25 | { 26 | Tokenizer::Tokenizer(const std::string &text, Tokens &tokens): _text(text), _tokens(tokens), _inputPosition(0) 27 | { 28 | void *scanner; 29 | args_lex_init_extra(this, &scanner); 30 | //token_set_debug(1, scanner); 31 | args_lex(scanner); 32 | args_lex_destroy(scanner); //not exception safe 33 | NextArgument(); 34 | } 35 | 36 | void Tokenizer::NextArgument() 37 | { 38 | std::string arg = _tempString.str(); 39 | if (!arg.empty()) 40 | { 41 | _tokens.push_back(arg); 42 | _tempString.str(std::string()); 43 | } 44 | } 45 | 46 | size_t Tokenizer::Input(char *buf, size_t max_size) 47 | { 48 | size_t n = std::min(max_size, _text.size() - _inputPosition); 49 | std::copy_n(_text.begin() + _inputPosition, n, buf); 50 | _inputPosition += n; 51 | return n; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Endpoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LINUX_USB_ENDPOINT_H 21 | #define AFTL_MTP_BACKEND_LINUX_USB_ENDPOINT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | class Endpoint; 31 | DECLARE_PTR(Endpoint); 32 | 33 | class Endpoint 34 | { 35 | EndpointDirection _direction; 36 | EndpointType _type; 37 | u8 _addr; 38 | u16 _maxPacketSize; 39 | 40 | public: 41 | Endpoint(const std::string &path); 42 | 43 | u8 GetAddress() const 44 | { return _addr; } 45 | 46 | int GetMaxPacketSize() const 47 | { return _maxPacketSize; } 48 | 49 | EndpointDirection GetDirection() const 50 | { return _direction; } 51 | 52 | EndpointType GetType() const 53 | { return _type; } 54 | 55 | static EndpointPtr TryOpen(const std::string &path); 56 | }; 57 | DECLARE_PTR(Endpoint); 58 | 59 | }} 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /mtp/mtpz/TrustedApp.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_MTPZ_TRUSTEDAPP_H 21 | #define AFTL_MTP_MTPZ_TRUSTEDAPP_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp 27 | { 28 | class Session; 29 | DECLARE_PTR(Session); 30 | 31 | class TrustedApp; 32 | DECLARE_PTR(TrustedApp); 33 | 34 | class TrustedApp 35 | { 36 | private: 37 | struct Keys; 38 | DECLARE_PTR(Keys); 39 | 40 | private: 41 | SessionPtr _session; 42 | KeysPtr _keys; 43 | 44 | public: 45 | static bool Probe(const SessionPtr & session); 46 | 47 | ~TrustedApp(); 48 | 49 | static TrustedAppPtr Create(const SessionPtr & session, const std::string &mtpzDataPath); 50 | void Authenticate(); 51 | 52 | bool KeysLoaded() const 53 | { return !!_keys; } 54 | 55 | private: 56 | TrustedApp(const SessionPtr & session, const std::string & mtpzDataPath); 57 | static KeysPtr LoadKeys(const std::string & path); 58 | 59 | }; 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /mtp/ptp/Response.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp 25 | { 26 | # define R(NAME) case ResponseType::NAME: return #NAME 27 | 28 | std::string ToString(ResponseType responseType) 29 | { 30 | switch(responseType) 31 | { 32 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(ResponseType, NAME, VALUE) 33 | # include 34 | ENUM_VALUE_TO_STRING_DEFAULT(ResponseType, responseType, 4); 35 | } 36 | } 37 | 38 | namespace 39 | { 40 | std::string FormatMessage(ResponseType r) 41 | { 42 | char buf[1024]; 43 | snprintf(buf, sizeof(buf), "invalid response code %s (0x%04hx)", ToString(r).c_str(), static_cast(r)); 44 | return buf; 45 | } 46 | } 47 | 48 | InvalidResponseException::InvalidResponseException(const std::string &where, ResponseType type): std::runtime_error(where + ": " + FormatMessage(type)), Type(type) 49 | { } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /mtp/function_invoker.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_FUNCTION_INVOKER_H 21 | #define AFTL_MTP_FUNCTION_INVOKER_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | 28 | namespace impl 29 | { 30 | template struct seq {}; 31 | 32 | template struct gens : gens {}; 33 | 34 | template struct gens<0, S...>{ typedef seq type; }; 35 | 36 | template 37 | struct function_invoker 38 | { 39 | std::tuple params; 40 | std::function func; 41 | 42 | R dispatch() 43 | { return call(typename gens::type()); } 44 | 45 | template 46 | R call(seq) 47 | { return func(std::get(params) ...); } 48 | }; 49 | } 50 | 51 | template 52 | void invoke(const std::function &func, const TupleType &tuple) 53 | { 54 | impl::function_invoker invoker = { tuple, func }; 55 | invoker.dispatch(); 56 | } 57 | 58 | } 59 | 60 | 61 | #endif 62 | 63 | -------------------------------------------------------------------------------- /qt/progressdialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_PROGRESSDIALOG_H 21 | #define AFTL_QT_PROGRESSDIALOG_H 22 | 23 | #include 24 | 25 | namespace Ui { 26 | class ProgressDialog; 27 | } 28 | 29 | class QPropertyAnimation; 30 | 31 | class ProgressDialog : public QDialog 32 | { 33 | Q_OBJECT 34 | Q_PROPERTY(float progress READ progress WRITE setProgress); 35 | 36 | public: 37 | explicit ProgressDialog(QWidget *parent = 0, bool showAbort = true); 38 | ~ProgressDialog(); 39 | 40 | float progress() const 41 | { return _progress; } 42 | 43 | void setProgress(float value); 44 | 45 | signals: 46 | void abort(); 47 | 48 | public slots: 49 | void setSpeed(qint64 speed); 50 | void setFilename(const QString &filename); 51 | void setValue(float current); 52 | virtual void reject(); 53 | 54 | private slots: 55 | void onAbortButtonPressed(); 56 | 57 | private: 58 | void closeEvent(QCloseEvent *event); 59 | 60 | private: 61 | Ui::ProgressDialog *ui; 62 | QPropertyAnimation *_animation; 63 | float _progress; 64 | int _duration; 65 | }; 66 | 67 | #endif // PROGRESSDIALOG_H 68 | -------------------------------------------------------------------------------- /mtp/ptp/ResponseType.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(OK, 0x2001) 2 | ENUM_VALUE(GeneralError, 0x2002) 3 | ENUM_VALUE(SessionNotOpen, 0x2003) 4 | ENUM_VALUE(InvalidTransaction, 0x2004) 5 | ENUM_VALUE(OperationNotSupported, 0x2005) 6 | ENUM_VALUE(ParameterNotSupported, 0x2006) 7 | ENUM_VALUE(IncompleteTransfer, 0x2007) 8 | ENUM_VALUE(InvalidStorageID, 0x2008) 9 | ENUM_VALUE(InvalidObjectHandle, 0x2009) 10 | ENUM_VALUE(DevicePropNotSupported, 0x200a) 11 | ENUM_VALUE(InvalidObjectFormatCode, 0x200b) 12 | ENUM_VALUE(StoreFull, 0x200c) 13 | ENUM_VALUE(ObjectWriteProtected, 0x200d) 14 | ENUM_VALUE(StoreReadOnly, 0x200e) 15 | ENUM_VALUE(AccessDenied, 0x200f) 16 | ENUM_VALUE(NoThumbnailPresent, 0x2010) 17 | ENUM_VALUE(SelfTestFailed, 0x2011) 18 | ENUM_VALUE(PartialDeletion, 0x2012) 19 | ENUM_VALUE(StoreNotAvailable, 0x2013) 20 | ENUM_VALUE(SpecificationByFormatUnsupported, 0x2014) 21 | ENUM_VALUE(NoValidObjectInfo, 0x2015) 22 | ENUM_VALUE(InvalidCodeFormat, 0x2016) 23 | ENUM_VALUE(UnknownVendorCode, 0x2017) 24 | ENUM_VALUE(CaptureAlreadyTerminated, 0x2018) 25 | ENUM_VALUE(DeviceBusy, 0x2019) 26 | ENUM_VALUE(InvalidParentObject, 0x201a) 27 | ENUM_VALUE(InvalidDevicePropFormat, 0x201b) 28 | ENUM_VALUE(InvalidDevicePropValue, 0x201c) 29 | ENUM_VALUE(InvalidParameter, 0x201d) 30 | ENUM_VALUE(SessionAlreadyOpen, 0x201e) 31 | ENUM_VALUE(TransactionCancelled, 0x201f) 32 | ENUM_VALUE(SpecificationOfDestinationUnsupported, 0x2020) 33 | ENUM_VALUE(InvalidServiceID, 0xa301) 34 | ENUM_VALUE(InvalidServicePropCode, 0xa302) 35 | ENUM_VALUE(TinyCLRNotResponding, 0xa401) 36 | ENUM_VALUE(NoDataWaiting, 0xa402) 37 | ENUM_VALUE(InvalidObjectPropCode, 0xa801) 38 | ENUM_VALUE(InvalidObjectPropFormat, 0xa802) 39 | ENUM_VALUE(InvalidObjectPropValue, 0xa803) 40 | ENUM_VALUE(InvalidObjectReference, 0xa804) 41 | ENUM_VALUE(GroupNotSupported, 0xa805) 42 | ENUM_VALUE(InvalidDataset, 0xa806) 43 | ENUM_VALUE(UnsupportedSpecByGroup, 0xa807) 44 | ENUM_VALUE(UnsupportedSpecByDepth, 0xa808) 45 | ENUM_VALUE(ObjectTooLarge, 0xa809) 46 | ENUM_VALUE(ObjectPropNotSupported, 0xa80) 47 | -------------------------------------------------------------------------------- /fuse/Exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_FUSE_EXCEPTION_H 21 | #define AFTL_FUSE_EXCEPTION_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mtp { namespace fuse 29 | { 30 | 31 | class Exception : public std::runtime_error 32 | { 33 | public: 34 | Exception(const std::string &what) throw() : std::runtime_error(what + ": " + GetErrorMessage(errno)) { } 35 | Exception(const std::string &what, int returnCode) throw() : std::runtime_error(what + ": " + GetErrorMessage(returnCode)) { } 36 | static std::string GetErrorMessage(int returnCode) 37 | { 38 | char buf[1024]; 39 | #if defined(_GNU_SOURCE) && defined(__GLIBC__) 40 | std::string text(strerror_r(returnCode, buf, sizeof(buf))); 41 | #else 42 | int r = strerror_r(returnCode, buf, sizeof(buf)); 43 | std::string text(r == 0? buf: "strerror_r() failed"); 44 | #endif 45 | return text; 46 | } 47 | }; 48 | 49 | #define FUSE_CALL(...) do { int _r = __VA_ARGS__ ; if (_r < 0) throw mtp::fuse::Exception(#__VA_ARGS__ " failed", -_r); } while(false) 50 | 51 | }} 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /mtp/ptp/Messages.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace mtp { namespace msg 7 | { 8 | bool DeviceInfo::Supports(OperationCode opcode) const 9 | { 10 | auto i = std::find(OperationsSupported.begin(), OperationsSupported.end(), opcode); 11 | return i != OperationsSupported.end(); 12 | } 13 | 14 | bool DeviceInfo::Supports(DeviceProperty property) const 15 | { 16 | auto i = std::find(DevicePropertiesSupported.begin(), DevicePropertiesSupported.end(), property); 17 | return i != DevicePropertiesSupported.end(); 18 | } 19 | 20 | bool DeviceInfo::Supports(EventCode event) const 21 | { 22 | auto i = std::find(EventsSupported.begin(), EventsSupported.end(), event); 23 | return i != EventsSupported.end(); 24 | } 25 | 26 | bool DeviceInfo::Supports(ObjectFormat format) const 27 | { 28 | auto i = std::find(ImageFormats.begin(), ImageFormats.end(), format); 29 | return i != ImageFormats.end(); 30 | } 31 | 32 | bool DeviceInfo::Matches(const std::string & haystack, const std::string & needle) 33 | { return strcasestr(haystack.c_str(), needle.c_str()); } 34 | 35 | bool DeviceInfo::Matches(const std::string & filter) const 36 | { 37 | if (filter.empty()) 38 | return true; 39 | auto fsname = GetFilesystemFriendlyName(); 40 | return Matches(fsname, filter); 41 | } 42 | 43 | 44 | namespace 45 | { 46 | std::string Strip(std::string str) 47 | { 48 | str.erase(std::remove_if(str.begin(), str.end(), isspace), str.end()); 49 | return str; 50 | } 51 | } 52 | 53 | std::string DeviceInfo::GetFilesystemFriendlyName() const 54 | { 55 | std::stringstream ss; 56 | ss << Strip(Manufacturer); 57 | ss << '-'; 58 | ss << Strip(Model); 59 | ss << '-'; 60 | ss << Strip(SerialNumber); 61 | return ss.str(); 62 | } 63 | 64 | bool ObjectPropertiesSupported::Supports(ObjectProperty prop) const 65 | { return std::find(ObjectPropertyCodes.begin(), ObjectPropertyCodes.end(), prop) != ObjectPropertyCodes.end(); } 66 | 67 | 68 | }} 69 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LINUX_USB_INTERFACE_H 21 | #define AFTL_MTP_BACKEND_LINUX_USB_INTERFACE_H 22 | 23 | #include 24 | #include 25 | #include //remove me later, when Endpoint.h will be available in all ports 26 | #include 27 | 28 | namespace mtp { namespace usb 29 | { 30 | 31 | class Endpoint; 32 | DECLARE_PTR(Endpoint); 33 | 34 | class Configuration; 35 | DECLARE_PTR(Configuration); 36 | 37 | class Interface 38 | { 39 | std::string _path; 40 | std::vector _endpoints; 41 | u8 _class; 42 | u8 _subclass; 43 | int _index; 44 | 45 | 46 | public: 47 | Interface(int index, const std::string &path); 48 | 49 | u8 GetClass() const 50 | { return _class; } 51 | 52 | u8 GetSubclass() const 53 | { return _subclass; } 54 | 55 | int GetIndex() const 56 | { return _index; } 57 | 58 | EndpointPtr GetEndpoint(int idx) const 59 | { return _endpoints.at(idx); } 60 | 61 | int GetEndpointsCount() const 62 | { return _endpoints.size(); } 63 | }; 64 | DECLARE_PTR(Interface); 65 | 66 | }} 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /qt/renamedialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | RenameDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 433 10 | 99 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | Rename Object 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | buttonBox 45 | accepted() 46 | RenameDialog 47 | accept() 48 | 49 | 50 | 248 51 | 254 52 | 53 | 54 | 157 55 | 274 56 | 57 | 58 | 59 | 60 | buttonBox 61 | rejected() 62 | RenameDialog 63 | reject() 64 | 65 | 66 | 316 67 | 260 68 | 69 | 70 | 286 71 | 274 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /mtp/metadata/Metadata.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #ifdef HAVE_TAGLIB 5 | # include 6 | # include 7 | # include 8 | #endif 9 | 10 | namespace mtp 11 | { 12 | #ifdef HAVE_TAGLIB 13 | MetadataPtr Metadata::Read(const std::string & path) 14 | { 15 | TagLib::FileRef f(path.c_str()); 16 | auto tag = f.tag(); 17 | if (f.isNull() || !tag) 18 | return nullptr; 19 | 20 | auto meta = std::make_shared(); 21 | auto artist = tag->artist(); 22 | 23 | const auto & props = tag->properties(); 24 | auto album_it = props.find("ALBUMARTIST"); 25 | if (album_it == props.end()) 26 | album_it = props.find("ALBUM ARTIST"); 27 | if (album_it == props.end()) 28 | album_it = props.find("MUSICBRAINZ_ALBUMARTIST"); 29 | if (album_it != props.end()) 30 | artist = album_it->second.toString(); 31 | 32 | meta->Title = tag->title().to8Bit(true); 33 | meta->Artist = artist.to8Bit(true); 34 | meta->Album = tag->album().to8Bit(true); 35 | meta->Genre = tag->genre().to8Bit(true); 36 | meta->Year = tag->year(); 37 | meta->Track = tag->track(); 38 | 39 | #if TAGLIB_MAJOR_VERSION >= 2 40 | for(auto & props : tag->complexProperties("PICTURE")) 41 | { 42 | auto &picture = meta->Picture; 43 | for(auto &kv : props) 44 | { 45 | auto &name = kv.first; 46 | auto &value = kv.second; 47 | if (name == "data") { 48 | auto data = value.toByteVector(); 49 | picture.Data.assign(data.begin(), data.end()); 50 | } else if (name == "pictureType") { 51 | picture.Type = value.toString().to8Bit(true); 52 | } else if (name == "mimeType") { 53 | picture.MimeType = value.toString().to8Bit(true); 54 | } else if (name == "description") { 55 | picture.Description = value.toString().to8Bit(true); 56 | } else { 57 | mtp::debug("unhandled PICTURE property ", name.toCString(true)); 58 | } 59 | } 60 | } 61 | #endif 62 | return meta; 63 | } 64 | 65 | #else 66 | MetadataPtr Metadata::Read(const std::string & path) 67 | { return nullptr; } 68 | #endif 69 | } 70 | -------------------------------------------------------------------------------- /mtp/ptp/DeviceProperty.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(Undefined, 0x5000) 2 | ENUM_VALUE(BatteryLevel, 0x5001) 3 | ENUM_VALUE(FunctionalMode, 0x5002) //0 - normal, 1 - sleeping 4 | ENUM_VALUE(ImageSize, 0x5003) 5 | ENUM_VALUE(CompressionSetting, 0x5004) 6 | ENUM_VALUE(WhiteBalance, 0x5005) 7 | ENUM_VALUE(RgbGain, 0x5006) 8 | ENUM_VALUE(FNumber, 0x5007) 9 | ENUM_VALUE(FocalLength, 0x5008) 10 | ENUM_VALUE(FocusDistance, 0x5009) 11 | ENUM_VALUE(FocusMode, 0x500a) 12 | ENUM_VALUE(ExposureMeteringMode, 0x500b) 13 | ENUM_VALUE(FlashMode, 0x500c) 14 | ENUM_VALUE(ExposureTime, 0x500d) 15 | ENUM_VALUE(ExposureProgramMode, 0x500e) 16 | ENUM_VALUE(ExposureIndex, 0x500f) 17 | ENUM_VALUE(ExposureBiasCompensation, 0x5010) 18 | ENUM_VALUE(Datetime, 0x5011) 19 | ENUM_VALUE(CaptureDelay, 0x5012) 20 | ENUM_VALUE(StillCaptureMode, 0x5013) 21 | ENUM_VALUE(Contrast, 0x5014) 22 | ENUM_VALUE(Sharpness, 0x5015) 23 | ENUM_VALUE(DigitalZoom, 0x5016) 24 | ENUM_VALUE(EffectMode, 0x5017) 25 | ENUM_VALUE(BurstNumber, 0x5018) 26 | ENUM_VALUE(BurstInterval, 0x5019) 27 | ENUM_VALUE(TimelapseNumber, 0x501a) 28 | ENUM_VALUE(TimelapseInterval, 0x501b) 29 | ENUM_VALUE(FocusMeteringMode, 0x501c) 30 | ENUM_VALUE(UploadUrl, 0x501d) 31 | ENUM_VALUE(Artist, 0x501e) 32 | ENUM_VALUE(CopyrightInfo, 0x501f) 33 | 34 | ENUM_VALUE(SecureTime, 0xd101) 35 | ENUM_VALUE(DeviceCertificate, 0xd102) 36 | ENUM_VALUE(RevocationInfo, 0xd103) 37 | ENUM_VALUE(PlaysForSureID, 0xd131) 38 | 39 | ENUM_VALUE(DeviceEUI64, 0xd210) 40 | ENUM_VALUE(FirmwareVersion, 0xd233) 41 | ENUM_VALUE(SerialNumber, 0xd235) 42 | 43 | ENUM_VALUE(FunctionalID, 0xd301) 44 | ENUM_VALUE(ModelID, 0xd302) 45 | ENUM_VALUE(UseDeviceStage, 0xd303) 46 | 47 | ENUM_VALUE(SynchronizationPartner, 0xd401) 48 | ENUM_VALUE(DeviceFriendlyName, 0xd402) 49 | ENUM_VALUE(Volume, 0xd403) 50 | ENUM_VALUE(SupportedFormatsOrdered, 0xd404) 51 | ENUM_VALUE(DeviceIcon, 0xd405) 52 | ENUM_VALUE(SessionInitiatorVersionInfo, 0xd406) 53 | ENUM_VALUE(PerceivedDeviceType, 0xd407) 54 | ENUM_VALUE(PlaybackRate, 0xd410) 55 | ENUM_VALUE(PlaybackObject, 0xd411) 56 | ENUM_VALUE(PlaybackContainerIndex, 0xd412) 57 | ENUM_VALUE(PlaybackPosition, 0xd413) 58 | -------------------------------------------------------------------------------- /qt/createdirectorydialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | CreateDirectoryDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 401 10 | 99 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 20 | Create New Directory 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | Qt::Horizontal 33 | 34 | 35 | QDialogButtonBox::Cancel|QDialogButtonBox::Ok 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | buttonBox 45 | accepted() 46 | CreateDirectoryDialog 47 | accept() 48 | 49 | 50 | 248 51 | 254 52 | 53 | 54 | 157 55 | 274 56 | 57 | 58 | 59 | 60 | buttonBox 61 | rejected() 62 | CreateDirectoryDialog 63 | reject() 64 | 65 | 66 | 316 67 | 260 68 | 69 | 70 | 286 71 | 274 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/DeviceDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | namespace mtp { namespace usb 24 | { 25 | DeviceDescriptor::DeviceDescriptor(libusb_device *dev): _dev(dev) 26 | { 27 | USB_CALL(libusb_get_device_descriptor(_dev, &_descriptor)); 28 | } 29 | 30 | ConfigurationPtr DeviceDescriptor::GetConfiguration(int conf) 31 | { 32 | libusb_config_descriptor *desc; 33 | USB_CALL(libusb_get_config_descriptor(_dev, conf, &desc)); 34 | return std::make_shared(desc); 35 | } 36 | 37 | DevicePtr DeviceDescriptor::Open(ContextPtr context) 38 | { 39 | libusb_device_handle *handle; 40 | USB_CALL(libusb_open(_dev, &handle)); 41 | return std::make_shared(context, handle); 42 | } 43 | 44 | DevicePtr DeviceDescriptor::TryOpen(ContextPtr context) 45 | { 46 | libusb_device_handle *handle; 47 | int r = libusb_open(_dev, &handle); 48 | return r == 0? std::make_shared(context, handle): nullptr; 49 | } 50 | 51 | DeviceDescriptor::~DeviceDescriptor() 52 | { libusb_unref_device(_dev); } 53 | 54 | ByteArray DeviceDescriptor::GetDescriptor() const 55 | { throw std::runtime_error("not possible with libusb"); } 56 | 57 | }} 58 | -------------------------------------------------------------------------------- /mtp/log.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | #include 20 | #include 21 | 22 | namespace mtp 23 | { 24 | 25 | bool g_debug = false; 26 | 27 | void HexDump(std::stringstream & ss, const std::string &prefix, size_t size, InputStream & is) 28 | { 29 | ss << prefix << "[" << size << "]:\n"; 30 | size_t i; 31 | 32 | std::string chars; 33 | chars.reserve(16); 34 | for(i = 0; i < size; ++i) 35 | { 36 | bool first = ((i & 0xf) == 0); 37 | bool last = ((i & 0xf) == 0x0f); 38 | if (first) 39 | ss << hex(i, 8) << ": "; 40 | 41 | u8 value = is.Read8(); 42 | ss << hex(value, 2); 43 | chars.push_back(value < 0x20 || value >= 0x7f? '.': value); 44 | if (last) 45 | { 46 | ss << " " << chars << "\n"; 47 | chars.clear(); 48 | } 49 | else 50 | ss << " "; 51 | } 52 | if (chars.size()) 53 | { 54 | ss << std::string((size_t)(16 - chars.size()) * 3, ' ') << chars << "\n"; 55 | } 56 | } 57 | 58 | void HexDump(const std::string &prefix, const ByteArray &data, bool force) 59 | { 60 | if (!g_debug && !force) 61 | return; 62 | 63 | std::stringstream ss; 64 | InputStream is(data); 65 | HexDump(ss, prefix, data.size(), is); 66 | error(ss.str()); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /mtp/ptp/PipePacketer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_PIPEPACKETER_H 21 | #define AFTL_MTP_PTP_PIPEPACKETER_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp 28 | { 29 | class Device; 30 | DECLARE_PTR(Device); 31 | 32 | class PipePacketer //! BulkPipe high-level controller class, package all read/write operation into streams and send it to BulkPipe 33 | { 34 | usb::BulkPipePtr _pipe; 35 | 36 | public: 37 | PipePacketer(const usb::BulkPipePtr &pipe): _pipe(pipe) { } 38 | 39 | usb::BulkPipePtr GetPipe() const 40 | { return _pipe; } 41 | 42 | void Write(const IObjectInputStreamPtr &inputStream, int timeout); 43 | void Write(const ByteArray &data, int timeout); 44 | 45 | void Read(u32 transaction, const IObjectOutputStreamPtr &outputStream, ResponseType &code, ByteArray &response, int timeout); 46 | void Read(u32 transaction, ByteArray &data, ResponseType &code, ByteArray &response, int timeout); 47 | 48 | void PollEvent(int timeout); 49 | void Abort(u32 transaction, int timeout); 50 | 51 | private: 52 | void ReadMessage(const IObjectOutputStreamPtr &outputStream, int timeout); 53 | }; 54 | 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /fuse/FuseDirectory.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_FUSE_FUSEDIRECTORY_H 21 | #define AFTL_FUSE_FUSEDIRECTORY_H 22 | 23 | #include 24 | 25 | #include 26 | 27 | namespace mtp { namespace fuse 28 | { 29 | 30 | using CharArray = std::vector; 31 | 32 | struct FuseDirectory 33 | { 34 | fuse_req_t Request; 35 | 36 | FuseDirectory(fuse_req_t request): Request(request) { } 37 | 38 | void Add(CharArray & data, const std::string &name, const struct stat & entry) 39 | { 40 | if (data.empty()) 41 | data.reserve(4096); 42 | size_t size = fuse_add_direntry(Request, NULL, 0, name.c_str(), NULL, 0); 43 | size_t offset = data.size(); 44 | data.resize(data.size() + size); 45 | fuse_add_direntry(Request, data.data() + offset, size, name.c_str(), &entry, data.size()); //request is not used inside fuse here, so we could cache resulting dirent data 46 | } 47 | 48 | static void Reply(fuse_req_t req, const CharArray &data, off_t off, size_t size) 49 | { 50 | if (off >= (off_t)data.size()) 51 | FUSE_CALL(fuse_reply_buf(req, NULL, 0)); 52 | else 53 | { 54 | FUSE_CALL(fuse_reply_buf(req, data.data() + off, std::min(size, data.size() - off))); 55 | } 56 | } 57 | }; 58 | 59 | }} 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /mtp/ptp/Container.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_CONTAINER_H 21 | #define AFTL_MTP_PTP_CONTAINER_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace mtp 30 | { 31 | struct Container //! MTP container for MTP message, appends type and size 32 | { 33 | ByteArray Data; 34 | 35 | void WriteSize(OutputStream &stream, u64 size) 36 | { 37 | if (size > MaxObjectSize) 38 | size = MaxObjectSize; 39 | stream << (u32)size; 40 | } 41 | 42 | template 43 | Container(const Message &msg) 44 | { 45 | OutputStream stream(Data); 46 | WriteSize(stream, msg.Data.size() + 6); 47 | stream << Message::Type; 48 | std::copy(msg.Data.begin(), msg.Data.end(), std::back_inserter(Data)); 49 | } 50 | 51 | template 52 | Container(const Message &msg, IObjectInputStreamPtr inputStream) 53 | { 54 | OutputStream stream(Data); 55 | WriteSize(stream, inputStream->GetSize() + msg.Data.size() + 6); 56 | stream << Message::Type; 57 | std::copy(msg.Data.begin(), msg.Data.end(), std::back_inserter(Data)); 58 | } 59 | }; 60 | 61 | } 62 | 63 | #endif /* CONTAINER_H */ 64 | -------------------------------------------------------------------------------- /mtp/ptp/Device.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_DEVICE_H 21 | #define AFTL_MTP_PTP_DEVICE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mtp 29 | { 30 | class Device //! Generic MTP Device class representing physical device, creates \ref Session 31 | { 32 | PipePacketer _packeter; 33 | 34 | private: 35 | static u8 GetInterfaceStringIndex(usb::DeviceDescriptorPtr desc, u8 number); 36 | 37 | public: 38 | Device(usb::BulkPipePtr pipe); 39 | 40 | msg::DeviceInfo GetInfo(); 41 | 42 | ///This could be very expensive, it calls GetDeviceInfo 43 | bool Matches(const std::string & filter); 44 | 45 | SessionPtr OpenSession(u32 sessionId, int timeout = Session::DefaultTimeout); 46 | 47 | static DevicePtr Open(usb::ContextPtr context, usb::DeviceDescriptorPtr desc, bool claimInterface = true, bool resetDevice = false); //fixme: add flags here 48 | static DevicePtr FindFirst(usb::ContextPtr context, const std::string & filter = std::string(), bool claimInterface = true, bool resetDevice = false); 49 | static DevicePtr FindFirst(const std::string & filter = std::string(), bool claimInterface = true, bool resetDevice = false); 50 | }; 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /mtp/ptp/ObjectId.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_OBJECTID_H 21 | #define AFTL_MTP_PTP_OBJECTID_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | 28 | #define DECLARE_ID(NAME, TYPE, MEMBER) \ 29 | struct NAME { \ 30 | TYPE MEMBER; \ 31 | static const TYPE Canary = 0xaaaaaaaau; \ 32 | \ 33 | NAME ( ): MEMBER ( Canary ) { } \ 34 | explicit NAME ( TYPE id ): MEMBER ( id ) { } \ 35 | \ 36 | bool operator == (const NAME &o) const \ 37 | { return MEMBER == o.MEMBER; } \ 38 | bool operator != (const NAME &o) const \ 39 | { return !((*this) == o); } \ 40 | bool operator < (const NAME &o) const \ 41 | { return MEMBER < o.MEMBER; } \ 42 | }; \ 43 | template Stream & operator >> (Stream &stream, NAME & value) \ 44 | { stream >> value. MEMBER ; return stream; } \ 45 | template Stream & operator << (Stream &stream, const NAME &value) \ 46 | { stream << value. MEMBER ; return stream; } \ 47 | 48 | 49 | DECLARE_ID(ObjectId, mtp::u32, Id); 50 | DECLARE_ID(StorageId, mtp::u32, Id); 51 | 52 | #undef DECLARE_ID 53 | 54 | } 55 | 56 | namespace std 57 | { 58 | template<> struct hash 59 | { public: size_t operator()(const mtp::ObjectId &id) const { return id.Id; } }; 60 | template<> struct hash 61 | { public: size_t operator()(const mtp::StorageId &id) const { return id.Id; } }; 62 | } 63 | #endif 64 | 65 | 66 | -------------------------------------------------------------------------------- /cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find readline include dirs and libraries 2 | # 3 | # Usage of this module as follows: 4 | # 5 | # find_package(Readline) 6 | # 7 | # Variables used by this module, they can change the default behaviour and need 8 | # to be set before calling find_package: 9 | # 10 | # Readline_ROOT_DIR Set this variable to the root installation of 11 | # readline if the module has problems finding the 12 | # proper installation path. 13 | # 14 | # Variables defined by this module: 15 | # 16 | # READLINE_FOUND System has readline, include and lib dirs found 17 | # Readline_INCLUDE_DIR The readline include directories. 18 | # Readline_LIBRARY The readline library. 19 | 20 | find_path(Readline_ROOT_DIR 21 | NAMES include/readline/readline.h includes/editline/readline.h 22 | develop/headers/x86/readline/readline.h develop/headers/x86/editline/readline.h 23 | develop/headers/readline/readline.h develop/headers/editline/readline.h 24 | ) 25 | 26 | find_path(Readline_INCLUDE_DIR 27 | NAMES readline.h 28 | HINTS ${Readline_ROOT_DIR}/include/readline ${Readline_ROOT_DIR}/develop/headers/x86/readline 29 | ${Readline_ROOT_DIR}/develop/headers/readline 30 | ${Readline_ROOT_DIR}/include/editline ${Readline_ROOT_DIR}/develop/headers/x86/editline 31 | ${Readline_ROOT_DIR}/develop/headers/editline 32 | ) 33 | 34 | if(EXISTS ${Readline_INCLUDE_DIR}/history.h) 35 | add_definitions(-DHAVE_READLINE_HISTORY_H=1) 36 | endif() 37 | 38 | find_library(Readline_LIBRARY 39 | NAMES readline edit 40 | HINTS ${Readline_ROOT_DIR}/lib ${Readline_ROOT_DIR}/develop/lib/x86 41 | ${Readline_ROOT_DIR}/develop/lib 42 | ) 43 | 44 | if(Readline_INCLUDE_DIR AND Readline_LIBRARY) 45 | set(READLINE_FOUND TRUE) 46 | else(Readline_INCLUDE_DIR AND Readline_LIBRARY) 47 | FIND_LIBRARY(Readline_LIBRARY NAMES readline edit) 48 | include(FindPackageHandleStandardArgs) 49 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG Readline_INCLUDE_DIR Readline_LIBRARY ) 50 | MARK_AS_ADVANCED(Readline_INCLUDE_DIR Readline_LIBRARY) 51 | endif(Readline_INCLUDE_DIR AND Readline_LIBRARY) 52 | 53 | mark_as_advanced( 54 | Readline_ROOT_DIR 55 | Readline_INCLUDE_DIR 56 | Readline_LIBRARY 57 | ) 58 | -------------------------------------------------------------------------------- /mtp/ptp/Response.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_RESPONSE_H 21 | #define AFTL_MTP_PTP_RESPONSE_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp 27 | { 28 | enum struct ContainerType : u16 29 | { 30 | Command = 1, 31 | Data = 2, 32 | Response = 3, 33 | Event = 4, 34 | }; 35 | DECLARE_ENUM(ContainerType, u16); 36 | 37 | enum struct ResponseType : u16 38 | { 39 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 40 | # include 41 | #undef ENUM_VALUE 42 | }; 43 | std::string ToString(ResponseType response); 44 | DECLARE_ENUM(ResponseType, u16); 45 | 46 | struct Response //! MTP Response class 47 | { 48 | static const size_t Size = 8; 49 | 50 | mtp::ContainerType ContainerType; 51 | mtp::ResponseType ResponseType; 52 | u32 Transaction; 53 | 54 | Response() { } 55 | 56 | template 57 | Response(Stream &stream) 58 | { Read(stream); } 59 | 60 | template 61 | void Read(Stream &stream) 62 | { 63 | stream >> ContainerType; 64 | stream >> ResponseType; 65 | stream >> Transaction; 66 | } 67 | }; 68 | 69 | struct InvalidResponseException : public std::runtime_error //!Invalid MTP Response Exception 70 | { 71 | ResponseType Type; 72 | InvalidResponseException(const std::string &where, ResponseType type); 73 | }; 74 | 75 | } 76 | 77 | #endif /* RESPONSE_H */ 78 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Context.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace mtp { namespace usb 27 | { 28 | 29 | Context::Context() 30 | { 31 | std::string rootPath("/sys/bus/usb/devices"); 32 | Directory usbDir(rootPath); 33 | std::map > devices; 34 | while(true) 35 | { 36 | std::string entry = usbDir.Read(); 37 | if (entry.empty()) 38 | break; 39 | 40 | try 41 | { 42 | unsigned busId, conf, interface; 43 | char portBuf[256]; 44 | if (sscanf(entry.c_str(), "%u-%255[0-9.]:%u.%u", &busId, portBuf, &conf, &interface) == 4) 45 | { 46 | std::string port = portBuf; 47 | if ((port.size() == 1 && port[0] == '0')) 48 | continue; 49 | DeviceDescriptorPtr &device = devices[busId][port]; 50 | if (!device) 51 | { 52 | char deviceRoot[64]; 53 | snprintf(deviceRoot, sizeof(deviceRoot), "%u-%s", busId, port.c_str()); 54 | device = std::make_shared(busId, rootPath + "/" + std::string(deviceRoot)); 55 | _devices.push_back(device); 56 | } 57 | device->AddInterface(conf, interface, rootPath + "/" + entry); 58 | } 59 | } 60 | catch(const std::exception &ex) 61 | { 62 | error(ex.what()); 63 | } 64 | } 65 | } 66 | 67 | Context::~Context() 68 | { 69 | } 70 | 71 | 72 | }} 73 | -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_INTERFACE_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_INTERFACE_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp { namespace usb 27 | { 28 | 29 | class Configuration; 30 | DECLARE_PTR(Configuration); 31 | 32 | class InterfaceToken : public IToken 33 | { 34 | BUSBDevice * _handle; 35 | int _index; 36 | 37 | public: 38 | InterfaceToken(BUSBDevice *handle, int index); 39 | ~InterfaceToken(); 40 | }; 41 | DECLARE_PTR(InterfaceToken); 42 | 43 | class Interface 44 | { 45 | DevicePtr _device; 46 | ConfigurationPtr _config; 47 | const BUSBInterface & _interface; 48 | 49 | public: 50 | Interface(DevicePtr device, ConfigurationPtr config, const BUSBInterface &interface): _device(device), _config(config), _interface(interface) { } 51 | 52 | u8 GetClass() const 53 | { return _interface.Class(); } 54 | 55 | u8 GetSubclass() const 56 | { return _interface.Subclass(); } 57 | 58 | int GetIndex() const 59 | { return _interface.Index(); } 60 | 61 | EndpointPtr GetEndpoint(int idx) const 62 | { return std::make_shared(*_interface.EndpointAt(idx)); } 63 | 64 | int GetEndpointsCount() const 65 | { return _interface.CountEndpoints(); } 66 | 67 | std::string GetName() const 68 | { return _interface.InterfaceString(); } 69 | }; 70 | DECLARE_PTR(Interface); 71 | 72 | }} 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Endpoint.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | namespace mtp { namespace usb 25 | { 26 | Endpoint::Endpoint(const std::string &path): _maxPacketSize(0) 27 | { 28 | _addr = Directory::ReadInt(path + "/bEndpointAddress"); 29 | 30 | std::string type = Directory::ReadString(path + "/type"); 31 | if (type == "Bulk") 32 | _type = EndpointType::Bulk; 33 | else if (type == "Control") 34 | _type = EndpointType::Control; 35 | else if (type == "Interrupt") 36 | _type = EndpointType::Interrupt; 37 | else if (type == "Isoc") 38 | _type = EndpointType::Isochronous; 39 | else 40 | throw std::runtime_error("invalid endpoint type " + type); 41 | 42 | std::string dir = Directory::ReadString(path + "/direction"); 43 | if (dir == "out") 44 | _direction = EndpointDirection::Out; 45 | else if (dir == "in") 46 | _direction = EndpointDirection::In; 47 | else if (dir == "both") 48 | _direction = EndpointDirection::Both; 49 | else 50 | throw std::runtime_error("invalid endpoint direction " + dir); 51 | 52 | _maxPacketSize = Directory::ReadInt(path + "/wMaxPacketSize"); 53 | } 54 | 55 | EndpointPtr Endpoint::TryOpen(const std::string &path) 56 | { 57 | try 58 | { return std::make_shared(path); } 59 | catch(const std::exception &ex) 60 | { error("failed adding endpoint: ", ex.what()); } 61 | return nullptr; 62 | } 63 | 64 | }} 65 | -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/Device.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Device.cpp 3 | * Copyright (C) 2022 pulkomandy 4 | * 5 | * Distributed under terms of the MIT license. 6 | */ 7 | 8 | #include "Device.h" 9 | 10 | 11 | namespace mtp { namespace usb 12 | { 13 | 14 | Device::Device(ContextPtr ctx, BUSBDevice* handle) 15 | : _context(ctx) 16 | , _handle(handle) 17 | { 18 | } 19 | 20 | Device::~Device() 21 | { 22 | } 23 | 24 | void Device::Reset() 25 | { 26 | } 27 | 28 | void Device::ReadControl(u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout) 29 | { 30 | fprintf(stderr, "Control read(type %x req %x value %x index %d size %lu) with timeout %d…", 31 | type, req, value, index, data.size(), timeout); 32 | ssize_t result = _handle->ControlTransfer(type, req, value, index, data.size(), const_cast(data.data())); 33 | if (result >= 0) 34 | data.resize(result); 35 | else 36 | throw std::runtime_error("read fail"); 37 | fprintf(stderr, " complete (%ld).\n", result); 38 | } 39 | 40 | void Device::WriteControl(u8 type, u8 req, u16 value, u16 index, const ByteArray &data, int timeout) 41 | { 42 | fprintf(stderr, "Control write with timeout %d\n", timeout); 43 | _handle->ControlTransfer(USB_REQTYPE_DEVICE_IN, req, value, index, data.size(), const_cast(data.data())); 44 | } 45 | 46 | void Device::SetConfiguration(int idx) 47 | { 48 | _handle->SetConfiguration(_handle->ConfigurationAt(idx)); 49 | } 50 | 51 | void Device::WriteBulk(const EndpointPtr & ep, const IObjectInputStreamPtr &inputStream, int timeout) 52 | { 53 | ByteArray data(inputStream->GetSize()); 54 | inputStream->Read(data.data(), data.size()); 55 | ssize_t tr = ep->_endpoint.BulkTransfer(data.data(), data.size()); 56 | if (tr != (int)data.size()) 57 | throw std::runtime_error("short write"); 58 | } 59 | 60 | void Device::ReadBulk(const EndpointPtr & ep, const IObjectOutputStreamPtr &outputStream, int timeout) 61 | { 62 | ByteArray data(ep->GetMaxPacketSize()); 63 | ssize_t tr; 64 | { 65 | tr = ep->_endpoint.BulkTransfer(data.data(), data.size()); 66 | outputStream->Write(data.data(), tr); 67 | } 68 | while(tr == (int)data.size()); 69 | } 70 | 71 | void Device::ClearHalt(const EndpointPtr & ep) 72 | { 73 | ep->_endpoint.ClearStall(); 74 | } 75 | 76 | InterfaceTokenPtr Device::ClaimInterface(const InterfacePtr & interface) 77 | { 78 | return InterfaceTokenPtr(); 79 | } 80 | 81 | }} 82 | -------------------------------------------------------------------------------- /mtp/ptp/ObjectFormat.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_OBJECTFORMAT_H 21 | #define AFTL_MTP_PTP_OBJECTFORMAT_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp 28 | { 29 | static const u64 MaxObjectSize = 0xffffffffull; 30 | 31 | //please look here: https://msdn.microsoft.com/en-us/library/jj584872(v=winembedded.70).aspx 32 | 33 | enum struct ObjectFormat : u16 34 | { 35 | #define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_DECL(NAME, VALUE) 36 | # include 37 | #undef ENUM_VALUE 38 | }; 39 | 40 | DECLARE_ENUM(ObjectFormat, u16); 41 | std::string ToString(ObjectFormat property); 42 | 43 | enum struct AssociationType : u16 44 | { 45 | GenericFolder = 0x0001, 46 | Album = 0x0002, 47 | TimeSequence = 0x0003, 48 | HorizontalPanoramic = 0x0004, 49 | VerticalPanoramic = 0x0005, 50 | Panoramic2D = 0x0006, 51 | AncillaryData = 0x0007 52 | }; 53 | 54 | DECLARE_ENUM(AssociationType, u16); 55 | 56 | ObjectFormat ObjectFormatFromFilename(const std::string &filename); 57 | 58 | bool IsAudioFormat(ObjectFormat format); 59 | bool IsImageFormat(ObjectFormat format); 60 | 61 | time_t ConvertDateTime(const std::string ×pec); 62 | std::string ConvertDateTime(time_t); 63 | std::string ConvertYear(int year); 64 | 65 | } 66 | 67 | namespace std 68 | { 69 | template<> struct hash 70 | { public: size_t operator()(mtp::ObjectFormat format) const { return static_cast(format); } }; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /mtp/make_function.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_MAKE_FUNCTION_H 21 | #define AFTL_MTP_MAKE_FUNCTION_H 22 | 23 | #include 24 | 25 | namespace mtp 26 | { 27 | 28 | template struct remove_class { }; 29 | template 30 | struct remove_class { using type = R(A...); }; 31 | template 32 | struct remove_class { using type = R(A...); }; 33 | template 34 | struct remove_class { using type = R(A...); }; 35 | template 36 | struct remove_class { using type = R(A...); }; 37 | 38 | template 39 | struct get_signature_impl { using type = typename remove_class< 40 | decltype(&std::remove_reference::type::operator())>::type; }; 41 | template 42 | struct get_signature_impl { using type = R(A...); }; 43 | template 44 | struct get_signature_impl { using type = R(A...); }; 45 | template 46 | struct get_signature_impl { using type = R(A...); }; 47 | template using get_signature = typename get_signature_impl::type; 48 | 49 | template using make_function_type = std::function>; 50 | template make_function_type make_function(F &&f) { 51 | return make_function_type(std::forward(f)); } 52 | 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /qt/fileuploader.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_FILEUPLOADER_H 21 | #define AFTL_QT_FILEUPLOADER_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | class MtpObjectsModel; 31 | struct Command; 32 | class CommandQueue; 33 | 34 | namespace mtp 35 | { 36 | struct ObjectId; 37 | class Library; 38 | DECLARE_PTR(Library); 39 | } 40 | 41 | class FileUploader : public QObject 42 | { 43 | Q_OBJECT 44 | 45 | private: 46 | MtpObjectsModel * _model; 47 | QThread _workerThread; 48 | CommandQueue * _worker; 49 | qint64 _total; 50 | QDateTime _startedAt; 51 | bool _aborted; 52 | 53 | private slots: 54 | void onTotal(qint64 total); 55 | void onProgress(qint64 current); 56 | void onStarted(const QString &file); 57 | void onFinished(); 58 | 59 | public: 60 | explicit FileUploader(MtpObjectsModel * model, QObject *parent = 0); 61 | ~FileUploader(); 62 | 63 | void tryCreateLibrary(); 64 | mtp::LibraryPtr library() const; 65 | 66 | void upload(QStringList files, mtp::ObjectFormat format); 67 | void importMusic(const QString & path); 68 | void download(const QString &path, const QVector & objectIds); 69 | 70 | public slots: 71 | void abort(); 72 | 73 | signals: 74 | void executeCommand(Command *cmd); 75 | 76 | //incoming signals (from worker) 77 | void uploadStarted(QString file); 78 | void uploadProgress(float); 79 | void uploadSpeed(qint64); 80 | void finished(); 81 | }; 82 | 83 | #endif // FILEUPLOADER_H 84 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/DeviceDescriptor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace mtp { namespace usb 30 | { 31 | DeviceDescriptor::DeviceDescriptor(int busId, const std::string &path): _busId(busId), _path(path) 32 | { 33 | debug("creating device descriptor at ", path); 34 | _vendor = Directory::ReadInt(path + "/idVendor"); 35 | _product = Directory::ReadInt(path + "/idProduct"); 36 | _deviceNumber = Directory::ReadInt(path + "/devnum", 10); 37 | _controlEp = std::make_shared(path + "/ep_00"); 38 | _descriptor = Directory::ReadAll(path + "/descriptors"); 39 | _configurationValue = Directory::ReadInt(path + "/bConfigurationValue", 10); 40 | } 41 | 42 | DevicePtr DeviceDescriptor::Open(ContextPtr context) 43 | { 44 | DevicePtr device = TryOpen(context); 45 | if (!device) 46 | throw std::runtime_error("cannot open device at " + _path); 47 | return device; 48 | } 49 | 50 | DevicePtr DeviceDescriptor::TryOpen(ContextPtr context) 51 | { 52 | char fname[256]; 53 | snprintf(fname, sizeof(fname), "/dev/bus/usb/%03d/%03u", _busId, _deviceNumber); 54 | int fd = open(fname, O_RDWR); 55 | if (fd != -1) 56 | return std::make_shared(fd, _controlEp, _configurationValue); 57 | debug("error: ", posix::Exception::GetErrorMessage(errno)); 58 | return nullptr; 59 | } 60 | 61 | DeviceDescriptor::~DeviceDescriptor() 62 | { } 63 | 64 | }} 65 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_INTERFACE_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_INTERFACE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | 30 | class Configuration; 31 | DECLARE_PTR(Configuration); 32 | 33 | class InterfaceToken : public IToken 34 | { 35 | libusb_device_handle * _handle; 36 | int _index; 37 | 38 | public: 39 | InterfaceToken(libusb_device_handle *handle, int index); 40 | ~InterfaceToken(); 41 | }; 42 | DECLARE_PTR(InterfaceToken); 43 | 44 | class Interface 45 | { 46 | DevicePtr _device; 47 | ConfigurationPtr _config; 48 | const libusb_interface_descriptor & _interface; 49 | 50 | public: 51 | Interface(DevicePtr device, ConfigurationPtr config, const libusb_interface_descriptor &interface): _device(device), _config(config), _interface(interface) { } 52 | 53 | u8 GetClass() const 54 | { return _interface.bInterfaceClass; } 55 | 56 | u8 GetSubclass() const 57 | { return _interface.bInterfaceSubClass; } 58 | 59 | int GetIndex() const 60 | { return _interface.bInterfaceNumber; } 61 | 62 | EndpointPtr GetEndpoint(int idx) const 63 | { return std::make_shared(_interface.endpoint[idx]); } 64 | 65 | int GetEndpointsCount() const 66 | { return _interface.bNumEndpoints; } 67 | 68 | std::string GetName() const 69 | { return _interface.iInterface? _device->GetString(_interface.iInterface): std::string(); } 70 | }; 71 | DECLARE_PTR(Interface); 72 | 73 | }} 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/DeviceDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_DEVICEDESCRIPTOR_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_DEVICEDESCRIPTOR_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | 29 | #include 30 | 31 | namespace mtp { namespace usb 32 | { 33 | class Configuration : Noncopyable 34 | { 35 | //IOUSBDeviceType **_dev; 36 | IOUSBConfigurationDescriptorPtr _conf; 37 | 38 | std::vector _interfaces; 39 | 40 | public: 41 | Configuration(IOUSBDeviceType ** dev, IOUSBConfigurationDescriptorPtr conf); 42 | 43 | int GetIndex() const 44 | { return _conf->bConfigurationValue; } 45 | 46 | int GetInterfaceCount() const 47 | { return _interfaces.size(); } 48 | 49 | int GetInterfaceAltSettingsCount(int idx) const 50 | { return 1; } 51 | 52 | InterfacePtr GetInterface(DevicePtr device, ConfigurationPtr config, int idx, int settings) const 53 | { return std::make_shared(device, config, _interfaces.at(idx)); } 54 | }; 55 | 56 | class DeviceDescriptor 57 | { 58 | private: 59 | IOUSBDeviceType **_dev; 60 | 61 | public: 62 | DeviceDescriptor(io_service_t desc); 63 | ~DeviceDescriptor(); 64 | 65 | u16 GetVendorId() const; 66 | u16 GetProductId() const; 67 | 68 | DevicePtr Open(ContextPtr context); 69 | DevicePtr TryOpen(ContextPtr context); 70 | 71 | int GetConfigurationsCount() const; 72 | 73 | ConfigurationPtr GetConfiguration(int conf); 74 | ByteArray GetDescriptor(); 75 | }; 76 | DECLARE_PTR(DeviceDescriptor); 77 | 78 | }} 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /mtp/ptp/IObjectStream.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_PTP_IOBJECTSTREAM_H 21 | #define AFTL_MTP_PTP_IOBJECTSTREAM_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp 28 | { 29 | struct ICancellableStream //! interfaces for streams with cancellation functionality 30 | { 31 | virtual ~ICancellableStream() = default; 32 | virtual void Cancel() = 0; 33 | }; 34 | DECLARE_PTR(ICancellableStream); 35 | 36 | struct OperationCancelledException : public std::runtime_error //! exception thrown if stream was cancelled 37 | { 38 | OperationCancelledException(): std::runtime_error("operation cancelled") { } 39 | }; 40 | 41 | class CancellableStream : public virtual ICancellableStream //! default implementation of \ref ICancellableStream 42 | { 43 | std::atomic_bool _cancelled; 44 | 45 | public: 46 | CancellableStream(): _cancelled(false) 47 | { } 48 | 49 | void Cancel() 50 | { _cancelled.store(true); } 51 | 52 | void CheckCancelled() 53 | { 54 | bool cancelled = _cancelled.load(); 55 | if (cancelled) 56 | throw OperationCancelledException(); 57 | } 58 | }; 59 | 60 | struct IObjectInputStream : public virtual ICancellableStream //! Basic input stream interface 61 | { 62 | virtual u64 GetSize() const = 0; 63 | virtual size_t Read(u8 *data, size_t size) = 0; 64 | }; 65 | DECLARE_PTR(IObjectInputStream); 66 | 67 | struct IObjectOutputStream : public virtual ICancellableStream //! Basic output stream interface 68 | { 69 | virtual size_t Write(const u8 *data, size_t size) = 0; 70 | }; 71 | DECLARE_PTR(IObjectOutputStream); 72 | 73 | } 74 | 75 | #endif /* IOBJECTSTREAM_H */ 76 | -------------------------------------------------------------------------------- /qt/mtpstoragesmodel.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "mtpstoragesmodel.h" 21 | #include "utils.h" 22 | #include 23 | 24 | MtpStoragesModel::MtpStoragesModel(QObject *parent): QAbstractListModel(parent) 25 | { } 26 | 27 | bool MtpStoragesModel::update(const mtp::SessionPtr &session) 28 | { 29 | beginResetModel(); 30 | _storages.clear(); 31 | mtp::msg::StorageIDs storages = session->GetStorageIDs(); 32 | for(auto id : storages.StorageIDs) 33 | { 34 | mtp::msg::StorageInfo info; 35 | try { info = session->GetStorageInfo(id); } 36 | catch (const mtp::InvalidResponseException &ex) 37 | { 38 | if (ex.Type == mtp::ResponseType::InvalidStorageID) 39 | return false; 40 | else 41 | throw; 42 | } 43 | _storages.append(qMakePair(id, info)); 44 | } 45 | mtp::msg::StorageInfo anyStorage; 46 | anyStorage.StorageDescription = toUtf8(tr("All storages (BUGS, BEWARE)")); 47 | _storages.append(qMakePair(mtp::Session::AllStorages, anyStorage)); 48 | endResetModel(); 49 | return !storages.StorageIDs.empty(); 50 | } 51 | 52 | mtp::StorageId MtpStoragesModel::getStorageId(int idx) const 53 | { 54 | return idx >= 0 && idx < _storages.size()? _storages[idx].first: mtp::Session::AllStorages; 55 | } 56 | 57 | int MtpStoragesModel::rowCount(const QModelIndex &parent) const 58 | { 59 | return _storages.size(); 60 | } 61 | 62 | QVariant MtpStoragesModel::data(const QModelIndex &index, int role) const 63 | { 64 | const mtp::msg::StorageInfo & si = _storages[index.row()].second; 65 | switch(role) 66 | { 67 | case Qt::DisplayRole: 68 | { 69 | auto name = si.GetName(); 70 | return fromUtf8(name); 71 | } 72 | default: 73 | return QVariant(); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/Device.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_DEVICE_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_DEVICE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | 31 | #include "Interface.h" 32 | 33 | namespace mtp { namespace usb 34 | { 35 | class Context; 36 | DECLARE_PTR(Context); 37 | 38 | class Endpoint; 39 | DECLARE_PTR(Endpoint); 40 | class Interface; 41 | DECLARE_PTR(Interface); 42 | class InterfaceToken; 43 | DECLARE_PTR(InterfaceToken); 44 | 45 | class Device : Noncopyable 46 | { 47 | private: 48 | ContextPtr _context; 49 | IOUSBDeviceType ** _dev; 50 | 51 | public: 52 | Device(ContextPtr ctx, IOUSBDeviceType **dev); //must be opened 53 | ~Device(); 54 | 55 | InterfaceTokenPtr ClaimInterface(const InterfacePtr &interface); 56 | 57 | int GetConfiguration() const; 58 | void SetConfiguration(int idx); 59 | void Reset(); 60 | 61 | void WriteBulk(const EndpointPtr & ep, const IObjectInputStreamPtr &inputStream, int timeout); 62 | void ReadBulk(const EndpointPtr & ep, const IObjectOutputStreamPtr &outputStream, int timeout); 63 | void ClearHalt(const EndpointPtr & ep); 64 | 65 | static void ReadControl(IOUSBDeviceType **dev, u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout); //result buffer must be allocated 66 | void ReadControl(u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout); //result buffer must be allocated 67 | void WriteControl(u8 type, u8 req, u16 value, u16 index, const ByteArray &data, int timeout); 68 | }; 69 | DECLARE_PTR(Device); 70 | }} 71 | 72 | #endif /* DEVICE_H */ 73 | 74 | -------------------------------------------------------------------------------- /mtp/ptp/ObjectProperty.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace mtp 6 | { 7 | std::string ToString(ObjectProperty property) 8 | { 9 | switch(property) 10 | { 11 | # define ENUM_VALUE(NAME, VALUE) ENUM_VALUE_TO_STRING(ObjectProperty, NAME, VALUE) 12 | # include 13 | ENUM_VALUE_TO_STRING_DEFAULT(ObjectProperty, property, 4); 14 | } 15 | } 16 | namespace 17 | { 18 | template 19 | void ArrayToString(std::stringstream & ss, InputStream & is, u32 size) 20 | { 21 | ss << "[ "; 22 | while(size--) { 23 | T value; 24 | is >> value; 25 | ss << value; 26 | if (size) 27 | ss << " "; 28 | } 29 | ss << "]"; 30 | } 31 | 32 | void ToString(std::stringstream & ss, InputStream & is, DataTypeCode type) 33 | { 34 | if (IsArray(type)) 35 | { 36 | u32 size = is.Read32(); 37 | 38 | switch(type) 39 | { 40 | #define CASE(CODE, TYPE) case CODE : ArrayToString(ss, is, size); break 41 | CASE(DataTypeCode::ArrayInt8, s8); 42 | CASE(DataTypeCode::ArrayInt16, s16); 43 | CASE(DataTypeCode::ArrayInt32, s32); 44 | CASE(DataTypeCode::ArrayInt64, s64); 45 | CASE(DataTypeCode::ArrayUint16, u16); 46 | CASE(DataTypeCode::ArrayUint32, u32); 47 | CASE(DataTypeCode::ArrayUint64, u64); 48 | case DataTypeCode::ArrayUint8: 49 | HexDump(ss, "value", size, is); 50 | break; 51 | #undef CASE 52 | 53 | default: 54 | ss << "(value of unknown type " << ToString(type) << ")"; 55 | } 56 | } 57 | else 58 | { 59 | switch(type) 60 | { 61 | #define CASE(BITS) \ 62 | case DataTypeCode::Uint##BITS: \ 63 | case DataTypeCode::Int##BITS: \ 64 | ss << is.Read##BITS (); break; 65 | CASE(8); CASE(16); CASE(32); CASE(64); 66 | #undef CASE 67 | case mtp::DataTypeCode::Uint128: 68 | case mtp::DataTypeCode::Int128: 69 | HexDump(ss, "value", 16, is); 70 | break; 71 | case mtp::DataTypeCode::String: 72 | ss << is.ReadString(); break; 73 | default: 74 | ss << "(value of unknown type " << ToString(type) << ")"; 75 | } 76 | } 77 | } 78 | 79 | bool IsString(const ByteArray & value) 80 | { 81 | return true; 82 | } 83 | } 84 | 85 | std::string ToString(DataTypeCode type, const ByteArray & value) 86 | { 87 | std::stringstream ss; 88 | InputStream is(value); 89 | if (type == DataTypeCode::ArrayUint16 && IsString(value)) 90 | { 91 | u32 size = is.Read32(); 92 | ss << is.ReadString(size); 93 | } else 94 | ToString(ss, is, type); 95 | return ss.str(); 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /mtp/usb/BulkPipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_USB_BULKPIPE_H 21 | #define AFTL_MTP_USB_BULKPIPE_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | class Device; 30 | DECLARE_PTR(Device); 31 | class Configuration; 32 | DECLARE_PTR(Configuration); 33 | class Interface; 34 | DECLARE_PTR(Interface); 35 | class Endpoint; 36 | DECLARE_PTR(Endpoint); 37 | class BulkPipe; 38 | DECLARE_PTR(BulkPipe); 39 | 40 | class BulkPipe //! USB BulkPipe, incapsulate three (in, out, interrupt) endpoints, allowing easier data transfer 41 | { 42 | std::mutex _mutex; 43 | DevicePtr _device; 44 | ConfigurationPtr _conf; 45 | InterfacePtr _interface; 46 | EndpointPtr _in, _out, _interrupt; 47 | ITokenPtr _claimToken; 48 | ICancellableStreamPtr _currentStream; 49 | 50 | private: 51 | void SetCurrentStream(const ICancellableStreamPtr &stream); 52 | ICancellableStreamPtr GetCurrentStream(); 53 | 54 | class CurrentStreamSetter; 55 | 56 | public: 57 | BulkPipe(DevicePtr device, ConfigurationPtr conf, InterfacePtr interface, EndpointPtr in, EndpointPtr out, EndpointPtr interrupt, ITokenPtr claimToken, bool clearHalt = false); 58 | ~BulkPipe(); 59 | 60 | DevicePtr GetDevice() const; 61 | InterfacePtr GetInterface() const; 62 | 63 | ByteArray ReadInterrupt(int timeout); 64 | 65 | void Read(const IObjectOutputStreamPtr &outputStream, int timeout = 10000); 66 | void Write(const IObjectInputStreamPtr &inputStream, int timeout = 10000); 67 | void Cancel(); 68 | 69 | static BulkPipePtr Create(const usb::DevicePtr & device, const ConfigurationPtr & conf, const usb::InterfacePtr & owner, ITokenPtr claimToken); 70 | }; 71 | 72 | }} 73 | 74 | #endif /* BULKPIPE_H */ 75 | -------------------------------------------------------------------------------- /mtp/backend/haiku/usb/DeviceDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_DEVICEDESCRIPTOR_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_DEVICEDESCRIPTOR_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace mtp { namespace usb 28 | { 29 | class Configuration : Noncopyable 30 | { 31 | const BUSBConfiguration *_config; 32 | 33 | public: 34 | Configuration(const BUSBConfiguration *config) : _config(config) { } 35 | ~Configuration() { /* configuration is owned by its parent device */ } 36 | 37 | int GetIndex() const 38 | { return _config->Index(); } 39 | 40 | int GetInterfaceCount() const 41 | { return _config->CountInterfaces(); } 42 | 43 | int GetInterfaceAltSettingsCount(int idx) const 44 | { return _config->InterfaceAt(idx)->CountAlternates(); } 45 | 46 | // TODO figure out what to do with "int settings" 47 | InterfacePtr GetInterface(DevicePtr device, ConfigurationPtr config, int idx, int settings) const 48 | { return std::make_shared(device, config, *_config->InterfaceAt(idx)->AlternateAt(settings)); } 49 | }; 50 | 51 | class DeviceDescriptor 52 | { 53 | private: 54 | BUSBDevice * _dev; 55 | 56 | public: 57 | DeviceDescriptor(BUSBDevice *dev); 58 | ~DeviceDescriptor(); 59 | 60 | u16 GetVendorId() const 61 | { return _dev->VendorID(); } 62 | 63 | u16 GetProductId() const 64 | { return _dev->ProductID(); } 65 | 66 | DevicePtr Open(ContextPtr context); 67 | DevicePtr TryOpen(ContextPtr context); 68 | 69 | int GetConfigurationsCount() const 70 | { return _dev->CountConfigurations(); } 71 | 72 | ConfigurationPtr GetConfiguration(int conf); 73 | 74 | ByteArray GetDescriptor() const; 75 | }; 76 | DECLARE_PTR(DeviceDescriptor); 77 | 78 | }} 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /mtp/backend/libusb/usb/DeviceDescriptor.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LIBUSB_USB_DEVICEDESCRIPTOR_H 21 | #define AFTL_MTP_BACKEND_LIBUSB_USB_DEVICEDESCRIPTOR_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace mtp { namespace usb 29 | { 30 | class Configuration : Noncopyable 31 | { 32 | libusb_config_descriptor *_config; 33 | 34 | public: 35 | Configuration(libusb_config_descriptor *config) : _config(config) { } 36 | ~Configuration() { libusb_free_config_descriptor(_config); } 37 | 38 | int GetIndex() const 39 | { return _config->bConfigurationValue; } 40 | 41 | int GetInterfaceCount() const 42 | { return _config->bNumInterfaces; } 43 | 44 | int GetInterfaceAltSettingsCount(int idx) const 45 | { return _config->interface[idx].num_altsetting; } 46 | 47 | InterfacePtr GetInterface(DevicePtr device, ConfigurationPtr config, int idx, int settings) const 48 | { return std::make_shared(device, config, _config->interface[idx].altsetting[settings]); } 49 | }; 50 | 51 | class DeviceDescriptor 52 | { 53 | private: 54 | libusb_device * _dev; 55 | libusb_device_descriptor _descriptor; 56 | 57 | public: 58 | DeviceDescriptor(libusb_device *dev); 59 | ~DeviceDescriptor(); 60 | 61 | u16 GetVendorId() const 62 | { return _descriptor.idVendor; } 63 | 64 | u16 GetProductId() const 65 | { return _descriptor.idProduct; } 66 | 67 | DevicePtr Open(ContextPtr context); 68 | DevicePtr TryOpen(ContextPtr context); 69 | 70 | int GetConfigurationsCount() const 71 | { return _descriptor.bNumConfigurations; } 72 | 73 | ConfigurationPtr GetConfiguration(int conf); 74 | 75 | ByteArray GetDescriptor() const; 76 | }; 77 | DECLARE_PTR(DeviceDescriptor); 78 | 79 | }} 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /python/example/menu.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # -*- coding: utf-8 -*- 4 | """ 5 | hierarchical prompt usage example 6 | """ 7 | from __future__ import print_function, unicode_literals 8 | from InquirerPy import prompt, separator 9 | 10 | import aftl 11 | 12 | def get_storage_prompt(session, s): 13 | info = session.get_storage_info(s) 14 | name = info.StorageDescription 15 | if not name: 16 | name = repr(s) 17 | return { 'name': name, 'value': s } 18 | 19 | def get_storage(session): 20 | storage_prompt = { 21 | 'type': 'list', 22 | 'name': 'storage', 23 | 'message': 'Select storage', 24 | 'choices': list(map(lambda s: get_storage_prompt(session, s), session.get_storage_ids())) + [{'name': 'Quit', 'value': None}] 25 | } 26 | answers = prompt(storage_prompt) 27 | return answers.get('storage') 28 | 29 | def get_object_prompt(session, object): 30 | info = session.get_object_info(object) 31 | name = info.Filename 32 | if info.ObjectFormat == aftl.ObjectFormat.Association: 33 | name += '/' 34 | return {'name': name, 'value': (object, info.ObjectFormat) } 35 | 36 | def get_object(session, storage, parent): 37 | objects = session.get_object_handles(storage, aftl.ObjectFormat.Any, parent) 38 | object_prompt = { 39 | 'type': 'list', 40 | 'name': 'object', 41 | 'message': 'Browse objects', 42 | 'choices': [{'name': '..', 'value': (None, None) }] + \ 43 | list(map(lambda o: get_object_prompt(session, o), objects)) 44 | } 45 | answers = prompt(object_prompt) 46 | return answers.get('object') 47 | 48 | def get_object_action(session): 49 | action_prompt = { 50 | 'type': 'expand', 51 | 'name': 'action', 52 | 'message': 'Object Action (press h for help)', 53 | 'choices': [ 54 | { 'key': 'b', 'name': 'Back', 'value': 'back' }, 55 | separator.Separator(), 56 | { 'key': 'd', 'name': 'Download', 'value': 'download' }, 57 | ] 58 | } 59 | return prompt(action_prompt).get('action') 60 | 61 | def main(): 62 | session = aftl.Device.find_first().open_session() 63 | while True: 64 | storage = get_storage(session) 65 | if storage is None: 66 | break 67 | 68 | path = [aftl.Session.Root] 69 | while path: 70 | object, type = get_object(session, storage, path[-1]) 71 | if type == aftl.ObjectFormat.Association: 72 | path.append(object) 73 | continue 74 | 75 | if object is None: 76 | path.pop() 77 | continue 78 | 79 | while True: 80 | action = get_object_action(session) 81 | if action == 'back': 82 | break 83 | 84 | if action == 'download': 85 | name = session.get_object_string_property(object, aftl.ObjectProperty.ObjectFilename) 86 | with open(name, "wb") as f: 87 | session.get_object(object, f) 88 | 89 | 90 | if __name__ == '__main__': 91 | main() 92 | -------------------------------------------------------------------------------- /qt/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include "mainwindow.h" 21 | #include "utils.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #if QT_VERSION >= 0x050000 29 | # include 30 | #endif 31 | 32 | namespace 33 | { 34 | class Application : public QApplication 35 | { 36 | public: 37 | Application(int &argc, char **argv, int flags = ApplicationFlags): 38 | QApplication(argc, argv, flags) 39 | { } 40 | 41 | virtual bool notify ( QObject * receiver, QEvent * e ) 42 | { 43 | try { 44 | return QApplication::notify( receiver, e ); 45 | } catch ( const std::exception& e ) { 46 | QMessageBox::warning(0, "Error", fromUtf8(e.what())); 47 | return false; 48 | } 49 | } 50 | }; 51 | } 52 | 53 | int main(int argc, char *argv[]) 54 | { 55 | QApplication app(argc, argv); 56 | Q_INIT_RESOURCE(android_file_transfer); 57 | 58 | QCoreApplication::setApplicationName("aft-linux-qt"); 59 | QCoreApplication::setOrganizationDomain("whoozle.github.io"); 60 | QCoreApplication::setOrganizationName("whoozle.github.io"); 61 | 62 | #if QT_VERSION >= 0x050000 63 | QGuiApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 64 | #endif 65 | 66 | QTranslator qtTranslator; 67 | 68 | qtTranslator.load("qt_" + QLocale::system().name(), 69 | QLibraryInfo::location(QLibraryInfo::TranslationsPath)); 70 | app.installTranslator(&qtTranslator); 71 | 72 | QTranslator aTranslator; 73 | aTranslator.load(":/android-file-transfer-linux_" + QLocale::system().name()); 74 | app.installTranslator(&aTranslator); 75 | 76 | MainWindow w; 77 | 78 | for (int i = 0; i < argc; ++i) { 79 | if (strcmp(argv[i], "-R") == 0) 80 | w.enableDeviceReset(true); 81 | else if (strcmp(argv[i], "-v") == 0) 82 | mtp::g_debug = true; 83 | } 84 | 85 | w.show(); 86 | 87 | if (!w.started()) 88 | return 1; 89 | 90 | return app.exec(); 91 | } 92 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | # FAQ 2 | 3 | ## Is it possible to use cli tool for automated file management? 4 | 5 | Yes. There's two options of achieving this. 6 | 1. Pass every command as **single** command line argument, e.g. ```aft-mtp-cli "get Pictures" "cd Pictures" "ls"```. If you need quoted argument for commands, you have to escape them, e.g. ```aft-mtp-cli "get \"Pictures\""```. 7 | 2. Pass -b command line option and feed your script to stdin. 8 | 9 | ## How to unmount my device? 10 | 11 | Run 12 | ```fusermount -u ``` 13 | 14 | 15 | ## I'm getting «ioctl(_fd, USBDEVFS_CLAIMINTERFACE, &interfaceNumber): Device or resource busy» or «Device is already used by another process» exception/message box right after you started the application. This clearly indicates that some other process is accessing MTP device right now. 16 | You could do the following steps to find the offending process: 17 | * Open you console emulator (gnome-terminal, konsole, whatever) and type: ```lsusb``` (sudo apt-get install usbutils if it did not start) and find your device in its output, for example 18 | ``` 19 | Bus 006 Device 070: ID 18d1:4ee2 Google Inc. Nexus 4 (debug) 20 | ``` 21 | * Start fuser ```sudo fuser /dev/bus/usb//``` (sudo apt-get install psmisc if it did not start) 22 | * It should output something like this: ```/dev/bus/usb/006/070: 23253 24377``` (actually, there could be more of them after semicolon, like : 24377, 24378, …) so, 23253 and 24377 are the pids of the processes which opened your device. 23 | * So, finally run: 24 | ``` 25 | ps -x -q 23253 26 | 23253 ? Sl 0:00 /usr/local/bin/android-file-transfer 27 | ps -x -q 24377 28 | 24377 ? Sl 21:14 adb -P 5037 fork-server server 29 | ``` 30 | Usually, adb is not offending process, because it uses another interface, so the /usr/local/bin/android-file-transfer is the one 31 | 32 | ## No MTP device found, but it's listed in lsusb 33 | 34 | Maybe you don't have sufficient privileges to access usb device under /dev/bus/usb 35 | 36 | First, try checking what bus and device numbers your device has by running lsusb command and finding your device in its output. 37 | 38 | For instance, my old Nexus 5 phone: 39 | ``` 40 | Bus 010 Device 003: ID 18d1:4ee2 Google Inc. Nexus Device (debug) 41 | ``` 42 | 43 | Note the bus/device number in row with your device Then, go /dev/bus/usb/ and check file there. (010 and 003 respectively in my case). 44 | ``` 45 | ls -l /dev/bus/usb/010/ 46 | crw-rw-r-- 1 root usb 189, 1152 Jan 5 21:30 001 47 | crw-rw----+ 1 root plugdev 189, 1154 Jan 5 22:46 003 48 | ``` 49 | 50 | plugdev group may have different name for different distros, consult your distro's manual for details. You can check what groups you're in by running 'id' command. 51 | 52 | If device's group is 'root', then you have to add udev rule: 53 | http://reactivated.net/writing_udev_rules.html 54 | Please find some examples there. 55 | -------------------------------------------------------------------------------- /qt/progressdialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | ProgressDialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 334 10 | 138 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | Upload Progress 21 | 22 | 23 | true 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 24 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | Qt::Horizontal 60 | 61 | 62 | QDialogButtonBox::Abort 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | buttonBox 72 | accepted() 73 | ProgressDialog 74 | accept() 75 | 76 | 77 | 248 78 | 254 79 | 80 | 81 | 157 82 | 274 83 | 84 | 85 | 86 | 87 | buttonBox 88 | rejected() 89 | ProgressDialog 90 | reject() 91 | 92 | 93 | 316 94 | 260 95 | 96 | 97 | 286 98 | 274 99 | 100 | 101 | 102 | 103 | 104 | -------------------------------------------------------------------------------- /fuse/FuseEntry.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_FUSE_FUSEENTRY_H 21 | #define AFTL_FUSE_FUSEENTRY_H 22 | 23 | #include 24 | 25 | #include 26 | #include 27 | 28 | #include 29 | 30 | namespace mtp { namespace fuse 31 | { 32 | 33 | struct FuseEntry : fuse_entry_param 34 | { 35 | static constexpr const double Timeout = 60.0; 36 | static constexpr unsigned FileMode = S_IFREG | 0644; 37 | static constexpr unsigned DirectoryMode = S_IFDIR | 0755; 38 | 39 | fuse_req_t Request; 40 | 41 | FuseEntry(fuse_req_t req): fuse_entry_param(), Request(req) 42 | { 43 | generation = 1; 44 | attr_timeout = entry_timeout = Timeout; 45 | }; 46 | 47 | void SetId(FuseId id) 48 | { 49 | ino = id.Inode; 50 | attr.st_ino = id.Inode; 51 | } 52 | 53 | void SetFileMode() 54 | { attr.st_mode = FileMode; } 55 | 56 | void SetDirectoryMode() 57 | { attr.st_mode = DirectoryMode; } 58 | 59 | static mode_t GetMode(mtp::ObjectFormat format) 60 | { 61 | switch(format) 62 | { 63 | case mtp::ObjectFormat::Association: 64 | return DirectoryMode; 65 | default: 66 | return FileMode; 67 | } 68 | } 69 | 70 | void Reply() 71 | { 72 | if (attr.st_mode == 0) 73 | throw std::runtime_error("uninitialized attr in FuseEntry::Reply"); 74 | FUSE_CALL(fuse_reply_entry(Request, this)); 75 | } 76 | 77 | void ReplyCreate(fuse_file_info *fi) 78 | { 79 | if (attr.st_mode == 0) 80 | throw std::runtime_error("uninitialized attr in FuseEntry::Reply"); 81 | FUSE_CALL(fuse_reply_create(Request, this, fi)); 82 | } 83 | 84 | void ReplyAttr() 85 | { 86 | if (attr.st_mode == 0) 87 | throw std::runtime_error("uninitialized attr in FuseEntry::ReplyAttr"); 88 | FUSE_CALL(fuse_reply_attr(Request, &attr, Timeout)); 89 | } 90 | 91 | void ReplyError(int err) 92 | { 93 | FUSE_CALL(fuse_reply_err(Request, err)); 94 | } 95 | }; 96 | 97 | }} 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /mtp/ptp/ObjectFormat.values.h: -------------------------------------------------------------------------------- 1 | ENUM_VALUE(Any, 0x0000) 2 | ENUM_VALUE(Undefined, 0x3000) 3 | ENUM_VALUE(Association, 0x3001) 4 | ENUM_VALUE(Script, 0x3002) 5 | ENUM_VALUE(Executable, 0x3003) 6 | ENUM_VALUE(Text, 0x3004) 7 | ENUM_VALUE(Html, 0x3005) 8 | ENUM_VALUE(Dpof, 0x3006) 9 | ENUM_VALUE(Aiff, 0x3007) 10 | ENUM_VALUE(Wav, 0x3008) 11 | ENUM_VALUE(Mp3, 0x3009) 12 | ENUM_VALUE(Avi, 0x300a) 13 | ENUM_VALUE(Mpeg, 0x300b) 14 | ENUM_VALUE(Asf, 0x300c) 15 | 16 | ENUM_VALUE(UndefinedImage, 0x3800) 17 | ENUM_VALUE(ExifJpeg, 0x3801) 18 | ENUM_VALUE(TiffEp, 0x3802) 19 | ENUM_VALUE(Flashpix, 0x3803) 20 | ENUM_VALUE(Bmp, 0x3804) 21 | ENUM_VALUE(Ciff, 0x3805) 22 | ENUM_VALUE(Gif, 0x3807) 23 | ENUM_VALUE(Jfif, 0x3808) 24 | ENUM_VALUE(Pcd, 0x3809) 25 | ENUM_VALUE(Pict, 0x380a) 26 | ENUM_VALUE(Png, 0x380b) 27 | ENUM_VALUE(Tiff, 0x380d) 28 | ENUM_VALUE(TiffIt, 0x380e) 29 | ENUM_VALUE(Jp2, 0x380f) 30 | ENUM_VALUE(Jpx, 0x3810) 31 | ENUM_VALUE(Dng, 0x3811) 32 | ENUM_VALUE(Heif, 0x3812) 33 | 34 | ENUM_VALUE(NetworkAssociation, 0xb102) 35 | 36 | ENUM_VALUE(M4a, 0xb215) 37 | ENUM_VALUE(Artist, 0xb218) 38 | 39 | ENUM_VALUE(UndefinedFirmware, 0xb802) 40 | ENUM_VALUE(WindowsImageFormat, 0xb881) 41 | 42 | ENUM_VALUE(UndefinedAudio, 0xb900) 43 | ENUM_VALUE(Wma, 0xb901) 44 | ENUM_VALUE(Ogg, 0xb902) 45 | ENUM_VALUE(Aac, 0xb903) 46 | ENUM_VALUE(Audible, 0xb904) 47 | ENUM_VALUE(Flac, 0xb906) 48 | 49 | ENUM_VALUE(UndefinedVideo, 0xb980) 50 | ENUM_VALUE(Wmv, 0xb981) 51 | ENUM_VALUE(Mp4, 0xb982) 52 | ENUM_VALUE(Mp2, 0xb983) 53 | ENUM_VALUE(_3gp, 0xb984) 54 | 55 | ENUM_VALUE(UndefinedCollection, 0xba00) 56 | ENUM_VALUE(AbstractMultimediaAlbum, 0xba01) 57 | ENUM_VALUE(AbstractImageAlbum, 0xba02) 58 | ENUM_VALUE(AbstractAudioAlbum, 0xba03) 59 | ENUM_VALUE(AbstractVideoAlbum, 0xba04) 60 | ENUM_VALUE(AbstractAVPlaylist, 0xba05) 61 | ENUM_VALUE(AbstractContactGroup, 0xba06) 62 | ENUM_VALUE(AbstractMessageFolder, 0xba07) 63 | ENUM_VALUE(AbstractChapteredProduction, 0xba08) 64 | ENUM_VALUE(AbstractAudioPlaylist, 0xba09) 65 | ENUM_VALUE(AbstractVideoPlaylist, 0xba0a) 66 | ENUM_VALUE(AbstractMediacast, 0xba0b) 67 | ENUM_VALUE(WplPlaylist, 0xba10) 68 | ENUM_VALUE(M3uPlaylist, 0xba11) 69 | ENUM_VALUE(MplPlaylist, 0xba12) 70 | ENUM_VALUE(AsxPlaylist, 0xba13) 71 | ENUM_VALUE(PlsPlaylist, 0xba14) 72 | 73 | ENUM_VALUE(UndefinedDocument, 0xba80) 74 | ENUM_VALUE(AbstractDocument, 0xba81) 75 | ENUM_VALUE(XmlDocument, 0xba82) 76 | ENUM_VALUE(MicrosoftWordDocument, 0xba83) 77 | ENUM_VALUE(MhtCompiledHtmlDocument, 0xba84) 78 | ENUM_VALUE(MicrosoftExcelSpreadsheet, 0xba85) 79 | ENUM_VALUE(MicrosoftPowerPointPresentation, 0xba86) 80 | 81 | ENUM_VALUE(UndefinedMessage, 0xbb00) 82 | ENUM_VALUE(AbstractMessage, 0xbb01) 83 | ENUM_VALUE(UndefinedContact, 0xbb80) 84 | ENUM_VALUE(AbstractContact, 0xbb81) 85 | ENUM_VALUE(VCard2, 0xbb82) 86 | ENUM_VALUE(VCard3, 0xbb83) 87 | 88 | ENUM_VALUE(UndefinedCalendarItem, 0xbe00) 89 | ENUM_VALUE(AbstractCalendarItem, 0xbe01) 90 | ENUM_VALUE(VCalendar1, 0xbe02) 91 | ENUM_VALUE(VCalendar2, 0xbe03) 92 | ENUM_VALUE(UndefinedWindowsExecutable, 0xbe80) 93 | -------------------------------------------------------------------------------- /qt/qtobjectstream.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_QT_QTOBJECTSTREAM_H 21 | #define AFTL_QT_QTOBJECTSTREAM_H 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | class QtObjectInputStream : public QObject, public mtp::IObjectInputStream, public mtp::CancellableStream 28 | { 29 | Q_OBJECT 30 | 31 | signals: 32 | void positionChanged(qint64, qint64); 33 | 34 | private: 35 | QFile _file; 36 | qint64 _size; 37 | int _progress; 38 | 39 | public: 40 | QtObjectInputStream(const QString &file) : _file(file), _size(_file.size()), _progress(-1) { 41 | _file.open(QFile::ReadOnly); 42 | } 43 | 44 | bool Valid() const 45 | { return _file.isOpen(); } 46 | 47 | virtual mtp::u64 GetSize() const 48 | { return _size; } 49 | 50 | virtual size_t Read(mtp::u8 *data, size_t size) 51 | { 52 | CheckCancelled(); 53 | qint64 r = _file.read(static_cast(static_cast(data)), size); 54 | if (r < 0) 55 | throw std::runtime_error(_file.errorString().toStdString()); 56 | 57 | int progress = _size > 0? _file.pos() * 1000L / _size: 0; 58 | if (progress != _progress) //throttle events a bit 59 | { 60 | _progress = progress; 61 | emit positionChanged(_file.pos(), _size); 62 | } 63 | return r; 64 | } 65 | }; 66 | 67 | class QtObjectOutputStream : public QObject, public mtp::IObjectOutputStream, public mtp::CancellableStream 68 | { 69 | Q_OBJECT 70 | 71 | signals: 72 | void positionChanged(qint64, qint64); 73 | 74 | private: 75 | QFile _file; 76 | qint64 _size; 77 | 78 | public: 79 | QtObjectOutputStream(const QString &file): _file(file) 80 | { _file.open(QFile::WriteOnly | QFile::Truncate); } 81 | 82 | bool Valid() const 83 | { return _file.isOpen(); } 84 | 85 | virtual size_t Write(const mtp::u8 *data, size_t size) 86 | { 87 | CheckCancelled(); 88 | qint64 r = _file.write(static_cast(static_cast(data)), size); 89 | if (r < 0) 90 | throw std::runtime_error(_file.errorString().toStdString()); 91 | emit positionChanged(_file.pos(), _size); 92 | return r; 93 | } 94 | }; 95 | 96 | #endif // QTOBJECTSTREAM_H 97 | -------------------------------------------------------------------------------- /cli/CommandLine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #if HAVE_READLINE_HISTORY_H 28 | #include 29 | #endif 30 | 31 | namespace cli 32 | { 33 | CommandLine::CommandLine() 34 | { 35 | rl_readline_name = const_cast("AFT"); 36 | rl_attempted_completion_function = &CommandLine::CompletionCallback; 37 | char *home = getenv("HOME"); 38 | if (home) 39 | { 40 | _historyPath = std::string(home) + "/.config"; 41 | mkdir(_historyPath.c_str(), 0700); 42 | _historyPath += "/whoozle.github.io"; 43 | mkdir(_historyPath.c_str(), 0700); 44 | _historyPath += "/aft-linux-cli.history"; 45 | read_history(_historyPath.c_str()); 46 | } 47 | } 48 | 49 | CommandLine::~CommandLine() 50 | { 51 | write_history(_historyPath.c_str()); 52 | } 53 | 54 | CommandLine & CommandLine::Get() 55 | { 56 | static CommandLine cmd; 57 | return cmd; 58 | } 59 | 60 | char * CommandLine::CompletionGenerator(const char *text, int state) 61 | { return NULL; } 62 | 63 | char ** CommandLine::CompletionCallback(const char *text, int start, int end) 64 | { 65 | try 66 | { 67 | if (Get()._callback) 68 | return Get()._callback(text, start, end); 69 | else 70 | return NULL; 71 | } 72 | catch(const std::exception &ex) 73 | { mtp::error(ex.what()); } 74 | return NULL; 75 | } 76 | 77 | bool CommandLine::ReadLine(const std::string &prompt, std::string &input) 78 | { 79 | char *line = readline(prompt.c_str()); 80 | if (!line) 81 | return false; 82 | 83 | input.assign(line); 84 | add_history(input.c_str()); 85 | return true; 86 | } 87 | 88 | bool CommandLine::ReadRawLine(std::string &input) 89 | { 90 | char buf[4096]; 91 | char *r = fgets(buf, sizeof(buf), stdin); 92 | if (r) 93 | input.assign(r); 94 | else 95 | input.clear(); 96 | return r; 97 | } 98 | 99 | std::string CommandLine::GetLineBuffer() const 100 | { return rl_line_buffer; } 101 | } 102 | -------------------------------------------------------------------------------- /mtp/backend/darwin/usb/Interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_DARWIN_USB_INTERFACE_H 21 | #define AFTL_MTP_BACKEND_DARWIN_USB_INTERFACE_H 22 | 23 | #include 24 | #include 25 | 26 | namespace mtp { namespace usb 27 | { 28 | class Endpoint 29 | { 30 | private: 31 | IOUSBInterfaceInterface ** _interface; 32 | int _refIndex; 33 | int _address; 34 | int _maxPacketSize; 35 | EndpointDirection _direction; 36 | EndpointType _type; 37 | 38 | public: 39 | Endpoint(IOUSBInterfaceInterface **interface, int idx); 40 | 41 | IOUSBInterfaceInterface ** GetInterfaceHandle() 42 | { return _interface; } 43 | 44 | int GetRefIndex() 45 | { return _refIndex; } 46 | 47 | u8 GetAddress() const 48 | { return _address; } 49 | 50 | int GetMaxPacketSize() const 51 | { return _maxPacketSize; } 52 | 53 | EndpointDirection GetDirection() const 54 | { return _direction; } 55 | 56 | EndpointType GetType() const 57 | { return _type; } 58 | }; 59 | DECLARE_PTR(Endpoint); 60 | 61 | class Configuration; 62 | DECLARE_PTR(Configuration); 63 | class Device; 64 | DECLARE_PTR(Device); 65 | 66 | class InterfaceToken : public IToken 67 | { 68 | IOUSBInterfaceInterface **_interface; 69 | 70 | public: 71 | InterfaceToken(IOUSBInterfaceInterface **interface); 72 | ~InterfaceToken(); 73 | }; 74 | DECLARE_PTR(InterfaceToken); 75 | 76 | class Interface 77 | { 78 | DevicePtr _device; 79 | ConfigurationPtr _config; 80 | IOUSBInterfaceInterface ** _interface; 81 | 82 | public: 83 | Interface(DevicePtr device, ConfigurationPtr config, IOUSBInterfaceInterface **interface); 84 | ~Interface(); 85 | 86 | IOUSBInterfaceInterface ** GetInterfaceHandle() 87 | { return _interface; } 88 | 89 | u8 GetClass() const; 90 | u8 GetSubclass() const; 91 | int GetIndex() const; 92 | int GetEndpointsCount() const; 93 | 94 | InterfaceTokenPtr Claim(); 95 | 96 | EndpointPtr GetEndpoint(int idx) const 97 | { return std::make_shared(_interface, idx + 1); } 98 | 99 | }; 100 | DECLARE_PTR(Interface); 101 | 102 | }} 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /mtp/backend/linux/usb/Device.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of Android File Transfer For Linux. 3 | Copyright (C) 2015-2020 Vladimir Menshakov 4 | 5 | This library is free software; you can redistribute it and/or modify it 6 | under the terms of the GNU Lesser General Public License as published by 7 | the Free Software Foundation; either version 2.1 of the License, 8 | or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, but 11 | WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 | */ 19 | 20 | #ifndef AFTL_MTP_BACKEND_LINUX_USB_DEVICE_H 21 | #define AFTL_MTP_BACKEND_LINUX_USB_DEVICE_H 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | namespace mtp { namespace usb 34 | { 35 | class Context; 36 | DECLARE_PTR(Context); 37 | class BufferAllocator; 38 | DECLARE_PTR(BufferAllocator); 39 | 40 | class InterfaceToken : public IToken 41 | { 42 | int _fd; 43 | unsigned _interfaceNumber; 44 | public: 45 | InterfaceToken(int fd, unsigned interfaceNumber); 46 | ~InterfaceToken(); 47 | }; 48 | DECLARE_PTR(InterfaceToken); 49 | 50 | class Device : Noncopyable 51 | { 52 | private: 53 | posix::FileHandler _fd; 54 | u32 _capabilities; 55 | EndpointPtr _controlEp; 56 | u8 _configuration; 57 | BufferAllocatorPtr _bufferAllocator; 58 | 59 | struct Urb; 60 | //DECLARE_PTR(Urb); 61 | std::queue> _controls; 62 | 63 | public: 64 | Device(int fd, const EndpointPtr &controlEp, u8 configuration); 65 | ~Device(); 66 | 67 | InterfaceTokenPtr ClaimInterface(const InterfacePtr & interface) 68 | { return std::make_shared(_fd.Get(), interface->GetIndex()); } 69 | 70 | void Reset(); 71 | int GetConfiguration() const; 72 | void SetConfiguration(int idx); 73 | 74 | void ClearHalt(const EndpointPtr & ep); 75 | void WriteBulk(const EndpointPtr & ep, const IObjectInputStreamPtr &inputStream, int timeout); 76 | void ReadBulk(const EndpointPtr & ep, const IObjectOutputStreamPtr &outputStream, int timeout); 77 | 78 | void WriteControl(u8 type, u8 req, u16 value, u16 index, const ByteArray &data, int timeout); 79 | void ReadControl(u8 type, u8 req, u16 value, u16 index, ByteArray &data, int timeout); //result buffer must be allocated 80 | 81 | private: 82 | static u8 TransactionType(const EndpointPtr &ep); 83 | void * Reap(int timeout); 84 | void * AsyncReap(); 85 | void Submit(Urb *urb, int timeout); 86 | }; 87 | DECLARE_PTR(Device); 88 | }} 89 | 90 | #endif /* DEVICE_H */ 91 | 92 | --------------------------------------------------------------------------------