From bc1301d3368d4296806735be1918f7c7d390fa49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Tue, 24 Jan 2006 16:16:26 +0000 Subject: [PATCH] * 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 --- src/apps/installer/CopyEngine.cpp | 65 ++++++++++++------- .../installer/InstallerCopyLoopControl.cpp | 10 +++ src/apps/installer/InstallerWindow.cpp | 17 +++-- src/apps/installer/InstallerWindow.h | 1 + 4 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp index a7a5a15bc1..a2c97a5e39 100644 --- a/src/apps/installer/CopyEngine.cpp +++ b/src/apps/installer/CopyEngine.cpp @@ -8,9 +8,10 @@ #include "PartitionMenuItem.h" #include "FSUndoRedo.h" #include "FSUtils.h" -#include +#include #include #include +#include #include #include #include @@ -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(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; } diff --git a/src/apps/installer/InstallerCopyLoopControl.cpp b/src/apps/installer/InstallerCopyLoopControl.cpp index 05ebe21aac..3a143a3f79 100644 --- a/src/apps/installer/InstallerCopyLoopControl.cpp +++ b/src/apps/installer/InstallerCopyLoopControl.cpp @@ -5,6 +5,7 @@ */ #include "InstallerCopyLoopControl.h" #include "InstallerWindow.h" +#include 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; } diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 82dd2310e7..99633ce252 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -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."); } diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index d4f901ebcb..da825ace51 100644 --- a/src/apps/installer/InstallerWindow.h +++ b/src/apps/installer/InstallerWindow.h @@ -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 {