kOS-scripts/boot/default.ks
2019-02-08 18:45:13 +01:00

58 lines
1.7 KiB
Plaintext

@LAZYGLOBAL OFF.
clearscreen.
clearguis().
clearvecdraws().
set TERMINAL:width to 50.
set TERMINAL:height to 30.
CORE:doaction("Open Terminal", true).
print "==================== BOOTING =====================".
wait until SHIP:loaded and SHIP:unpacked.
wait 0.001. // wait one physics tick
if HOMECONNECTION:isconnected {
copy_scripts().
} else {
print "No connection to KSC: not updating scripts.".
}
print "============= BOOT SEQUENCE COMPLETE =============".
function copy_scripts {
//
// Copy all .ks-files from the archive to the CPU's internal storage.
//
parameter archive_dir is ARCHIVE:files.
for item in archive_dir:values {
function iteration { // allows for quick-bailing using 'return' (kOS doesn't have the 'continue' keyword
local item_path is "/" + path(item):segments:join("/"). // full path of item without volume id
if item:name[0] = "." // skip Linux hidden files and directories (e.g. .git)
return.
// Recurse on directories
if not item:isfile {
copy_scripts(item:list).
return.
}
if item:extension <> "ks" // skip non-script items (e.g. README.md)
return.
if CORE:volume:exists(item_path) and item:size = CORE:volume:open(item_path):size // skip if file exists locally with the same size
return.
print "Copying " + item_path.
copypath(item, path(CORE:volume):combine(item_path)).
if item_path = CORE:bootfilename {
print "Rebooting to apply new bootfile".
wait 2.
reboot.
}
}
iteration().
}
}