Ticket #2061: instpatch.patch

File instpatch.patch, 8.5 KB (added by korli, 16 years ago)

the patch

  • installer/CopyEngine.cpp

     
    7474        {
    7575            status_t err = Start(fWindow->GetSourceMenu(),
    7676                fWindow->GetTargetMenu());
    77             if (err != B_OK)
     77            if (err != B_OK) {
    7878                ERR("Start failed");
     79                BMessenger(fWindow).SendMessage(RESET_INSTALL);
     80            }
    7981            break;
    8082        }
    8183    }
     
    182184            "Try choosing a different disk or choose to not install optional "
    183185            "items.", "Try installing anyway", "Cancel", 0,
    184186            B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
     187        BMessenger(fWindow).SendMessage(RESET_INSTALL);
    185188        return B_OK;
    186189    }
    187190
     
    203206    if (strcmp(srcDirectory.Path(), targetDirectory.Path()) == 0) {
    204207        SetStatusMessage("You can't install the contents of a disk onto "
    205208            "itself. Please choose a different disk.");
     209        BMessenger(fWindow).SendMessage(RESET_INSTALL);
    206210        return B_OK;
    207211    }
    208212
     
    213217            "machine if you proceed.", "OK", "Cancel", 0,
    214218            B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0)) {
    215219        SetStatusMessage("Installation stopped.");
     220        BMessenger(fWindow).SendMessage(RESET_INSTALL);
    216221        return B_OK;
    217222    }
    218223
     
    230235        BDirectory packageDir;
    231236        int32 count = fPackages->CountItems();
    232237        for (int32 i = 0; i < count; i++) {
     238            if (fControl->CheckUserCanceled())
     239                return B_OK;
    233240            Package *p = static_cast<Package*>(fPackages->ItemAt(i));
    234241            packageDir.SetTo(&srcDir, p->Folder());
    235242            CopyFolder(packageDir, targetDir);
    236243        }
    237244    }
    238245
    239     LaunchFinishScript(targetDirectory);
     246    if (!fControl->CheckUserCanceled()) {
     247        LaunchFinishScript(targetDirectory);
    240248
    241     BMessage msg(INSTALL_FINISHED);
    242     BMessenger(fWindow).SendMessage(&msg);
     249        BMessage msg(INSTALL_FINISHED);
     250        BMessenger(fWindow).SendMessage(&msg);
     251    }
    243252
    244253    return B_OK;
    245254}
     
    250259{
    251260    BEntry entry;
    252261    status_t err;
    253     while (srcDir.GetNextEntry(&entry) == B_OK) {
     262    while (srcDir.GetNextEntry(&entry) == B_OK
     263        && !fControl->CheckUserCanceled()) {
    254264        StatStruct statbuf;
    255265        entry.GetStat(&statbuf);
    256266       
     
    299309}
    300310
    301311
     312bool
     313CopyEngine::Cancel()
     314{
     315    return fControl->Cancel();
     316}
     317
     318
    302319// #pragma mark -
    303320
    304321
  • installer/CopyEngine.h

     
    2828        void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu);
    2929        void SetPackagesList(BList *list);
    3030        void SetSpaceRequired(off_t bytes) { fSpaceRequired = bytes; };
     31        bool Cancel();
    3132    private:
    3233        void LaunchInitScript(BPath &path);
    3334        void LaunchFinishScript(BPath &path);
  • installer/InstallerCopyLoopControl.cpp

     
    99
    1010InstallerCopyLoopControl::InstallerCopyLoopControl(InstallerWindow *window)
    1111    : fWindow(window),
    12     fMessenger(window)
     12    fMessenger(window),
     13    fUserCanceled(false)
    1314{
    1415}
    1516
     
    4849bool
    4950InstallerCopyLoopControl::CheckUserCanceled()
    5051{
    51     return false;
     52    return fUserCanceled;
    5253}
    5354
    5455
     
    9798    return false;
    9899}
    99100
     101
     102bool
     103InstallerCopyLoopControl::Cancel()
     104{
     105    fUserCanceled = (new BAlert("",
     106            "Are you sure you want to to stop the installation?",
     107            "Continue", "Stop", 0,
     108            B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go() != 0;
     109    return fUserCanceled;
     110}
     111
  • installer/InstallerWindow.cpp

     
    7171    : BWindow(frame_rect, "Installer", B_TITLED_WINDOW,
    7272        B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
    7373    fDriveSetupLaunched(false),
     74    fInstallStatus(kReadyForInstall),
    7475    fLastSrcItem(NULL),
    7576    fLastTargetItem(NULL)
    7677{
     
    110111        "begin_button", "Begin", new BMessage(BEGIN_MESSAGE),
    111112        B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
    112113    fBeginButton->MakeDefault(true);
     114    fBeginButton->SetEnabled(false);
    113115    fBackBox->AddChild(fBeginButton);
    114116
    115117    fSetupButton = new BButton(BRect(bounds.left + 11, bounds.bottom - 35,
     
    135137    fDestMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
    136138    fSrcMenu = new BPopUpMenu("scanning" B_UTF8_ELLIPSIS, true, false);
    137139
    138     BRect fieldRect(bounds.left + 50, bounds.top + 70, bounds.right - 13,
     140    BRect fieldRect(bounds.left + 13, bounds.top + 70, bounds.right - 13,
    139141        bounds.top + 90);
    140142    fSrcMenuField = new BMenuField(fieldRect, "srcMenuField",
    141143        "Install from: ", fSrcMenu);
    142     fSrcMenuField->SetDivider(bounds.right - 274);
     144    fSrcMenuField->SetDivider(bounds.right - 300);
    143145    fSrcMenuField->SetAlignment(B_ALIGN_RIGHT);
    144146    fBackBox->AddChild(fSrcMenuField);
    145147
    146148    fieldRect.OffsetBy(0, 23);
    147149    fDestMenuField = new BMenuField(fieldRect, "destMenuField",
    148150        "Onto: ", fDestMenu);
    149     fDestMenuField->SetDivider(bounds.right - 274);
     151    fDestMenuField->SetDivider(bounds.right - 300);
    150152    fDestMenuField->SetAlignment(B_ALIGN_RIGHT);
    151153    fBackBox->AddChild(fDestMenuField);
    152154
     
    182184InstallerWindow::MessageReceived(BMessage *msg)
    183185{
    184186    switch (msg->what) {
     187        case RESET_INSTALL:
     188            fInstallStatus = kReadyForInstall;
     189            fBeginButton->SetEnabled(true);
     190            DisableInterface(false);
     191            fBeginButton->SetLabel("Begin");
     192            break;
    185193        case START_SCAN:
    186194            StartScan();
     195            fBeginButton->SetEnabled(true);
    187196            break;
    188197        case BEGIN_MESSAGE:
    189198        {
    190199            BList *list = new BList();
    191             int32 size = 0;
    192             fPackagesView->GetPackagesToInstall(list, &size);
    193             fCopyEngine->SetPackagesList(list);
    194             fCopyEngine->SetSpaceRequired(size);
    195             BMessenger(fCopyEngine).SendMessage(ENGINE_START);
    196             DisableInterface(true);
     200            switch (fInstallStatus) {
     201                case kReadyForInstall:
     202                {
     203                    int32 size = 0;
     204                    fPackagesView->GetPackagesToInstall(list, &size);
     205                    fCopyEngine->SetPackagesList(list);
     206                    fCopyEngine->SetSpaceRequired(size);
     207                    BMessenger(fCopyEngine).SendMessage(ENGINE_START);
     208                    fBeginButton->SetLabel("Stop");
     209                    DisableInterface(true);
     210                    fInstallStatus = kInstalling;
     211                    break;
     212                }
     213                case kInstalling:
     214                    if (fCopyEngine->Cancel())
     215                        PostMessage(INSTALL_FINISHED);
     216                    break;
     217                case kFinished:
     218                    QuitRequested();
     219                    break;
     220            }
    197221            break;
    198222        }
    199223        case SHOW_BOTTOM_MESSAGE:
     
    230254                SetStatusMessage(status);
    231255            } else
    232256                SetStatusMessage(fLastStatus.String());
     257            break;
    233258        }
    234259        case INSTALL_FINISHED:
     260            fBeginButton->SetLabel("Quit");
     261            fInstallStatus = kFinished;
    235262            DisableInterface(false);
    236263            break;
    237264        case B_SOME_APP_LAUNCHED:
     
    241268            if (msg->FindString("be:signature", &signature) == B_OK
    242269                && strcasecmp(signature, DRIVESETUP_SIG) == 0) {
    243270                fDriveSetupLaunched = msg->what == B_SOME_APP_LAUNCHED;
     271                fBeginButton->SetEnabled(!fDriveSetupLaunched);
    244272                DisableInterface(fDriveSetupLaunched);
    245273                if (fDriveSetupLaunched)
    246274                    SetStatusMessage("Running DriveSetup" B_UTF8_ELLIPSIS
     
    306334void
    307335InstallerWindow::DisableInterface(bool disable)
    308336{
    309     fBeginButton->SetEnabled(!disable);
    310337    fSetupButton->SetEnabled(!disable);
    311338    fSrcMenuField->SetEnabled(!disable);
    312339    fDestMenuField->SetEnabled(!disable);
  • installer/InstallerCopyLoopControl.h

     
    3535        virtual bool ChecksumFile(const entry_ref *);
    3636        virtual bool SkipAttribute(const char *attributeName);
    3737        virtual bool PreserveAttribute(const char *attributeName);
     38        bool Cancel();
    3839
    3940    private:
    4041        InstallerWindow *fWindow;
    4142        BMessenger fMessenger;
     43        bool fUserCanceled;
    4244};
    4345
    4446#endif
  • installer/InstallerWindow.h

     
    2020
    2121#define INSTALLER_RIGHT 402
    2222
     23enum InstallStatus {
     24    kReadyForInstall,
     25    kInstalling,
     26    kFinished
     27};
     28
    2329const uint32 STATUS_MESSAGE = 'iSTM';
    2430const uint32 INSTALL_FINISHED = 'iIFN';
     31const uint32 RESET_INSTALL = 'iRSI';
    2532const char PACKAGES_DIRECTORY[] = "_packages_";
    2633
    2734class InstallerWindow : public BWindow {
     
    4653        BButton *fBeginButton, *fSetupButton;
    4754        DrawButton *fDrawButton;
    4855        bool fDriveSetupLaunched;
     56        InstallStatus fInstallStatus;
    4957        BTextView *fStatusView;
    5058        BMenu* fSrcMenu, *fDestMenu;
    5159        BMenuField* fSrcMenuField, *fDestMenuField;