*/
#include <unistd.h>
+#include <unique_ptr.h>
+
+#include <app2ext_interface.h>
#include <FIoFile.h>
#include <FIoDirectory.h>
#include <FBase_StringConverter.h>
+#include <FAppPkgPackageInfo.h>
+#include <FAppPkg_PackageManagerImpl.h>
#include <FAppPkg_PackageInfoImpl.h>
#include <FSysSystemTime.h>
}
int
+InstallerManager::RequestMove(const PackageId& packageId, int moveType)
+{
+ result r = E_SUCCESS;
+ int res = 0;
+ InstallerError errorType = INSTALLER_ERROR_NONE;
+ app2ext_handle* pHandle = null;
+ app2ext_move_type location = APP2EXT_MOVE_TO_EXT;
+ GList* pDirectoryList = null;
+ Directory* pDir = null;
+ DirEnumerator* pDirEnum = null;
+ PackageInfo* pPackageInfo = null;
+ _PackageInfoImpl* pPackageInfoImpl = null;
+ String rootPath;
+
+ std::unique_ptr<char[]> pPackageId(_StringConverter::CopyToCharArrayN(packageId));
+ TryReturn(pPackageId, INSTALLER_ERROR_OUT_OF_MEMORY, "pPackageId is null");
+
+ if (moveType == PM_MOVE_TO_INTERNAL)
+ {
+ location = APP2EXT_MOVE_TO_PHONE;
+ }
+
+ pPackageInfo = _PackageManagerImpl::GetInstance()->GetPackageInfoN(packageId);
+ TryCatch(pPackageInfo != null, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetPackageInfoN() failed");
+
+ pPackageInfoImpl = _PackageInfoImpl::GetInstance(pPackageInfo);
+ TryCatch(pPackageInfoImpl, errorType = INSTALLER_ERROR_INTERNAL_STATE, "GetInstance() failed");
+
+ rootPath = pPackageInfoImpl->GetAppRootPath();
+
+ pDir = new (std::nothrow) Directory;
+ TryCatch(pDir, errorType = INSTALLER_ERROR_OUT_OF_MEMORY, "pDir is null");
+
+ r = pDir->Construct(rootPath);
+ TryCatch(!IsFailed(r), errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDir->Construct() failed, path = [%ls]", rootPath.GetPointer());
+
+ pDirEnum = pDir->ReadN();
+ TryCatch(pDirEnum, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirEnum is null");
+
+ while (pDirEnum->MoveNext() == E_SUCCESS)
+ {
+ DirEntry entry = pDirEnum->GetCurrentDirEntry();
+
+ String entryName = entry.GetName();
+ String rootDirectory = rootPath;
+ rootDirectory += L"/";
+ rootDirectory += entryName;
+
+ if (entryName == L"." || entryName == L"..")
+ {
+ continue;
+ }
+
+ int length = 0;
+ app2ext_dir_details* pDirDetails = null;
+
+ pDirDetails = (app2ext_dir_details*) calloc(1, sizeof(app2ext_dir_details));
+ TryCatch(pDirDetails, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pDirDetails is null");
+
+ length = rootDirectory.GetLength();
+ pDirDetails->name = (char*) calloc(1, (sizeof(char) * length) + 1);
+ snprintf(pDirDetails->name, length + 1, "%ls", rootDirectory.GetPointer());
+
+ String bin(L"bin");
+ String res(L"res");
+ String icons(L"icons");
+
+ if (rootDirectory.Contains(bin) || rootDirectory.Contains(res) || rootDirectory.Contains(icons))
+ {
+ pDirDetails->type = APP2EXT_DIR_RO;
+ }
+ else
+ {
+ pDirDetails->type = APP2EXT_DIR_RW;
+ }
+
+ AppLog("------------------------------------------");
+ AppLog("# Root Directory = [%s], Type = [%d]", pDirDetails->name, pDirDetails->type);
+
+ pDirectoryList = g_list_append(pDirectoryList, pDirDetails);
+ }
+
+ pHandle = app2ext_init(APP2EXT_SD_CARD);
+ TryCatch(pHandle, errorType = INSTALLER_ERROR_INTERNAL_STATE, "app2ext_init() failed");
+
+ res = pHandle->interface.move(pPackageId.get(), pDirectoryList, location);
+ TryCatch(res == 0, errorType = INSTALLER_ERROR_INTERNAL_STATE, "pHandle->interface.move() failed [%d]", res);
+
+ app2ext_deinit(pHandle);
+
+CATCH:
+ if (pDirectoryList)
+ {
+ GList* pList = null;
+ app2ext_dir_details* pDirDetails = null;
+
+ pList = g_list_first(pDirectoryList);
+ while (pList)
+ {
+ pDirDetails = (app2ext_dir_details*)pList->data;
+ if (pDirDetails && pDirDetails->name)
+ {
+ free(pDirDetails->name);
+ }
+ pList = g_list_next(pList);
+ }
+ g_list_free(pDirectoryList);
+ }
+
+ delete pDirEnum;
+ delete pDir;
+ delete pPackageInfo;
+
+ return errorType;
+}
+
+int
InstallerManager::ParseCommandArg(int argc, char **argv, int *mode, char *buf, bool *output)
{
const char* pOpts_str = "u:i:r:v";