Installer: WorkerThread: Remove InstallerWindow dependency
* Move message constants to InstallerDefs.h. * Determine the source and target partition ID already in InstallerWindow and pass those to WorkerThread instead of fiddling with menu items in _PerformInstall(). And instead of the window object pass a messenger to the constructor.
This commit is contained in:
@@ -6,6 +6,14 @@
|
|||||||
#define INSTALLER_DEFS_H
|
#define INSTALLER_DEFS_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <SupportDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
static const uint32 MSG_STATUS_MESSAGE = 'iSTM';
|
||||||
|
static const uint32 MSG_INSTALL_FINISHED = 'iIFN';
|
||||||
|
static const uint32 MSG_RESET = 'iRSI';
|
||||||
|
static const uint32 MSG_WRITE_BOOT_SECTOR = 'iWBS';
|
||||||
|
|
||||||
extern const char* const kPackagesDirectoryPath;
|
extern const char* const kPackagesDirectoryPath;
|
||||||
extern const char* const kSourcesDirectoryPath;
|
extern const char* const kSourcesDirectoryPath;
|
||||||
extern const char* const kSwapFilePath;
|
extern const char* const kSwapFilePath;
|
||||||
|
|||||||
@@ -370,6 +370,14 @@ InstallerWindow::MessageReceived(BMessage *msg)
|
|||||||
switch (fInstallStatus) {
|
switch (fInstallStatus) {
|
||||||
case kReadyForInstall:
|
case kReadyForInstall:
|
||||||
{
|
{
|
||||||
|
// get source and target
|
||||||
|
PartitionMenuItem* targetItem
|
||||||
|
= (PartitionMenuItem*)fDestMenu->FindMarked();
|
||||||
|
PartitionMenuItem* srcItem
|
||||||
|
= (PartitionMenuItem*)fSrcMenu->FindMarked();
|
||||||
|
if (srcItem == NULL || targetItem == NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
_SetCopyEngineCancelSemaphore(create_sem(1,
|
_SetCopyEngineCancelSemaphore(create_sem(1,
|
||||||
"copy engine cancel"));
|
"copy engine cancel"));
|
||||||
|
|
||||||
@@ -380,7 +388,8 @@ InstallerWindow::MessageReceived(BMessage *msg)
|
|||||||
fWorkerThread->SetPackagesList(list);
|
fWorkerThread->SetPackagesList(list);
|
||||||
fWorkerThread->SetSpaceRequired(size);
|
fWorkerThread->SetSpaceRequired(size);
|
||||||
fInstallStatus = kInstalling;
|
fInstallStatus = kInstalling;
|
||||||
fWorkerThread->StartInstall();
|
fWorkerThread->StartInstall(srcItem->ID(),
|
||||||
|
targetItem->ID());
|
||||||
fBeginButton->SetLabel(B_TRANSLATE("Stop"));
|
fBeginButton->SetLabel(B_TRANSLATE("Stop"));
|
||||||
_DisableInterface(true);
|
_DisableInterface(true);
|
||||||
|
|
||||||
|
|||||||
@@ -34,11 +34,6 @@ enum InstallStatus {
|
|||||||
kCancelled
|
kCancelled
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32 MSG_STATUS_MESSAGE = 'iSTM';
|
|
||||||
const uint32 MSG_INSTALL_FINISHED = 'iIFN';
|
|
||||||
const uint32 MSG_RESET = 'iRSI';
|
|
||||||
const uint32 MSG_WRITE_BOOT_SECTOR = 'iWBS';
|
|
||||||
|
|
||||||
|
|
||||||
class InstallerWindow : public BWindow {
|
class InstallerWindow : public BWindow {
|
||||||
public:
|
public:
|
||||||
@@ -48,8 +43,6 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
BMenu* GetSourceMenu() { return fSrcMenu; };
|
|
||||||
BMenu* GetTargetMenu() { return fDestMenu; };
|
|
||||||
private:
|
private:
|
||||||
void _ShowOptionalPackages();
|
void _ShowOptionalPackages();
|
||||||
void _LaunchDriveSetup();
|
void _LaunchDriveSetup();
|
||||||
|
|||||||
@@ -19,8 +19,9 @@
|
|||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
#include "InstallerWindow.h"
|
#include "InstallerDefs.h"
|
||||||
#include "StringForSize.h"
|
#include "StringForSize.h"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,6 @@
|
|||||||
#include "AutoLocker.h"
|
#include "AutoLocker.h"
|
||||||
#include "CopyEngine.h"
|
#include "CopyEngine.h"
|
||||||
#include "InstallerDefs.h"
|
#include "InstallerDefs.h"
|
||||||
#include "InstallerWindow.h"
|
|
||||||
#include "PackageViews.h"
|
#include "PackageViews.h"
|
||||||
#include "PartitionMenuItem.h"
|
#include "PartitionMenuItem.h"
|
||||||
#include "ProgressReporter.h"
|
#include "ProgressReporter.h"
|
||||||
@@ -156,10 +155,10 @@ private:
|
|||||||
// #pragma mark - WorkerThread
|
// #pragma mark - WorkerThread
|
||||||
|
|
||||||
|
|
||||||
WorkerThread::WorkerThread(InstallerWindow *window)
|
WorkerThread::WorkerThread(const BMessenger& owner)
|
||||||
:
|
:
|
||||||
BLooper("copy_engine"),
|
BLooper("copy_engine"),
|
||||||
fWindow(window),
|
fOwner(owner),
|
||||||
fPackages(NULL),
|
fPackages(NULL),
|
||||||
fSpaceRequired(0),
|
fSpaceRequired(0),
|
||||||
fCancelSemaphore(-1)
|
fCancelSemaphore(-1)
|
||||||
@@ -175,7 +174,8 @@ WorkerThread::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case MSG_START_INSTALLING:
|
case MSG_START_INSTALLING:
|
||||||
_PerformInstall(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
|
_PerformInstall(message->GetInt32("source", -1),
|
||||||
|
message->GetInt32("target", -1));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_WRITE_BOOT_SECTOR:
|
case MSG_WRITE_BOOT_SECTOR:
|
||||||
@@ -262,10 +262,15 @@ WorkerThread::SetPackagesList(BList *list)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
WorkerThread::StartInstall()
|
WorkerThread::StartInstall(partition_id sourcePartitionID,
|
||||||
|
partition_id targetPartitionID)
|
||||||
{
|
{
|
||||||
// Executed in window thread.
|
// Executed in window thread.
|
||||||
PostMessage(MSG_START_INSTALLING, this);
|
BMessage message(MSG_START_INSTALLING);
|
||||||
|
message.AddInt32("source", sourcePartitionID);
|
||||||
|
message.AddInt32("target", targetPartitionID);
|
||||||
|
|
||||||
|
PostMessage(&message, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -323,7 +328,8 @@ WorkerThread::_LaunchFinishScript(BPath &path)
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
WorkerThread::_PerformInstall(partition_id sourcePartitionID,
|
||||||
|
partition_id targetPartitionID)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
@@ -341,16 +347,14 @@ WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
|||||||
const char* mountError = B_TRANSLATE("The disk can't be mounted. Please "
|
const char* mountError = B_TRANSLATE("The disk can't be mounted. Please "
|
||||||
"choose a different disk.");
|
"choose a different disk.");
|
||||||
|
|
||||||
PartitionMenuItem* targetItem = (PartitionMenuItem*)targetMenu->FindMarked();
|
if (sourcePartitionID < 0 || targetPartitionID < 0) {
|
||||||
PartitionMenuItem* srcItem = (PartitionMenuItem*)srcMenu->FindMarked();
|
ERR("bad source or target partition ID\n");
|
||||||
if (!srcItem || !targetItem) {
|
|
||||||
ERR("bad menu items\n");
|
|
||||||
return _InstallationError(err);
|
return _InstallationError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if target is initialized
|
// check if target is initialized
|
||||||
// ask if init or mount as is
|
// ask if init or mount as is
|
||||||
if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device,
|
if (fDDRoster.GetPartitionWithID(targetPartitionID, &device,
|
||||||
&partition) == B_OK) {
|
&partition) == B_OK) {
|
||||||
if (!partition->IsMounted()) {
|
if (!partition->IsMounted()) {
|
||||||
if ((err = partition->Mount()) < B_OK) {
|
if ((err = partition->Mount()) < B_OK) {
|
||||||
@@ -367,7 +371,7 @@ WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
|||||||
ERR("BPartition::GetMountPoint");
|
ERR("BPartition::GetMountPoint");
|
||||||
return _InstallationError(err);
|
return _InstallationError(err);
|
||||||
}
|
}
|
||||||
} else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) {
|
} else if (fDDRoster.GetDeviceWithID(targetPartitionID, &device) == B_OK) {
|
||||||
if (!device.IsMounted()) {
|
if (!device.IsMounted()) {
|
||||||
if ((err = device.Mount()) < B_OK) {
|
if ((err = device.Mount()) < B_OK) {
|
||||||
_SetStatusMessage(mountError);
|
_SetStatusMessage(mountError);
|
||||||
@@ -398,12 +402,13 @@ WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
|||||||
return _InstallationError(err);
|
return _InstallationError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) {
|
if (fDDRoster.GetPartitionWithID(sourcePartitionID, &device, &partition)
|
||||||
|
== B_OK) {
|
||||||
if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) {
|
if ((err = partition->GetMountPoint(&srcDirectory)) != B_OK) {
|
||||||
ERR("BPartition::GetMountPoint");
|
ERR("BPartition::GetMountPoint");
|
||||||
return _InstallationError(err);
|
return _InstallationError(err);
|
||||||
}
|
}
|
||||||
} else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) {
|
} else if (fDDRoster.GetDeviceWithID(sourcePartitionID, &device) == B_OK) {
|
||||||
if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
|
if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
|
||||||
ERR("BDiskDevice::GetMountPoint");
|
ERR("BDiskDevice::GetMountPoint");
|
||||||
return _InstallationError(err);
|
return _InstallationError(err);
|
||||||
@@ -470,8 +475,7 @@ WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
|||||||
|
|
||||||
// Begin actual installation
|
// Begin actual installation
|
||||||
|
|
||||||
BMessenger messenger(fWindow);
|
ProgressReporter reporter(fOwner, new BMessage(MSG_STATUS_MESSAGE));
|
||||||
ProgressReporter reporter(messenger, new BMessage(MSG_STATUS_MESSAGE));
|
|
||||||
EntryFilter entryFilter(srcDirectory.Path());
|
EntryFilter entryFilter(srcDirectory.Path());
|
||||||
CopyEngine engine(&reporter, &entryFilter);
|
CopyEngine engine(&reporter, &entryFilter);
|
||||||
BList unzipEngines;
|
BList unzipEngines;
|
||||||
@@ -552,7 +556,7 @@ WorkerThread::_PerformInstall(BMenu* srcMenu, BMenu* targetMenu)
|
|||||||
|
|
||||||
_LaunchFinishScript(targetDirectory);
|
_LaunchFinishScript(targetDirectory);
|
||||||
|
|
||||||
BMessenger(fWindow).SendMessage(MSG_INSTALL_FINISHED);
|
fOwner.SendMessage(MSG_INSTALL_FINISHED);
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,7 +570,7 @@ WorkerThread::_InstallationError(status_t error)
|
|||||||
else
|
else
|
||||||
statusMessage.AddInt32("error", error);
|
statusMessage.AddInt32("error", error);
|
||||||
ERR("_PerformInstall failed");
|
ERR("_PerformInstall failed");
|
||||||
BMessenger(fWindow).SendMessage(&statusMessage);
|
fOwner.SendMessage(&statusMessage);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -707,7 +711,7 @@ WorkerThread::_SetStatusMessage(const char *status)
|
|||||||
{
|
{
|
||||||
BMessage msg(MSG_STATUS_MESSAGE);
|
BMessage msg(MSG_STATUS_MESSAGE);
|
||||||
msg.AddString("status", status);
|
msg.AddString("status", status);
|
||||||
BMessenger(fWindow).SendMessage(&msg);
|
fOwner.SendMessage(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,11 @@
|
|||||||
|
|
||||||
class BList;
|
class BList;
|
||||||
class BMenu;
|
class BMenu;
|
||||||
class InstallerWindow;
|
|
||||||
class ProgressReporter;
|
class ProgressReporter;
|
||||||
|
|
||||||
class WorkerThread : public BLooper {
|
class WorkerThread : public BLooper {
|
||||||
public:
|
public:
|
||||||
WorkerThread(InstallerWindow* window);
|
WorkerThread(const BMessenger& owner);
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
@@ -35,15 +34,16 @@ public:
|
|||||||
void SetLock(sem_id cancelSemaphore)
|
void SetLock(sem_id cancelSemaphore)
|
||||||
{ fCancelSemaphore = cancelSemaphore; }
|
{ fCancelSemaphore = cancelSemaphore; }
|
||||||
|
|
||||||
void StartInstall();
|
void StartInstall(partition_id sourcePartitionID,
|
||||||
|
partition_id targetPartitionID);
|
||||||
void WriteBootSector(BMenu* dstMenu);
|
void WriteBootSector(BMenu* dstMenu);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _LaunchInitScript(BPath& path);
|
void _LaunchInitScript(BPath& path);
|
||||||
void _LaunchFinishScript(BPath& path);
|
void _LaunchFinishScript(BPath& path);
|
||||||
|
|
||||||
status_t _PerformInstall(BMenu* srcMenu,
|
status_t _PerformInstall(partition_id sourcePartitionID,
|
||||||
BMenu* dstMenu);
|
partition_id targetPartitionID);
|
||||||
status_t _InstallationError(status_t error);
|
status_t _InstallationError(status_t error);
|
||||||
status_t _MirrorIndices(const BPath& srcDirectory,
|
status_t _MirrorIndices(const BPath& srcDirectory,
|
||||||
const BPath& targetDirectory) const;
|
const BPath& targetDirectory) const;
|
||||||
@@ -60,7 +60,7 @@ private:
|
|||||||
class EntryFilter;
|
class EntryFilter;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InstallerWindow* fWindow;
|
BMessenger fOwner;
|
||||||
BDiskDeviceRoster fDDRoster;
|
BDiskDeviceRoster fDDRoster;
|
||||||
BList* fPackages;
|
BList* fPackages;
|
||||||
off_t fSpaceRequired;
|
off_t fSpaceRequired;
|
||||||
|
|||||||
Reference in New Issue
Block a user