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 "core/common/flutter/flutter_asset_manager.h"
23 #include "core/components_ng/property/safe_area_insets.h"
24
25 namespace OHOS::Rosen {
26 class AvoidArea;
27 }
28 namespace OHOS::Ace {
29
30 std::string GetStringFromFile(const std::string& packagePathStr, const std::string& fileName);
31 std::string GetStringFromHap(const std::string& hapPath, const std::string& fileName);
32
33 RefPtr<FlutterAssetProvider> CreateAssetProvider(
34 const std::string& packagePath, const std::vector<std::string>& assetBasePaths, bool useCache = true);
35
GenerateFullPath(const std::string & prePath,const std::string & postPath)36 inline const std::string GenerateFullPath(const std::string& prePath, const std::string& postPath)
37 {
38 if (prePath.empty() && postPath.empty()) {
39 return "";
40 }
41 std::string tmpPostPath = postPath;
42 if (tmpPostPath.back() == '/') {
43 tmpPostPath.pop_back();
44 }
45 std::string fullPath = prePath;
46 if (fullPath.empty() || fullPath.back() == '/') {
47 fullPath += tmpPostPath;
48 } else {
49 fullPath += "/" + tmpPostPath;
50 }
51 return fullPath;
52 }
53
54 NG::SafeAreaInsets ConvertAvoidArea(const OHOS::Rosen::AvoidArea& avoidArea);
55 } // namespace OHOS::Ace
56
57 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H
58