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
24 namespace OHOS::Ace {
25
26 std::string GetStringFromFile(const std::string& packagePathStr, const std::string& fileName);
27 std::string GetStringFromHap(const std::string& hapPath, const std::string& fileName);
28 bool GetIsArkFromConfig(const std::string& packagePathStr, bool isHap);
29
30 RefPtr<FlutterAssetProvider> CreateAssetProvider(const std::string& packagePath,
31 const std::vector<std::string>& assetBasePaths);
32
GenerateFullPath(const std::string & prePath,const std::string & postPath)33 inline const std::string GenerateFullPath(const std::string& prePath, const std::string& postPath)
34 {
35 if (prePath.empty() && postPath.empty()) {
36 return "";
37 }
38 std::string tmpPostPath = postPath;
39 if (tmpPostPath.back() == '/') {
40 tmpPostPath.pop_back();
41 }
42 std::string fullPath = prePath;
43 if (fullPath.empty() || fullPath.back() == '/') {
44 fullPath += tmpPostPath;
45 } else {
46 fullPath += "/" + tmpPostPath;
47 }
48 return fullPath;
49 }
50 } // namespace OHOS::Ace
51
52 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_ENTRANCE_UTILS_H
53