From cbdfe279477d8a54af8cc2459c95129cc279f660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Mon, 23 Jan 2006 17:36:24 +0000 Subject: [PATCH] reworked a bit to install packages git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16048 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/installer/CopyEngine.cpp | 45 ++++++++++++++++--- src/apps/installer/CopyEngine.h | 4 +- .../installer/InstallerCopyLoopControl.cpp | 4 +- src/apps/installer/InstallerWindow.cpp | 12 ++++- src/apps/installer/InstallerWindow.h | 1 + src/apps/installer/PackageViews.cpp | 24 ++++++++-- src/apps/installer/PackageViews.h | 6 ++- 7 files changed, 82 insertions(+), 14 deletions(-) diff --git a/src/apps/installer/CopyEngine.cpp b/src/apps/installer/CopyEngine.cpp index 8eded33c5b..30e8d33ef8 100644 --- a/src/apps/installer/CopyEngine.cpp +++ b/src/apps/installer/CopyEngine.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2005, Jérôme DUVAL. All rights reserved. + * Copyright 2005-2006, Jérôme DUVAL. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -49,7 +49,8 @@ private: CopyEngine::CopyEngine(InstallerWindow *window) : BLooper("copy_engine"), - fWindow(window) + fWindow(window), + fPackages(NULL) { fControl = new InstallerCopyLoopControl(window); Run(); @@ -159,9 +160,36 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) // copy source volume BDirectory targetDir(targetDirectory.Path()); BDirectory srcDir(srcDirectory.Path()); + CopyFolder(srcDir, targetDir); + + // copy selected packages + srcDirectory.Append(PACKAGES_DIRECTORY); + srcDir.SetTo(srcDirectory.Path()); + BDirectory packageDir; + if (fPackages) { + int32 count = fPackages->CountItems(); + for (int32 i=0; i(fPackages->ItemAt(i)); + packageDir.SetTo(&srcDir, p->Folder()); + CopyFolder(packageDir, targetDir); + } + } + + LaunchFinishScript(targetDirectory); +} + + +void +CopyEngine::CopyFolder(BDirectory &srcDir, BDirectory &targetDir) +{ BEntry entry; status_t status; while (srcDir.GetNextEntry(&entry) == B_OK) { + char name[B_FILE_NAME_LENGTH]; + entry.GetName(name); + if (strcmp(name, PACKAGES_DIRECTORY) == 0) + continue; + Undo undo; status = FSCopyFolder(&entry, &targetDir, fControl, NULL, false, undo); if (status != B_OK) { @@ -170,10 +198,6 @@ CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu) fprintf(stderr, "error while copying %s : %s\n", path.Path(), strerror(status)); } } - - // copy selected packages - - LaunchFinishScript(targetDirectory); } @@ -193,6 +217,15 @@ CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu) } +void +CopyEngine::SetPackagesList(BList *list) +{ + if (fPackages) + delete fPackages; + fPackages = list; +} + + SourceVisitor::SourceVisitor(BMenu *menu) : fMenu(menu) { diff --git a/src/apps/installer/CopyEngine.h b/src/apps/installer/CopyEngine.h index b5edaabd57..7d591b2142 100644 --- a/src/apps/installer/CopyEngine.h +++ b/src/apps/installer/CopyEngine.h @@ -26,14 +26,16 @@ public: void SetStatusMessage(char *status); void Start(BMenu *srcMenu, BMenu *targetMenu); void ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu); - + void SetPackagesList(BList *list); private: void LaunchInitScript(BPath &path); void LaunchFinishScript(BPath &path); + void CopyFolder(BDirectory &srcDir, BDirectory &targetDir); InstallerWindow *fWindow; BDiskDeviceRoster fDDRoster; InstallerCopyLoopControl *fControl; + BList *fPackages; }; #endif /* _CopyEngine_h */ diff --git a/src/apps/installer/InstallerCopyLoopControl.cpp b/src/apps/installer/InstallerCopyLoopControl.cpp index 326b8a67ce..05ebe21aac 100644 --- a/src/apps/installer/InstallerCopyLoopControl.cpp +++ b/src/apps/installer/InstallerCopyLoopControl.cpp @@ -27,7 +27,9 @@ InstallerCopyLoopControl::UpdateStatus(const char *name, entry_ref ref, int32 co { if (name) { BMessage msg(STATUS_MESSAGE); - msg.AddString("status", name); + BString s = "Installing "; + s << name; + msg.AddString("status", s.String()); fMessenger.SendMessage(&msg); } } diff --git a/src/apps/installer/InstallerWindow.cpp b/src/apps/installer/InstallerWindow.cpp index 0bb8201353..82dd2310e7 100644 --- a/src/apps/installer/InstallerWindow.cpp +++ b/src/apps/installer/InstallerWindow.cpp @@ -164,9 +164,15 @@ InstallerWindow::MessageReceived(BMessage *msg) case START_SCAN: StartScan(); break; - case BEGIN_MESSAGE: + case BEGIN_MESSAGE: + { + BList *list = new BList(); + int32 size = 0; + fPackagesView->GetPackagesToInstall(list, &size); + fCopyEngine->SetPackagesList(list); BMessenger(fCopyEngine).SendMessage(ENGINE_START); break; + } case SHOW_BOTTOM_MESSAGE: ShowBottom(); break; @@ -341,7 +347,7 @@ InstallerWindow::PublishPackages() } else return; // shouldn't happen - directory.Append("_packages_"); + directory.Append(PACKAGES_DIRECTORY); BDirectory dir(directory.Path()); if (dir.InitCheck()!=B_OK) return; @@ -384,4 +390,6 @@ InstallerWindow::SetStatusMessage(const char *text) { BAutolock(this); fStatusView->SetText(text); + fStatusView->Invalidate(); } + diff --git a/src/apps/installer/InstallerWindow.h b/src/apps/installer/InstallerWindow.h index 2a07106e56..d4f901ebcb 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 char PACKAGES_DIRECTORY[] = "_packages_"; class InstallerWindow : public BWindow { public: diff --git a/src/apps/installer/PackageViews.cpp b/src/apps/installer/PackageViews.cpp index 532286dca9..f4df47e182 100644 --- a/src/apps/installer/PackageViews.cpp +++ b/src/apps/installer/PackageViews.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -42,12 +43,12 @@ SizeAsString(off_t size, char *string) } -Package::Package() +Package::Package(const char *folder) : Group(), fSize(0), fIcon(NULL) { - + SetFolder(folder); } @@ -60,10 +61,12 @@ Package::~Package() Package * Package::PackageFromEntry(BEntry &entry) { + char folder[B_FILE_NAME_LENGTH]; + entry.GetName(folder); BDirectory directory(&entry); if (directory.InitCheck()!=B_OK) return NULL; - Package *package = new Package(); + Package *package = new Package(folder); bool alwaysOn; bool onByDefault; int32 size; @@ -246,3 +249,18 @@ PackagesView::GetTotalSizeAsString(char *string) SizeAsString(size, string); } + +void +PackagesView::GetPackagesToInstall(BList *list, int32 *size) +{ + int32 count = CountChildren(); + *size = 0; + for (int32 i=0; i(ChildAt(i)); + if (cb && cb->Value()) { + list->AddItem(cb->GetPackage()); + *size += cb->GetPackage()->Size(); + } + } +} + diff --git a/src/apps/installer/PackageViews.h b/src/apps/installer/PackageViews.h index 015097c115..df70f4cced 100644 --- a/src/apps/installer/PackageViews.h +++ b/src/apps/installer/PackageViews.h @@ -26,14 +26,16 @@ private: class Package : public Group { public: - Package(); + Package(const char *folder); virtual ~Package(); + void SetFolder(const char *folder) { strcpy(fFolder, folder); }; void SetName(const char *name) { strcpy(fName, name);}; void SetDescription(const char *description) { strcpy(fDescription, description);}; void SetSize(const int32 size) { fSize = size; }; void SetIcon(BBitmap * icon) { delete fIcon; fIcon = icon; }; void SetOnByDefault(bool onByDefault) { fOnByDefault = onByDefault; }; void SetAlwaysOn(bool alwaysOn) { fAlwaysOn = alwaysOn; }; + const char * Folder() const { return fFolder; }; const char * Name() const { return fName; }; const char * Description() const { return fDescription; }; const int32 Size() const { return fSize; }; @@ -44,6 +46,7 @@ public: static Package *PackageFromEntry(BEntry &dir); private: + char fFolder[64]; char fName[64]; char fDescription[64]; int32 fSize; @@ -79,6 +82,7 @@ public: void Clean(); void AddPackages(BList &list, BMessage *msg); void GetTotalSizeAsString(char *string); + void GetPackagesToInstall(BList *list, int32 *size); private: BList fViews; };