xref: /haiku/src/tests/apps/installer/CopyEngine.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2005-2006, Jérôme DUVAL. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include "CopyEngine.h"
7 #include "InstallerWindow.h"
8 #include "PartitionMenuItem.h"
9 #include <Alert.h>
10 #include <FindDirectory.h>
11 #include <Path.h>
12 #include <String.h>
13 #include <VolumeRoster.h>
14 
15 //#define COPY_TRACE
16 #ifdef COPY_TRACE
17 #define CALLED() 			printf("CALLED %s\n",__PRETTY_FUNCTION__)
18 #else
19 #define CALLED()
20 #endif
21 
22 const char BOOT_PATH[] = "/boot";
23 
24 extern void SizeAsString(off_t size, char *string);
25 
26 
27 CopyEngine::CopyEngine(InstallerWindow *window)
28 	: BLooper("copy_engine"),
29 	fWindow(window),
30 	fPackages(NULL),
31 	fSpaceRequired(0)
32 {
33 	Run();
34 }
35 
36 
37 void
38 CopyEngine::MessageReceived(BMessage*msg)
39 {
40 	CALLED();
41 	switch (msg->what) {
42 		case ENGINE_START:
43 			Start(fWindow->GetSourceMenu(), fWindow->GetTargetMenu());
44 			break;
45 	}
46 }
47 
48 
49 void
50 CopyEngine::SetStatusMessage(char *status)
51 {
52 	BMessage msg(STATUS_MESSAGE);
53 	msg.AddString("status", status);
54 	BMessenger(fWindow).SendMessage(&msg);
55 }
56 
57 
58 void
59 CopyEngine::Start(BMenu *srcMenu, BMenu *targetMenu)
60 {
61 	CALLED();
62 	PartitionMenuItem *targetItem = (PartitionMenuItem *)targetMenu->FindMarked();
63 	PartitionMenuItem *srcItem = (PartitionMenuItem *)srcMenu->FindMarked();
64 	if (!srcItem || !targetItem) {
65 		fprintf(stderr, "bad menu items\n");
66 		return;
67 	}
68 
69 	BMessage msg(INSTALL_FINISHED);
70 	BMessenger(fWindow).SendMessage(&msg);
71 }
72 
73 
74 void
75 CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu)
76 {
77 	PartitionMenuItem *item = new PartitionMenuItem(NULL, "boot", NULL, new BMessage(SRC_PARTITION), 0);
78 	srcMenu->AddItem(item);
79 
80 	PartitionMenuItem *item2 = new PartitionMenuItem(NULL, "target", NULL, new BMessage(TARGET_PARTITION), 0);
81 	targetMenu->AddItem(item2);
82 }
83 
84 
85 void
86 CopyEngine::SetPackagesList(BList *list)
87 {
88 	if (fPackages)
89 		delete fPackages;
90 	fPackages = list;
91 }
92 
93