-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.cc
1209 lines (1073 loc) · 44.8 KB
/
installer.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
/* ipl/installer/installer.cc -*- C++ -*- Copyright (c) 2006 Joshua Oreman
* Distributed under the GPL. See COPYING for details.
*/
#include "installer.h"
#include "actions.h"
#include "panes.h"
#include "rawpod/partition.h"
#include "rawpod/device.h"
#include "rawpod/fat32.h"
#include "rawpod/ext2.h"
#include "scsi_inquiry.h"
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPixmap>
#include <QCheckBox>
#include <QRadioButton>
#include <QSpinBox>
#include <QTimer>
#include <QAbstractEventDispatcher>
#include <string.h>
#include <ctype.h>
#ifdef __APPLE__
#include <sys/mount.h> // for unmount()
#endif
InstallerMode Mode;
LoaderType iPodLoader = UnknownLoader;
QList<Action*> *PendingActions;
int iPodLocation;
int iPodVersion;
PartitionTable *iPodPartitionTable;
int iPodPartitionToShrink;
int iPodLinuxPartitionSize;
VFS::Device *iPodDevice;
VFS::Device *iPodFirmwarePartitionDevice, *iPodMusicPartitionDevice, *iPodLinuxPartitionDevice;
VFS::Filesystem *iPodMusicPartitionFS, *iPodLinuxPartitionFS;
bool iPodDoBackup;
QString iPodBackupLocation;
QString InstallerHome;
QString PackageListFile;
QString ProxyString;
bool InstallAutomatically;
Installer *installer;
Installer::Installer (QWidget *parent)
: ComplexWizard (parent)
{
installer = this;
setFirstPage (new IntroductionPage (this));
setWindowTitle (tr ("iPodLinux Installer"));
resize (530, 410);
setMinimumSize (500, 410);
setMaximumSize (640, 500);
PendingActions = new QList<Action*>;
}
IntroductionPage::IntroductionPage (Installer *wizard)
: InstallerPage (wizard)
{
blurb = new QLabel;
blurb->setWordWrap (true);
blurb->setAlignment (Qt::AlignTop | Qt::AlignLeft);
blurb->setText (tr ("<p><b>Welcome to the iPodLinux installer!</b></p>\n"
"<p>In just a few short steps, this program will help you install Linux "
"on your iPod. Please close all programs accessing your iPod "
#ifdef __linux__
"and unmount it "
#endif
"before continuing.</p>\n"
"<p>If something goes wrong during this process, and your iPod refuses to boot "
"normally, <i>don't panic!</i> Follow the directions at "
"<a href=\"http://ipodlinux.org/wiki/Key_Combinations\">the iPodLinux website</a> "
"to reboot the iPod to disk mode, then rerun this installer and choose to "
"restore the backup you hopefully made. <i>It is impossible to permanently "
"damage your iPod by installing iPodLinux!</i></p>\n"
"<p>Now, make sure your iPod is plugged in and nothing is using it, verify "
"that you are "
#ifdef __linux__
"root"
#else
"an administrator"
#endif
", and press Next to run a few checks. This may take a few seconds;"
" be patient.</p>\n"));
blurb->setMaximumWidth (370);
QLabel *pic = new QLabel;
pic->setPixmap (QPixmap (":/installer.png"));
pic->setAlignment (Qt::AlignTop | Qt::AlignLeft);
QHBoxLayout *layout = new QHBoxLayout;
layout->addWidget (pic);
layout->addSpacing (10);
layout->addWidget (blurb);
setLayout (layout);
}
WizardPage *IntroductionPage::nextPage()
{
return new PodLocationPage (wizard);
}
PodLocationPage::PodLocationPage (Installer *wizard)
: InstallerPage (wizard), wasError (0)
{
enum { CantFindIPod, InvalidPartitionTable, FSErr, BadSysInfo,
NotAnIPod, MacPod, WinPod, SLinPod, BLinPod, UnsupPod, UnmountFailed } status;
int hw_ver = 0;
int podloc = find_iPod();
int ipodtype = PART_NOT_IPOD;
unsigned char mbr[512];
PartitionTable *ptbl = 0;
char *p = 0;
int rev = 0;
VFS::Device *part = 0;
FATFS *fat32 = 0;
blurb = subblurb = 0;
advancedCheck = 0;
upgradeRadio = changeLoaderRadio = uninstallRadio = 0;
stateOK = 0;
wizard->resize (530, 440);
wizard->setMinimumSize (500, 410);
wizard->setMaximumSize (640, 500);
int rdlen;
VFS::File *sysinfo;
char sysinfo_contents[4096];
if (podloc < 0) { status = CantFindIPod; goto err; }
#ifdef __APPLE__
// we need to unmount the iPod before we can access it on block level
// we cannot use the unmount() function on the mac (would return "disk is busy")
char path[32];
int pid, pstatus;
strcpy (path, "/dev/diskXs2"); // !TT should fill in the correct partition number here
path[strlen(path)-3] = podloc + '0';
if (!fork()) execlp ("diskutil", "diskutil", "unmount", path);
// otherwise, in parent
do {
// Wait for the cmd to finish - it may take a while
//
// At this point event dispatching needs to happen - the diskutil call
// wants to talk to apps on a high level thru the event dispatcher.
// Therefore, processEvents() is called. Note that this also allows
// the user to press the Cancel button, which is good.
QAbstractEventDispatcher::instance()->processEvents(QEventLoop::AllEvents);
pid = wait4 (0, &pstatus, WNOHANG, NULL);
} while (pid != -1);
if (pstatus) {
status = UnmountFailed;
goto err;
}
sleep (1); // pause for a second, otherwise the next device access in write mode might fail sometimes
#endif
iPodDevice = new LocalRawDevice (podloc);
if (iPodDevice->read (mbr, 512) != 512) { status = InvalidPartitionTable; goto err; }
ptbl = PartitionTable::create (podloc, true);
if (!ptbl || !*ptbl) { status = InvalidPartitionTable; goto err; }
ipodtype = ptbl->figureOutType (mbr);
switch (ipodtype) {
case PART_WINPOD:
status = WinPod;
break;
case PART_MACPOD:
status = MacPod;
goto err;
case PART_SLINPOD:
status = SLinPod;
break;
case PART_BLINPOD:
status = BLinPod;
break;
default:
case PART_NOT_IPOD:
status = NotAnIPod;
goto err;
}
part = setup_partition (iPodDevice, 2);
if (!part) { status = CantFindIPod; goto err; }
fat32 = new FATFS (part);
int e;
if ((e = fat32->init()) < 0) {
fprintf (stderr, "FAT32 init failed: error %d (%s)\n", -e, strerror (-e));
status = FSErr;
errno = -e;
goto err;
}
if ((hw_ver = scsi_inquiry_get_hw_ver (podloc)) > 0) {
goto err; // Not an error, but jump over the SysInfo code.
}
sysinfo = fat32->open ("/IPOD_C~1/DEVICE/SYSINFO", O_RDONLY);
if (!sysinfo || sysinfo->error()) {
if (!sysinfo)
fprintf (stderr, "sysinfo open failed ?\n");
else
fprintf (stderr, "sysinfo open failed: error %d (%s)\n", sysinfo->error(),
strerror (sysinfo->error()));
status = FSErr;
#ifndef WIN32
errno = sysinfo? sysinfo->error() : 0;
#endif
goto err;
}
rdlen = sysinfo->read (sysinfo_contents, 4096);
sysinfo->close();
delete sysinfo;
if (rdlen <= 0) {
status = BadSysInfo;
fprintf (stderr, "sysinfo read error %d\n", -rdlen);
#ifndef WIN32
errno = -rdlen;
#endif
goto err;
} else if (rdlen >= 4096) {
status = BadSysInfo;
fprintf (stderr, "sysinfo too big\n");
#ifndef WIN32
errno = E2BIG;
#endif
goto err;
}
p = sysinfo_contents;
rev = 0;
while (p) {
while (isspace (*p)) p++;
if (!strncmp (p, "boardHwSwInterfaceRev:", strlen ("boardHwSwInterfaceRev:"))) {
if ((p = strchr (p, ':'))) {
p++;
while (isspace (*p)) p++;
rev = strtol (p, 0, 0);
break;
}
status = BadSysInfo;
fprintf (stderr, "sysinfo line has and does not have colon (?)\n");
errno = EINVAL;
break;
}
p = strchr (p, '\n');
}
if (!rev || !(rev >> 16) || (rev >> 20)) {
fprintf (stderr, "sysinfo has bad hw rev\n");
errno = EINVAL;
printf ("Invalid hw rev: %x (%d)\n", rev, rev);
status = BadSysInfo;
} else {
hw_ver = rev >> 16;
fprintf (stderr, "sysinfo OK, rev %05x\n", rev);
}
err:
delete fat32;
delete part;
if (!(INSTALLER_WORKING_IPODS & (1 << hw_ver)))
status = UnsupPod;
if (!hw_ver || (hw_ver >= 0xA && status == SLinPod)) { // error
blurb = new QLabel;
blurb->setWordWrap (true);
blurb->setAlignment (Qt::AlignTop | Qt::AlignLeft);
bool restoreOK = false;
wasError = 1;
QString err;
switch (status) {
case CantFindIPod:
err = tr("<p><b>Could not find your iPod.</b> I checked all the drives "
"in your system for something that looks like an iPod, but "
"I didn't find anything. Please verify the following.</p>\n"
"<ul><li>Make sure you have administrator privileges on the "
"system. You need them.</li>\n"
"<li>Make sure your iPod is a WinPod, not a MacPod. Use the Apple "
"restore utility if you need to convert it.</li>\n"
"<li>Make sure exactly one iPod is indeed plugged in.</li>\n"
"<li>Be sure your iPod is not ejected; "
#ifdef __linux__
"it's okay to run <tt>umount</tt> but not <tt>eject</tt>."
#else
"just exit programs that are using the iPod."
#endif
"</li></ul>\n"
"<i>If you've followed all these directions and nothing works, this "
"is a bug. Report it.</i>");
break;
case InvalidPartitionTable:
err = tr("<p><b>Invalid partition table.</b> The iPod I found didn't look "
"like it had a valid partition table. It's probably a MacPod; those don't "
"work.</p>");
restoreOK = true;
break;
case FSErr:
err = tr("<p><b>Error accessing filesystem.</b> I was unable to properly access "
"the <tt>SysInfo</tt> file on your iPod; either it didn't exist, there's "
"something wrong with your iPod's filesystem, or (most likely) there's "
"a bug in the installer. Check if the file exists at "
"<i>iPod</i><tt>/iPod_Control/Device/SysInfo</tt>; if it does, report a bug. "
"If not, try restarting your iPod into the Apple firmware to recreate it.</p>");
restoreOK = true;
break;
case BadSysInfo:
err = tr("<p><b>Invalid SysInfo file.</b> There was something wrong with the syntax "
"of your SysInfo file; try restarting your iPod.</p>");
restoreOK = true;
break;
case NotAnIPod:
err = tr("<p><b>Not an iPod.</b> The iPod I identified turned out not to be an iPod "
"at all. This shouldn't happen; did you unplug your iPod in the middle of "
"detection? If not, it's a bug.</p>");
break;
case MacPod:
err = tr("<p><b>iPod is a MacPod.</b> Sorry, but those aren't supported for Windows "
"and Linux installations. You may want to use iTunes to convert it to a WinPod.</p>");
break;
case SLinPod:
err = tr("<p><b>Invalid preexisting iPodLinux installation.</b> You have a 5G or nano "
"and you did not install Linux correctly when you installed it. Sorry, "
"but I don't know enough to fix the problem myself. Restore with iTunes or "
"restore your backup, then re-run this installer.</p>");
restoreOK = true;
break;
case UnsupPod:
err = tr("<p><b>Unsupported iPod type.</b> You may either have forgotten to plug in your "
"iPod or have a new model that Installer 2 does not yet support. Note that Installer "
"2 currently works with all iPod models supported by iPodLinux, with the exception of "
"the 5.5G iPod video (for which we need a willing developer to help submit a patch). "
"If you are not sure what model your iPod is, check the "
"<a href=\"http://ipodlinux.org/wiki/Generations\">Generations</a> wiki page.</p>");
restoreOK = true;
break;
case UnmountFailed:
err = tr("<p><b>Unmount failed.</b> The iPod could not be unmounted. "
"Make sure you have no files or folders open on the iPod, then try again.</p>");
restoreOK = true;
break;
default:
err = tr("<p><b>Unknown error.</b> Something's up. Report a bug.</p>");
break;
}
stateOK = 0;
emit completeStateChanged();
#ifdef WIN32
char e[512];
TCHAR E[512];
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError(), 0, E, 512, 0);
TCHAR *p = E;
char *q = e;
while (*p) *q++ = *p++;
*q = '\0';
#endif
err = QString (tr ("<p><b><font color=\"red\">Sorry, but an error occurred. Installation "
"cannot continue.</font></b></p>\n")) + err
#ifdef WIN32
+ QString (tr ("<p>Error code: %1 (%2)</p>")).arg (GetLastError()).arg (e)
#else
+ QString (tr ("<p>Error code: %1 (%2)</p>")).arg (errno).arg (errno? strerror (errno) :
tr ("Success?!"))
#endif
;
blurb->setText (err);
wizard->setInfoText (tr ("<b>Error</b>"),
tr ("Read the message below and press Cancel to exit."));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
if (restoreOK) {
iPodLocation = podloc;
iPodDevice = new LocalRawDevice (podloc);
QPushButton *restoreBackup = new QPushButton (tr ("Restore a previously-made backup"));
connect (restoreBackup, SIGNAL(clicked(bool)), this, SLOT(doBackupRestore(bool)));
layout->addSpacing (20);
layout->addWidget (restoreBackup);
}
layout->addStretch (1);
setLayout (layout);
return;
}
const char *gens[] = { "generation 0x0", // 0x0
"first generation", // 0x1
"second generation", // 0x2
"third generation", // 0x3
"first generation mini", // 0x4
"black-and-white fourth generation (Click Wheel)", // 0x5
"photo", // 0x6
"second generation mini", // 0x7
"generation 0x8",
"generation 0x9",
"generation 0xA",
"fifth generation (video)", // 0xB
"nano", // 0xC
"generation 0xD",
"generation 0xE",
"generation 0xF" };
blurb = new QLabel;
blurb->setWordWrap (true);
blurb->setAlignment (Qt::AlignTop | Qt::AlignLeft);
blurb->setText (QString ("<p>I found a <b>%1GB</b> iPod at physical drive <b>%2</b>. "
"It seems to be a <b>%3</b> iPod, ")
.arg ((devGetSize(podloc) + 1000000) / 2000000)
.arg (podloc)
.arg (gens[hw_ver]));
if (status == WinPod) {
blurb->setText (blurb->text() +
tr ("and does not have iPodLinux installed. If you continue, "
"it will be installed. If you already have iPodLinux installed, "
"<i>do not continue</i>.</p>\n"));
if (hw_ver >= 0xA) {
blurb->setText (blurb->text() +
tr ("<p><font color=\"red\">You seem to have a Nano or Video. Due to some "
"complicated suspend-to-disk logic in the Apple firmware, I will have to "
"shrink your music partition to make room for iPodLinux. Thus, "
"<b>all data on the iPod will be lost!</b></font></p>\n"));
} else {
if (hw_ver >= 0x4) {
blurb->setText (blurb->text() +
tr ("<p>You seem to have a fourth-generation or newer iPod. While these iPods "
"should work, be aware that they are <b>UNSUPPORTED</b>.</p>\n"));
}
blurb->setText (blurb->text() +
tr ("<p>Due to the layout of your iPod's hard drive, I should be able to install "
"Linux without erasing anything on it. However, if this goes wrong, you may need "
"to use iTunes to \"Restore\" the iPod, which <i>does</i> erase data. "
"Thus, <b>please</b> ensure that you have a backup of all data on your iPod!</p>\n"));
}
wizard->setInfoText (tr ("<b>Installation Information</b>"),
tr ("Read the information below and choose your installation type."));
advancedCheck = new QCheckBox (tr ("Advanced partitioning and package selection"));
upgradeRadio = changeLoaderRadio = uninstallRadio = 0;
subblurb = 0;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
layout->addStretch (1);
layout->addWidget (advancedCheck);
layout->addSpacing (5);
setLayout (layout);
stateOK = 1;
emit completeStateChanged();
} else {
blurb->setText (blurb->text() + tr ("with iPodLinux already installed.</p>"));
wizard->setInfoText (tr ("<b>What to do?</b>"), tr ("Select an action below."));
advancedCheck = 0;
upgradeRadio = new QRadioButton (tr ("Update my existing installation"));
changeLoaderRadio = new QRadioButton (tr ("Change loader type and/or boot order"));
uninstallRadio = new QRadioButton (tr ("Uninstall iPodLinux"));
subblurb = new QLabel (tr ("Please choose either an update or an uninstall "
"so I can display something more informative here."));
subblurb->setAlignment (Qt::AlignTop | Qt::AlignLeft);
subblurb->setIndent (10);
subblurb->setWordWrap (true);
subblurb->resize (width(), 100);
connect (upgradeRadio, SIGNAL(clicked(bool)), this, SLOT(upgradeRadioClicked(bool)));
connect (changeLoaderRadio, SIGNAL(clicked(bool)), this, SLOT(changeLoaderRadioClicked(bool)));
connect (uninstallRadio, SIGNAL(clicked(bool)), this, SLOT(uninstallRadioClicked(bool)));
if (Mode == Uninstall) QTimer::singleShot (100, uninstallRadio, SLOT(animateClick()));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
layout->addSpacing (10);
layout->addWidget (upgradeRadio);
layout->addWidget (changeLoaderRadio);
layout->addWidget (uninstallRadio);
layout->addStretch (1);
layout->addWidget (subblurb);
setLayout (layout);
stateOK = 0;
emit completeStateChanged();
}
iPodLocation = podloc;
iPodVersion = hw_ver;
iPodPartitionTable = ptbl;
}
void PodLocationPage::uninstallRadioClicked (bool clicked)
{
(void)clicked;
subblurb->setText (tr ("<p>OK, I guess you really do want to uninstall iPodLinux. "
"Please be sure you have the backup you made handy if you "
"want an easy uninstall. If you've lost it, I'll make do, "
"but I might not get everything right.</p>"
"<p>Press Next when you're ready.</p>"));
stateOK = 1;
emit completeStateChanged();
}
void PodLocationPage::upgradeRadioClicked (bool clicked)
{
(void)clicked;
subblurb->setText (tr ("<p>The update will check for new versions of all packages "
"you have installed; you will be given the chance to upgrade "
"any that have updates, uninstall some packages, install some "
"new ones, or any combination of those.</p>\n"
"<p>Press Next to continue.</p>"));
stateOK = 1;
emit completeStateChanged();
}
void PodLocationPage::changeLoaderRadioClicked (bool clicked)
{
(void)clicked;
subblurb->setText (tr ("<p>This will give you the opportunity to change the boot order "
"(whether Linux or the Apple firmware is default) or, if you so "
"desire, to change to iPodLoader2.</p>\n"
"<p>Press Next to continue.</p>"));
stateOK = 1;
emit completeStateChanged();
}
void PodLocationPage::resetPage()
{
if (advancedCheck) advancedCheck->setChecked (1);
if (upgradeRadio) upgradeRadio->setChecked (0);
if (changeLoaderRadio) changeLoaderRadio->setChecked (0);
if (uninstallRadio) uninstallRadio->setChecked (0);
if (subblurb) subblurb->setText (tr ("Please choose either an update or an uninstall "
"so I can display something more informative here."));
stateOK = !upgradeRadio;
emit completeStateChanged();
}
void Installer::setupDevices (PartitionTable *ptbl)
{
if (iPodFirmwarePartitionDevice) delete iPodFirmwarePartitionDevice;
if (iPodMusicPartitionDevice) delete iPodMusicPartitionDevice;
if (iPodLinuxPartitionDevice) delete iPodLinuxPartitionDevice;
// Yes, this is a memory leak. Oh well. I don't really care.
if (iPodPartitionTable != ptbl) iPodPartitionTable = ptbl;
PartitionTable& t = *iPodPartitionTable;
iPodFirmwarePartitionDevice = new PartitionDevice (iPodDevice, t[0]->offset(), t[0]->length());
iPodMusicPartitionDevice = new PartitionDevice (iPodDevice, t[1]->offset(), t[1]->length());
iPodLinuxPartitionDevice = new PartitionDevice (iPodDevice, t[2]->offset(), t[2]->length());
}
void Installer::setupFilesystems()
{
int err;
iPodMusicPartitionFS = new FATFS (iPodMusicPartitionDevice);
if ((err = iPodMusicPartitionFS->init()) < 0) {
QMessageBox::critical (0, tr ("Error"),
tr ("Error creating filesystem accessor for music partition: %1").arg (strerror (-err)),
tr ("Quit"));
exit (1);
}
iPodLinuxPartitionFS = new Ext2FS (iPodLinuxPartitionDevice);
if ((err = iPodLinuxPartitionFS->init()) < 0) {
QMessageBox::critical (0, tr ("Error"),
tr ("Error creating filesystem accessor for ext2 partition: %1").arg (strerror (-err)),
tr ("Quit"));
exit (1);
}
return;
}
void PodLocationPage::doBackupRestore (bool c)
{
(void)c;
Mode = Uninstall;
wizard->changePage (new UninstallPage (wizard));
}
WizardPage *PodLocationPage::nextPage()
{
if (upgradeRadio) {
if (upgradeRadio->isChecked()) {
Mode = Update;
} else if (changeLoaderRadio->isChecked()) {
Mode = ChangeLoader;
} else {
Mode = Uninstall;
}
iPodPartitionToShrink = 0;
} else {
if (advancedCheck && advancedCheck->isChecked()) {
Mode = AdvancedInstall;
} else {
Mode = StandardInstall;
}
if (iPodVersion >= 0xA) {
iPodPartitionToShrink = 2;
iPodLinuxPartitionSize = 128 * 2048; /* 128M */
if (iPodPartitionTable->length(1) > 8192 * 2048)
iPodLinuxPartitionSize = 256 * 2048; /* 256M if data ptn is >=8GB */
} else {
iPodPartitionToShrink = 1;
iPodLinuxPartitionSize = iPodPartitionTable->length(0) / 2;
if (iPodLinuxPartitionSize < 24 * 2048)
iPodLinuxPartitionSize = 24 * 2048; /* make it at least 24M */
if ((iPodPartitionTable->length(0) - iPodLinuxPartitionSize) < 8 * 2048)
iPodLinuxPartitionSize = iPodPartitionTable->length(0) - 8 * 2048; /* keep at least 8MB for the firmware */
}
}
VFS::File *fh;
switch (Mode) {
case StandardInstall:
return new InstallPage (wizard);
case AdvancedInstall:
return new PartitioningPage (wizard);
case Update:
case ChangeLoader:
installer->setupDevices (iPodPartitionTable);
installer->setupFilesystems();
fh = iPodLinuxPartitionFS->open ("/etc/loadertype", O_RDONLY);
if (fh && !fh->error()) {
char buf[4] = "?";
fh->read (buf, 3);
buf[3] = 0;
switch (buf[0]) {
case 'a':
case 'A':
iPodLoader = Loader1Apple;
break;
case 'l':
case 'L':
iPodLoader = Loader1Linux;
break;
case '2':
iPodLoader = Loader2;
break;
default:
iPodLoader = UnknownLoader;
break;
}
fh->close();
}
delete fh;
if (Mode == ChangeLoader)
return new ChangeLoaderPage (wizard);
else
return new PackagesPage (wizard);
case Uninstall:
return new UninstallPage (wizard);
}
return 0;
}
bool PodLocationPage::isComplete()
{
return stateOK;
}
bool PodLocationPage::isLastPage()
{
return wasError;
}
PartitioningPage::PartitioningPage (Installer *wiz)
: InstallerPage (wiz)
{
wiz->setInfoText (tr ("<b>Advanced Partitioning</b>"), tr ("Fill in the requested information and click Next."));
topblurb = new QLabel (tr ("<p>If you've chosen this path, I assume you know what you're doing. "
"If you don't understand this, just click Next; the defaults are "
"OK.</p><p>Make room for iPodLinux by:</p>"));
topblurb->setWordWrap (true);
partitionSmall = new QRadioButton (tr ("Shrinking the firmware partition"));
partitionBig = new QRadioButton (tr ("Shrinking the data partition"));
if (iPodPartitionToShrink == 2)
partitionBig->setChecked (true);
else
partitionSmall->setChecked (true);
size = new QSpinBox;
size->setSuffix (" MB");
sizeBlurb = new QLabel (tr ("How big should the Linux partition be?"));
sizeBlurb->setAlignment (Qt::AlignRight);
sizeBlurb->setIndent (10);
spaceLeft = new QLabel;
spaceLeft->setWordWrap (true);
QVBoxLayout *layout = new QVBoxLayout;
QHBoxLayout *szlayout = new QHBoxLayout;
szlayout->addWidget (sizeBlurb);
szlayout->addWidget (size);
layout->addWidget (topblurb);
layout->addWidget (partitionSmall);
layout->addWidget (partitionBig);
layout->addSpacing (15);
layout->addLayout (szlayout);
layout->addWidget (spaceLeft);
layout->addStretch (1);
layout->addWidget (new QLabel (tr ("Press Next to continue.")));
setLayout (layout);
setStuff();
size->setValue (iPodLinuxPartitionSize / 2048);
connect (size, SIGNAL(valueChanged(int)), this, SLOT(setStuff(int)));
connect (partitionSmall, SIGNAL(toggled(bool)), this, SLOT(setSmallStuff(bool)));
connect (partitionBig, SIGNAL(toggled(bool)), this, SLOT(setBigStuff(bool)));
}
void PartitioningPage::setStuff (int newVal)
{
(void)newVal;
if (iPodPartitionToShrink == 2) {
size->setRange (24, (iPodPartitionTable->length(1) / 2048) / 2);
} else {
size->setRange (16, (iPodPartitionTable->length(1) / 2048) - 8);
}
spaceLeft->setText (QString (tr ("This size configuration gives <b>%1MB</b> of space "
"left for music and data."))
.arg ((iPodPartitionTable->length(iPodPartitionToShrink - 1) / 2048) -
size->value()));
if (iPodPartitionToShrink != 2) spaceLeft->hide();
else spaceLeft->show();
}
void PartitioningPage::setBigStuff (bool chk)
{
if (chk) {
iPodPartitionToShrink = 2;
iPodLinuxPartitionSize = 128 * 2048; /* 128M */
if (iPodPartitionTable->length(1) > 8192 * 2048)
iPodLinuxPartitionSize = 256 * 2048; /* 256M if data ptn is >=8GB */
setStuff(0);
size->setValue (iPodLinuxPartitionSize / 2048);
}
}
void PartitioningPage::setSmallStuff (bool chk)
{
if (chk) {
iPodPartitionToShrink = 1;
iPodLinuxPartitionSize = iPodPartitionTable->length(0) / 2;
if (iPodLinuxPartitionSize < 24 * 2048)
iPodLinuxPartitionSize = 24 * 2048; /* make it at least 24M */
if ((iPodPartitionTable->length(0) - iPodLinuxPartitionSize) < 8 * 2048)
iPodLinuxPartitionSize = iPodPartitionTable->length(0) - 8 * 2048; /* keep at least 8MB for the firmware */
setStuff(0);
size->setValue (iPodLinuxPartitionSize / 2048);
}
}
void PartitioningPage::resetPage()
{}
WizardPage *PartitioningPage::nextPage()
{
iPodLinuxPartitionSize = size->value() * 2048;
return new InstallPage (wizard);
}
bool PartitioningPage::isComplete()
{
return true;
}
ChangeLoaderPage::ChangeLoaderPage (Installer *wiz)
: InstallerPage (wiz)
{
wiz->setInfoText (tr ("<b>Loader Selection</b>"), tr ("Select the radio button for the loader to which you would like to change and click Next."));
blurb = new QLabel (tr ("Please select the radio button for the load order or loader you want to "
"change to below. The currently selected one is your current loader."));
blurb->setWordWrap (true);
loader1apple = new QRadioButton (tr ("Standard loader with Apple firmware default"));
loader1linux = new QRadioButton (tr ("Standard loader with iPodLinux default"));
loader2 = new QRadioButton (tr ("iPodLoader2 (nice menu interface, but still experimental)"));
ldrchoiceblurb = new QLabel;
ldrchoiceblurb->setWordWrap (true);
connect (loader1apple, SIGNAL(toggled(bool)), this, SLOT(setLoader1Blurb(bool)));
connect (loader1linux, SIGNAL(toggled(bool)), this, SLOT(setLoader1Blurb(bool)));
connect (loader2, SIGNAL(toggled(bool)), this, SLOT(setLoader2Blurb(bool)));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
layout->addWidget (loader1apple);
layout->addWidget (loader1linux);
layout->addWidget (loader2);
layout->addWidget (ldrchoiceblurb);
layout->addStretch (1);
setLayout (layout);
resetPage();
}
void ChangeLoaderPage::resetPage()
{
loader1apple->setChecked (false);
loader1linux->setChecked (false);
loader2->setChecked (false);
if (iPodLoader == Loader1Apple)
loader1apple->setChecked (true);
else if (iPodLoader == Loader1Linux)
loader1linux->setChecked (true);
else if (iPodLoader == Loader2)
loader2->setChecked (true);
}
void ChangeLoaderPage::setLoader1Blurb (bool chk)
{
if (chk) {
ldrchoiceblurb->setText (tr ("To boot the non-default OS, hold rewind as your iPod restarts."));
}
emit completeStateChanged();
}
void ChangeLoaderPage::setLoader2Blurb (bool chk)
{
if (chk) {
ldrchoiceblurb->setText (tr ("iPodLoader2 can also load Rockbox, multiple kernels, etc; see "
"the iPodLinux wiki for more information."));
}
emit completeStateChanged();
}
WizardPage *ChangeLoaderPage::nextPage()
{
LoaderType newLoader;
if (loader2->isChecked()) newLoader = Loader2;
else if (loader1linux->isChecked()) newLoader = Loader1Linux;
else newLoader = Loader1Apple;
PendingActions->append (new ChangeLoaderAction (iPodLoader, newLoader));
if ((iPodLoader == Loader2 && !loader2->isChecked()) ||
(iPodLoader != Loader2 && loader2->isChecked())) {
iPodLoader = newLoader;
return new PackagesPage (wizard, true);
} else {
PendingActions->append (new FirmwareRecreateAction);
return new DoActionsPage (wizard, new DonePage (wizard));
}
}
UninstallPage::UninstallPage (Installer *wiz)
: InstallerPage (wiz)
{
wiz->setInfoText (tr ("<b>Uninstallation Information</b>"), tr ("Fill in the information below and click Next."));
blurb = new QLabel (tr ("Uninstallation can be done most reliably if you made a backup. If you did, "
"please browse to its path below. If not, uncheck the box and I'll see what "
"I can do."));
blurb->setWordWrap (true);
nobackupblurb = new QLabel (tr ("OK, I guess you didn't make one. In the future, please do so. I'll "
"try my best to restore your iPod to normal, but I may not be able to; "
"in this case, you'll need to use iTunes to restore it, "
"erasing all music and data. Sorry. Click Next."));
nobackupblurb->setWordWrap (true);
haveBackup = new QCheckBox (tr ("Yes! I made a backup."));
haveBackup->setChecked (true);
backupPathLabel = new QLabel (tr ("Load backup:"));
backupPath = new QLineEdit ("");
backupBrowse = new QPushButton (tr ("Browse..."));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (blurb);
layout->addSpacing (10);
layout->addWidget (haveBackup);
QHBoxLayout *bkplayout = new QHBoxLayout;
bkplayout->addWidget (backupPathLabel);
bkplayout->addWidget (backupPath);
bkplayout->addWidget (backupBrowse);
layout->addLayout (bkplayout);
layout->addWidget (nobackupblurb);
layout->addStretch (1);
nobackupblurb->hide();
setLayout (layout);
connect (haveBackup, SIGNAL(toggled(bool)), this, SLOT(setBackupBlurb(bool)));
connect (backupPath, SIGNAL(textChanged(QString)), this, SIGNAL(completeStateChanged()));
connect (backupBrowse, SIGNAL(released()), this, SLOT(openBrowseDialog()));
setBackupBlurb (true);
if (InstallAutomatically && iPodDoBackup) {
backupPath->setText (iPodBackupLocation);
emit completeStateChanged();
}
}
void UninstallPage::setBackupBlurb (bool chk)
{
if (chk) {
nobackupblurb->hide();
backupPathLabel->show();
backupPath->show();
backupBrowse->show();
} else {
nobackupblurb->show();
backupPathLabel->hide();
backupPath->hide();
backupBrowse->hide();
}
emit completeStateChanged();
}
void UninstallPage::openBrowseDialog()
{
QString ret = QFileDialog::getOpenFileName (this, "Choose a backup file to restore:",
QString(), "Firmware backup files (*.fw)");
if (ret != "")
backupPath->setText (ret);
}
WizardPage *UninstallPage::nextPage()
{
if (haveBackup->isChecked()) {
PendingActions->append (new RestoreBackupAction (iPodLocation, backupPath->text()));
} else {
PendingActions->append (new HeuristicUninstallAction (iPodLocation));
}
return new DoActionsPage (wizard, new DonePage (wizard));
}
void UninstallPage::resetPage()
{}
bool UninstallPage::isComplete()
{
return (!haveBackup->isChecked() || (backupPath->text().length() && QFile::exists (backupPath->text())));
}
InstallPage::InstallPage (Installer *wiz)
: InstallerPage (wiz)
{
wiz->setInfoText (tr ("<b>Installation Information</b>"), tr ("Fill in the information below and click Next."));
topblurb = new QLabel (tr ("I'm almost ready to install, but first I need some info."));
ldrblurb = new QLabel (tr ("First, you need to pick how you're going to load Linux. There are three ways: "));
ldrblurb->setWordWrap (true);
loader1apple = new QRadioButton (tr ("Standard loader with Apple firmware default"));
loader1linux = new QRadioButton (tr ("Standard loader with iPodLinux default"));
loader2 = new QRadioButton (tr ("iPodLoader2 - Nice interface, capable of loading iPodLinux, Apple firmware and Rockbox."));
loader2->setChecked (true);
ldrchoiceblurb = new QLabel;
ldrchoiceblurb->setWordWrap (true);
bkpblurb = new QLabel (tr ("Second, it is <i>highly</i> recommended that you make a backup of "
"your iPod's firmware partition. It will be 40 to 120 MB in size."));
bkpblurb->setWordWrap (true);
bkpchoiceblurb = new QLabel (tr ("A backup is <b>highly recommended</b>. Without one, "
"we can't guarantee that uninstallation will go smoothly. "
"If you have an <b>iPod video or nano</b> with a recent firmware, "
"however, choosing to create a backup <b>may cause Installer 2 "
"to crash</b> (but not harm your iPod)."));
bkpchoiceblurb->setWordWrap (true);
makeBackup = new QCheckBox (tr ("Yes, I want to save a backup."));
makeBackup->setChecked (true);
backupPathLabel = new QLabel (tr ("Save as:"));
backupPath = new QLineEdit (InstallerHome + "/ipod_os_backup.fw");
backupBrowse = new QPushButton (tr ("Browse..."));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (topblurb);
layout->addSpacing (10);
layout->addWidget (ldrblurb);
layout->addWidget (loader1apple);