-
Notifications
You must be signed in to change notification settings - Fork 0
/
packages.cc
1976 lines (1757 loc) · 74.6 KB
/
packages.cc
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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* packages.cc -*- C++ -*- Copyright (c) 2006 Joshua Oreman. All rights reserved.
* The iPodLinux installer, of which this file is a part, is licensed under the
* GNU General Public License, which may be found in the file COPYING in the
* source distribution.
*/
#include "installer.h"
#include "packages.h"
#include "panes.h"
#include "rawpod/vfs.h"
#include "rawpod/device.h"
#include "rawpod/ext2.h"
#include "zlib/zlib.h"
#include "libtar/libtar.h"
#include <QHttp>
#include <QRegExp>
#include <QTreeWidget>
#include <QUrl>
#include <QVBoxLayout>
#include <QtDebug>
#include <QTextStream>
#include <QMessageBox>
#include <QFileDialog>
#include <QDir>
#include <QTimer>
#include <QCheckBox>
#include <QPushButton>
#include <QRadioButton>
#include <QGroupBox>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QDate>
#include <QTime>
#include <ctype.h>
#ifndef DONT_HAVE_LIBCRYPTO
#include <openssl/md5.h>
#endif
Package::Package()
: _name ("unk"), _version ("0.1a"), _dest (""), _desc ("???"), _url ("http://127.0.0.1/"),
_subfile ("."), _category (""), _idinfo (NoIdentifyingInfo), _filesize (0),
_type (Archive), _unsupported (false), _reqs (QStringList()),
_provs (QStringList()), _ipods (INSTALLER_WORKING_IPODS), _valid (false),
_orig (false), _upgrade (false), _selected (false), _reallyselected (false), _required (false)
{}
Package::Package (QString line)
: _name ("unk"), _version ("0.0"), _dest (""), _desc ("???"), _url ("http://127.0.0.1/"),
_subfile ("."), _category (""), _idinfo (NoIdentifyingInfo), _filesize (0),
_type (Archive), _unsupported (false), _reqs (QStringList()),
_provs (QStringList()), _ipods (INSTALLER_WORKING_IPODS), _valid (false),
_orig (false), _upgrade (false), _selected (false), _reallyselected (false), _required (false)
{
parseLine (line);
}
static int hex2nyb (char ch)
{
if (ch >= 'a' && ch <= 'f')
return ch - 'a' + 10;
if (ch >= 'A' && ch <= 'F')
return ch - 'A' + 10;
if (ch >= '0' && ch <= '9')
return ch - '0';
return 0;
}
void Package::parseLine (QString line)
{
if (line.indexOf ('#') >= 0)
line.truncate (line.indexOf ('#'));
line = line.trimmed();
if (line == "") return;
QRegExp rx ("^"
"\\s*" "\\[(kernel|loader|file|archive)\\]"
"\\s*" "([a-zA-Z0-9_-]+)"
"\\s+" "([a-z0-9.YMDNCVS-]+)"
"\\s*" ":"
"\\s*" "\"([^\"]*)\""
"\\s*" "at"
"\\s+" "(\\S+)"
"\\s*");
if (rx.indexIn (line, 0) < 0) {
qWarning ("Bad package list line: |%s| (doesn't match rx)", line.toAscii().data());
return;
}
QString rest = line;
rest = rest.remove (0, rx.matchedLength()).simplified();
if (rx.cap (1) == "kernel")
_type = Kernel;
else if (rx.cap (1) == "loader")
_type = Loader;
else if (rx.cap (1) == "file")
_type = File;
else
_type = Archive;
_name = rx.cap (2);
_version = rx.cap (3);
_desc = rx.cap (4);
_url = rx.cap (5);
_valid = true;
if (rest != "") {
QStringList bits = rest.split (" ");
QStringListIterator it (bits);
while (it.hasNext()) {
QString key = it.next();
if (!it.hasNext()) {
qWarning ("Bad package file line: |%s| (odd keyword)", line.toAscii().data());
_valid = false;
return;
}
QString value = it.next();
if (key == "file") {
_subfile = value;
} else if (key == "to") {
_dest = value;
} else if (key == "category" ) {
_category = value;
} else if (key == "size") {
_idinfo = HasFileSize;
_filesize = value.toInt();
#ifndef DONT_HAVE_LIBCRYPTO
} else if (key == "md5") {
if (value.length() == 32) {
_idinfo = HasMD5;
for (int i = 0; i < 16; i++) {
_md5[i] = (hex2nyb (value[2*i].toAscii()) << 4) | hex2nyb (value[2*i+1].toAscii());
}
}
#endif
} else if (key == "unsupported") {
_unsupported = true;
} else if (key == "provides") {
if (!_provs.contains (value))
_provs << value;
} else if (key == "requires") {
if (!_reqs.contains (value))
_reqs << value;
} else if (key == "supports") {
// Flags in _ipods: 0x10000 - specific 'pod type set
// 0x20000 - supports WinPod
// 0x40000 - supports MacPod
_ipods = 0;
for (int c = 0; c < value.length(); ++c) {
char ch = value[c].toAscii();
if (ch >= '0' && ch <= '9') {
_ipods ^= (1 << (ch - '0'));
} else if (toupper (ch) >= 'A' && toupper (ch) <= 'F') {
_ipods ^= (1 << (toupper (ch) - 'A' + 10));
} else if (ch == 'w' || ch == 'W') {
_ipods |= 0x10000;
_ipods ^= 0x20000;
} else if (ch == 'm' || ch == 'M') {
_ipods |= 0x10000;
_ipods ^= 0x40000;
} else if (ch == '~' || ch == '^' || ch == '!') {
_ipods = ~(_ipods & ~0x10000) | (_ipods & 0x10000);
} else {
qWarning ("Bad package list line: |%s| (unsupported supports character `%c')",
line.toAscii().data(), ch);
}
}
if ((_ipods & 0x10000) && !(_ipods & 0x20000))
_ipods = 0;
_ipods &= 0xffff;
} else if (key == "default") {
_selected = _required = true;
} else if (key == "selected") {
_selected = true;
} else if (key == "loadreq") {
if (!((value == "loader1" && (iPodLoader == Loader1Apple || iPodLoader == Loader1Linux)) ||
(value == "loader2" && iPodLoader == Loader2) ||
(value == "loader1apple" && iPodLoader == Loader1Apple) ||
(value == "loader1linux" && iPodLoader == Loader1Linux)))
_valid = false;
} else {
qWarning ("Bad package list line: |%s| (unrecognized keyword %s)",
line.toAscii().data(), key.toAscii().data());
_valid = false;
return;
}
}
}
}
void Package::readPackingList (VFS::Device *dev)
{
if (!dev) return;
Ext2FS *ext2 = new Ext2FS (dev);
ext2->setWritable (0);
if (ext2->init() < 0) {
qWarning ("Could not open ext2 filesystem to read packing list.");
delete ext2;
return;
}
VFS::Dir *dirp = ext2->opendir ("/etc/packages");
if (dirp->error()) {
qWarning ("/etc/packages: %s", strerror (dirp->error()));
delete ext2;
return;
}
_orig = _selected = _upgrade = false;
struct VFS::dirent d;
while (dirp->readdir (&d) > 0) {
if (!strcmp (d.d_name, _name.toAscii().data())) {
qDebug ("Found packing list for %s", d.d_name);
VFS::File *packlist = ext2->open (QString ("/etc/packages/%1").arg (d.d_name).toAscii().data(),
O_RDONLY);
if (packlist->error()) {
qWarning ("/etc/packages/%s: %s", d.d_name, strerror (packlist->error()));
delete packlist;
delete ext2;
return;
}
char *buf = new char[16384];
int rdlen = packlist->read (buf, 16384);
if (rdlen <= 0) {
if (rdlen < 0)
qWarning ("Reading packing list for %s: %s", d.d_name, strerror (-rdlen));
else
qWarning ("Packing list for %s is empty", d.d_name);
delete[] buf;
delete packlist;
delete ext2;
return;
} else if (rdlen >= 16383) {
qWarning ("Packing list for %s too big; truncated", d.d_name);
}
buf[rdlen] = 0;
QByteArray bary (buf, rdlen);
QTextStream reader (&bary, QIODevice::ReadOnly);
QString line;
QRegExp vrx ("\\s*[Vv]ersion\\s+([0-9A-Za-z.-]+)\\s*");
while (!((line = reader.readLine()).isNull())) {
if (vrx.exactMatch (line)) { // the "version" line
_upgrade = (vrx.cap(1) != _version);
} else {
_packlist << line;
}
}
_selected = true;
_orig = true;
delete[] buf;
delete packlist;
}
}
delete dirp;
delete ext2;
}
static void writeLine (VFS::File *out, QString line, int addnl = true)
{
out->write (line.toAscii().data(), line.length());
if (addnl) out->write ("\n", 1);
}
void Package::writePackingList()
{
iPodLinuxPartitionFS->mkdir ("/etc");
iPodLinuxPartitionFS->mkdir ("/etc/packages");
VFS::File *packlist = iPodLinuxPartitionFS->open (QString ("/etc/packages/%1").arg (_name).toAscii(),
O_WRONLY | O_TRUNC | O_CREAT);
if (packlist->error()) {
fprintf (stderr, "Error writing packing list: /etc/packages/%s: %s\n", _name.toAscii().data(),
strerror (packlist->error()));
return;
}
writeLine (packlist, QString ("Version %1").arg (_version));
QStringListIterator it (_packlist);
while (it.hasNext()) {
writeLine (packlist, it.next());
}
packlist->close();
delete packlist;
}
bool Package::fileAlreadyDownloaded (QString path)
{
QFile file (path);
if (!file.exists()) return false;
switch (_idinfo) {
case NoIdentifyingInfo:
return false; // we can't tell
case HasFileSize:
return (file.size() == _filesize);
case HasMD5:
break;
}
// Check the MD5 sum.
#ifndef DONT_HAVE_LIBCRYPTO
if (!file.open (QIODevice::ReadOnly))
return false;
MD5_CTX ctx;
MD5_Init (&ctx);
char buf[4096];
while (!file.atEnd()) {
int rdlen = file.read (buf, 4096);
if (rdlen <= 0) break;
MD5_Update (&ctx, buf, rdlen);
}
unsigned char md5[16];
MD5_Final (md5, &ctx);
file.close();
return !memcmp (_md5, md5, 16);
#endif
return false;
}
Package& Package::operator= (Package& other)
{
_name = other._name;
_version = other._version;
_dest = other._dest;
_desc = other._desc;
_url = other._url;
_subfile = other._subfile;
_category = other._category;
_idinfo = other._idinfo;
_filesize = other._filesize;
memcpy (_md5, other._md5, 16);
_type = other._type;
_unsupported = other._unsupported;
_reqs = other._reqs;
_provs = other._provs;
_ipods = other._ipods;
_valid = other._valid;
_orig = other._orig;
_upgrade = other._upgrade;
_selected = other._selected;
_required = other._required;
_packlist = other._packlist;
return *this;
}
void Package::debug()
{
qDebug ("Package: %s v%s (\"%s\")", _name.toAscii().data(),
_version.toAscii().data(), _desc.toAscii().data());
qDebug (" URL: %s (subfile %s) (installing to %s)", _url.toAscii().data(),
_subfile.toAscii().data(), _dest.toAscii().data());
qDebug (" Reqs: %s", _reqs.join (", ").toAscii().data());
qDebug (" Provs: %s", _provs.join (", ").toAscii().data());
qDebug (" Flags: %c%c%c%c", _valid? 'V' : 'v', _orig? 'I' : 'i',
_upgrade? 'U' : 'u', _selected? 'S' : 's');
qDebug (" Type: %d", _type);
}
PackagesPage::PackagesPage (Installer *wiz, bool atm)
: InstallerPage (wiz), advok (false), errored (false), automatic (atm)
{
if (automatic)
blurb = new QLabel (tr ("<p>Please wait while the package list is downloaded and resolved "
"so the installer can make some decisions about what to install.</p>"));
else if (Mode == Update)
blurb = new QLabel (tr ("<p>Here you may modify your installed iPodLinux packages. Check the box "
"next to a package to have it installed; uncheck it to have it removed. "
"If an upgrade is available, the Status column will read \"Upgrade\"; "
"if you do not want this upgrade for some reason, uncheck the box "
"next to that text.</p>"
"<p><i>Please wait while the package list is downloaded.</i></p>"));
else
blurb = new QLabel (tr ("<p>Here you may select packages to install for iPodLinux. Check the boxes "
"next to each package you would like to install.</p>"
"<p><i>Please wait while the package list is downloaded.</i></p>"));
blurb->setWordWrap (true);
progressStmt = new QLabel (tr ("<b>Initializing...</b>"));
QStringList headers;
headers << "Name" << "Version" << "Action" << "Description";
packages = new QTreeWidget;
packages->setHeaderLabels (headers);
loadpkg = new QPushButton (tr ("Load package(s) information"));
savepkg = new QPushButton (tr ("list"));
savesel = new QPushButton (tr ("choices"));
rmconstraints = new QPushButton (tr ("Remove constraints"));
connect (packages, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),
this, SLOT(listDoubleClicked(QTreeWidgetItem*)));
connect (packages, SIGNAL(itemChanged(QTreeWidgetItem*, int)),
this, SLOT(listClicked(QTreeWidgetItem*, int)));
connect (packages, SIGNAL(itemCollapsed(QTreeWidgetItem*)),
this, SLOT(itemCollapsed(QTreeWidgetItem*)));
connect (packages, SIGNAL(itemExpanded(QTreeWidgetItem*)),
this, SLOT(itemExpanded(QTreeWidgetItem*)));
connect (loadpkg, SIGNAL(clicked(bool)), this, SLOT(doLoadExtraPackageList()));
connect (savepkg, SIGNAL(clicked(bool)), this, SLOT(doSavePackageList()));
connect (savesel, SIGNAL(clicked(bool)), this, SLOT(doSaveSelection()));
connect (rmconstraints, SIGNAL(clicked(bool)), this, SLOT(doRemoveConstraints()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
layout->addSpacing (10);
layout->addWidget (progressStmt);
layout->addWidget (packages);
QHBoxLayout *buttons = new QHBoxLayout;
buttons->addWidget (loadpkg);
buttons->addWidget (rmconstraints);
buttons->addStretch (1);
buttons->addWidget (savelabel = new QLabel ("Save:"));
buttons->addWidget (savesel);
buttons->addWidget (savepkg);
layout->addLayout (buttons);
packages->hide();
loadpkg->hide();
savelabel->hide();
savesel->hide();
savepkg->hide();
rmconstraints->hide();
if (automatic)
layout->addStretch (1);
setLayout (layout);
if (QFile::exists (InstallerHome + "/packages.ipl"))
PackageListFile = InstallerHome + "/packages.ipl";
if (PackageListFile.contains ("://")) {
QUrl packlistURL (PackageListFile);
packlistHTTP = new QHttp;
host = packlistURL.host();
packlistHTTP->setHost (packlistURL.host(), packlistURL.port(80));
char *http_proxy = NULL;
QUrl proxyURL ("");
if(!ProxyString.isEmpty()) {
if(!ProxyString.contains ("://")) {
ProxyString.prepend ("http://");
}
proxyURL.setUrl (ProxyString);
}
else if((http_proxy = getenv("HTTP_PROXY"))) {
proxyURL.setUrl (QString (http_proxy));
}
else if((http_proxy = getenv("http_proxy"))) {
proxyURL.setUrl (QString (http_proxy));
}
if(proxyURL.isValid()) {
packlistHTTP->setProxy (proxyURL.host(), proxyURL.port(8080),
proxyURL.userName(), proxyURL.password());
printf ("Using proxy '%s' on port %d\n",
proxyURL.host().toAscii().data(), proxyURL.port(8080));
}
if(http_proxy)
free(http_proxy);
connect (packlistHTTP, SIGNAL(dataSendProgress(int, int)), this, SLOT(httpSendProgress(int, int)));
connect (packlistHTTP, SIGNAL(dataReadProgress(int, int)), this, SLOT(httpReadProgress(int, int)));
connect (packlistHTTP, SIGNAL(stateChanged(int)), this, SLOT(httpStateChanged(int)));
connect (packlistHTTP, SIGNAL(requestFinished(int, bool)), this, SLOT(httpRequestFinished(int, bool)));
connect (packlistHTTP, SIGNAL(done(bool)), this, SLOT(httpDone(bool)));
connect (packlistHTTP, SIGNAL(responseHeaderReceived(const QHttpResponseHeader&)),
this, SLOT(httpResponseHeaderReceived(const QHttpResponseHeader&)));
packlistHTTP->get (packlistURL.toString (QUrl::RemoveScheme | QUrl::RemoveAuthority));
} else {
loadExternalPackageList (PackageListFile, false);
QTimer::singleShot (0, this, SLOT(done()));
}
}
void PackagesPage::doRemoveConstraints()
{
QList <QTreeWidgetItem *> allItems = packages->findItems (".*", Qt::MatchRegExp | Qt::MatchRecursive);
QListIterator <QTreeWidgetItem *> it (allItems);
while (it.hasNext()) {
QTreeWidgetItem *i = it.next();
PkgTreeWidgetItem *item;
if ((item = dynamic_cast<PkgTreeWidgetItem*>(i)) != 0) {
if (item->package().constrained()) {
if (item->package().selected()) item->package().select();
else item->package().deselect();
item->update();
}
}
}
}
void PackagesPage::doLoadExtraPackageList()
{
QString filename = QFileDialog::getOpenFileName (this, "Choose a package list to load:",
QString(), "iPodLinux package lists (*.ipl)");
if (filename == "") return;
loadExternalPackageList (filename, true);
QMessageBox::information (this, tr ("Package list loaded"),
tr ("Packages successfully loaded from %1.").arg (filename),
tr ("Ok"));
}
void PackagesPage::doSaveSelection()
{
QString filename = QFileDialog::getSaveFileName (this, "Please select where to save your package choices:",
QString(), "iPodLinux package lists (*.ipl)");
if (filename == "") return;
QFile pkglistfile (filename);
if (!pkglistfile.open (QIODevice::WriteOnly)) {
QMessageBox::critical (this, tr ("Error opening package list"),
tr ("Could not open %1 for writing: %2").arg (filename).arg (pkglistfile.errorString()),
tr ("Cancel"));
return;
}
QTextStream pkglist (&pkglistfile);
pkglist << "# Automatically generated by installer2"
<< " on " << QDate::currentDate().toString ("yyyy-MM-dd")
<< " at " << QTime::currentTime().toString ("hh:mm:ss") << "\n";
QList <QTreeWidgetItem *> allPackages =
packages->findItems (".*", Qt::MatchRecursive | Qt::MatchRegExp);
QListIterator <QTreeWidgetItem *> it (allPackages);
while (it.hasNext()) {
QTreeWidgetItem *i = it.next();
PkgTreeWidgetItem *item;
if ((item = dynamic_cast <PkgTreeWidgetItem *> (i)) != 0) {
if (item->package().selected()) {
pkglist << "select " << item->package().name() << "\n";
} else {
pkglist << "deselect " << item->package().name() << "\n";
}
}
}
pkglist.flush();
pkglistfile.close();
QMessageBox::information (this, tr ("Package choices saved"),
tr ("Package choices successfully saved to %1.").arg (filename),
tr ("Ok"));
}
void PackagesPage::doSavePackageList()
{
QString filename = QFileDialog::getSaveFileName (this, "Please select where to save the package list:",
QString(), "iPodLinux package lists (*.ipl)");
if (filename == "") return;
QFile pkglistfile (filename);
if (!pkglistfile.open (QIODevice::WriteOnly)) {
QMessageBox::critical (this, tr ("Error opening package list"),
tr ("Could not open %1 for writing: %2").arg (filename).arg (pkglistfile.errorString()),
tr ("Cancel"));
return;
}
QTextStream pkglist (&pkglistfile);
pkglist << "# Automatically generated by installer2"
<< " on " << QDate::currentDate().toString ("yyyy-MM-dd")
<< " at " << QTime::currentTime().toString ("hh:mm:ss") << "\n";
QList <QTreeWidgetItem *> allPackages =
packages->findItems (".*", Qt::MatchRecursive | Qt::MatchRegExp);
QListIterator <QTreeWidgetItem *> it (allPackages);
while (it.hasNext()) {
QTreeWidgetItem *i = it.next();
PkgTreeWidgetItem *item;
if ((item = dynamic_cast <PkgTreeWidgetItem *> (i)) != 0) {
Package& pkg = item->package();
// Type
pkglist << "[";
if (pkg.type() == Package::Kernel) pkglist << "kernel";
if (pkg.type() == Package::Loader) pkglist << "loader";
if (pkg.type() == Package::File) pkglist << "file";
if (pkg.type() == Package::Archive) pkglist << "archive";
pkglist << "] ";
// Name, version, desc, url, etc.
pkglist << pkg.name() << " " << pkg.version() << ": \"" << pkg.description() << "\""
<< " at " << pkg.url();
// Other stuff
if (pkg.destination() != "") pkglist << " to " << pkg.destination();
if (pkg.subfile() != "" && pkg.subfile() != ".") pkglist << " file " << pkg.subfile();
if (pkg.category() != "") pkglist << " category " << pkg.category();
if (pkg.requires().size()) pkglist << " requires " << pkg.requires().join (" requires ");
if (pkg.provides().size()) pkglist << " provides " << pkg.provides().join (" provides ");
if (pkg.unsupported()) pkglist << " unsupported yes";
if (pkg.supports()) {
pkglist << " supports ";
const char *hexdigits = "0123456789abcdef";
int supp = pkg.supports();
if (supp & 1) {
pkglist << "~";
supp = ~supp;
}
for (int i = 0; i < 16; i++) {
if (supp & (1 << i))
pkglist << hexdigits[i];
}
}
if (pkg.selected()) pkglist << " selected yes";
if (pkg.required()) pkglist << " default yes";
pkglist << "\n";
} else if (i->type() == CategoryHeaderType && i->childCount() > 0) {
PkgTreeWidgetItem *ptwi = dynamic_cast <PkgTreeWidgetItem *> (i->child (0));
if (ptwi) {
if (ptwi->package().category() != "")
pkglist << "[category] " << ptwi->package().category() << ": \"" << i->text(0) << "\"\n";
else if (ptwi->package().provides().size() && ptwi->package().provides()[0] != "")
pkglist << "[category] " << ptwi->package().provides()[0] << ": \"" << i->text(0) << "\"\n";
}
}
}
pkglist.flush();
pkglistfile.close();
QMessageBox::information (this, tr ("Package list saved"),
tr ("Package list successfully saved to %1.").arg (filename),
tr ("Ok"));
}
void PackagesPage::loadExternalPackageList (QString filename, bool markBold)
{
QFile pkglist (filename);
if (!pkglist.open (QIODevice::ReadOnly)) {
QMessageBox::critical (this, tr ("Error opening package list"),
tr ("Could not open %1 for reading: %2").arg (filename).arg (pkglist.errorString()),
tr ("Cancel"));
return;
}
QStringList filepath = filename.split ("/");
filepath.removeAll ("");
filepath.removeLast();
QDir pkglistdir (filepath.join ("/"));
QByteArray bline;
while (!pkglist.atEnd() && !(bline = pkglist.readLine()).isNull()) {
QString line = bline;
QRegExp vrx ("\\s*[Vv]ersion\\s+(\\d+)\\s*");
QRegExp nrx ("\\s*[Ii]nstaller\\s+([0-9A-Za-z.-]+)\\s*");
if (vrx.exactMatch (line)) {
if (vrx.cap (1).toInt() != INSTALLER_PACKAGE_VERSION) {
QMessageBox::critical (this, tr ("Version mismatch"),
tr ("Package format version mismatch (need %1, got %2)")
.arg (INSTALLER_PACKAGE_VERSION).arg (vrx.cap (1)),
tr ("Cancel"));
}
} else if (nrx.exactMatch (line)) {
if (nrx.cap (1) != INSTALLER_VERSION) {
QMessageBox::critical (this, tr ("Version mismatch"),
tr ("Installer version mismatch (need %1, got %2)")
.arg (INSTALLER_VERSION).arg (vrx.cap (1)),
tr ("Cancel"));
}
} else {
Package *pkgp = parsePackageListLine (line, markBold, &pkglistdir);
if (pkgp) { // munge URLs and such to be relative to the filename
pkgp->url() = pkglistdir.absoluteFilePath (pkgp->url());
}
}
}
pkglist.close();
}
void PackagesPage::httpSendProgress (int done, int total)
{
if (total)
progressStmt->setText (QString (tr ("<b>Sending request...</b> %1%")).arg (done * 100 / total));
else
progressStmt->setText (QString (tr ("<b>Sending request...</b> %1 bytes")).arg (done));
}
void PackagesPage::httpReadProgress (int done, int total)
{
if (total)
progressStmt->setText (QString (tr ("<b>Transferring data...</b> %1%")).arg (done * 100 / total));
else
progressStmt->setText (QString (tr ("<b>Transferring data...</b> %1 bytes")).arg (done));
}
void PackagesPage::httpStateChanged (int state)
{
if (state == QHttp::HostLookup)
progressStmt->setText (tr ("<b>Looking up host...</b>"));
else if (state == QHttp::Connecting)
progressStmt->setText (tr ("<b>Connecting to %1...</b>").arg (host));
else if (state == QHttp::Sending)
progressStmt->setText (tr ("<b>Sending request...</b>"));
else if (state == QHttp::Reading)
progressStmt->setText (tr ("<b>Transferring data...</b>"));
else if (state == QHttp::Connected)
progressStmt->setText (tr ("<b>Connected.</b>"));
else if (state == QHttp::Closing)
progressStmt->setText (tr ("<b>Closing connection...</b>"));
else if (state == QHttp::Unconnected)
progressStmt->setText (tr ("Done."));
}
static QStringList requiredProvides;
void PackagesPage::httpRequestFinished (int req, bool err)
{
(void)req;
if (err) {
qDebug ("Request %d has errored out (%s)", req, packlistHTTP->errorString().toAscii().data());
if (!errored) {
progressStmt->setText (QString (tr ("<b><font color=\"red\">Error: %1</font></b>"))
.arg (packlistHTTP->errorString()));
errored = true;
}
return;
} else if (resolvers [req] && packlistHTTP->bytesAvailable()) {
PkgTreeWidgetItem *item = resolvers [req];
QString pat = item->package().url();
pat.remove (0, pat.lastIndexOf ('/') + 1);
if (pat.contains ("YYYYMMDD"))
pat.replace ("YYYYMMDD", "([0-9][0-9][0-9][0-9]-?[0-9][0-9]-?[0-9][0-9])");
if (pat.contains ("NNN"))
pat.replace ("NNN", "([0-9][0-9][0-9][0-9]?[0-9]?)");
QRegExp rx ("<[Aa] [Hh][Rr][Ee][Ff]=\"[^\"]+\">" + pat + "</[Aa]>");
QStringList lines = QString (packlistHTTP->readAll().constData()).split ("\n");
QStringListIterator it (lines);
QString cap = "";
while (it.hasNext()) {
QString line = it.next();
if (rx.indexIn (line) >= 0)
cap = rx.cap(1);
}
if (cap != "") {
item->package().version().replace ("YYYYMMDD", cap);
item->package().version().replace ("NNN", cap);
item->package().url().replace ("YYYYMMDD", cap);
item->package().url().replace ("NNN", cap);
item->package().subfile().replace ("YYYYMMDD", cap);
item->package().subfile().replace ("NNN", cap);
}
item->update();
} else if (packlistHTTP->bytesAvailable()) {
if (packlistHTTP->lastResponse().statusCode() == 200) {
QStringList lines = QString (packlistHTTP->readAll().constData()).split ("\n");
QStringListIterator it (lines);
while (it.hasNext()) {
QString line = it.next();
QRegExp vrx ("\\s*[Vv]ersion\\s+(\\d+)\\s*");
QRegExp nrx ("\\s*[Ii]nstaller\\s+([0-9A-Za-z.-]+)\\s*");
if (vrx.exactMatch (line)) {
if (vrx.cap (1).toInt() != INSTALLER_PACKAGE_VERSION) {
if (!errored) {
progressStmt->setText (QString (tr ("<b><font color=\"red\">Error: Invalid "
"package list version (need %1, got %2)."
"</font></b>"))
.arg (INSTALLER_PACKAGE_VERSION).arg (vrx.cap (1)));
errored = true;
}
return;
}
} else if (nrx.exactMatch (line)) {
if (nrx.cap (1) != INSTALLER_VERSION) {
if (!errored) {
progressStmt->setText (QString (tr ("<b><font color=\"red\">Error: Out-of date "
"installer (this is %1, current is %2). Please "
"update.</font></b>"))
.arg (INSTALLER_VERSION).arg (nrx.cap (1)));
errored = true;
}
return;
}
} else {
parsePackageListLine (line);
}
}
if (requiredProvides.size()) {
QMessageBox::critical (this, QObject::tr ("Unsupported required provide"),
QObject::tr ("A package providing `%1' is required for an iPodLinux "
"installation, but none of the ones in the list I have "
"is supported by the iPod version you have. Sorry, but "
"installation cannot continue.")
.arg (requiredProvides[0]),
QObject::tr ("Quit"));
}
}
}
}
Package *PackagesPage::parsePackageListLine (QString line, bool makeBold, QDir *relativeTo)
{
if (line.indexOf ('#') >= 0)
line.truncate (line.indexOf ('#'));
line = line.trimmed();
if (line == "") return 0;
QRegExp crx ("\\s*\\[category\\]\\s*([a-zA-Z0-9_-]+)\\s*:\\s*\"([^\"]*)\"");
if (crx.exactMatch (line)) {
QTreeWidgetItem *catitem;
if (!categories.contains (crx.cap (1))) {
catitem = new QTreeWidgetItem (packages, CategoryHeaderType);
categories.insert (crx.cap (1), catitem);
} else
catitem = categories[crx.cap (1)];
catitem->setText (0, crx.cap (2));
catitem->setFlags (Qt::ItemIsEnabled);
packages->setItemExpanded (catitem, true);
return 0;
}
QRegExp srx ("\\s*(de|)select\\s+([a-zA-Z0-9_-]+)\\s*");
if (srx.exactMatch (line)) {
QList <QTreeWidgetItem *> pkglist =
packages->findItems (srx.cap (2), Qt::MatchRecursive | Qt::MatchExactly);
if (pkglist.size() == 1) {
if (srx.cap (1) == "de")
((PkgTreeWidgetItem *)pkglist[0])->deselect (PkgTreeWidgetItem::ChangeForce);
else
((PkgTreeWidgetItem *)pkglist[0])->select (PkgTreeWidgetItem::ChangeForce);
}
return 0;
}
QRegExp irx ("\\s*<<\\s*(\\S+)\\s*>>\\s*");
if (irx.exactMatch (line)) {
if (irx.cap (1).contains ("://")) {
QUrl url (irx.cap (1));
if (!url.isValid()) {
qWarning ("Invalid URL in package list: |%s|", irx.cap (1).toAscii().data());
} else {
host = url.host();
packlistHTTP->setHost (url.host(), (url.port() > 0)? url.port() : 80);
packlistHTTP->get (url.toString (QUrl::RemoveScheme | QUrl::RemoveAuthority));
}
} else {
if (relativeTo)
loadExternalPackageList (relativeTo->absoluteFilePath (irx.cap (1)), makeBold);
else
loadExternalPackageList (irx.cap (1), makeBold);
}
return 0;
}
Package *pkgp = new Package (line);
if (!pkgp->supports (iPodVersion) && pkgp->required()) {
if (!pkgp->provides().size()) {
QMessageBox::critical (this, QObject::tr ("Unsupported required package"),
QObject::tr ("The package `%1' is required for an iPodLinux "
"installation, but it is not supported on the "
"iPod version you have. Sorry, but installation "
"cannot continue.")
.arg (pkgp->name()),
QObject::tr ("Quit"));
exit (1);
}
requiredProvides << pkgp->provides()[0];
}
if (pkgp->supports (iPodVersion) && pkgp->valid()) {
PkgTreeWidgetItem *twi;
if (packageMap.contains (pkgp->name())) {
twi = packageMap[pkgp->name()];
twi->package() = *pkgp;
twi->update();
} else {
QTreeWidgetItem *pkgparent = 0;
Package& pkg = *pkgp;
if (pkg.category() != "" && categories[pkg.category()]) {
pkgparent = categories[pkg.category()];
}
if (pkg.requires().size()) {
QList <QTreeWidgetItem *> reqlist =
packages->findItems (pkg.requires()[0], Qt::MatchExactly | Qt::MatchRecursive);
if (reqlist.size() && (!pkgparent || pkgparent == reqlist[0]->parent())) {
pkgparent = reqlist[0];
}
}
if (pkg.provides().size()) {
QList <QTreeWidgetItem *> provlist =
packages->findItems ("Packages providing `" + pkg.provides()[0] + "'",
Qt::MatchExactly | Qt::MatchRecursive);
if (provlist.size()) {
twi = new PkgTreeWidgetItem (this, provlist[0], pkg);
if (provlist[0]->parent() && !pkg.requires().contains (provlist[0]->parent()->text(0))) {
// Take the `Packages providing whatever' header item out of
// the children of the package required by one of the providers
// but not all, and put it into the top-level list.
provlist[0]->parent()->takeChild (provlist[0]->parent()->indexOfChild (provlist[0]));
packages->addTopLevelItem (provlist[0]);
}
} else if (categories[pkg.provides()[0]]) {
twi = new PkgTreeWidgetItem (this, categories[pkg.provides()[0]], pkg);
} else {
QTreeWidgetItem *provitem;
if (pkgparent)
provitem = new QTreeWidgetItem (pkgparent, ProvidesHeaderType);
else
provitem = new QTreeWidgetItem (packages, ProvidesHeaderType);
provitem->setText (0, "Packages providing `" + pkg.provides()[0] + "'");
provitem->setFlags (0);
packages->setItemExpanded (provitem, true);
twi = new PkgTreeWidgetItem (this, provitem, pkg);
}
twi->setProv (true);
} else {
if (pkgparent)
twi = new PkgTreeWidgetItem (this, pkgparent, pkg);
else
twi = new PkgTreeWidgetItem (this, packages, pkg);
}
if (makeBold) {
QFont boldFont = twi->font (0);
boldFont.setBold (true);
twi->setFont (0, boldFont);
}
packageMap[pkg.name()] = twi;
}
Package& pkg = twi->package();
packageProvides.insert (pkg.name(), twi);
QStringListIterator pi (pkg.provides());
while (pi.hasNext()) {
QString prov = pi.next();
if (requiredProvides.contains (prov)) {
requiredProvides.removeAll (prov);
pkg.select();
pkg.makeRequired();
}
packageProvides.insert (prov, twi);
}
if (!pkg.url().contains ("://"))
fixupPackageItem (twi);
if (pkg.url().contains ("YYYYMMDD") || pkg.url().contains ("NNN")) {
QString dir = pkg.url();
dir.truncate (dir.lastIndexOf ('/') + 1);
if (dir.contains ("://")) {
// it's a URL; get a directory listing. It'll be parsed in httpRequestFinished.
QUrl url (dir);
host = url.host();
packlistHTTP->setHost (url.host(), (url.port() > 0)? url.port() : 80);
resolvers [packlistHTTP->get (url.toString (QUrl::RemoveScheme |
QUrl::RemoveAuthority))] = twi;
} else {
QDir pkgdir (dir);
QString pat = pkg.url();
pat.remove (0, pat.lastIndexOf ('/') + 1);
if (pat.contains ("YYYYMMDD"))
pat.replace ("YYYYMMDD", "([0-9][0-9][0-9][0-9]-?[0-9][0-9]-?[0-9][0-9])");
if (pat.contains ("NNN"))
pat.replace ("NNN", "([0-9][0-9][0-9][0-9]?[0-9]?)");
QRegExp rx (pat);
QStringList files = pkgdir.entryList();
QStringListIterator it (files);
QString cap = "";
while (it.hasNext()) {
QString file = it.next();
if (rx.exactMatch (file)) {
cap = rx.cap(1);
}
}
if (cap != "") {
pkg.version().replace ("YYYYMMDD", cap);
pkg.version().replace ("NNN", cap);
pkg.url().replace ("YYYYMMDD", cap);
pkg.url().replace ("NNN", cap);
pkg.subfile().replace ("YYYYMMDD", cap);
pkg.subfile().replace ("NNN", cap);
}
QList <QTreeWidgetItem *> items =
packages->findItems (pkg.name(), Qt::MatchRecursive | Qt::MatchExactly);
if (items.size()) ((PkgTreeWidgetItem *)items[0])->update();
}
}
return &pkg;
} else if (Mode == ChangeLoader && pkgp->type() == Package::Loader) {
// If we're changing loader, and this loader is installed but not
// the new one, remove it.