1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
13 #include "base/at_exit.h"
14 #include "base/files/file_util.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h"
17 #include "xwalk/application/common/id_util.h"
18 #include "xwalk/application/common/tizen/application_storage.h"
19 #include "xwalk/application/tools/tizen/xwalk_package_installer.h"
20 #include "xwalk/application/tools/tizen/xwalk_tizen_user.h"
21 #include "xwalk/runtime/common/xwalk_paths.h"
23 using xwalk::application::ApplicationData;
24 using xwalk::application::ApplicationStorage;
28 char* install_path = NULL;
29 char* uninstall_id = NULL;
30 char* reinstall_id = NULL;
31 char* operation_key = NULL;
34 gboolean continue_tasks = FALSE;
36 GOptionEntry entries[] = {
37 { "install", 'i', 0, G_OPTION_ARG_STRING, &install_path,
38 "Path of the application to be installed/updated", "PATH" },
39 { "uninstall", 'd', 0, G_OPTION_ARG_STRING, &uninstall_id,
40 "Uninstall the application with this pkgid", "ID" },
41 { "continue", 'c' , 0, G_OPTION_ARG_NONE, &continue_tasks,
42 "Continue the previous unfinished tasks", NULL},
43 { "reinstall", 'r', 0, G_OPTION_ARG_STRING, &reinstall_id,
44 "Reinstall the application with this pkgid "
45 "(This option is ONLY for SDK to support RDS mode"
46 " (Rapid Development Support)", "ID" },
47 { "key", 'k', 0, G_OPTION_ARG_STRING, &operation_key,
48 "Unique operation key", "KEY" },
49 { "quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet,
56 int main(int argc, char* argv[]) {
58 GOptionContext* context;
61 #if !GLIB_CHECK_VERSION(2, 36, 0)
62 // g_type_init() is deprecated on GLib since 2.36, Tizen has 2.32.
66 if (xwalk_tizen_check_user_for_xwalk_backend())
69 context = g_option_context_new("- Crosswalk Application Management");
71 g_print("g_option_context_new failed\n");
74 g_option_context_add_main_entries(context, entries, NULL);
75 if (!g_option_context_parse(context, &argc, &argv, &error)) {
76 g_print("option parsing failed: %s\n", error->message);
77 g_option_context_free(context);
81 g_option_context_free(context);
83 base::AtExitManager at_exit;
84 base::FilePath data_path;
85 xwalk::RegisterPathProvider();
86 PathService::Get(xwalk::DIR_DATA_PATH, &data_path);
87 scoped_ptr<ApplicationStorage> storage(new ApplicationStorage(data_path));
88 scoped_ptr<PackageInstaller> installer =
89 PackageInstaller::Create(storage.get());
91 installer->SetQuiet(static_cast<bool>(quiet));
93 installer->SetInstallationKey(operation_key);
96 g_print("trying to continue previous unfinished tasks.\n");
97 installer->ContinueUnfinishedTasks();
99 g_print("Previous tasks have been finished.\n");
104 const base::FilePath& path =
105 base::MakeAbsoluteFilePath(base::FilePath(install_path));
106 success = installer->Install(path, &app_id);
107 if (!success && !app_id.empty() && storage->Contains(app_id)) {
108 g_print("trying to update %s\n", app_id.c_str());
109 success = installer->Update(app_id, path);
111 } else if (uninstall_id) {
112 success = installer->Uninstall(uninstall_id);
113 } else if (reinstall_id) {
114 success = installer->Reinstall(reinstall_id);
116 return success ? 0 : 1;