1 /*
2  * Copyright (c) 2021-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 FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H
17 #define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H
18 
19 #include <string>
20 
21 #include "base/log/log.h"
22 #include "base/geometry/rect.h"
23 #include "core/common/asset_manager_impl.h"
24 #include "core/components_ng/property/safe_area_insets.h"
25 
26 namespace OHOS::Rosen {
27     class AvoidArea;
28     struct DMRect;
29 }
30 namespace OHOS::Ace {
31 
32 std::string GetStringFromFile(const std::string& packagePathStr, const std::string& fileName);
33 std::string GetStringFromHap(const std::string& hapPath, const std::string& fileName);
34 bool CheckUrlValid(const std::string& url, const std::string& hapPath);
35 
36 RefPtr<AssetProviderImpl> CreateAssetProviderImpl(
37     const std::string& packagePath, const std::vector<std::string>& assetBasePaths, bool useCache = true);
38 
GenerateFullPath(const std::string & prePath,const std::string & postPath)39 inline const std::string GenerateFullPath(const std::string& prePath, const std::string& postPath)
40 {
41     if (prePath.empty() && postPath.empty()) {
42         return "";
43     }
44     std::string tmpPostPath = postPath;
45     if (tmpPostPath.back() == '/') {
46         tmpPostPath.pop_back();
47     }
48     std::string fullPath = prePath;
49     if (fullPath.empty() || fullPath.back() == '/') {
50         fullPath += tmpPostPath;
51     } else {
52         fullPath += "/" + tmpPostPath;
53     }
54     return fullPath;
55 }
56 
57 NG::SafeAreaInsets ConvertAvoidArea(const OHOS::Rosen::AvoidArea& avoidArea);
58 Rect ConvertDMRect2Rect(const OHOS::Rosen::DMRect& displayAvailableRect);
59 } // namespace OHOS::Ace
60 
61 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H
62