1/*
2 * Copyright (c) 2022 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_RESTOOL_FILE_ENTRY_H
17#define OHOS_RESTOOL_FILE_ENTRY_H
18
19#include <memory>
20#include <vector>
21#include <string>
22
23namespace OHOS {
24namespace Global {
25namespace Restool {
26class FileEntry {
27public:
28    class FilePath {
29    public:
30        FilePath(const std::string &path);
31        virtual ~FilePath();
32        FilePath Append(const std::string &path);
33        FilePath ReplaceExtension(const std::string &extension);
34        FilePath GetParent();
35        const std::string &GetPath() const;
36        const std::string &GetFilename() const;
37        const std::string &GetExtension() const;
38        const std::vector<std::string> GetSegments() const;
39    private:
40        void Init();
41        void Format();
42        std::string filePath_;
43        std::string filename_;
44        std::string parent_;
45        std::string extension_;
46    };
47
48    FileEntry(const std::string &path);
49    virtual ~FileEntry();
50    bool Init();
51    const std::vector<std::unique_ptr<FileEntry>> GetChilds() const;
52    bool IsFile() const;
53    const FilePath &GetFilePath() const;
54    static bool Exist(const std::string &path);
55    static bool RemoveAllDir(const std::string &path);
56    static bool RemoveFile(const std::string &path);
57    static bool CreateDirs(const std::string &path);
58    static bool CopyFileInner(const std::string &src, const std::string &dst);
59    static bool IsDirectory(const std::string &path);
60    static std::string RealPath(const std::string &path);
61    static std::string AdaptLongPath(const std::string &path);
62
63private:
64    bool IsIgnore(const std::string &filename) const;
65    static bool RemoveAllDirInner(const FileEntry &entry);
66    static bool CreateDirsInner(const std::string &path, std::string::size_type offset);
67    FilePath filePath_;
68    bool isFile_;
69    static const std::string SEPARATE;
70};
71}
72}
73}
74#endif