From 01c93c363adda30b7b412e7532f141be23e81956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 2 Feb 2006 10:41:44 +0000 Subject: [PATCH] added a test installer app source directory is currently hardcoded in InstallerWindow.cpp, it could be changed in a macro git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16197 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/apps/Jamfile | 1 + src/tests/apps/installer/CopyEngine.cpp | 120 ++++++++++++++++++++++++ src/tests/apps/installer/CopyEngine.h | 35 +++++++ src/tests/apps/installer/Jamfile | 27 ++++++ 4 files changed, 183 insertions(+) create mode 100644 src/tests/apps/installer/CopyEngine.cpp create mode 100644 src/tests/apps/installer/CopyEngine.h create mode 100644 src/tests/apps/installer/Jamfile diff --git a/src/tests/apps/Jamfile b/src/tests/apps/Jamfile index 80ba1c65a4..e9e4c9972f 100644 --- a/src/tests/apps/Jamfile +++ b/src/tests/apps/Jamfile @@ -2,3 +2,4 @@ SubDir HAIKU_TOP src tests apps ; SubInclude HAIKU_TOP src tests apps miniterminal ; SubInclude HAIKU_TOP src tests apps fake_app_server ; +SubInclude HAIKU_TOP src tests apps installer ; diff --git a/src/tests/apps/installer/CopyEngine.cpp b/src/tests/apps/installer/CopyEngine.cpp new file mode 100644 index 0000000000..6dcf328eb1 --- /dev/null +++ b/src/tests/apps/installer/CopyEngine.cpp @@ -0,0 +1,120 @@ +/* + * Copyright 2005-2006, Jérôme DUVAL. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#include "CopyEngine.h" +#include "InstallerWindow.h" +#include "PartitionMenuItem.h" +#include +#include +#include +#include +#include + +//#define COPY_TRACE +#ifdef COPY_TRACE +#define CALLED() printf("CALLED %s\n",__PRETTY_FUNCTION__) +#else +#define CALLED() +#endif + +const char BOOT_PATH[] = "/boot"; + +extern void SizeAsString(off_t size, char *string); + + +CopyEngine::CopyEngine(InstallerWindow *window) + : BLooper("copy_engine"), + fWindow(window), + fPackages(NULL), + fSpaceRequired(0) +{ + Run(); +} + + +void +CopyEngine::MessageReceived(BMessage*msg) +{ + CALLED(); + switch (msg->what) { + case ENGINE_START: + Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu()); + break; + } +} + + +void +CopyEngine::SetStatusMessage(char *status) +{ + BMessage msg(STATUS_MESSAGE); + msg.AddString("status", status); + BMessenger(fWindow).SendMessage(&msg); +} + + +void +CopyEngine::LaunchInitScript(BPath &path) +{ + BPath bootPath; + find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); + BString command("/bin/sh "); + command += bootPath.Path(); + command += "/InstallerInitScript "; + command += path.Path(); + SetStatusMessage("Starting Installation."); + system(command.String()); +} + + +void +CopyEngine::LaunchFinishScript(BPath &path) +{ + BPath bootPath; + find_directory(B_BEOS_BOOT_DIRECTORY, &bootPath); + BString command("/bin/sh "); + command += bootPath.Path(); + command += "/InstallerFinishScript "; + command += path.Path(); + SetStatusMessage("Finishing Installation."); + system(command.String()); +} + + +void +CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) +{ + CALLED(); + PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked(); + PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked(); + if (!srcItem || !targetItem) { + fprintf(stderr, "bad menu items\n"); + return; + } + + BMessage msg(INSTALL_FINISHED); + BMessenger(fWindow).SendMessage(&msg); +} + + +void +CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu) +{ + PartitionMenuItem *item = new PartitionMenuItem(NULL, "boot", NULL, new BMessage(SRC_PARTITION), 0); + srcMenu->AddItem(item); + + PartitionMenuItem *item2 = new PartitionMenuItem(NULL, "target", NULL, new BMessage(TARGET_PARTITION), 0); + targetMenu->AddItem(item2); +} + + +void +CopyEngine::SetPackagesList(BList *list) +{ + if (fPackages) + delete fPackages; + fPackages = list; +} + diff --git a/src/tests/apps/installer/CopyEngine.h b/src/tests/apps/installer/CopyEngine.h new file mode 100644 index 0000000000..61b31024df --- /dev/null +++ b/src/tests/apps/installer/CopyEngine.h @@ -0,0 +1,35 @@ +/* + * Copyright 2005, Jérôme DUVAL. All rights reserved. + * Distributed under the terms of the MIT License. + */ + +#ifndef _CopyEngine_h +#define _CopyEngine_h + +#include +#include + +class InstallerWindow; + +const uint32 ENGINE_START = 'eSRT'; + +class CopyEngine : public BLooper { +public: + CopyEngine(InstallerWindow *window); + void MessageReceived(BMessage *msg); + void SetStatusMessage(char *status); + void Start(BMenu *srcMenu, BMenu *targetMenu); + void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); + void SetPackagesList(BList *list); + void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; +private: + void LaunchInitScript(BPath &path); + void LaunchFinishScript(BPath &path); + void CopyFolder(BDirectory &srcDir, BDirectory &targetDir); + + InstallerWindow *fWindow; + BList *fPackages; + off_t fSpaceRequired; +}; + +#endif /* _CopyEngine_h */ diff --git a/src/tests/apps/installer/Jamfile b/src/tests/apps/installer/Jamfile new file mode 100644 index 0000000000..7f233d7901 --- /dev/null +++ b/src/tests/apps/installer/Jamfile @@ -0,0 +1,27 @@ +SubDir HAIKU_TOP src tests apps installer ; + +SetSubDirSupportedPlatformsBeOSCompatible ; + +UsePrivateHeaders shared ; +UsePrivateHeaders storage ; +SubDirHdrs [ FDirName $(HAIKU_TOP) src kits tracker ] ; +SubDirHdrs [ FDirName $(HAIKU_TOP) src apps installer ] ; + +Application TestInstaller : + CopyEngine.cpp + DrawButton.cpp + InstallerApp.cpp + InstallerWindow.cpp + PackageViews.cpp + PartitionMenuItem.cpp + : be tracker translation + : Installer.rdef ; + +SEARCH on [ FGristFiles + DrawButton.cpp + InstallerApp.cpp + InstallerWindow.cpp + PackageViews.cpp + PartitionMenuItem.cpp + Installer.rdef + ] = [ FDirName $(HAIKU_TOP) src apps installer ] ;