1 /*
2 * Copyright (c) 2023 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 #include "rosen_asset_manager.h"
17
18 namespace OHOS::Ace {
GetAsset(const std::string & assetName)19 RefPtr<Asset> RSAssetManager::GetAsset(const std::string& assetName)
20 {
21 if (assetName.empty()) {
22 LOGE("GetAsset assetName is empty");
23 return nullptr;
24 }
25
26 for (const auto& provider : providers_) {
27 auto fileProvider = AceType::DynamicCast<RSAssetProvider>(provider);
28 if (fileProvider == nullptr) {
29 continue;
30 }
31
32 auto asset = fileProvider->GetAsset(assetName);
33 if (asset == nullptr) {
34 continue;
35 }
36
37 return asset;
38 }
39
40 LOGW("find asset failed, assetName = %{public}s", assetName.c_str());
41 return nullptr;
42 }
43
GetAssetPath(const std::string & assetName,bool isAddHapPath)44 std::string RSAssetManager::GetAssetPath(const std::string& assetName, bool isAddHapPath)
45 {
46 for (const auto& provider : providers_) {
47 std::string path = provider->GetAssetPath(assetName, isAddHapPath);
48 if (!path.empty()) {
49 return path;
50 }
51 }
52
53 return "";
54 }
55
GetAssetList(const std::string & path,std::vector<std::string> & assetList) const56 void RSAssetManager::GetAssetList(const std::string& path, std::vector<std::string>& assetList) const
57 {
58 for (const auto& provider : providers_) {
59 provider->GetAssetList(path, assetList);
60 }
61 }
62
GetFileInfo(const std::string & fileName,MediaFileInfo & fileInfo) const63 bool RSAssetManager::GetFileInfo(const std::string& fileName, MediaFileInfo& fileInfo) const
64 {
65 for (const auto& provider : providers_) {
66 if (provider->GetFileInfo(fileName, fileInfo)) {
67 return true;
68 }
69 }
70 return false;
71 }
72
73 } // namespace OHOS::Ace
74