reworked a bit to install packages

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16048 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2006-01-23 17:36:24 +00:00
parent 141f2cefe9
commit cbdfe27947
7 changed files with 82 additions and 14 deletions

View File

@ -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<count; i++) {
Package *p = static_cast<Package*>(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)
{

View File

@ -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 */

View File

@ -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);
}
}

View File

@ -165,8 +165,14 @@ InstallerWindow::MessageReceived(BMessage *msg)
StartScan();
break;
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();
}

View File

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

View File

@ -5,6 +5,7 @@
#include <fs_attr.h>
#include <Directory.h>
#include <Entry.h>
#include <ScrollBar.h>
#include <String.h>
#include <stdio.h>
@ -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<count; i++) {
PackageCheckBox *cb = dynamic_cast<PackageCheckBox*>(ChildAt(i));
if (cb && cb->Value()) {
list->AddItem(cb->GetPackage());
*size += cb->GetPackage()->Size();
}
}
}

View File

@ -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;
};