/
index.lua
855 lines (788 loc) · 31.4 KB
/
index.lua
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
--Corbenik/Skeith CFW Updater
--Author: gnmmarechal
--Runs on Lua Player Plus 3DS
-- Run updated index.lua: If a file is available on the server, that file will be downloaded and used instead.
-- Skipped if useupdate = 0
isupdate = 0
if ((not System.doesFileExist("/skeith/firmware/native") and System.doesFileExist("/corbenik-updater/useskeith")) and (not System.doesFileExist("/skeith/lib/firmware/native") and System.doesFileExist("/corbenik-updater/useskeith"))) then -- Stops people without Skeith from using the wrong updater.
System.deleteFile("/corbenik-updater/useskeith")
end
if not System.doesFileExist("/corbenik/firmware/native") and System.doesFileExist("/skeith/firmware/native") then --If Corbenik isn't found but Skeith is, force Skeith updater.
if not System.doesFileExist("/corbenik/lib/firmware/native") and System.doesFileExist("/skeith/lib/firmware/native") then --If Corbenik isn't found but Skeith is, force Skeith updater. (new structure)
skeithstream = io.open("/corbenik-updater/useskeith",FCREATE)
io.write(skeithstream,0,"SkeithCFW", 9)
io.close(skeithstream)
end
end
-- useupdate = 0
updateserverlua = "http://gs2012.xyz/3ds/corbenikupdater/updatedindex.lua"
skeithupdateserverlua = "http://gs2012.xyz/3ds/skeithupdater/updatedindex.lua"
System.createDirectory("/corbenik-updater")
System.createDirectory("/skeith-updater")
--[[
if System.doesFileExist("/skeith-updater/updatedindex.lua") then
System.deleteFile("/skeith-updater/updatedindex.lua")
end
if System.doesFileExist("/corbenik-updater/updatedindex.lua") then
System.deleteFile("/corbenik-updater/updatedindex.lua")
end
--]]
if not Network.isWifiEnabled() then --Checks for Wi-Fi
error("Failed to connect to the network.")
end
if ((not System.doesFileExist("/corbenik/lib/firmware/native")) and (not System.doesFileExist("/skeith/lib/firmware/native")) and (not System.doesFileExist("/corbenik/firmware/native")) and (not System.doesFileExist("/skeith/firmware/native"))) then
error("Corbenik/Skeith CFW not found. Please install one or both.")
end
--Switches to Skeith script if setting is found.
if System.doesFileExist("/corbenik-updater/useskeith") then -- Checks if it should switch to Skeith AND if Corbenik exists. If not, it'll default to Skeith.
skeithusage = 1
if System.doesFileExist("/skeith-updater/updatedindex.lua") then
System.deleteFile("/skeith-updater/updatedindex.lua")
end
Network.downloadFile(skeithupdateserverlua, "/skeith-updater/updatedindex.lua")
dofile("/skeith-updater/updatedindex.lua")
System.exit()
else
skeithusage = 0
end
--[[
if System.doesFileExist("romfs:/skeithindex.lua") and skeithusage == 1 then
elseif not System.doesFileExist("romfs:/skeithindex.lua") and skeithusage == 1 then
if System.doesFileExist("/skeith-updater/updatedindex.lua") then
System.deleteFile("/skeith-updater/updatedindex.lua")
end
Network.downloadFile(skeithupdateserverlua, "/skeith-updater/updatedindex.lua")
dofile("/skeith-updater/updatedindex.lua")
System.exit()
end
--]]
--[[
-- Update script
if isupdate == 0 then
coremajor = 0
coreminor = 3
corerev = 0
coreversionstring = coremajor.."."..coreminor.."."..corerev
end
--]]
if System.doesFileExist("/corbenik-updater/useupdate") then
if isupdate == 0 then
useupdate = 1
else
useupdate = 1
end
else
useupdate = 1
end
if (Network.isWifiEnabled()) and useupdate == 1 then
if System.doesFileExist("/corbenik-updater/updatedindex.lua") then
System.deleteFile("/corbenik-updater/updatedindex.lua")
end
Network.downloadFile(updateserverlua, "/corbenik-updater/updatedindex.lua")
dofile("/corbenik-updater/updatedindex.lua")
System.exit()
end
--End
--Sound init for BGM :)
if System.doesFileExist("/corbenik-updater/usebgm") or System.doesFileExist("/skeith-updater/usebgm") then
if System.doesFileExist("/3ds/dspfirm.cdc") then --csnd seems glitchy. I'll disable BGM for older releases of lpp.
usebgm = 1
else
usebgm = 0
end
else
usebgm = 0
end
if usebgm == 1 then
Sound.init()
if System.doesFileExist("romfs:/bgm.wav") then
bgm = Sound.openWav("romfs:/bgm.wav",false)
Sound.play(bgm,LOOP)
end
if System.doesFileExist("/3ds/corbenikupdater/bgm.wav") then
bgm = Sound.openWav("/3ds/corbenikupdater/bgm.wav",false)
Sound.play(bgm,LOOP)
end
if System.doesFileExist("/corbenik-updater/bgm.wav") then
bgm = Sound.openWav("/corbenik-updater/bgm.wav",false)
Sound.play(bgm,LOOP)
elseif System.doesFileExist("/corbenik-updater/bgm.ogg") then
bgm = Sound.openOgg("/corbenik-updater/bgm.ogg",false)
Sound.play(bgm,LOOP)
elseif System.doesFileExist("/corbenik-updater/bgm.aiff") then
bgm = Sound.openAiff("/corbenik-updater/bgm.aiff",false)
Sound.play(bgm,LOOP)
end
end
--Some variables
System.currentDirectory("/")
root = System.currentDirectory()
consolehbdir = root.."3ds/"
consoleerror = 0
scr = 1
oldpad = Controls.read()
debugmode = 1
updatechecked = 0
setnight = 0
MAX_RAM_ALLOCATION = 10485760
--App details
versionmajor = 0
versionminor = 6
versionrev = 0
versionstring = versionmajor.."."..versionminor.."."..versionrev
versionrelno = 3
selfname = "corbenikupdater"
selfpath = consolehbdir..selfname.."/"
selfexepath = selfpath..selfname..".3dsx" -- This is for the 3DSX version only
selfstring = "Corbenik CFW Updater v."..versionstring
selfauthor = "gnmmarechal"
newstructure = 1 -- By default 0 for the current stable doesn't use it, but the next nightly might use it.
--Affected app details
appname = "Corbenik CFW"
appinstallname = "corbenik"
appinstallpath = root
downloadedzip = root..appinstallname..".zip"
cfwpath = appinstallpath..appinstallname
config = root..appinstallname.."-updater.cfg"
usechainpayload = root..appinstallname.."-updater/nochain"
nightlyfile = root..appinstallname.."-updater/usenightly"
--Server strings (some vars are declared by functions after reading the strings from the server)
serverpath = "http://gs2012.xyz/3ds/"..selfname.."/"
servergetnochainzippath = serverpath.."latest.txt"
servergetchainzippath = serverpath.."chainlatest.txt"
servergetnightlyzippath = serverpath.."latest-nightly.txt"
servergetzipver = serverpath.."version.txt"
servergetziprel = serverpath.."rel.cfg"
-- Colours
white = Color.new(255,255,255)
green = Color.new(0,240,32)
red = Color.new(255,0,0)
yellow = Color.new(255,255,0)
--Update-check functions
--Variables
serverhashbaseurl = "http://gs2012.xyz/3ds/corbenikupdater/"
serverhashext = ".sha512"
localhashdl = root..appinstallname.."-updater/newhash.sha512"
localcurrenthash = root..appinstallname.."-updater/currenthash.sha512"
--Hash URLs for the various versions
serverhashurlstable = "latest-chain"
serverhashurlstablenochain = "latest"
serverhashurlnightly = "latest-nightly"
nightlyhash = 1
function sethashurl(mode)
if mode == 0 then --nochain
serverhashurl = serverhashbaseurl..serverhashurlstablenochain..serverhashext
elseif mode == 1 then
serverhashurl = serverhashbaseurl..serverhashurlstable..serverhashext
elseif mode == 2 then
serverhashurl = serverhashbaseurl..serverhashurlnightly..serverhashext
nightlyhash = 1
end
end
function comparehash()
Network.downloadFile(serverhashurl,localhashdl)
if System.doesFileExist(localcurrenthash) then
localhashstream = io.open(localcurrenthash, FREAD)
localshahash = io.read(localhashstream,0,128)
io.close(localhashstream)
else
localhashstream = io.open(localcurrenthash, FCREATE)
io.write(localhashstream, 0, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 128)
System.deleteFile(localhashdl)
io.close(localhashstream)
comparehash()
end
serverhashstream = io.open(localhashdl, FREAD)
servershahash = io.read(serverhashstream, 0,128)
io.close(serverhashstream)
if servershahash == localshahash then
updated = 1
forcehashupdate = 0
else
updated = 0
forcehashupdate = 1
end
end
function updatehash()
if System.doesFileExist(localcurrenthash) then
System.deleteFile(localcurrenthash)
end
if System.doesFileExist(localhashdl) then
System.deleteFile(localhashdl)
end
Network.downloadFile(serverhashurl,localcurrenthash)
end
--Old stuff
function checkupdate() --Checks for new version of Corbenik CFW -- Apparently broken
if updatechecked == 0 then
if System.doesFileExist("/corbenikupdater/cfw-rel.cfg") then
relstream = io.open("/corbenikupdater/cfw-rel.cfg",FREAD)
localrel = io.read(relstream,0,io.size(relstream))
if tonumber(localrel) >= tonumber(serverrel) then
updated = 1
end
updatechecked = 1
else
System.createDirectory("/corbenikupdater")
Network.downloadFile(servergetziprel, "/corbenikupdater/cfw-rel.cfg")
updatechecked = 1
end
end
end
-- Server/network functions
function iswifion()
if (Network.isWifiEnabled()) or updated == 1 then
return 1
else
consoleerror = 1
scr = 0
return 0
end
end
function servergetVars()
if iswifion() == 1 then
serverzippath = Network.requestString(servergetzippath)
serverver = Network.requestString(servergetzipver)
serverrel = Network.requestString(servergetziprel)
if usenightly == 1 then
servernightlyzippath = Network.requestString(servergetnightlyzippath)
end
end
end
--System functions
function fileCopy(input, output)
inp = io.open(input,FREAD)
if System.doesFileExist(output) then
System.deleteFile(output)
end
out = io.open(output,FCREATE)
size = io.size(inp)
index = 0
while (index+(MAX_RAM_ALLOCATION/2) < size) do
io.write(out,index,io.read(inp,index,MAX_RAM_ALLOCATION/2),(MAX_RAM_ALLOCATION/2))
index = index + (MAX_RAM_ALLOCATION/2)
end
if index < size then
io.write(out,index,io.read(inp,index,size-index),(size-index))
end
io.close(inp)
io.close(out)
end
function clear()
Screen.refresh()
Screen.clear(TOP_SCREEN)
Screen.clear(BOTTOM_SCREEN)
end
function flip()
Screen.flip()
Screen.waitVblankStart()
oldpad = pad
end
function waitloop()
loop = 0
end
function quit()
if bgm == nil then
else
Sound.close(bgm)
end
Sound.term()
System.exit()
end
function runoncevars()
checkedicon = 0
end
updated = 0
skipped = 0
--Input functions
function inputscr(newscr, inputkey)
if Controls.check(pad,inputkey) and not Controls.check(oldpad,inputkey) then
if newscr == -1 then
quit()
end
if newscr == -4 then
if bgm == nil then
else
Sound.close(bgm)
end
Sound.term()
System.reboot()
end
Screen.clear(TOP_SCREEN)
scr = newscr
end
end
function nextscr(skrin)
inputscr(skrin, KEY_A)
end
function checkreboot()
inputscr(-4, KEY_A)
end
function checkquit()
inputscr(-1, KEY_B)
end
function checkrestart()
inputscr(-3, KEY_R)
end
function endquit()
inputscr(-1, KEY_A)
end
--Installer functions
function precleanup()
if System.doesFileExist(downloadedzip) then
System.deleteFile(downloadedzip)
end
end
function precheck()
if System.getModel() == 2 or System.getModel() == 4 then
System.setCpuSpeed(NEW_3DS_CLOCK)
newconsole = 1
else
newconsole = 0
end
if System.doesFileExist(usechainpayload) then
servergetzippath = servergetnochainzippath
sethashurl(0)
else
servergetzippath = servergetchainzippath
sethashurl(1)
end
if System.doesFileExist(nightlyfile) then
servergetzippathnight = servergetnightlyzippath
usenightly = 1
sethashurl(2)
else
usenightly = 0
end
if (not System.doesFileExist(cfwpath.."/firmware/native")) and (not System.doesFileExist(cfwpath.."/lib/firmware/native")) then
usenightly = 0
if System.doesFileExist(usechainpayload) then
servergetzippath = servergetnochainzippath
else
servergetzippath = servergetchainzippath
end
newinstall = 1
else
newinstall = 0
end
if System.doesFileExist(config) then
configstream = io.open(config,FREAD)
armpayloadpath = io.read(configstream,0,io.size(configstream))
if (not System.doesFileExist(armpayloadpath)) then
System.deleteFile(config)
precheck()
end
else
armpayloadpath = root.."arm9loaderhax.bin"
if System.doesFileExist("/arm9loaderhax_si.bin") then
setconfigstream = io.open(config,FCREATE)
io.write(setconfigstream,0,"/arm9loaderhax_si.bin", 21)
io.close(setconfigstream)
precheck() --Calls itself again after setting the payload path to arm9loaderhax_si.bin.
end
end
if nightlyhash == 0 then
--comparehash()
end
end
function installfilechecker()
if newinstall == 1 then
if not System.doesFileExist("/corbenik-updater/firmware.bin") then
end
end
end
--Data migration function (to upgrade to the new directory structure while keeping the data)
function migrate()
if migrationon == 1 then
if keepconfig == 1 then --Moving Config
if System.doesFileExist(cfwpath.."/config/main.conf") then
System.renameDirectory(cfwpath.."/config", cfwpath.."/etc")
end
end
--Moving firmwares
if (System.doesFileExist(cfwpath.."/firmware/native")) or (System.doesFileExist(cfwpath.."/firmware/agb")) or (System.doesFileExist(cfwpath.."/firmware/twl")) then
System.createDirectory(cfwpath.."/lib")
System.renameDirectory(cfwpath.."/firmware", cfwpath.."/lib/firmware")
end
--Moving keys
if (System.doesFileExist(cfwpath.."/keys/native.key")) or (System.doesFileExist(cfwpath.."/keys/agb.key")) or (System.doesFileExist(cfwpath.."/keys/twl.key")) or (System.doesFileExist(cfwpath.."/keys/agb.cetk")) or (System.doesFileExist(cfwpath.."/keys/twl.cetk")) or (System.doesFileExist(cfwpath.."/keys/11key96.key")) then
System.createDirectory(cfwpath.."/share")
System.renameDirectory(cfwpath.."/keys", cfwpath.."/share/keys")
end
--Moving splash screens
if (System.doesFileExist(cfwpath.."/bits/top.bin")) then
System.createDirectory(cfwpath.."/share")
System.renameFile(cfwpath.."/bits/top.bin", cfwpath.."/share/top.bin")
end
if (System.doesFileExist(cfwpath.."/bits/bottom.bin")) then
System.createDirectory(cfwpath.."/share")
System.renameFile(cfwpath.."/bits/bottom.bin", cfwpath.."/share/bottom.bin")
end
--Moving termfont.bin
if (System.doesFileExist(cfwpath.."/bits/termfont.bin")) then
System.createDirectory(cfwpath.."/share")
System.renameFile(cfwpath.."/bits/termfont.bin", cfwpath.."/share/termfont.bin")
end
--Moving cache
System.createDirectory(cfwpath.."/var")
System.renameDirectory(cfwpath.."/cache", cfwpath.."/var/cache")
--Moving chain payloads
System.createDirectory(cfwpath.."/chain")
System.renameDirectory(cfwpath.."/chain", cfwpath.."/boot")
--Moving locale
if System.doesFileExist(cfwpath.."/locale/info") then
System.createDirectory(cfwpath.."/share/locale")
System.renameDirectory(cfwpath.."/locale", cfwpath.."/share/locale/emu")
end
else -- Reverse migration function? NOW USELESS
if keepconfig == 1 then --Moving Config
if System.doesFileExist(cfwpath.."/etc/main.conf") then
System.renameDirectory(cfwpath.."/etc", cfwpath.."/config")
end
end
--Moving firmwares
if (System.doesFileExist(cfwpath.."/lib/firmware/native")) or (System.doesFileExist(cfwpath.."/lib/firmware/agb")) or (System.doesFileExist(cfw.."/lib/firmware/twl")) then
System.renameDirectory(cfwpath.."/lib/firmware", cfwpath.."/firmware")
end
--Moving keys
if (System.doesFileExist(cfwpath.."/share/keys/native.key")) or (System.doesFileExist(cfwpath.."/share/keys/agb.key")) or (System.doesFileExist(cfwpath.."/share/keys/twl.key")) or (System.doesFileExist(cfwpath.."/share/keys/agb.cetk")) or (System.doesFileExist(cfwpath.."/share/keys/twl.cetk")) or (System.doesFileExist(cfwpath.."/share/keys/11key96.key")) then
System.renameDirectory(cfwpath.."/share/keys", cfwpath.."/keys")
end
--Moving splash screens
if (System.doesFileExist(cfwpath.."/share/top.bin")) then
System.createDirectory(cfwpath.."/bits")
System.renameFile(cfwpath.."/share/top.bin", cfwpath.."/share/top.bin")
end
if (System.doesFileExist(cfwpath.."/share/bottom.bin")) then
System.createDirectory(cfwpath.."/bits")
System.renameFile(cfwpath.."/share/bottom.bin", cfwpath.."/share/bottom.bin")
end
--Moving cache
System.renameDirectory(cfwpath.."/var/cache", cfwpath.."/cache")
--Moving chain payloads
System.createDirectory(cfwpath.."/boot")
System.renameDirectory(cfwpath.."/boot", cfwpath.."/chain")
--Moving locale
if System.doesFileExist(cfwpath.."/share/locale/emu/info") then
System.createDirectory(cfwpath.."/share/locale")
System.renameDirectory(cfwpath.."/locale", cfwpath.."/share/locale/emu")
end
end
end
--[[
function installnewunixstructure()
headflip = 1
migrationon = 1
head()
debugWrite(0,60,"Downloading ZIP...", white, TOP_SCREEN)
if updated == 0 then
Network.downloadFile(serverzippath, downloadedzip)
end
debugWrite(0,80,"Backing up old files...", red, TOP_SCREEN)
if updated == 0 then
migrate()
h,m,s = System.getTime()
day_value,day,month,year = System.getDate()
System.renameDirectory(cfwpath,root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year)
System.renameFile(armpayloadpath,armpayloadpath.."-BACKUP-"..h..m..s..day_value..day..month..year)
end
debugWrite(0,100,"Extracting to path...", white, TOP_SCREEN)
if updated == 0 then
System.renameFile("/arm9loaderhax.bin", "/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.renameFile("/arm9loaderhax_si.bin", "/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.extractZIP(downloadedzip,appinstallpath)
System.deleteFile("/arm9loaderhax.bin")
System.extractFromZIP(downloadedzip,"arm9loaderhax.bin",armpayloadpath)
if not System.doesFileExist("/arm9loaderhax.bin") and not System.doesFileExist("/arm9loaderhax_si.bin") then
System.renameFile("/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax_si.bin")
System.renameFile("/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax.bin")
end
System.deleteDirectory(cfwpath.."/lib/firmware")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/lib/firmware",cfwpath.."/lib/firmware")
System.deleteDirectory(cfwpath.."/share/keys")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/keys",cfwpath.."/share/keys")
if keepconfig == 1 then
System.deleteDirectory(cfwpath.."/etc")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc",cfwpath.."/etc")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/var/cache",cfwpath.."/var/cache")
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc")
fileCopy(cfwpath.."/etc".."/main.conf",root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc".."/main.conf")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/libexec/top.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/libexec/top.bin", cfwpath.."/libexec/top.bin")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/libexec/bottom.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/libexec/bottom.bin", cfwpath.."/libexec/bottom.bin")
end
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/boot")
if System.doesFileExist(cfwpath.."/boot/Corbenik") then
System.renameFile(cfwpath.."/boot/Corbenik", cfwpath.."/Corbenik.bin")
end
System.deleteDirectory(cfwpath.."/boot")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/boot",cfwpath.."/boot")
if System.doesFileExist(cfwpath.."/Corbenik.bin") then
System.renameFile(cfwpath.."/Corbenik.bin", cfwpath.."/boot/Corbenik")
end
System.deleteDirectory(cfwpath.."/share/locale/emu")
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/locale/emu")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/locale/emu",cfwpath.."/share/locale/emu")
if isnightly == 1 then
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bin",cfwpath.."/bin")
end
System.deleteFile(downloadedzip)
if nightlyhash == 0 then
updatehash()
end
end
debugWrite(0,120,"DONE! Press A to reboot, B to quit!", green, TOP_SCREEN)
updated = 1
end
--]]
function installnewunixstructure()
headflip = 1
migrationon = 1
head()
debugWrite(0,60,"Downloading ZIP...", white, TOP_SCREEN)
if updated == 0 then
Network.downloadFile(serverzippath, downloadedzip)
end
debugWrite(0,80,"Backing up old files...", red, TOP_SCREEN)
if updated == 0 then
migrate()
h,m,s = System.getTime()
day_value,day,month,year = System.getDate()
System.renameDirectory(cfwpath,root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year)
System.renameFile(armpayloadpath,armpayloadpath.."-BACKUP-"..h..m..s..day_value..day..month..year)
end
debugWrite(0,100,"Extracting to path...", white, TOP_SCREEN)
if updated == 0 then
System.renameFile("/arm9loaderhax.bin", "/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.renameFile("/arm9loaderhax_si.bin", "/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.extractZIP(downloadedzip,appinstallpath)
System.deleteFile("/arm9loaderhax.bin")
System.extractFromZIP(downloadedzip,"arm9loaderhax.bin",armpayloadpath)
if not System.doesFileExist("/arm9loaderhax.bin") and not System.doesFileExist("/arm9loaderhax_si.bin") then
System.renameFile("/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax_si.bin")
System.renameFile("/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax.bin")
end
System.deleteDirectory(cfwpath.."/lib/firmware")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/lib/firmware",cfwpath.."/lib/firmware")
System.deleteDirectory(cfwpath.."/share/keys")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/keys",cfwpath.."/share/keys")
if keepconfig == 1 then
System.deleteDirectory(cfwpath.."/etc")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc",cfwpath.."/etc")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/var/cache",cfwpath.."/var/cache")
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc")
--fileCopy(cfwpath.."/etc".."/main.conf",root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/etc".."/main.conf")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/top.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/top.bin", cfwpath.."/share/top.bin")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/bottom.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/bottom.bin", cfwpath.."/share/bottom.bin")
end
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/boot")
if System.doesFileExist(cfwpath.."/boot/Corbenik") then
System.renameFile(cfwpath.."/boot/Corbenik", cfwpath.."/Corbenik.bin")
end
System.deleteDirectory(cfwpath.."/boot")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/boot",cfwpath.."/boot")
if System.doesFileExist(cfwpath.."/Corbenik.bin") then
System.renameFile(cfwpath.."/Corbenik.bin", cfwpath.."/boot/Corbenik")
end
System.deleteDirectory(cfwpath.."/share/locale/emu")
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/locale/emu")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/share/locale/emu",cfwpath.."/share/locale/emu")
if isnightly == 1 then
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bin",cfwpath.."/bin")
end
System.deleteFile(downloadedzip)
if nightlyhash == 0 then
--updatehash()
end
end
debugWrite(0,120,"DONE! Press A to reboot, B to quit!", green, TOP_SCREEN)
updated = 1
end
function installnew()
headflip = 1
head()
debugWrite(0,60,"Downloading ZIP...", white, TOP_SCREEN)
if updated == 0 then
Network.downloadFile(serverzippath, downloadedzip)
end
debugWrite(0,80,"Backing up old files...", red, TOP_SCREEN)
if updated == 0 then
migrate()
h,m,s = System.getTime()
day_value,day,month,year = System.getDate()
System.renameDirectory(cfwpath,root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year)
System.renameFile(armpayloadpath,armpayloadpath.."-BACKUP-"..h..m..s..day_value..day..month..year)
end
debugWrite(0,100,"Extracting to path...", white, TOP_SCREEN)
if updated == 0 then
System.renameFile("/arm9loaderhax.bin", "/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.renameFile("/arm9loaderhax_si.bin", "/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin")
System.extractZIP(downloadedzip,appinstallpath)
System.deleteFile("/arm9loaderhax.bin")
System.extractFromZIP(downloadedzip,"arm9loaderhax.bin",armpayloadpath)
if not System.doesFileExist("/arm9loaderhax.bin") and not System.doesFileExist("/arm9loaderhax_si.bin") then
System.renameFile("/arm9loaderhax_si".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax_si.bin")
System.renameFile("/arm9loaderhax".."-BACKUP-"..h..m..s..day_value..day..month..year..".bin", "/arm9loaderhax.bin")
end
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/firmware",cfwpath.."/firmware")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/keys",cfwpath.."/keys")
if keepconfig == 1 then
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/config",cfwpath.."/config")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/cache",cfwpath.."/cache")
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/config")
fileCopy(cfwpath.."/config".."/main.conf",root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/config".."/main.conf")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bits/top.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bits/top.bin", cfwpath.."/bits/top.bin")
end
if System.doesFileExist(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bits/bottom.bin") then
System.renameFile(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/bits/bottom.bin", cfwpath.."/bits/bottom.bin")
end
System.createDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/chain")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/chain",cfwpath.."/chain")
if isnightly == 1 then
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/locale",cfwpath.."/locale")
System.renameDirectory(root..appinstallname.."-BACKUP-"..h..m..s..day_value..day..month..year.."/contrib",cfwpath.."/contrib")
end
System.deleteFile(downloadedzip)
if nightlyhash == 0 then
--updatehash()
end
end
debugWrite(0,120,"DONE! Press A to reboot, B to quit!", green, TOP_SCREEN)
updated = 1
end
--UI Screens
function head() -- Head of all screens
if headflip == 1 then
debugWrite(0,0,selfstring, white, TOP_SCREEN)
debugWrite(0,20,"==============================", red, TOP_SCREEN)
end
Screen.debugPrint(0,0,selfstring, white, TOP_SCREEN)
Screen.debugPrint(0,20,"==============================", red, TOP_SCREEN)
end
function errorscreen() --scr == 0
head()
Screen.debugPrint(0,40,"An error has occurred.", white, TOP_SCREEN)
Screen.debugPrint(0,60,"Please refer to the documentation.", white, TOP_SCREEN)
Screen.debugPrint(0,80,"Error code: "..consoleerror, red, TOP_SCREEN)
Screen.debugPrint(0,100,"Press A/B to quit.", white, TOP_SCREEN)
checkquit()
endquit()
end
function lowhead()
Screen.debugPrint(0,0,selfstring, white, BOTTOM_SCREEN)
end
function bottomscreen(no) -- if no = 1, the original, regular screen will show. If not, an error-screen will come up.
lowhead()
if no == 1 then
Screen.debugPrint(0,20,"Latest CFW: "..serverver, green, BOTTOM_SCREEN)
-- Screen.debugPrint(0,20,"Core Version: "..coreversionstring, white, BOTTOM_SCREEN)
Screen.debugPrint(0,40,"Author: gnmmarechal", white, BOTTOM_SCREEN)
Screen.debugPrint(0,60,"Special Thanks:", white, BOTTOM_SCREEN)
Screen.debugPrint(0,80,"Rinnegatamante (LPP-3DS/Help)", white, BOTTOM_SCREEN)
Screen.debugPrint(0,100,"Crystal the Glaceon (Testing)", white, BOTTOM_SCREEN)
Screen.debugPrint(0,120,"chaoskagami (Corbenik CFW)", white, BOTTOM_SCREEN)
-- Screen.debugPrint(0,160,"Portugal Euro 2016!!!!", red, BOTTOM_SCREEN)
-- Screen.debugPrint(0,180,"Portugal Euro 2016!!!!", yellow, BOTTOM_SCREEN)
-- Screen.debugPrint(0,200,"Portugal Euro 2016!!!!", green, BOTTOM_SCREEN)
--Screen.debugPrint(0,120,Sound.getService(), white, BOTTOM_SCREEN) -- Displays used audio-service
else
Screen.debugPrint(0,20,"Internet connection failed.", red, BOTTOM_SCREEN)
end
end
function firstscreen() -- scr == 1
head()
Screen.debugPrint(0,40,"Welcome to Corbenik CFW Updater!", white, TOP_SCREEN)
Screen.debugPrint(0,100,"Please select an option:", white, TOP_SCREEN)
Screen.debugPrint(0,120,"A) Clean Update (Recommended)", white, TOP_SCREEN)
Screen.debugPrint(0,140,"X) Dirty Update (Keep Config)", white, TOP_SCREEN)
if usenightly == 1 then
Screen.debugPrint(0,160,"Y) Nightly Update (Keep Config)", white, TOP_SCREEN)
end
Screen.debugPrint(0,180,"B) Quit", white, TOP_SCREEN)
inputscr(2, KEY_A)
inputscr(4, KEY_X)
inputscr(5, KEY_Y)
if debugmode == 1 then
inputscr(-2, KEY_L)
end
checkquit()
end
function installer() --scr == 2 / scr == 4
head()
debugWrite(0,40,"Started Installation...", white, TOP_SCREEN)
if newstructure == 1 then
installnewunixstructure()
else
installnew()
end
checkquit()
checkreboot()
checkrestart()
end
--Prints text
function debugWrite(x,y,text,color,display)
if updated == 1 or downloadcompleted == 1 then
Screen.debugPrint(x,y,text,color,display)
else
i = 0
while i < 2 do
Screen.refresh()
Screen.debugPrint(x,y,text,color,display)
Screen.waitVblankStart()
Screen.flip()
i = i + 1
end
end
end
--Main loop
--checkupdate()
runoncevars()
iswifion()
precheck()
servergetVars()
precleanup()
while true do
clear()
pad = Controls.read()
bottomscreen(iswifion())
if scr == 5 and usenightly == 1 then
serverzippath = servernightlyzippath
isnightly = 1
keepconfig = 1
--newstructure = 1 -- This will be used when a nighly supporting the new structure comes out. Till then, it won't work as it'll try to migrate data. --Now default for ALL Corbenik releases
installer()
end
if scr == 4 then
isnightly = 0
keepconfig = 1
installer()
end
if scr == 2 then
isnightly = 0
keepconfig = 0
installer()
end
if scr == 0 then
errorscreen()
end
if scr == 1 then
firstscreen()
end
if scr == -2 then
error("Debug Break")
end
if scr == -3 then
error("Program ended")
end
iswifion()
flip()
end