• 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 std::string & displayName)35 static std::vector<std::string> QueryMediaFiles(const std::string &displayName)
36 {
37     std::vector<std::string> queryfilePaths;
38     std::string fileTableName = MediaFileUtils::GetTableNameByDisplayName(displayName);
39     if (fileTableName == AudioColumn::AUDIOS_TABLE || fileTableName == PhotoColumn::PHOTOS_TABLE) {
40         auto resultSet = UserFileClientEx::GetResultsetByDisplayName(fileTableName, displayName);
41         if (resultSet == nullptr || resultSet->GoToFirstRow() != 0) {
42             printf("The displayName you want to query do not exist!\n");
43             printf("find 0 result\n");
44             return queryfilePaths;
45         }
46         do {
47             auto path = GetStringVal(MediaColumn::MEDIA_FILE_PATH, resultSet);
48             auto pos = path.find("/storage/cloud/file", 0);
49             if (pos != string::npos) {
50                 path.insert(pos + PATH_HEAD.length(), "100/");
51             }
52             queryfilePaths.push_back(path);
53         } while (!resultSet->GoToNextRow());
54     } else {
55         printf("The displayName format is not correct!\n");
56     }
57     return queryfilePaths;
58 }
59 
Start(const ExecEnv & env)60 int32_t QueryCommandV10::Start(const ExecEnv &env)
61 {
62     std::vector<std::string> filePaths;
63     filePaths = QueryMediaFiles(env.queryParam.displayName);
64     int count = filePaths.size();
65     if (filePaths.empty()) {
66         return Media::E_OK;
67     }
68     printf("find %d result: \n", count);
69     for (auto path:filePaths) {
70         printf("%s\n", path.c_str());
71     }
72     return Media::E_OK;
73 }
74 }
75 }
76 }
77