|
@@ -15,10 +15,14 @@
|
|
|
|
|
|
|
|
// simple test to see if the file exits or not
|
|
// simple test to see if the file exits or not
|
|
|
function FileExists(filename){
|
|
function FileExists(filename){
|
|
|
- local fd = file(filename, "r");
|
|
|
|
|
- if (fd == null) return false;
|
|
|
|
|
- fd.close(file);
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ local fd = file(filename, "r");
|
|
|
|
|
+ fd.close();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ catch(e){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////-
|
|
//////////////////////////////////////////////////////////////////////////////-
|
|
@@ -40,15 +44,15 @@ function main(){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
local in_squiluFreeze = vargv[0];
|
|
local in_squiluFreeze = vargv[0];
|
|
|
- local in_luafltkscript = vargv[1];
|
|
|
|
|
|
|
+ local in_squiluScript = vargv[1];
|
|
|
local out_squiluFreeze = vargv[2];
|
|
local out_squiluFreeze = vargv[2];
|
|
|
|
|
|
|
|
if (!FileExists(in_squiluFreeze)) {
|
|
if (!FileExists(in_squiluFreeze)) {
|
|
|
printf("Input squiluFreeze program '%s' does not exist! Aborting.\n", in_squiluFreeze);
|
|
printf("Input squiluFreeze program '%s' does not exist! Aborting.\n", in_squiluFreeze);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (!FileExists(in_luafltkscript)){
|
|
|
|
|
- printf("Input luafltk script '%s' does not exist! Aborting.\n", in_luafltkscript);
|
|
|
|
|
|
|
+ if (!FileExists(in_squiluScript)){
|
|
|
|
|
+ printf("Input luafltk script '%s' does not exist! Aborting.\n", in_squiluScript);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
if (FileExists(out_squiluFreeze)){
|
|
if (FileExists(out_squiluFreeze)){
|
|
@@ -56,7 +60,7 @@ function main(){
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
printf("Appending '%s' to squiluFreeze program '%s' and outputting to '%s'\n",
|
|
printf("Appending '%s' to squiluFreeze program '%s' and outputting to '%s'\n",
|
|
|
- in_luafltkscript, in_squiluFreeze, out_squiluFreeze);
|
|
|
|
|
|
|
+ in_squiluScript, in_squiluFreeze, out_squiluFreeze);
|
|
|
|
|
|
|
|
// read the whole squiluFreeze program into memory
|
|
// read the whole squiluFreeze program into memory
|
|
|
local in_squiluFreeze_handle = file(in_squiluFreeze, "rb");
|
|
local in_squiluFreeze_handle = file(in_squiluFreeze, "rb");
|
|
@@ -65,23 +69,28 @@ function main(){
|
|
|
in_squiluFreeze_handle.close();
|
|
in_squiluFreeze_handle.close();
|
|
|
|
|
|
|
|
// check to see if they're trying to append another script to squiluFreeze
|
|
// check to see if they're trying to append another script to squiluFreeze
|
|
|
- if (in_squiluFreeze_data.sub(in_squiluFreeze_length-21, in_squiluFreeze_length-10) == "squiluFreeze:"){
|
|
|
|
|
|
|
+ if (in_squiluFreeze_data.slice(in_squiluFreeze_length-21, in_squiluFreeze_length-10) == "squiluFreeze:"){
|
|
|
printf("Input squiluFreeze program '%s' already has a squilu script attached! Aborting.\n", in_squiluFreeze);
|
|
printf("Input squiluFreeze program '%s' already has a squilu script attached! Aborting.\n", in_squiluFreeze);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// read the whole luafltk script into memory
|
|
// read the whole luafltk script into memory
|
|
|
- local in_luafltkscript_handle = file(in_luafltkscript, "rb")
|
|
|
|
|
- local in_luafltkscript_length = in_luafltkscript_handle.len();
|
|
|
|
|
- local in_luafltkscript_data = in_luafltkscript_handle.read(in_luafltkscript_length);
|
|
|
|
|
- in_luafltkscript_handle.close()
|
|
|
|
|
|
|
+ local in_squiluScript_handle = file(in_squiluScript, "rb")
|
|
|
|
|
+ local in_squiluScript_length = in_squiluScript_handle.len();
|
|
|
|
|
+ local in_squiluScript_data = in_squiluScript_handle.read(in_squiluScript_length);
|
|
|
|
|
+ in_squiluScript_handle.close()
|
|
|
|
|
+
|
|
|
|
|
+ local zipedScript = zlib.deflate(in_squiluScript_data);
|
|
|
|
|
+ print("zipedScript", in_squiluScript_length, zipedScript.len());
|
|
|
|
|
+ in_squiluScript_length = zipedScript.len();
|
|
|
|
|
+ in_squiluScript_data = zipedScript;
|
|
|
|
|
|
|
|
// write the output file and our tag at the end
|
|
// write the output file and our tag at the end
|
|
|
local out_squiluFreeze_handle = file(out_squiluFreeze, "wb+");
|
|
local out_squiluFreeze_handle = file(out_squiluFreeze, "wb+");
|
|
|
out_squiluFreeze_handle.write(in_squiluFreeze_data);
|
|
out_squiluFreeze_handle.write(in_squiluFreeze_data);
|
|
|
- out_squiluFreeze_handle.write(in_luafltkscript_data);
|
|
|
|
|
|
|
+ out_squiluFreeze_handle.write(in_squiluScript_data);
|
|
|
// 2^32 = 4294967296, should be enough? Our data is 29 bytes from end.
|
|
// 2^32 = 4294967296, should be enough? Our data is 29 bytes from end.
|
|
|
- out_squiluFreeze_handle.write(format("<DAD:%010d>ooOo(^.^)oOoo", in_luafltkscript_length));
|
|
|
|
|
|
|
+ out_squiluFreeze_handle.write(format("<DAD:%010d>ooOo(^.^)oOoo", in_squiluScript_length));
|
|
|
out_squiluFreeze_handle.close();
|
|
out_squiluFreeze_handle.close();
|
|
|
}
|
|
}
|
|
|
|
|
|