* added checks for installing on source volume, or boot volume

* added alert for file error: lots of errors happening when updating a volume:
* it seems BEntry::IsDirectory() returns false whereas it should return true for some directories
this is to be checked with a test app
* boot volume is now marked automatically as the source volume (a rule is yet to be found for the target volume)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16066 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-01-24 16:16:26 +00:00
parent 19de443e9a
commit bc1301d336
4 changed files with 64 additions and 29 deletions

View File

@ -8,9 +8,10 @@
#include "PartitionMenuItem.h"
#include "FSUndoRedo.h"
#include "FSUtils.h"
#include <FindDirectory.h>
#include <Alert.h>
#include <DiskDeviceVisitor.h>
#include <DiskDeviceTypes.h>
#include <FindDirectory.h>
#include <Path.h>
#include <String.h>
#include <VolumeRoster.h>
@ -22,6 +23,8 @@
#define CALLED()
#endif
const char BOOT_PATH[] = "/boot";
extern void SizeAsString(off_t size, char *string);
class SourceVisitor : public BDiskDeviceVisitor
@ -127,6 +130,10 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
} else
return; // shouldn't happen
// check if target is initialized
// ask if init or mount as is
// check if target has enough space
BPath srcDirectory;
if (fDDRoster.GetPartitionWithID(srcItem->ID(), &device, &partition) == B_OK) {
if (partition->GetMountPoint(&srcDirectory)!=B_OK)
@ -137,23 +144,20 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
} else
return; // shouldn't happen
// check not installing on boot volume
BVolume bootVolume;
BDirectory bootDir;
BEntry bootEntry;
BPath bootPath;
BVolumeRoster().GetBootVolume(&bootVolume);
bootVolume.GetRootDirectory(&bootDir);
bootDir.GetEntry(&bootEntry);
bootEntry.GetPath(&bootPath);
printf("Copying to boot disk ? '%s' / '%s'\n", bootPath.Path(), targetDirectory.Path());
if (strncmp(bootPath.Path(), targetDirectory.Path(), strlen(bootPath.Path())) == 0) {
// check not installing on itself
if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
SetStatusMessage("You can't install the contents of a disk onto itself. Please choose a different disk.");
return;
}
// check not installing on boot volume
if ((strncmp(BOOT_PATH, targetDirectory.Path(), strlen(BOOT_PATH)) == 0)
&& ((new BAlert("", "Are you sure you want to install onto the current boot disk? \
The installer will have to reboot your machine if you proceed.", "OK", "Cancel", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
SetStatusMessage("Installation stopped.");
return;
}
// check if target is initialized
// ask if init ou mount as is
LaunchInitScript(targetDirectory);
@ -163,10 +167,10 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
CopyFolder(srcDir, targetDir);
// copy selected packages
srcDirectory.Append(PACKAGES_DIRECTORY);
srcDir.SetTo(srcDirectory.Path());
BDirectory packageDir;
if (fPackages) {
srcDirectory.Append(PACKAGES_DIRECTORY);
srcDir.SetTo(srcDirectory.Path());
BDirectory packageDir;
int32 count = fPackages->CountItems();
for (int32 i=0; i<count; i++) {
Package *p = static_cast<Package*>(fPackages->ItemAt(i));
@ -176,6 +180,9 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
}
LaunchFinishScript(targetDirectory);
BMessage msg(INSTALL_FINISHED);
BMessenger(fWindow).SendMessage(&msg);
}
@ -240,7 +247,14 @@ SourceVisitor::Visit(BDiskDevice *device)
if (device->GetPath(&path)==B_OK)
printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n",
path.Path(), device->Type(), device->ContentType());
fMenu->AddItem(new PartitionMenuItem(NULL, device->ContentName(), NULL, new BMessage(SRC_PARTITION), device->ID()));
PartitionMenuItem *item = new PartitionMenuItem(NULL, device->ContentName(), NULL, new BMessage(SRC_PARTITION), device->ID());
if (device->IsMounted()) {
BPath mountPoint;
device->GetMountPoint(&mountPoint);
if (strcmp(BOOT_PATH, mountPoint.Path())==0)
item->SetMarked(true);
}
fMenu->AddItem(item);
return false;
}
@ -254,7 +268,14 @@ SourceVisitor::Visit(BPartition *partition, int32 level)
if (partition->GetPath(&path)==B_OK)
printf("SourceVisitor::Visit(BPartition *) : %s\n", path.Path());
printf("SourceVisitor::Visit(BPartition *) : %s\n", partition->Name());
fMenu->AddItem(new PartitionMenuItem(NULL, partition->ContentName(), NULL, new BMessage(SRC_PARTITION), partition->ID()));
PartitionMenuItem *item = new PartitionMenuItem(NULL, partition->ContentName(), NULL, new BMessage(SRC_PARTITION), partition->ID());
if (partition->IsMounted()) {
BPath mountPoint;
partition->GetMountPoint(&mountPoint);
if (strcmp(BOOT_PATH, mountPoint.Path())==0)
item->SetMarked(true);
}
fMenu->AddItem(item);
return false;
}

View File

@ -5,6 +5,7 @@
*/
#include "InstallerCopyLoopControl.h"
#include "InstallerWindow.h"
#include <Alert.h>
InstallerCopyLoopControl::InstallerCopyLoopControl(InstallerWindow *window)
: fWindow(window),
@ -17,6 +18,15 @@ bool
InstallerCopyLoopControl::FileError(const char *message, const char *name, status_t error,
bool allowContinue)
{
char buffer[512];
sprintf(buffer, message, name, strerror(error));
if (allowContinue)
return (new BAlert("", buffer, "Cancel", "OK", 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0;
(new BAlert("", buffer, "Cancel", 0, 0,
B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go();
return false;
}

View File

@ -171,6 +171,7 @@ InstallerWindow::MessageReceived(BMessage *msg)
fPackagesView->GetPackagesToInstall(list, &size);
fCopyEngine->SetPackagesList(list);
BMessenger(fCopyEngine).SendMessage(ENGINE_START);
DisableInterface(true);
break;
}
case SHOW_BOTTOM_MESSAGE:
@ -199,13 +200,21 @@ InstallerWindow::MessageReceived(BMessage *msg)
if (msg->FindString("status", &status) == B_OK)
SetStatusMessage(status);
}
case INSTALL_FINISHED:
DisableInterface(false);
break;
case B_SOME_APP_LAUNCHED:
case B_SOME_APP_QUIT:
{
const char *signature;
if (msg->FindString("be:signature", &signature)==B_OK
&& strcasecmp(signature, DRIVESETUP_SIG)==0) {
DisableInterface(msg->what == B_SOME_APP_LAUNCHED);
fDriveSetupLaunched = msg->what == B_SOME_APP_LAUNCHED;
DisableInterface(fDriveSetupLaunched);
if (fDriveSetupLaunched)
SetStatusMessage("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation.");
else
StartScan();
}
break;
}
@ -263,16 +272,10 @@ InstallerWindow::LaunchDriveSetup()
void
InstallerWindow::DisableInterface(bool disable)
{
if (!disable) {
StartScan();
}
fDriveSetupLaunched = disable;
fBeginButton->SetEnabled(!disable);
fSetupButton->SetEnabled(!disable);
fSrcMenuField->SetEnabled(!disable);
fDestMenuField->SetEnabled(!disable);
if (disable)
SetStatusMessage("Running DriveSetup" B_UTF8_ELLIPSIS "\nClose DriveSetup to continue with the\ninstallation.");
}

View File

@ -20,6 +20,7 @@
#define INSTALLER_RIGHT 402
const uint32 STATUS_MESSAGE = 'iSTM';
const uint32 INSTALL_FINISHED = 'iIFN';
const char PACKAGES_DIRECTORY[] = "_packages_";
class InstallerWindow : public BWindow {