-
Notifications
You must be signed in to change notification settings - Fork 245
Expand file tree
/
Copy pathBundleCreator.java
More file actions
544 lines (501 loc) · 19.1 KB
/
BundleCreator.java
File metadata and controls
544 lines (501 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
package gui;
import flashsystem.Bundle;
import flashsystem.BundleEntry;
import flashsystem.BundleMetaData;
import flashsystem.Category;
import gui.models.CategoriesContentProvider;
import gui.models.CategoriesModel;
import gui.models.SinfilesLabelProvider;
import gui.tools.WidgetTask;
import gui.tools.WidgetsTool;
import gui.tools.createFTFJob;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.Vector;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.List;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.layout.TreeColumnLayout;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.system.DeviceEntry;
import org.system.Devices;
import org.system.OS;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
public class BundleCreator extends Dialog {
protected Object result = new String("Create");
protected Shell shlBundler;
private Text sourceFolder;
private Text device;
private Text branding;
private Text version;
Vector<BundleEntry> files = new Vector<BundleEntry>();
ListViewer listViewerFiles;
private Label lblSelectSourceFolder;
private Button btnNewButton;
private Label lblNewLabel_2;
private List list;
private Label lblNewLabel;
private FormData fd_btnNewButton_1;
private Button btnNewButton_1;
private Composite composite_5;
private BundleMetaData meta = new BundleMetaData();
private CategoriesModel model = new CategoriesModel(meta);
TreeViewer treeViewerCategories;
Button btnNoFinalVerification;
private Label lblNewLabel_3;
private FormData fd_lblNewLabel;
private String _branding = "";
private String _version = "";
private String _deviceName="";
private String _variant = "";
public void setBranding(String lbranding) {
_branding = lbranding;
}
public void setVersion(String lversion) {
_version = lversion;
}
public void setVariant(String lid, String lvariant) {
_deviceName=lid;
_variant = lvariant;
}
/**
* Create the dialog.
* @param parent
* @param style
*/
public BundleCreator(Shell parent, int style) {
super(parent, style);
setText("SWT Dialog");
}
/**
* Open the dialog.
* @return the result
*/
public Object open() {
createContents();
WidgetsTool.setSize(shlBundler);
shlBundler.open();
shlBundler.layout();
Display display = getParent().getDisplay();
while (!shlBundler.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return result;
}
public Object open(String folder) {
createContents();
WidgetsTool.setSize(shlBundler);
sourceFolder.setText(folder);
meta.clear();
files = new Vector<BundleEntry>();
File srcdir = new File(sourceFolder.getText());
File[] chld = srcdir.listFiles();
for(int i = 0; i < chld.length; i++) {
if (chld[i].getName().toUpperCase().endsWith("SIN") || (chld[i].getName().toUpperCase().endsWith("TA")) || (chld[i].getName().toUpperCase().endsWith("XML") && (!chld[i].getName().toUpperCase().contains("UPDATE") && !chld[i].getName().toUpperCase().contains("FWINFO")))) {
files.add(new BundleEntry(chld[i]));
}
}
srcdir = new File(sourceFolder.getText()+File.separator+"boot");
if (srcdir.exists()) {
chld = srcdir.listFiles();
for(int i = 0; i < chld.length; i++) {
if (chld[i].getName().toUpperCase().endsWith("XML")) {
files.add(new BundleEntry(chld[i]));
}
}
}
model.refresh(meta);
treeViewerCategories.setInput(model);
listViewerFiles.setInput(files);
shlBundler.open();
shlBundler.layout();
Display display = getParent().getDisplay();
while (!shlBundler.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
return result;
}
/**
* Create contents of the dialog.
*/
private void createContents() {
shlBundler = new Shell(getParent(), getStyle());
shlBundler.setSize(626, 447);
shlBundler.setText("Bundler");
shlBundler.setLayout(new FormLayout());
listViewerFiles = new ListViewer(shlBundler, SWT.BORDER | SWT.V_SCROLL | SWT.MULTI);
list = listViewerFiles.getList();
FormData fd_list = new FormData();
fd_list.left = new FormAttachment(0, 10);
list.setLayoutData(fd_list);
listViewerFiles.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) {
Vector v = (Vector)inputElement;
return v.toArray();
}
public void dispose() {
}
public void inputChanged(
Viewer viewer,
Object oldInput,
Object newInput) {
}
});
listViewerFiles.setLabelProvider(new LabelProvider() {
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
return ((BundleEntry)element).getName();
}
});
listViewerFiles.setSorter(new ViewerSorter(){
public int compare(Viewer viewer, Object e1, Object e2) {
return ((BundleEntry)e1).getName().compareTo(((BundleEntry)e2).getName());
}
});
lblNewLabel_3 = new Label(shlBundler, SWT.NONE);
fd_list.top = new FormAttachment(lblNewLabel_3, 6);
fd_lblNewLabel = new FormData();
fd_lblNewLabel.left = new FormAttachment(0, 10);
lblNewLabel_3.setLayoutData(fd_lblNewLabel);
lblNewLabel_3.setText("folder list :");
composite_5 = new Composite(shlBundler, SWT.NONE);
fd_list.bottom = new FormAttachment(composite_5, 0, SWT.BOTTOM);
composite_5.setLayout(new TreeColumnLayout());
FormData fd_composite_5 = new FormData();
fd_composite_5.top = new FormAttachment(lblNewLabel_3, 6);
fd_composite_5.right = new FormAttachment(100, -10);
composite_5.setLayoutData(fd_composite_5);
treeViewerCategories = new TreeViewer(composite_5, SWT.BORDER | SWT.MULTI);
Tree treeCategories = treeViewerCategories.getTree();
treeCategories.setHeaderVisible(true);
treeCategories.setLinesVisible(true);
treeViewerCategories.setContentProvider(new CategoriesContentProvider());
treeViewerCategories.setLabelProvider(new SinfilesLabelProvider());
treeViewerCategories.setSorter(new ViewerSorter(){
public int compare(Viewer viewer, Object e1, Object e2) {
int cat1 = category(e1);
int cat2 = category(e2);
if (cat1 != cat2) return cat1 - cat2;
if ((e1 instanceof Category) && (e2 instanceof Category))
return ((Category)e1).getId().compareTo(((Category)e2).getId());
else
return ((File)e1).getName().compareTo(((File)e2).getName());
}
});
// Expand the tree
treeViewerCategories.setAutoExpandLevel(2);
// Provide the input to the ContentProvider
treeViewerCategories.setInput(new CategoriesModel(meta));
treeViewerCategories.refresh();
Button btnCancel = new Button(shlBundler, SWT.NONE);
fd_composite_5.bottom = new FormAttachment(btnCancel, -5);
btnCancel.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
result = new String("Cancel");
shlBundler.dispose();
}
});
FormData fd_btnCancel = new FormData();
fd_btnCancel.right = new FormAttachment(100, -10);
fd_btnCancel.bottom = new FormAttachment(100, -10);
btnCancel.setLayoutData(fd_btnCancel);
btnCancel.setText("Cancel");
Button btnCreate = new Button(shlBundler, SWT.NONE);
btnCreate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (sourceFolder.getText().length()==0) {
showErrorMessageBox("You must point to a folder containing sin files");
return;
}
if ((device.getText().length()==0) || (version.getText().length()==0) || (branding.getText().length()==0)) {
showErrorMessageBox("Device, Versio, Branding : all fields must be set");
return;
}
File f = new File(OS.getFolderFirmwares()+File.separator+_variant+"_"+version.getText()+"_"+branding.getText()+".ftf");
if (f.exists()) {
showErrorMessageBox("This bundle name already exists");
return;
}
try {
if (f.createNewFile())
f.delete();
else {
showErrorMessageBox("The built filename from variant, version and branding is not valid. Choose another name");
return;
}
}
catch (IOException ioe) {
showErrorMessageBox("The built filename from variant, version and branding is not valid. Choose another name");
return;
}
Bundle b = new Bundle();
try {
b.setMeta(meta);
} catch (Exception ex) {}
b.setDevice(_variant);
b.setVersion(version.getText());
b.setBranding(branding.getText());
b.setCmd25(btnNoFinalVerification.getSelection()?"true":"false");
if (!b.hasLoader()) {
String result = Devices.getIdFromVariant(_variant);
DeviceEntry ent = new DeviceEntry(result);
if (ent.hasUnlockedLoader()) {
String res = WidgetTask.openLoaderSelect(shlBundler);
if (res.equals("U"))
b.setLoader(new File(ent.getLoaderUnlocked()));
else
if (res.equals("L"))
b.setLoader(new File(ent.getLoader()));
else {
showErrorMessageBox("This bundle must contain a loader");
return;
}
}
else {
b.setLoader(new File(ent.getLoader()));
}
}
createFTFJob j = new createFTFJob("Create FTF");
j.setBundle(b);
j.schedule();
shlBundler.dispose();
}
});
FormData fd_btnCreate = new FormData();
fd_btnCreate.bottom = new FormAttachment(btnCancel, 0, SWT.BOTTOM);
fd_btnCreate.right = new FormAttachment(btnCancel, -6);
btnCreate.setLayoutData(fd_btnCreate);
btnCreate.setText("Create");
btnNewButton_1 = new Button(shlBundler, SWT.NONE);
fd_list.right = new FormAttachment(btnNewButton_1, -6);
fd_composite_5.left = new FormAttachment(btnNewButton_1, 6);
btnNewButton_1.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)listViewerFiles.getSelection();
Iterator i = selection.iterator();
while (i.hasNext()) {
BundleEntry f = (BundleEntry)i.next();
files.remove(f);
try {
meta.process(f);
model.refresh(meta);
treeViewerCategories.setInput(model);
} catch (Exception ex) {ex.printStackTrace();}
treeViewerCategories.setAutoExpandLevel(2);
treeViewerCategories.refresh();
listViewerFiles.refresh();
}
}
});
fd_btnNewButton_1 = new FormData();
fd_btnNewButton_1.left = new FormAttachment(0, 353);
fd_btnNewButton_1.right = new FormAttachment(100, -224);
btnNewButton_1.setLayoutData(fd_btnNewButton_1);
btnNewButton_1.setText("->");
Button btnNewButton_2 = new Button(shlBundler, SWT.NONE);
fd_btnNewButton_1.bottom = new FormAttachment(100, -143);
btnNewButton_2.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
IStructuredSelection selection = (IStructuredSelection)treeViewerCategories.getSelection();
Iterator i = selection.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof Category) {
Category c = (Category)o;
Iterator<BundleEntry> j = c.getEntries().iterator();
while (j.hasNext()) {
BundleEntry f=j.next();
files.add(f);
meta.remove(f);
model.refresh(meta);
treeViewerCategories.setAutoExpandLevel(2);
treeViewerCategories.refresh();
listViewerFiles.refresh();
}
}
if (o instanceof BundleEntry) {
BundleEntry f = (BundleEntry)o;
files.add(f);
meta.remove(f);
model.refresh(meta);
treeViewerCategories.setAutoExpandLevel(2);
treeViewerCategories.refresh();
listViewerFiles.refresh();
}
}
}
});
FormData fd_btnNewButton_2 = new FormData();
fd_btnNewButton_2.top = new FormAttachment(btnNewButton_1, 23);
fd_btnNewButton_2.right = new FormAttachment(btnNewButton_1, 0, SWT.RIGHT);
fd_btnNewButton_2.left = new FormAttachment(0, 353);
btnNewButton_2.setLayoutData(fd_btnNewButton_2);
btnNewButton_2.setText("<-");
Composite composite = new Composite(shlBundler, SWT.NONE);
composite.setLayout(new GridLayout(3, false));
FormData fd_composite = new FormData();
fd_composite.left = new FormAttachment(0, 10);
fd_composite.right = new FormAttachment(100, -10);
fd_composite.top = new FormAttachment(0, 10);
composite.setLayoutData(fd_composite);
lblSelectSourceFolder = new Label(composite, SWT.NONE);
GridData gd_lblSelectSourceFolder = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_lblSelectSourceFolder.widthHint = 121;
lblSelectSourceFolder.setLayoutData(gd_lblSelectSourceFolder);
lblSelectSourceFolder.setText("Select source folder :");
sourceFolder = new Text(composite, SWT.BORDER);
sourceFolder.setEditable(false);
GridData gd_sourceFolder = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_sourceFolder.widthHint = 428;
sourceFolder.setLayoutData(gd_sourceFolder);
btnNewButton = new Button(composite, SWT.NONE);
btnNewButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dlg = new DirectoryDialog(shlBundler);
// Set the initial filter path according
// to anything they've selected or typed in
dlg.setFilterPath(sourceFolder.getText());
// Change the title bar text
dlg.setText("Directory chooser");
// Customizable message displayed in the dialog
dlg.setMessage("Select a directory");
// Calling open() will open and run the dialog.
// It will return the selected directory, or
// null if user cancels
String dir = dlg.open();
if (dir != null) {
// Set the text box to the new selection
if (!sourceFolder.getText().equals(dir)) {
sourceFolder.setText(dir);
meta.clear();
files = new Vector();
File srcdir = new File(sourceFolder.getText());
File[] chld = srcdir.listFiles();
for(int i = 0; i < chld.length; i++) {
if (chld[i].getName().toUpperCase().endsWith("SIN") || (chld[i].getName().toUpperCase().endsWith("TA")) || (chld[i].getName().toUpperCase().endsWith("XML") && (!chld[i].getName().toUpperCase().contains("UPDATE") && !chld[i].getName().toUpperCase().contains("FWINFO")))) {
files.add(new BundleEntry(chld[i]));
}
}
srcdir = new File(sourceFolder.getText()+File.separator+"boot");
if (srcdir.exists()) {
chld = srcdir.listFiles();
for(int i = 0; i < chld.length; i++) {
if (chld[i].getName().toUpperCase().endsWith("XML")) {
files.add(new BundleEntry(chld[i]));
}
}
}
model.refresh(meta);
treeViewerCategories.setInput(model);
listViewerFiles.setInput(files);
}
}
}
});
btnNewButton.setText("...");
Composite composite_1 = new Composite(shlBundler, SWT.NONE);
fd_lblNewLabel.top = new FormAttachment(0, 154);
composite_1.setLayout(new GridLayout(3, false));
FormData fd_composite_1 = new FormData();
fd_composite_1.bottom = new FormAttachment(lblNewLabel_3, -6);
fd_composite_1.right = new FormAttachment(composite_5, 0, SWT.RIGHT);
fd_composite_1.top = new FormAttachment(composite, 2);
fd_composite_1.left = new FormAttachment(0, 10);
composite_1.setLayoutData(fd_composite_1);
lblNewLabel = new Label(composite_1, SWT.NONE);
GridData gd_lblNewLabel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
gd_lblNewLabel.widthHint = 68;
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText("Device :");
device = new Text(composite_1, SWT.BORDER);
device.setToolTipText("Double click to get list of devices");
device.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
String result = WidgetTask.openDeviceSelector(shlBundler);
if (result.length()>0) {
DeviceEntry ent = new DeviceEntry(result);
String variant = WidgetTask.openVariantSelector(ent.getId(),shlBundler);
device.setText(ent.getName() + " ("+variant+")");
_variant=variant;
}
}
});
device.setEditable(false);
GridData gd_device = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_device.widthHint = 355;
device.setLayoutData(gd_device);
new Label(composite_1, SWT.NONE);
lblNewLabel_2 = new Label(composite_1, SWT.NONE);
lblNewLabel_2.setText("Branding :");
branding = new Text(composite_1, SWT.BORDER);
GridData gd_branding = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_branding.widthHint = 355;
branding.setLayoutData(gd_branding);
btnNoFinalVerification = new Button(composite_1, SWT.CHECK);
btnNoFinalVerification.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
btnNoFinalVerification.setText("No final verification");
Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
lblNewLabel_1.setText("Version :");
version = new Text(composite_1, SWT.BORDER);
GridData gd_version = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
gd_version.widthHint = 355;
version.setLayoutData(gd_version);
new Label(composite_1, SWT.NONE);
Label lblFirmwareContent = new Label(shlBundler, SWT.NONE);
fd_lblNewLabel.right = new FormAttachment(lblFirmwareContent, -67);
FormData fd_lblFirmwareContent = new FormData();
fd_lblFirmwareContent.right = new FormAttachment(composite_5, 0, SWT.RIGHT);
fd_lblFirmwareContent.bottom = new FormAttachment(composite_5, -6);
fd_lblFirmwareContent.left = new FormAttachment(composite_5, 0, SWT.LEFT);
lblFirmwareContent.setLayoutData(fd_lblFirmwareContent);
lblFirmwareContent.setText("Firmware content :");
branding.setText(_branding);
version.setText(_version);
if (_deviceName.length()>0)
device.setText(_deviceName + " ("+_variant+")");
}
public void showErrorMessageBox(String message) {
MessageBox mb = new MessageBox(shlBundler,SWT.ICON_ERROR|SWT.OK);
mb.setText("Errorr");
mb.setMessage(message);
int result = mb.open();
}
}