summaryrefslogtreecommitdiff
path: root/src/Manager/InstallerManager.cpp
blob: 723fbac47821bf2a747f722525f9d6f4d6ac71b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
//
// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/**
 * @file	InstallerManager.cpp
 * @brief	This is the implementation file for %InstallerManager class.
 */

#include <unistd.h>

#include <FIoFile.h>
#include <FIoDirectory.h>
#include <FBase_StringConverter.h>
#include <FAppPkg_PackageInfoImpl.h>

#include "InstallerManager.h"
#include "GuestInstaller.h"
#include "IDEInstaller.h"
#include "PreloadedInstaller.h"
#include "RestorationInstaller.h"
#include "InstallerUtil.h"

using namespace Tizen::Base;
using namespace Tizen::Base::Utility;
using namespace Tizen::Base::Collection;
using namespace Tizen::Io;
using namespace Tizen::App::Package;

const int BUFSIZE = 512;
InstallerManager* InstallerManager::__pInstallerManager = null;

InstallerManager::InstallerManager(void)
:__pContext(null)
,__pInstaller(null)
,__errorType(0)
,__operation(INSTALLER_OPERATION_INSTALL)
{
}

InstallerManager::~InstallerManager(void)
{
	delete __pContext;
	__pContext = null;

	delete __pInstaller;
	__pInstaller = null;
}

InstallerManager*
InstallerManager::GetInstance()
{
	if (__pInstallerManager == null)
	{
		__pInstallerManager = new InstallerManager();
		TryReturn(__pInstallerManager, null, "[osp-installer] __pInstallerManager is null");
	}

	return __pInstallerManager;
}

InstallerError
InstallerManager::Construct(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService)
{
	InstallerError error = INSTALLER_ERROR_NONE;
	InstallerType installerType = INSTALLER_TYPE_INSTALLER;
	result r = E_SUCCESS;

	__pContext = new InstallationContext();
	TryReturn(__pContext, INSTALLER_ERROR_MEMORY, "[osp-installer] __pContext is null.");

	error = __pContext->Construct();
	TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pContext->Construct() failed.");

	// 1. operation
	if (operation == INSTALLER_OPERATION_INSTALL)
	{
		FileAttributes attr;
		r = File::GetAttributes(path, attr);
		TryReturn(!IsFailed(r), INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] File::GetAttributes() failed");

		if (attr.IsDirectory())
		{
			installerType = INSTALLER_TYPE_DIRECTORY;
			if (path.StartsWith(PATH_USR_APPS, 0) == true)
			{
				installerType = INSTALLER_TYPE_PRELOADED;
			}

			__pContext->SetInputPath(path);
			__pContext->SetInstallDir(path);
		}
		else
		{
			installerType = INSTALLER_TYPE_PACKAGE;
			__pContext->SetPackagePath(path);
		}

		// org.tizen.*
		if (path.Contains(PACKAGE_NAME_PREFIX_ORG) == true)
		{
			__pContext->SetPackageNameType(INSTALLER_PREFIX_TYPE_ORG);
		}
	}
	else if (operation == INSTALLER_OPERATION_UNINSTALL)
	{
		installerType = INSTALLER_TYPE_INSTALLER;

		AppLogTag(OSP_INSTALLER, "operation is INSTALLER_OPERATION_UNINSTALL");
		__pContext->SetCurrentInstallationStep(INSTALLER_STEP_INIT_UNINSTALL);
		__pContext->SetAppId(path);
	}

	__pContext->SetInstallerOperation(operation);

	// 2. requesterType
	if (requesterType == REQUESTER_TYPE_PRELOADED)
	{
		__pContext->SetPreloaded(true);
	}

	// 3. hybridService
	if (hybridService == true)
	{
		AppLogTag(OSP_INSTALLER, "Request to install HybridService app!");
		__pContext->SetHybridService(true);
	}

	__pInstaller = CreateInstaller(installerType);
	TryReturn(__pInstaller, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller is null.");

	error = __pInstaller->Construct(__pContext);
	TryReturn(error == INSTALLER_ERROR_NONE, INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] __pInstaller->Construct() failed");

	return error;
}

void
InstallerManager::Release(void)
{
	delete __pInstallerManager;
	__pInstallerManager = null;
}

Installer*
InstallerManager::CreateInstaller(InstallerType installerType)
{
	Installer* pInstaller = null;

	switch (installerType)
	{
	case INSTALLER_TYPE_INSTALLER:
		AppLogTag(OSP_INSTALLER, "InstallerType = [Installer]");
		pInstaller = new Installer();
		break;

	case INSTALLER_TYPE_PACKAGE:
		AppLogTag(OSP_INSTALLER, "InstallerType = [PackageInstaller]");
		pInstaller = new PackageInstaller();
		break;

	case INSTALLER_TYPE_DIRECTORY:
		AppLogTag(OSP_INSTALLER, "InstallerType = [DirectoryInstaller]");
		pInstaller = new DirectoryInstaller();
		break;

	case INSTALLER_TYPE_GUEST:
		AppLogTag(OSP_INSTALLER, "InstallerType = [GuestInstaller]");
		pInstaller = new GuestInstaller();
		break;

	case INSTALLER_TYPE_PRELOADED:
		AppLogTag(OSP_INSTALLER, "InstallerType = [PreloadedInstaller]");
		pInstaller = new PreloadedInstaller();
		break;

	case INSTALLER_TYPE_IDE:
		AppLogTag(OSP_INSTALLER, "InstallerType = [IDEInstaller]");
		pInstaller = new IDEInstaller();
		break;

	case INSTALLER_TYPE_RESTORATION:
		AppLogTag(OSP_INSTALLER, "InstallerType = [RestorationInstaller]");
		pInstaller = new RestorationInstaller();
		break;

	default:
		AppLogExceptionTag(OSP_INSTALLER, "Installer is not found.");
		break;
	}

	return pInstaller;
}

InstallationStep
InstallerManager::GetNext(void)
{
	InstallationStep step = __pContext->GetCurrentInstallationStep();
	return __pInstaller->GetNext(step);
}

InstallerError
InstallerManager::Init(void)
{
	return __pInstaller->OnInit();
}

InstallerError
InstallerManager::Error(void)
{
	return __pInstaller->OnError();
}

InstallerError
InstallerManager::Register(void)
{
	return __pInstaller->OnRegister();
}

InstallerError
InstallerManager::End(void)
{
	return __pInstaller->OnEnd();
}

InstallerError
InstallerManager::Rollback(void)
{
	return __pInstaller->OnRollback();
}

InstallerError
InstallerManager::UserCancel(void)
{
	return __pInstaller->OnUserCancel();
}

InstallerError
InstallerManager::Activate(void)
{
	InstallerError error = INSTALLER_ERROR_NONE;
	IInstallationStep* pStep = null;
	InstallationStep currentStep;

	while (__pContext->GetState() == INSTALLER_STATE_RUNNING)
	{
		currentStep = GetNext();
		__pContext->ChangeStep(currentStep);

		pStep = __pContext->GetStep();
		if (pStep)
		{
			error = pStep->Run(__pContext);

			if (error != INSTALLER_ERROR_NONE)
			{
				__pContext->SetError(error);
				fprintf(stderr, "Activate:: Error = [%d]\n", error);
				Error();
				return error;
			}
		}

		if (currentStep == INSTALLER_STEP_INIT)
		{
			error = Init();
			TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred.");
		}
		else if (currentStep == INSTALLER_STEP_END)
		{
			error = Register();
			TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred.");

			error = End();
			TryReturn(error == INSTALLER_ERROR_NONE, error, "[osp-installer] error is occurred.");
		}

		if (__pContext->IsContinue() == false)
		{
			break;
		}

		if (__pContext->GetCurrentInstallationStep() >= INSTALLER_STEP_MAX)
		{
			break;
		}
	}

	return error;
}

InstallerError
InstallerManager::Progress(void)
{
	return INSTALLER_ERROR_NONE;
}

InstallationContext*
InstallerManager::GetContext(void)
{
	return __pContext;
}

int
InstallerManager::Request(const String& path, InstallerOperation operation, RequesterType requesterType, bool hybridService)
{
	InstallationContext* pContext = null;
	InstallerError errorType = INSTALLER_ERROR_NONE;
	InstallerManager* pInstallManager = null;
	String appId;

	AppLogTag(OSP_INSTALLER, "------------------------------------------");
	AppLogTag(OSP_INSTALLER, "InstallerManager::Request");
	AppLogTag(OSP_INSTALLER, "------------------------------------------");
	AppLogTag(OSP_INSTALLER, " # operation = [%s]", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation");
	AppLogTag(OSP_INSTALLER, " # path      = [%ls]", path.GetPointer());
	AppLogTag(OSP_INSTALLER, "------------------------------------------");

	SetInstallerOperation(operation);

	pInstallManager = InstallerManager::GetInstance();
	TryCatch(pInstallManager, errorType = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pInstallManager is null.");

	errorType = pInstallManager->Construct(path, operation, requesterType, hybridService);
	TryCatch(errorType == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Construct() failed.");

	errorType = pInstallManager->Activate();
	TryCatch(errorType == INSTALLER_ERROR_NONE, , "[osp-installer] pInstallManager->Activate() failed.");

	pContext = pInstallManager->GetContext();
	TryCatch(pContext, errorType = INSTALLER_ERROR_INTERNAL_STATE, "[osp-installer] pContext is null.");

	appId = pContext->GetAppId();
	SetAppId(appId);

CATCH:
	if (File::IsFileExist(DIR_OSP_APPLICATIONS_TEMP) == true)
	{
		InstallerUtil::Remove(DIR_OSP_APPLICATIONS_TEMP);
	}

	if (errorType != INSTALLER_ERROR_NONE)
	{
		fprintf(stderr, " ErrorType [%d]\n", errorType);
	}

	SetErrorType(errorType);
	return errorType;
}

int
InstallerManager::RequestRecursiveDirectory(const Tizen::Base::String& path, int& errorType)
{
	Directory* pDir = null;
	DirEnumerator* pDirEnum = null;
	result r = E_SUCCESS;
	int res = false;
	String appid;
	InstallerError error = INSTALLER_ERROR_NONE;
	int totalCount = 0;
	int successCount = 0;
	int failureCount = 0;

	pDir = new Directory; // Allocate %Directory instance
	TryCatch(pDir, res = false, "[osp-installer] pDir is null");

	r = pDir->Construct(path);
	TryCatch(!IsFailed(r), res = false, "[osp-installer] pDir->Construct() failed, path = [%ls]", path.GetPointer());

	pDirEnum = pDir->ReadN();
	TryCatch(pDirEnum, res = false, "[osp-installer] pDirEnum is null");

	while (pDirEnum->MoveNext() == E_SUCCESS)
	{
		DirEntry entry = pDirEnum->GetCurrentDirEntry();

		String entryName = entry.GetName();
		String entryDir = path;
		entryDir += L"/";
		entryDir += entryName;

		if (entryName == L"." || entryName == L"..")
		{
			continue;
		}

		if (entry.IsDirectory() == false)
		{
			continue;
		}

		const int entryLength = entryName.GetLength();
		if (entryLength == APPID_LENGTH)
		{
			// AppId
		}
		else if (entryLength == APP_DIR_LENGTH)
		{
			if (entryName.Contains(PACKAGE_NAME_PREFIX_ORG) == false)
			{
				fprintf(stderr, " - Not osp = [%ls]: prefix mismatch\n", entryDir.GetPointer());
				continue;
			}
		}
		else
		{
			fprintf(stderr, " - Not osp = [%ls]: length(%d) mismatch\n", entryDir.GetPointer(), entryLength);
			continue;
		}

		String xmlFile;
		xmlFile.Format(1024, L"%ls%ls", entryDir.GetPointer(), PACKAGE_XML_FILE);

		FileAttributes attr;
		r = File::GetAttributes(xmlFile, attr);
		if (IsFailed(r))
		{
			fprintf(stderr, " - Not osp = [%ls]: No manifest.xml\n", entryDir.GetPointer());
			continue;
		}

		totalCount++;

		fprintf(stderr, "------------------------------------------\n");
		AppLogTag(OSP_INSTALLER, "------------------------------------------");

		fprintf(stderr, " # directory = [%ls]\n", entryDir.GetPointer());
		AppLogTag(OSP_INSTALLER, " # directory = [%ls]", entryDir.GetPointer());

		errorType = Request(entryDir, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_PRELOADED);
		if (errorType == 0)
		{
			successCount++;
		}
		else
		{
			failureCount++;
		}

		PrintResult();

		fprintf(stderr, "------------------------------------------\n");
		AppLogTag(OSP_INSTALLER, "------------------------------------------");
	}

	fprintf(stderr, "------------------------------------------\n");
	fprintf(stderr, "recursive directory installation\n");
	fprintf(stderr, " # totalCount   = [%d]\n", totalCount);
	fprintf(stderr, " # successCount = [%d]\n", successCount);
	fprintf(stderr, " # failureCount = [%d]\n", failureCount);

CATCH:
	delete pDirEnum;
	delete pDir;
	return error;
}

int
InstallerManager::RequestByCommand(int argc, char **argv)
{
	int mode = 0;
	char buf[BUFSIZE] = {0};
	// String appId;
	int errorType = 0;
	bool output = false;
	bool hybridService = false;

	fprintf(stderr, " # argc = [%d]\n", argc);
	AppLogTag(OSP_INSTALLER, " # argc = [%d]", argc);

	for (int i = 0; i < argc; i++)
	{
		fprintf(stderr, " # argv[%d] = [%s]\n", i, argv[i]);
		AppLogTag(OSP_INSTALLER, " # argv[%d] = [%s]", i, argv[i]);
	}

	ParseCommandArg(argc, argv, &mode, buf, &output);

	if (output == true)
	{
		AppLogTag(OSP_INSTALLER, "HybridService is detected in ParseCommandArg()");
		hybridService = true;
	}

	switch (mode)
	{
	case INSTALLER_MODE_INSTALL:
		{
			fprintf(stderr, "------------------------------------------\n");
			AppLogTag(OSP_INSTALLER, "------------------------------------------");
			fprintf(stderr, " # directory = [%s]\n", buf);
			AppLogTag(OSP_INSTALLER, " # directory = [%s]", buf);

			errorType = Request(buf, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL, hybridService);
			if (errorType != 0)
			{
				// in case of command, garbage directory is not deleted.
				// RemoveGarbage(buf);
			}
			PrintResult();
		}
		break;

	case INSTALLER_MODE_UNINSTALL:
		{
			fprintf(stderr, "------------------------------------------\n");
			AppLogTag(OSP_INSTALLER, "------------------------------------------");
			fprintf(stderr, " # directory = [%s]\n", buf);
			AppLogTag(OSP_INSTALLER, " # directory = [%s]", buf);

			errorType = Request(buf, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL, hybridService);
			PrintResult();
		}
		break;

	case INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL:
		{
			fprintf(stderr, "------------------------------------------\n");
			AppLogTag(OSP_INSTALLER, "------------------------------------------");

			errorType = RequestRecursiveDirectory(buf, errorType);
		}
		break;

	default:
		{
			fprintf(stderr, "__install_package_by_cmd, Invalid mode\n");
		}
		break;
	}

	fprintf(stderr, "==========================================\n");

	if (output == true)
	{
		AppLogTag(OSP_INSTALLER, "stdout is updated by errorType");
		fprintf(stdout, "%d", errorType);
	}

	return errorType;
}

int
InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output)
{
	const char* pOpts_str = "u:i:r:v";
	int s = 0;

	if (mode == NULL)
	{
		fprintf(stderr, "mode is null\n");
		exit(-1);
	}

	*mode = 0;

	while (1)
	{
		s = getopt(argc, argv, pOpts_str);

		if (s == -1)
		{
			break;
		}

		switch (s)
		{
		case 'i':
			if (*mode)
			{
				break;
			}

			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: i");
			*mode = INSTALLER_MODE_INSTALL;
			if (optarg[0] == 'v')
			{
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v");
				*output = true;
				strncpy(buf, argv[optind++], BUFSIZE);
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf);
			}
			else
			{
				strncpy(buf, optarg, BUFSIZE);
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg);
			}
			break;

		case 'u':
			if (*mode)
			{
				break;
			}

			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: u");
			*mode = INSTALLER_MODE_UNINSTALL;
			if (optarg[0] == 'v')
			{
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v");
				*output = true;
				strncpy(buf, argv[optind++], BUFSIZE);
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: buf = [%s]", buf);
			}
			else
			{
				strncpy(buf, optarg, BUFSIZE);
				AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg);
			}
			break;

		case 'r':
			if (*mode)
			{
				break;
			}

			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: r");
			*mode = INSTALLER_MODE_RECURSIVE_DIRECTORY_INSTALL;
			strncpy(buf, optarg, BUFSIZE);
			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg);
			break;

		case 'v':
			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: v");
			*output = true;
			AppLogTag(OSP_INSTALLER, "__osp_installer_parse_options: optarg = [%s]", optarg);
			break;

		default:
			fprintf(stderr, "Invalid option\n");
			exit(-1);
			break;
		}
	}

	if (mode == 0)
	{
		fprintf(stderr, "Invalid mode\n");
		exit(-1);
	}

	return 0;
}

bool
InstallerManager::RemoveGarbage(const String& filePath)
{
	AppLogTag(OSP_INSTALLER, "RemoveGarbage Directory = [%ls]", filePath.GetPointer());

	String realPath;
	if (InstallerUtil::IsSymlink(filePath) == true)
	{
		if (InstallerUtil::GetRealPath(filePath, realPath) == true)
		{
			InstallerUtil::Remove(realPath);
		}
	}

	InstallerUtil::Remove(filePath);

	return true;
}

int
InstallerManager::ReqeustByTest(void)
{
	int errorType = 0;
	String appId;
	Tizen::Io::File file;
	Tizen::Io::FileAttributes attr;
	result r = E_SUCCESS;
	char readBuf[512] = {0};

	r = File::GetAttributes(L"/opt/apps/cmtamb4mtv/data/configuration", attr);
	TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] file not found");

	r = file.Construct(L"/opt/apps/cmtamb4mtv/data/configuration", L"r");
	TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INVALID_PACKAGE, "[osp-installer] file.Construct failed");

	if (file.Read(readBuf, sizeof(readBuf)-1) > 1)
	{
		String path;
		path.Format(1024, L"%s", &readBuf[1]);

		if (readBuf[0] == '+')
		{
			errorType = Request(path, INSTALLER_OPERATION_INSTALL, REQUESTER_TYPE_NORMAL);
		}
		else if (readBuf[0] == '-')
		{
			errorType = Request(path, INSTALLER_OPERATION_UNINSTALL, REQUESTER_TYPE_NORMAL);
		}
		else if (readBuf[0] == '*')
		{
			errorType = RequestRecursiveDirectory(path, errorType);
		}
	}

CATCH:
	return errorType;
}

void
InstallerManager::PrintPackageInfo(const char* appId)
{
	_PackageInfoImpl* pPackageInfoImpl = null;
	ArrayList* pAppList = null;
	int totalCount = 0;

	pPackageInfoImpl = new (std::nothrow) _PackageInfoImpl;
	if (pPackageInfoImpl == null)
	{
		return;
	}

	pPackageInfoImpl->Construct(appId);

	AppLogTag(OSP_INSTALLER, "------------------------------------------");
	AppLogTag(OSP_INSTALLER, "PackageInfo");
	AppLogTag(OSP_INSTALLER, "------------------------------------------");
	AppLogTag(OSP_INSTALLER, "# id = [%S]",  pPackageInfoImpl->GetAppId().GetPointer());
	AppLogTag(OSP_INSTALLER, "# version = [%S]", pPackageInfoImpl->GetAppVersion().GetPointer());
	AppLogTag(OSP_INSTALLER, "# secret = [%S]", pPackageInfoImpl->GetAppSecret().GetPointer());
	AppLogTag(OSP_INSTALLER, "# name = [%S]", pPackageInfoImpl->GetAppName().GetPointer());
	AppLogTag(OSP_INSTALLER, "# vendor = [%S]", pPackageInfoImpl->GetAppVendor().GetPointer());
	AppLogTag(OSP_INSTALLER, "# description = [%S]", pPackageInfoImpl->GetAppDescription().GetPointer());
	AppLogTag(OSP_INSTALLER, "# mimeType = [%S]", pPackageInfoImpl->GetAppMimeType().GetPointer());
	AppLogTag(OSP_INSTALLER, "# api version = [%S]", pPackageInfoImpl->GetAppApiVersion().GetPointer());
	AppLogTag(OSP_INSTALLER, "# uri = [%S]", pPackageInfoImpl->GetAppUrl().GetPointer());
	AppLogTag(OSP_INSTALLER, "# cid = [%S]",  pPackageInfoImpl->GetAppCid().GetPointer());
	AppLogTag(OSP_INSTALLER, "# parentId = [%S]", pPackageInfoImpl->GetAppParentId().GetPointer());
	AppLogTag(OSP_INSTALLER, "# installationDate = [%S]", pPackageInfoImpl->GetAppInstallationTime().ToString().GetPointer());
	AppLogTag(OSP_INSTALLER, "# rootpath = [%S]", pPackageInfoImpl->GetAppRootPath().GetPointer());
	AppLogTag(OSP_INSTALLER, "# readOnlySize = [%d]", pPackageInfoImpl->GetAppReadOnlySize());
	AppLogTag(OSP_INSTALLER, "# dataSize = [%d]", pPackageInfoImpl->GetAppDataSize());
	AppLogTag(OSP_INSTALLER, "# storageType = [%d]", pPackageInfoImpl->GetAppStorageType());
	AppLogTag(OSP_INSTALLER, "# state = [%d]", pPackageInfoImpl->GetAppState());
	AppLogTag(OSP_INSTALLER, "# initiator = [%d]", pPackageInfoImpl->GetAppInitiatior());
	AppLogTag(OSP_INSTALLER, "------------------------------------------");

	pAppList = pPackageInfoImpl->GetAppInfoListN();
	if (pAppList == null)
	{
		delete pPackageInfoImpl;
		return;
	}

	totalCount = pAppList->GetCount();

	for (int i = 0; i < totalCount; i++)
	{
		_PackageAppInfoImpl* pAppInfoImpl = dynamic_cast<_PackageAppInfoImpl*>(pAppList->GetAt(i));

		AppLogTag(OSP_INSTALLER, "------------------------------------------");
		AppLogTag(OSP_INSTALLER, "AppInfo(%d/%d)", i+1, totalCount);
		AppLogTag(OSP_INSTALLER, "------------------------------------------");
		AppLogTag(OSP_INSTALLER, "# default = [%S]", pAppInfoImpl->GetDefault().GetPointer());
		AppLogTag(OSP_INSTALLER, "# appname = [%S]", pAppInfoImpl->GetName().GetPointer());
		AppLogTag(OSP_INSTALLER, "# packagename = [%S]", pAppInfoImpl->GetPackageName().GetPointer());
		AppLogTag(OSP_INSTALLER, "# mainmenu icon = [%S]", pAppInfoImpl->GetMainmenuIcon().GetPointer());
		AppLogTag(OSP_INSTALLER, "# setting icon = [%S]", pAppInfoImpl->GetSettingIcon().GetPointer());
		AppLogTag(OSP_INSTALLER, "# ticker icon = [%S]", pAppInfoImpl->GetTickerIcon().GetPointer());
		AppLogTag(OSP_INSTALLER, "# quickpanel icon = [%S]", pAppInfoImpl->GetQuickpanelIcon().GetPointer());
		AppLogTag(OSP_INSTALLER, "# launchImage icon = [%S]", pAppInfoImpl->GetLaunchImageIcon().GetPointer());
		AppLogTag(OSP_INSTALLER, "------------------------------------------");
	}

	pAppList->RemoveAll();
	delete pAppList;
	pAppList = null;

	delete pPackageInfoImpl;
}

void
InstallerManager::PrintResult(void)
{
	String appId = GetAppId();
	int errorType = GetErrorType();
	InstallerOperation operation = GetInstallerOperation();

	AppLogTag(OSP_INSTALLER, "==========================================");
	AppLogTag(OSP_INSTALLER, "%s Result", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation");
	AppLogTag(OSP_INSTALLER, " # %s", OSP_INSTALLER_VERSION);
	AppLogTag(OSP_INSTALLER, " # AppId     = [%ls], errorType = [%d]", appId.GetPointer(), errorType);
	AppLogTag(OSP_INSTALLER, " # result    = [%s]", (errorType == 0)?"Success":"Failure");
	AppLogTag(OSP_INSTALLER, "==========================================");

	fprintf(stderr, " # AppId     = [%ls], errorType = [%d]\n", appId.GetPointer(), errorType);
	fprintf(stderr, " # operation = [%s]\n", (operation == INSTALLER_OPERATION_INSTALL)?"Installation":"Uninstallation");
	fprintf(stderr, " # result    = [%s]\n", (errorType == 0)?"Success":"Failure");
}

const String&
InstallerManager::GetAppId(void) const
{
	return __appId;
}

void
InstallerManager::SetAppId(const String& appId)
{
	__appId = appId;
}

int
InstallerManager::GetErrorType(void) const
{
	return __errorType;
}

void
InstallerManager::SetErrorType(int errorType)
{
	__errorType = errorType;
}

void
InstallerManager::SetInstallerOperation(InstallerOperation op)
{
	__operation = op;
}

InstallerOperation
InstallerManager::GetInstallerOperation(void) const
{
	return __operation;
}