• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef STAGE_CONTEXT_H
17 #define STAGE_CONTEXT_H
18 
19 #include <string>
20 #include <vector>
21 #include <optional>
22 #include <map>
23 
24 namespace Json {
25     class Value;
26 }
27 
28 namespace OHOS::Ide {
29 class StageContext {
30 public:
31     static StageContext& GetInstance();
32     const std::optional<std::vector<uint8_t>> ReadFileContents(const std::string& filePath) const;
33     // for Previewer
34     void SetLoaderJsonPath(const std::string& assetPath);
35     void GetModulePathMapFromLoaderJson();
36     std::string GetHspAceModuleBuild(const std::string& hspConfigPath);
37     void ReleaseHspBuffers();
38     std::map<std::string, std::string> ParseMockJsonFile(const std::string& mockJsonFilePath);
39     // for ArkUI and Ability
40     std::vector<uint8_t>* GetModuleBuffer(const std::string& inputPath);
41     std::vector<uint8_t>* GetLocalModuleBuffer(const std::string& moduleName);
42     std::vector<uint8_t>* GetCloudModuleBuffer(const std::string& moduleName);
43     std::vector<uint8_t>* GetModuleBufferFromHsp(const std::string& hspFilePath,
44         const std::string& fileName);
45 private:
46     StageContext() = default;
47     ~StageContext() = default;
48     bool ContainsRelativePath(const std::string& path) const;
49     std::map<std::string, std::string> GetModulePathMap() const;
50     std::string GetCloudHspPath(const std::string& hspDir, const std::string& moduleName);
51     std::string ReplaceLastStr(const std::string& str, const std::string& find, const std::string& replace);
52     int GetHspActualName(const std::string& input, std::string& ret);
53     std::string GetActualCloudHspDir(const std::string& actualName);
54     std::string GetCloudModuleHspPath(const std::string& actualName);
55     std::string GetCloudProjectHspPath(const std::string& actualName);
56     std::string GetCloudHspVersion(const std::string& hspPath, const std::string& actualName);
57     std::vector<int> SplitHspVersion(const std::string& version);
58     int CompareHspVersion(const std::string& version1, const std::string& version2);
59     std::string loaderJsonPath;
60     std::map<std::string, std::string> modulePathMap;
61     std::map<std::string, std::string> harNameOhmMap;
62     std::string projectRootPath;
63     std::vector<std::vector<uint8_t>*> hspBufferPtrsVec;
64     int GetUpwardDirIndex(const std::string& path, const int upwardLevel) const;
65     std::string localBundleName = "bundle";
66 };
67 }
68 #endif // STAGE_CONTEXT_H