From 92cd10f4db338d2aa15f215025a61f8808d4f7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 3 May 2009 09:58:09 +0000 Subject: [PATCH] * Refactored the way targets are collected before copy process begins, this way, the optional packages (if there would be any) can be collected as well before the actual process starts and the progress bar will reflect them correctly. Before this change, the progress bar would have reset itself for every optional package. * In one of my previous commits, I added the error, if there was any, to the reset message. Now the Installer window looks for the error and tells the user about it. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30602 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/installer/CopyEngine.cpp | 32 ++++++++++++++++++-------- src/apps/installer/CopyEngine.h | 3 +++ src/apps/installer/InstallerWindow.cpp | 13 ++++++++++- src/apps/installer/WorkerThread.cpp | 23 ++++++++++++++++-- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp index 7ca3f8b274..9a0c5f0674 100644 --- a/src/apps/installer/CopyEngine.cpp +++ b/src/apps/installer/CopyEngine.cpp @@ -70,9 +70,8 @@ CopyEngine::~CopyEngine() } -status_t -CopyEngine::CopyFolder(const char* source, const char* destination, - BLocker* locker) +void +CopyEngine::ResetTargets() { fBytesRead = 0; fItemsCopied = 0; @@ -87,10 +86,27 @@ CopyEngine::CopyFolder(const char* source, const char* destination, fCurrentTargetFolder = NULL; fCurrentItem = NULL; + if (fMessage) { + BMessage message(*fMessage); + message.AddString("status", "Collecting copy information."); + fMessenger.SendMessage(&message); + } +} + + +status_t +CopyEngine::CollectTargets(const char* source) +{ int32 level = 0; - status_t ret = _CollectCopyInfo(source, level); - if (ret < B_OK) - return ret; + return _CollectCopyInfo(source, level); +} + + +status_t +CopyEngine::CopyFolder(const char* source, const char* destination, + BLocker* locker = NULL) +{ + printf("%lld bytes to read in %lld files\n", fBytesToCopy, fItemsToCopy); if (fMessage) { BMessage message(*fMessage); @@ -98,9 +114,7 @@ CopyEngine::CopyFolder(const char* source, const char* destination, fMessenger.SendMessage(&message); } -printf("%lld bytes to read in %lld files\n", fBytesToCopy, fItemsToCopy); - - level = 0; + int32 level = 0; return _CopyFolder(source, destination, level, locker); } diff --git a/src/apps/installer/CopyEngine.h b/src/apps/installer/CopyEngine.h index bce89981ac..f34560850c 100644 --- a/src/apps/installer/CopyEngine.h +++ b/src/apps/installer/CopyEngine.h @@ -25,6 +25,9 @@ public: BMessage* message); virtual ~CopyEngine(); + void ResetTargets(); + status_t CollectTargets(const char* source); + status_t CopyFolder(const char* source, const char* destination, BLocker* locker = NULL); diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index ba8e4f1114..638450dc05 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -359,9 +359,19 @@ InstallerWindow::MessageReceived(BMessage *msg) { switch (msg->what) { case MSG_RESET: + { delete fCopyEngineLock; fCopyEngineLock = NULL; + status_t error; + if (msg->FindInt32("error", &error) == B_OK) { + char errorMessage[2048]; + snprintf(errorMessage, sizeof(errorMessage), "An error was " + "encountered and the installation was not completed:\n\n" + "Error: %s", strerror(error)); + (new BAlert("error", errorMessage, "Ok"))->Go(); + } + fInstallStatus = kReadyForInstall; fBeginButton->SetEnabled(true); _DisableInterface(false); @@ -372,6 +382,7 @@ InstallerWindow::MessageReceived(BMessage *msg) fBeginButton->SetLabel("Begin"); break; + } case START_SCAN: _ScanPartitions(); break; @@ -530,7 +541,7 @@ InstallerWindow::QuitRequested() if (fDriveSetupLaunched) { (new BAlert("driveSetup", "Please close the DriveSetup window before closing the " - "Installer window.", "OK"))->Go(); + "Installer window.", "Ok"))->Go(); return false; } _QuitCopyEngine(false); diff --git a/src/apps/installer/WorkerThread.cpp b/src/apps/installer/WorkerThread.cpp index 688f1c5239..74341f764a 100644 --- a/src/apps/installer/WorkerThread.cpp +++ b/src/apps/installer/WorkerThread.cpp @@ -388,6 +388,25 @@ WorkerThread::_PerformInstall(BMenu *srcMenu, BMenu *targetMenu) _LaunchInitScript(targetDirectory); + // let the engine collect information for the progress bar later on + engine.ResetTargets(); + err = engine.CollectTargets(srcDirectory.Path()); + if (err != B_OK) + goto error; + + // collect selected packages also + if (fPackages) { + BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); + int32 count = fPackages->CountItems(); + for (int32 i = 0; i < count; i++) { + Package *p = static_cast(fPackages->ItemAt(i)); + BPath packageDir(pkgRootDir.Path(), p->Folder()); + err = engine.CollectTargets(packageDir.Path()); + if (err != B_OK) + goto error; + } + } + // copy source volume err = engine.CopyFolder(srcDirectory.Path(), targetDirectory.Path(), fCancelLock); @@ -396,11 +415,11 @@ WorkerThread::_PerformInstall(BMenu *srcMenu, BMenu *targetMenu) // copy selected packages if (fPackages) { - srcDirectory.Append(PACKAGES_DIRECTORY); + BPath pkgRootDir(srcDirectory.Path(), PACKAGES_DIRECTORY); int32 count = fPackages->CountItems(); for (int32 i = 0; i < count; i++) { Package *p = static_cast(fPackages->ItemAt(i)); - BPath packageDir(srcDirectory.Path(), p->Folder()); + BPath packageDir(pkgRootDir.Path(), p->Folder()); err = engine.CopyFolder(packageDir.Path(), targetDirectory.Path(), fCancelLock); if (err != B_OK)