Alex4386 1 год назад
Родитель
Сommit
c9bc43a1ef
2 измененных файлов с 23 добавлено и 30 удалено
  1. 21 26
      src/scenes/mtp/mtp.c
  2. 2 4
      src/scenes/mtp/mtp.h

+ 21 - 26
src/scenes/mtp/mtp.c

@@ -327,6 +327,15 @@ void handle_mtp_command(AppMTP* mtp, struct MTPContainer* container) {
             mtp, MTP_TYPE_RESPONSE, MTP_RESP_OK, container->header.transaction_id, NULL, 0);
         break;
     }
+    case MTP_OP_DELETE_OBJECT:
+        FURI_LOG_I("MTP", "DeleteObject operation");
+        if(DeleteObject(mtp, container->params[0])) {
+            send_mtp_response(mtp, 3, MTP_RESP_OK, container->header.transaction_id, NULL);
+        } else {
+            send_mtp_response(
+                mtp, 3, MTP_RESP_INVALID_OBJECT_HANDLE, container->header.transaction_id, NULL);
+        }
+        break;
 
     case MTP_OP_GET_DEVICE_PROP_VALUE:
         FURI_LOG_I("MTP", "GetDevicePropValue operation");
@@ -1061,36 +1070,22 @@ void WriteMTPBEString(uint8_t* buffer, const char* str, uint16_t* length) {
     *length = ptr - buffer;
 }
 
-uint32_t CreateObject(AppMTP* mtp, uint32_t parent_handle, const char* name, bool is_directory) {
+bool DeleteObject(AppMTP* mtp, uint32_t handle) {
     UNUSED(mtp);
-    MTPObject new_object;
-    UNUSED(new_object);
-    UNUSED(parent_handle);
-    UNUSED(name);
-    UNUSED(is_directory);
-
-    FURI_LOG_I("MTP", "Creating object %s", name);
-    return 0;
-}
+    FURI_LOG_I("MTP", "Deleting object %ld", handle);
 
-uint32_t ReadObject(AppMTP* mtp, uint32_t handle, uint8_t* buffer, uint32_t size) {
-    UNUSED(mtp);
-    UNUSED(buffer);
-    UNUSED(size);
-    FURI_LOG_I("MTP", "Reading object %ld", handle);
+    char* path = get_path_from_handle(mtp, handle);
+    if(path == NULL) {
+        return false;
+    }
 
-    return 0;
-}
+    if(!storage_file_exists(mtp->storage, path)) {
+        return false;
+    }
 
-void WriteObject(AppMTP* mtp, uint32_t handle, uint8_t* data, uint32_t size) {
-    UNUSED(mtp);
-    UNUSED(data);
-    UNUSED(size);
-    FURI_LOG_I("MTP", "Writing object %ld", handle);
-}
+    if(storage_common_remove(mtp->storage, path) != FSE_OK) {
+        return false;
+    }
 
-bool DeleteObject(AppMTP* mtp, uint32_t handle) {
-    UNUSED(mtp);
-    FURI_LOG_I("MTP", "Deleting object %ld", handle);
     return true;
 }

+ 2 - 4
src/scenes/mtp/mtp.h

@@ -24,9 +24,10 @@
 #define MTP_OP_GET_OBJECT_HANDLES 0x1007
 #define MTP_OP_GET_OBJECT_INFO 0x1008
 #define MTP_OP_GET_OBJECT 0x1009
+
+#define MTP_OP_DELETE_OBJECT 0x100B
 #define MTP_OP_SEND_OBJECT_INFO 0x100C
 #define MTP_OP_SEND_OBJECT 0x100D
-#define MTP_OP_DELETE_OBJECT 0x100B
 #define MTP_OP_GET_DEVICE_PROP_DESC 0x1014
 #define MTP_OP_GET_DEVICE_PROP_VALUE 0x1015
 
@@ -135,9 +136,6 @@ void OpenSession(AppMTP* mtp, uint32_t session_id);
 void CloseSession(AppMTP* mtp);
 void GetStorageIDs(AppMTP* mtp, uint32_t* storage_ids, uint32_t* count);
 int GetStorageInfo(AppMTP* mtp, uint32_t storage_id, uint8_t* buf);
-uint32_t CreateObject(AppMTP* mtp, uint32_t parent_handle, const char* name, bool is_directory);
-uint32_t ReadObject(AppMTP* mtp, uint32_t handle, uint8_t* buffer, uint32_t size);
-void WriteObject(AppMTP* mtp, uint32_t handle, uint8_t* data, uint32_t size);
 bool DeleteObject(AppMTP* mtp, uint32_t handle);
 
 void mtp_handle_bulk(AppMTP* mtp, uint8_t* buffer, uint32_t length);