* improved error and cancellation handling

* only enable Begin button when a menu item has been chosen


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27051 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2008-08-18 21:48:02 +00:00
parent e210364f75
commit 5d6a2a65da
3 changed files with 43 additions and 54 deletions
+37 -49
View File
@@ -72,15 +72,7 @@ CopyEngine::MessageReceived(BMessage*msg)
switch (msg->what) { switch (msg->what) {
case ENGINE_START: case ENGINE_START:
{ {
status_t err = Start(fWindow->GetSourceMenu(), Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
fWindow->GetTargetMenu());
if (err != B_OK) {
ERR("Start failed");
SetStatusMessage("Installation aborted.");
BMessenger(fWindow).SendMessage(RESET_INSTALL);
} else {
BMessenger(fWindow).SendMessage(INSTALL_FINISHED);
}
break; break;
} }
} }
@@ -124,45 +116,46 @@ CopyEngine::LaunchFinishScript(BPath &path)
} }
status_t void
CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
{ {
CALLED(); CALLED();
BPath targetDirectory, srcDirectory;
BDirectory targetDir, srcDir;
BDiskDevice device;
BPartition *partition;
BVolume targetVolume;
status_t err = B_OK;
fControl->Reset(); fControl->Reset();
status_t err = B_OK;
PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked(); PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked();
PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked(); PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked();
if (!srcItem || !targetItem) { if (!srcItem || !targetItem) {
ERR("bad menu items\n"); ERR("bad menu items\n");
return B_BAD_VALUE; goto error;
} }
// check if target is initialized // check if target is initialized
// ask if init or mount as is // ask if init or mount as is
BPath targetDirectory;
BDiskDevice device;
BPartition *partition;
BVolume targetVolume;
if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) { if (fDDRoster.GetPartitionWithID(targetItem->ID(), &device, &partition) == B_OK) {
if (!partition->IsMounted()) { if (!partition->IsMounted()) {
if ((err = partition->Mount()) < B_OK) { if ((err = partition->Mount()) < B_OK) {
SetStatusMessage("The disk can't be mounted. Please choose a " SetStatusMessage("The disk can't be mounted. Please choose a "
"different disk."); "different disk.");
ERR("BPartition::Mount"); ERR("BPartition::Mount");
return err; goto error;
} }
} }
if ((err = partition->GetVolume(&targetVolume)) != B_OK) { if ((err = partition->GetVolume(&targetVolume)) != B_OK) {
ERR("BPartition::GetVolume"); ERR("BPartition::GetVolume");
return err; goto error;
} }
if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) { if ((err = partition->GetMountPoint(&targetDirectory)) != B_OK) {
ERR("BPartition::GetMountPoint"); ERR("BPartition::GetMountPoint");
return err; goto error;
} }
} else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) { } else if (fDDRoster.GetDeviceWithID(targetItem->ID(), &device) == B_OK) {
if (!device.IsMounted()) { if (!device.IsMounted()) {
@@ -170,19 +163,19 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
SetStatusMessage("The disk can't be mounted. Please choose a " SetStatusMessage("The disk can't be mounted. Please choose a "
"different disk."); "different disk.");
ERR("BDiskDevice::Mount"); ERR("BDiskDevice::Mount");
return err; goto error;
} }
} }
if ((err = device.GetVolume(&targetVolume)) != B_OK) { if ((err = device.GetVolume(&targetVolume)) != B_OK) {
ERR("BDiskDevice::GetVolume"); ERR("BDiskDevice::GetVolume");
return err; goto error;
} }
if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) { if ((err = device.GetMountPoint(&targetDirectory)) != B_OK) {
ERR("BDiskDevice::GetMountPoint"); ERR("BDiskDevice::GetMountPoint");
return err; goto error;
} }
} else } else
return B_ERROR; // shouldn't happen goto error; // shouldn't happen
// check if target has enough space // check if target has enough space
if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired) if ((fSpaceRequired > 0 && targetVolume.FreeBytes() < fSpaceRequired)
@@ -190,30 +183,27 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
"Try choosing a different disk or choose to not install optional " "Try choosing a different disk or choose to not install optional "
"items.", "Try installing anyway", "Cancel", 0, "items.", "Try installing anyway", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
BMessenger(fWindow).SendMessage(RESET_INSTALL); goto error;
return B_OK;
} }
BPath srcDirectory;
if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) { if (fDDRoster.GetPartitionWithID(srcItem->ID(), &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 err; goto error;
} }
} else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) { } else if (fDDRoster.GetDeviceWithID(srcItem->ID(), &device) == B_OK) {
if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) { if ((err = device.GetMountPoint(&srcDirectory)) != B_OK) {
ERR("BDiskDevice::GetMountPoint"); ERR("BDiskDevice::GetMountPoint");
return err; goto error;
} }
} else } else
return B_ERROR; // shouldn't happen goto error; // shouldn't happen
// check not installing on itself // check not installing on itself
if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) { if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
SetStatusMessage("You can't install the contents of a disk onto " SetStatusMessage("You can't install the contents of a disk onto "
"itself. Please choose a different disk."); "itself. Please choose a different disk.");
BMessenger(fWindow).SendMessage(RESET_INSTALL); goto error;
return B_OK;
} }
// check not installing on boot volume // check not installing on boot volume
@@ -223,19 +213,18 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
"machine if you proceed.", "OK", "Cancel", 0, "machine if you proceed.", "OK", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) { B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
SetStatusMessage("Installation stopped."); SetStatusMessage("Installation stopped.");
BMessenger(fWindow).SendMessage(RESET_INSTALL); goto error;
return B_OK;
} }
LaunchInitScript(targetDirectory); LaunchInitScript(targetDirectory);
// copy source volume // copy source volume
BDirectory targetDir(targetDirectory.Path()); targetDir.SetTo(targetDirectory.Path());
BDirectory srcDir(srcDirectory.Path()); srcDir.SetTo(srcDirectory.Path());
err = CopyFolder(srcDir, targetDir); err = CopyFolder(srcDir, targetDir);
if (err != B_OK) if (err != B_OK || fControl->CheckUserCanceled())
return err; goto error;
// copy selected packages // copy selected packages
if (fPackages) { if (fPackages) {
@@ -244,25 +233,24 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
BDirectory packageDir; BDirectory packageDir;
int32 count = fPackages->CountItems(); int32 count = fPackages->CountItems();
for (int32 i = 0; i < count; i++) { for (int32 i = 0; i < count; i++) {
if (fControl->CheckUserCanceled())
return B_CANCELED;
Package *p = static_cast<Package*>(fPackages->ItemAt(i)); Package *p = static_cast<Package*>(fPackages->ItemAt(i));
packageDir.SetTo(&srcDir, p->Folder()); packageDir.SetTo(&srcDir, p->Folder());
err = CopyFolder(packageDir, targetDir); err = CopyFolder(packageDir, targetDir);
if (err != B_OK) if (err != B_OK || fControl->CheckUserCanceled())
break; goto error;
} }
} }
if (err != B_OK)
return err;
if (fControl->CheckUserCanceled())
return B_CANCELED;
LaunchFinishScript(targetDirectory); LaunchFinishScript(targetDirectory);
return B_OK; BMessenger(fWindow).SendMessage(INSTALL_FINISHED);
return;
error:
if (err == B_CANCELED || fControl->CheckUserCanceled())
SetStatusMessage("Installation canceled.");
ERR("Start failed");
BMessenger(fWindow).SendMessage(RESET_INSTALL);
} }
+2 -2
View File
@@ -23,8 +23,6 @@ class CopyEngine : public BLooper {
public: public:
CopyEngine(InstallerWindow *window); CopyEngine(InstallerWindow *window);
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void SetStatusMessage(char *status);
status_t Start(BMenu *srcMenu, BMenu *targetMenu);
void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu);
void SetPackagesList(BList *list); void SetPackagesList(BList *list);
void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; }; void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; };
@@ -32,6 +30,8 @@ class CopyEngine : public BLooper {
private: private:
void LaunchInitScript(BPath &path); void LaunchInitScript(BPath &path);
void LaunchFinishScript(BPath &path); void LaunchFinishScript(BPath &path);
void SetStatusMessage(char *status);
void Start(BMenu *srcMenu, BMenu *targetMenu);
status_t CopyFolder(BDirectory &srcDir, BDirectory &targetDir); status_t CopyFolder(BDirectory &srcDir, BDirectory &targetDir);
InstallerWindow *fWindow; InstallerWindow *fWindow;
+3 -2
View File
@@ -192,7 +192,6 @@ InstallerWindow::MessageReceived(BMessage *msg)
break; break;
case START_SCAN: case START_SCAN:
StartScan(); StartScan();
fBeginButton->SetEnabled(true);
break; break;
case BEGIN_MESSAGE: case BEGIN_MESSAGE:
switch (fInstallStatus) { switch (fInstallStatus) {
@@ -203,10 +202,10 @@ InstallerWindow::MessageReceived(BMessage *msg)
fPackagesView->GetPackagesToInstall(list, &size); fPackagesView->GetPackagesToInstall(list, &size);
fCopyEngine->SetPackagesList(list); fCopyEngine->SetPackagesList(list);
fCopyEngine->SetSpaceRequired(size); fCopyEngine->SetSpaceRequired(size);
fInstallStatus = kInstalling;
BMessenger(fCopyEngine).SendMessage(ENGINE_START); BMessenger(fCopyEngine).SendMessage(ENGINE_START);
fBeginButton->SetLabel("Stop"); fBeginButton->SetLabel("Stop");
DisableInterface(true); DisableInterface(true);
fInstallStatus = kInstalling;
break; break;
} }
case kInstalling: case kInstalling:
@@ -397,6 +396,8 @@ InstallerWindow::AdjustMenus()
sprintf(message, "Press the Begin button to install from '%s' onto '%s'", sprintf(message, "Press the Begin button to install from '%s' onto '%s'",
item1 ? item1->Name() : "null", item2 ? item2->Name() : "null"); item1 ? item1->Name() : "null", item2 ? item2->Name() : "null");
SetStatusMessage(message); SetStatusMessage(message);
if (item1 && item2)
fBeginButton->SetEnabled(true);
} }