xref: /haiku/src/apps/installer/CopyEngine.cpp (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 /*
2  * Copyright 2005, 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 <DiskDeviceVisitor.h>
10 #include <DiskDeviceTypes.h>
11 #include <Path.h>
12 
13 extern void SizeAsString(off_t size, char *string);
14 
15 class SourceVisitor : public BDiskDeviceVisitor
16 {
17 public:
18 	SourceVisitor(BMenu *menu);
19 	virtual bool Visit(BDiskDevice *device);
20 	virtual bool Visit(BPartition *partition, int32 level);
21 private:
22 	BMenu *fMenu;
23 };
24 
25 
26 class TargetVisitor : public BDiskDeviceVisitor
27 {
28 public:
29 	TargetVisitor(BMenu *menu);
30 	virtual bool Visit(BDiskDevice *device);
31 	virtual bool Visit(BPartition *partition, int32 level);
32 private:
33 	void MakeLabel(BPartition *partition, char *label, char *menuLabel);
34 	BMenu *fMenu;
35 };
36 
37 
38 CopyEngine::CopyEngine(InstallerWindow *window)
39 	: BLooper("copy_engine"),
40 	fWindow(window)
41 {
42 
43 }
44 
45 
46 void
47 CopyEngine::LaunchInitScript(BVolume *volume)
48 {
49 	fWindow->SetStatusMessage("Starting Installation.");
50 }
51 
52 
53 void
54 CopyEngine::LaunchFinishScript(BVolume *volume)
55 {
56 	fWindow->SetStatusMessage("Finishing Installation.");
57 }
58 
59 
60 void
61 CopyEngine::Start()
62 {
63 	BVolume *volume;
64 	// check not installing on boot volume
65 
66 
67 	// check if target is initialized
68 
69 	// ask if init ou mount as is
70 
71 	LaunchInitScript(volume);
72 
73 	// copy source volume
74 
75 	// copy selected packages
76 
77 	LaunchFinishScript(volume);
78 }
79 
80 
81 void
82 CopyEngine::ScanDisksPartitions(BMenu *srcMenu, BMenu *targetMenu)
83 {
84 	BDiskDevice device;
85 	BPartition *partition = NULL;
86 
87 	printf("ScanDisksPartitions partitions begin\n");
88 	SourceVisitor srcVisitor(srcMenu);
89 	fDDRoster.VisitEachMountedPartition(&srcVisitor, &device, &partition);
90 
91 	printf("ScanDisksPartitions partitions begin\n");
92 	TargetVisitor targetVisitor(targetMenu);
93 	fDDRoster.VisitEachPartition(&targetVisitor, &device, &partition);
94 }
95 
96 
97 SourceVisitor::SourceVisitor(BMenu *menu)
98 	: fMenu(menu)
99 {
100 }
101 
102 bool
103 SourceVisitor::Visit(BDiskDevice *device)
104 {
105 	if (!device->ContentType() || strcmp(device->ContentType(), kPartitionTypeBFS)!=0)
106 		return false;
107 	BPath path;
108 	if (device->GetPath(&path)==B_OK)
109 		printf("SourceVisitor::Visit(BDiskDevice *) : %s type:%s, contentType:%s\n",
110 			path.Path(), device->Type(), device->ContentType());
111 	fMenu->AddItem(new PartitionMenuItem(NULL, device->ContentName(), NULL, new BMessage(SRC_PARTITION), device->ID()));
112 	return false;
113 }
114 
115 
116 bool
117 SourceVisitor::Visit(BPartition *partition, int32 level)
118 {
119 	if (!partition->ContentType() || strcmp(partition->ContentType(), kPartitionTypeBFS)!=0)
120 		return false;
121 	BPath path;
122 	if (partition->GetPath(&path)==B_OK)
123 		printf("SourceVisitor::Visit(BPartition *) : %s\n", path.Path());
124 	printf("SourceVisitor::Visit(BPartition *) : %s\n", partition->Name());
125 	fMenu->AddItem(new PartitionMenuItem(NULL, partition->ContentName(), NULL, new BMessage(SRC_PARTITION), partition->ID()));
126 	return false;
127 }
128 
129 
130 TargetVisitor::TargetVisitor(BMenu *menu)
131 	: fMenu(menu)
132 {
133 }
134 
135 
136 bool
137 TargetVisitor::Visit(BDiskDevice *device)
138 {
139 	if (device->IsReadOnly())
140 		return false;
141 	BPath path;
142 	if (device->GetPath(&path)==B_OK)
143 		printf("TargetVisitor::Visit(BDiskDevice *) : %s\n", path.Path());
144 	char label[255], menuLabel[255];
145 	MakeLabel(device, label, menuLabel);
146 	fMenu->AddItem(new PartitionMenuItem(device->ContentName(), label, menuLabel, new BMessage(TARGET_PARTITION), device->ID()));
147 	return false;
148 }
149 
150 
151 bool
152 TargetVisitor::Visit(BPartition *partition, int32 level)
153 {
154 	if (partition->IsReadOnly())
155 		return false;
156 	BPath path;
157 	if (partition->GetPath(&path)==B_OK)
158 		printf("TargetVisitor::Visit(BPartition *) : %s\n", path.Path());
159 	printf("TargetVisitor::Visit(BPartition *) : %s\n", partition->Name());
160 	char label[255], menuLabel[255];
161 	MakeLabel(partition, label, menuLabel);
162 	fMenu->AddItem(new PartitionMenuItem(partition->ContentName(), label, menuLabel, new BMessage(TARGET_PARTITION), partition->ID()));
163 	return false;
164 }
165 
166 
167 void
168 TargetVisitor::MakeLabel(BPartition *partition, char *label, char *menuLabel)
169 {
170 	char size[15];
171 	SizeAsString(partition->ContentSize(), size);
172 	BPath path;
173 	if (partition->Parent())
174 		partition->Parent()->GetPath(&path);
175 
176 	sprintf(label, "%s - %s [%s] [%s partition:%li]", partition->ContentName(), size, partition->ContentType(),
177 			path.Path(), partition->ID());
178 	sprintf(menuLabel, "%s - %s [%s]", partition->ContentName(), size, partition->ContentType());
179 
180 }
181 
182