1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_FILE_FS_LIST_FILE_H
17 #define OHOS_FILE_FS_LIST_FILE_H
18 
19 #include <string>
20 #include "cj_common_ffi.h"
21 #include "file_filter.h"
22 
23 
24 namespace OHOS {
25 namespace CJSystemapi {
26 
27 struct RetDataCArrStringN {
28     int code;
29     CArrString data;
30 };
31 
32 struct CFilter {
33     CArrString suffix;
34     CArrString displayName;
35     CArrString mimeType;
36     int64_t fileSizeOver;
37     double lastModifiedAfter;
38     bool excludeMedia;
39 };
40 
41 struct CListFileOptions {
42     bool recursion;
43     int listNum;
44     CFilter filter;
45 };
46 
47 struct NameListArg {
48     struct dirent** namelist = { nullptr };
49     int direntNum = 0;
50 };
51 
52 constexpr int DEFAULT_SIZE = -1;
53 constexpr int DEFAULT_MODIFY_AFTER = -1;
54 constexpr int FILTER_MATCH = 1;
55 constexpr int FILTER_DISMATCH = 0;
56 const int32_t MAX_SUFFIX_LENGTH = 256;
57 
58 struct OptionArgs {
59     OHOS::FileManagement::ModuleFileIO::FileFilter filter = OHOS::FileManagement::ModuleFileIO::FileFilterBuilder()
60         .SetFileSizeOver(DEFAULT_SIZE)
61         .SetLastModifiedAfter(DEFAULT_MODIFY_AFTER)
62         .Build();
63     int listNum = 0;
64     int countNum = 0;
65     bool recursion = false;
66     std::string path = "";
ClearOptionArgs67     void Clear()
68     {
69         filter.FilterClear();
70         filter.SetFileSizeOver(DEFAULT_SIZE);
71         filter.SetLastModifiedAfter(DEFAULT_MODIFY_AFTER);
72         listNum = 0;
73         countNum = 0;
74         recursion = false;
75         path = "";
76     }
77 };
78 
79 class ListFileImpl {
80 public:
81     static RetDataCArrStringN ListFile(const std::string &path, CListFileOptions options);
82 };
83 
84 }
85 }
86 
87 
88 #endif // OHOS_FILE_FS_LIST_FILE_H