• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /*
3  * Copyright (C) 2024 Huawei Device Co., Ltd.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <string>
17 #include <vector>
18 #include "media_log.h"
19 #include "command/query_command_v10.h"
20 #include "userfile_client_ex.h"
21 #include "media_file_utils.h"
22 #include "utils/database_utils.h"
23 #include "medialibrary_errno.h"
24 #include "datashare_predicates.h"
25 #include "userfile_client.h"
26 #include "constant.h"
27 #include "result_set_utils.h"
28 #include "parameter.h"
29 #include "parameters.h"
30 
31 namespace OHOS {
32 namespace Media {
33 namespace MediaTool {
34 const string PATH_HEAD = "/storage/cloud/";
QueryMediaFiles(const QueryParam & queryParam)35 static int32_t QueryMediaFiles(const QueryParam &queryParam)
36 {
37     std::vector<std::string> queryfilePaths;
38     std::string fileTableName = MediaFileUtils::GetTableNameByDisplayName(queryParam.displayName);
39     if (fileTableName != AudioColumn::AUDIOS_TABLE && fileTableName != PhotoColumn::PHOTOS_TABLE) {
40         printf("find 0 result\n");
41         printf("The displayName format is not correct!\n");
42         return Media::E_ERR;
43     }
44 
45     auto resultSet = UserFileClientEx::GetResultsetByDisplayName(fileTableName, queryParam.displayName);
46     if (resultSet == nullptr || resultSet->GoToFirstRow() != 0) {
47         printf("find 0 result\n");
48         return Media::E_ERR;
49     }
50     int count = 0;
51     if (resultSet->GetRowCount(count) != 0) {
52         return Media::E_ERR;
53     }
54     printf("find %d result\n", count);
55     if (queryParam.pathFlag) {
56         printf("path\n");
57         do {
58             auto path = GetStringVal(MediaColumn::MEDIA_FILE_PATH, resultSet);
59             auto pos = path.find("/storage/cloud/file", 0);
60             if (pos != string::npos) {
61                 path.insert(pos + PATH_HEAD.length(), "100/");
62             }
63             printf("%s\n", path.c_str());
64         } while (!resultSet->GoToNextRow());
65         resultSet->Close();
66     } else if (queryParam.uriFlag) {
67         std::shared_ptr<FetchResult<FileAsset>> fetchResult = std::make_shared<FetchResult<FileAsset>>(resultSet);
68         fetchResult->SetResultNapiType(ResultNapiType::TYPE_USERFILE_MGR);
69         DumpOpt dumpOpt;
70         dumpOpt.count = fetchResult->GetCount();
71         MEDIA_DEBUG_LOG("count:%{public}d", dumpOpt.count);
72         dumpOpt.columns = {
73             MEDIA_DATA_DB_URI
74         };
75         DatabaseUtils::Dump(dumpOpt, fetchResult);
76     }
77     return Media::E_OK;
78 }
79 
Start(const ExecEnv & env)80 int32_t QueryCommandV10::Start(const ExecEnv &env)
81 {
82     return QueryMediaFiles(env.queryParam);
83 }
84 }
85 }
86 }
87