remove app profile data when app is updated
[platform/core/dotnet/launcher.git] / NativeLauncher / installer-plugin / dotnet_apptype_plugin.cc
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "log.h"
18 #include "utils.h"
19 #include "multi_target_resolver.h"
20 #include "ni_common.h"
21
22 #include <vector>
23
24 #ifdef  LOG_TAG
25 #undef  LOG_TAG
26 #endif
27 #define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
28
29 typedef struct _xmlDoc xmlDoc;
30 typedef xmlDoc* xmlDocPtr;
31
32 bool pluginInstalled = false;
33
34 extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
35 {
36         // Can be multiple apps in one package
37         if (pluginInstalled) {
38                 _INFO("Plugin already installed");
39                 return 0;
40         }
41         pluginInstalled = true;
42
43         std::string appType = getAppType(pkgId);
44         if (appType.empty()) {
45                 _ERR("Failed to get app type from [%s]", pkgId);
46                 return 0;
47         }
48
49         if (appType.find("dotnet") == std::string::npos) {
50                 return 0;
51         }
52
53         std::string rootPath = getRootPath(pkgId);
54         if (rootPath.empty()) {
55                 _ERR("Failed to get root path from [%s]", pkgId);
56                 return 0;
57         }
58
59         if (removeAppProfileData(pkgId) != NI_ERROR_NONE) {
60                 _ERR("Failed to remove [%s] profile data", pkgId);
61         }
62
63         if (resolvePlatformSpecificFiles(rootPath) != 0) {
64                 _ERR("Failed to resolve platform specific resources of nuget");
65         }
66
67         return 0;
68 }
69 extern "C" int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId)
70 {
71         return PKGMGR_PARSER_PLUGIN_INSTALL(doc, pkgId);
72 }
73 extern "C" int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId)
74 {
75         return 0;
76 }
77 extern "C" int PKGMGR_PARSER_PLUGIN_REMOVED(xmlDocPtr doc, const char* pkgId)
78 {
79         return 0;
80 }
81 extern "C" int PKGMGR_PARSER_PLUGIN_CLEAN(xmlDocPtr doc, const char* pkgId)
82 {
83         return 0;
84 }
85 extern "C" int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc, const char* pkgId)
86 {
87         return 0;
88 }
89 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId)
90 {
91         return 0;
92 }
93 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId)
94 {
95         return 0;
96 }
97 extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId)
98 {
99         return 0;
100 }
101 extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId)
102 {
103         return 0;
104 }
105 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId)
106 {
107         return 0;
108 }
109 extern "C" int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId)
110 {
111         return 0;
112 }