13e5483f6Sopenharmony_ci/*
23e5483f6Sopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
33e5483f6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
43e5483f6Sopenharmony_ci * you may not use this file except in compliance with the License.
53e5483f6Sopenharmony_ci * You may obtain a copy of the License at
63e5483f6Sopenharmony_ci *
73e5483f6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
83e5483f6Sopenharmony_ci *
93e5483f6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
103e5483f6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
113e5483f6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
123e5483f6Sopenharmony_ci * See the License for the specific language governing permissions and
133e5483f6Sopenharmony_ci * limitations under the License.
143e5483f6Sopenharmony_ci */
153e5483f6Sopenharmony_ci
163e5483f6Sopenharmony_ci#ifndef RINGTONE_FILE_UTILS_H
173e5483f6Sopenharmony_ci#define RINGTONE_FILE_UTILS_H
183e5483f6Sopenharmony_ci
193e5483f6Sopenharmony_ci#include <string>
203e5483f6Sopenharmony_ci#include <unordered_set>
213e5483f6Sopenharmony_ci
223e5483f6Sopenharmony_cinamespace OHOS {
233e5483f6Sopenharmony_cinamespace Media {
243e5483f6Sopenharmony_ci#define EXPORT __attribute__ ((visibility ("default")))
253e5483f6Sopenharmony_ci
263e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_READONLY = "r";
273e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_WRITEONLY = "w";
283e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_READWRITE = "rw";
293e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_WRITETRUNCATE = "wt";
303e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_WRITEAPPEND = "wa";
313e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_READWRITETRUNCATE = "rwt";
323e5483f6Sopenharmony_ciEXPORT const std::string RINGTONE_FILEMODE_READWRITEAPPEND = "rwa";
333e5483f6Sopenharmony_ciEXPORT const std::unordered_set<std::string> RINGTONE_OPEN_MODES = {
343e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_READONLY,
353e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_WRITEONLY,
363e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_READWRITE,
373e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_WRITETRUNCATE,
383e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_WRITEAPPEND,
393e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_READWRITETRUNCATE,
403e5483f6Sopenharmony_ci    RINGTONE_FILEMODE_READWRITEAPPEND
413e5483f6Sopenharmony_ci};
423e5483f6Sopenharmony_ci
433e5483f6Sopenharmony_ciconstexpr int64_t MSEC_TO_SEC = 1e3;
443e5483f6Sopenharmony_ciconstexpr int64_t MSEC_TO_NSEC = 1e6;
453e5483f6Sopenharmony_ciconstexpr size_t DEFAULT_TIME_SIZE = 32;
463e5483f6Sopenharmony_ci
473e5483f6Sopenharmony_ciclass RingtoneFileUtils {
483e5483f6Sopenharmony_cipublic:
493e5483f6Sopenharmony_ci    EXPORT static int64_t Timespec2Millisecond(const struct timespec &time);
503e5483f6Sopenharmony_ci    EXPORT static bool StartsWith(const std::string &str, const std::string &prefix);
513e5483f6Sopenharmony_ci    EXPORT static int64_t UTCTimeMilliSeconds();
523e5483f6Sopenharmony_ci    EXPORT static int64_t UTCTimeSeconds();
533e5483f6Sopenharmony_ci    EXPORT static std::string StrCreateTimeByMilliseconds(const std::string &format, int64_t time);
543e5483f6Sopenharmony_ci    EXPORT static std::string SplitByChar(const std::string &str, const char split);
553e5483f6Sopenharmony_ci    EXPORT static std::string GetExtensionFromPath(const std::string &path);
563e5483f6Sopenharmony_ci    EXPORT static std::string GetFileNameFromPath(const std::string &path);
573e5483f6Sopenharmony_ci    EXPORT static std::string GetFileNameFromPathOrUri(const std::string &path, bool &isTitle);
583e5483f6Sopenharmony_ci    EXPORT static std::string GetBaseNameFromPath(const std::string &path);
593e5483f6Sopenharmony_ci    EXPORT static int32_t OpenFile(const std::string &filePath, const std::string &mode);
603e5483f6Sopenharmony_ci    EXPORT static int32_t OpenVibrateFile(const std::string &filePath, const std::string &mode);
613e5483f6Sopenharmony_ci    EXPORT static int32_t CreateFile(const std::string &filePath);
623e5483f6Sopenharmony_ci    EXPORT static bool IsSameFile(const std::string &srcPath, const std::string &dstPath);
633e5483f6Sopenharmony_ci    EXPORT static bool IsFileExists(const std::string &fileName);
643e5483f6Sopenharmony_ci    EXPORT static bool DeleteFile(const std::string &fileName);
653e5483f6Sopenharmony_ci    EXPORT static bool MoveFile(const std::string &oldPath, const std::string &newPath);
663e5483f6Sopenharmony_ci    EXPORT static bool CopyFileUtil(const std::string &filePath, const std::string &newPath);
673e5483f6Sopenharmony_ci    EXPORT static int32_t RemoveDirectory(const std::string &path);
683e5483f6Sopenharmony_ci    EXPORT static bool Mkdir(const std::string &subStr, std::shared_ptr<int> errCodePtr = nullptr);
693e5483f6Sopenharmony_ci    EXPORT static bool IsDirectory(const std::string &dirName, std::shared_ptr<int> errCodePtr = nullptr);
703e5483f6Sopenharmony_ci    EXPORT static bool CreateDirectory(const std::string &dirPath, std::shared_ptr<int> errCodePtr = nullptr);
713e5483f6Sopenharmony_ci    EXPORT static std::string UrlDecode(const std::string &url);
723e5483f6Sopenharmony_ci    EXPORT static void CreateRingtoneDir();
733e5483f6Sopenharmony_ci    EXPORT static int32_t CreatePreloadFolder(const std::string &path);
743e5483f6Sopenharmony_ci    EXPORT static int32_t MoveDirectory(const std::string &srcDir, const std::string &dstDir);
753e5483f6Sopenharmony_ci    EXPORT static void AccessRingtoneDir();
763e5483f6Sopenharmony_ci    EXPORT static std::string GetFileExtension(const std::string &path);
773e5483f6Sopenharmony_ci};
783e5483f6Sopenharmony_ci} // namespace Media
793e5483f6Sopenharmony_ci} // namespace OHOS
803e5483f6Sopenharmony_ci
813e5483f6Sopenharmony_ci#endif // RINGTONE_FILE_UTILS_H
82