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 23 namespace OHOS { 24 namespace Global { 25 namespace Restool { 26 class FileEntry { 27 public: 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 CreateDirs(const std::string &path); 57 static bool CopyFileInner(const std::string &src, const std::string &dst); 58 static bool IsDirectory(const std::string &path); 59 static std::string RealPath(const std::string &path); 60 static std::string AdaptLongPath(const std::string &path); 61 62 private: 63 bool IsIgnore(const std::string &filename) const; 64 static bool RemoveAllDirInner(const FileEntry &entry); 65 static bool CreateDirsInner(const std::string &path, std::string::size_type offset); 66 FilePath filePath_; 67 bool isFile_; 68 static const std::string SEPARATE; 69 }; 70 } 71 } 72 } 73 #endif