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 FONT_MANAGER_FILE_UTILS_H 17 #define FONT_MANAGER_FILE_UTILS_H 18 19 #include <filesystem> 20 #include <string> 21 22 namespace OHOS { 23 namespace Global { 24 namespace FontManager { 25 class FileUtils { 26 public: 27 static bool CheckPathExist(const std::string &pathName); 28 static bool CreatDirWithPermission(const std::string &fileDir); 29 static bool CreateFileWithPermission(const std::string &filePath, const std::string &defalutStr = ""); 30 static std::string GetFileName(const std::string &path); 31 static bool CopyFile(int32_t sourceFd, const std::string& path); 32 static std::string GetFilePathByFd(const int32_t &fd); 33 static bool RenameFile(const std::string& src, const std::string& dest); 34 static std::string GetFileTime(); 35 static bool RemoveFile(const std::string &path); 36 static void DeleteDir(const std::string &rootPath, bool isDeleteRootDir); 37 private: 38 static bool CopyFileByFd(int32_t sourceFd, int32_t targetFd); 39 static bool RemoveAll(const std::filesystem::path &path); 40 }; 41 } // namespace FontManager 42 } // namespace Global 43 } // namespace OHOS 44 #endif // FONT_MANAGER_FILE_UTILS_H 45