Backup scripts

Backup scripts

This script is a modification of Lukas Morawietz​​’s save script in his multi tool script.

But this one is made with the purpose of having a backup of all your scripts. It saves all your current scripts in a custom folder (in Lightning folder by default) deleting the previous backup (all the items in that folder take care). It asks for confirmation, but you can change that in case you want to do it programmatically (in the resumed event, from tasker…)

If you want a ‘export’ scripts feature, check Lukas’s script.

The settings are: the directory, to ask or not for confirmation, and to write extra data in the file to use with Lukas’s import script.

]]>

13 Commentsto Backup scripts

  1. Anonymous says:

    < ![CDATA[

    var directory=”LightningLauncher/Backup scripts”;//use the slash as folder separator



    var confirmation=false;//set to false to save without user interaction



    var extradata=true;//if true it will save the flags and the name of the script in the file. set to false for an exact copy of the script




    //binds


    LL.bindClass(“java.io.File”);


    LL.bindClass(“java.io.FileWriter”);


    LL.bindClass(“android.os.Environment”);



    if(confirmation&&!confirm(“Do you want to make a backup of the scripts?\n Old saved scripts will be overwritten, and deleted if they are not in the editor. Your current scripts won’t be modified”))return;



    directory=File.separator+directory.replace(/\//g,File.separator);//not necessary I guess, but just in case



    // Create a new directory


    var createDirectory = new File(Environment.getExternalStorageDirectory()+directory);


    createDirectory.mkdirs();





    //backup previous one, in case something goes wrong


    var files=createDirectory.listFiles();


    for(var i=files.length-1;i>=0;–i){


    var file=files[i];


    files[i]=new File(file.getAbsolutePath()+”.tmp”);


    file.renameTo(files[i]);


    }



    //get all scripts


    var scripts=LL.getAllScriptMatching(Script.FLAG_ALL);




    //save current scripts


    for(var t=scripts.getLength()-1;t>=0;–t){



    var script=scripts.getAt(t);




    // create a new file


    var createFile = new File(Environment.getExternalStorageDirectory()+directory+File.separator+script.getId()+” _ “+converttofile(script.getName())+”.js”);



    createFile.createNewFile();




    // create the content of the script


    var content=””;



    if(extradata)content+=”//Flags: “+


    (script.hasFlag(Script.FLAG_APP_MENU)?”app “:””)+


    (script.hasFlag(Script.FLAG_ITEM_MENU)?”item “:””)+


    (script.hasFlag(Script.FLAG_CUSTOM_MENU)?”custom “:””)+


    “\n”+


    “//Name: “+script.getName()+


    “\n”;


    content+=script.getText();



    //write to file


    var createFileWriter = new FileWriter(createFile, false);



    createFileWriter.write(content);



    createFileWriter.flush();


    createFileWriter.close();



    }



    // readme file


    var createFile = new File(Environment.getExternalStorageDirectory()+directory+File.separator+”[readme].txt”);



    createFile.createNewFile();



    // write to the file



    var createFileWriter = new FileWriter(createFile, false);



    createFileWriter.write(“This folder contains a backup of the scripts in the editor. Any file here will be deleted at the backup”);



    createFileWriter.flush();


    createFileWriter.close();




    //delete tmp files…perhaps I need to check before if nothing went wrong


    for(var i=files.length-1;i>=0;–i){


    files[i].delete();


    }




    Android.makeNewToast(“Saved “+scripts.getLength()+” scripts”, true).show();








    function converttofile(n){


    return n.replace(/[,./\:*?””<>|]/g,”_”);


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    Cool. However, without a restore option it doesn’t do anything other than my script? Besides you can change the folder easier with this.


    I use the export/import functionally as backup/restore and it works fine, why do another one? 

    ]]>

  3. Anonymous says:

    < ![CDATA[

    This can be executed directly, without user interaction, also it will make a ‘perfect backup’, if you deleted a script, it will be deleted (in fact all scripts are deleted and saved again).


    With your script, you need to select it from a list, and deleted/renamed scripts in the editor won’t be deleted in the folder.



    (Maybe I’ll add your ‘save flags’ feature, so it can be used by your script to import them)



    But the real reason I made this script is:


    I had the idea, and I made a basic script based on the ‘note editor’ or similar you helped (can’t remember the author now)


    When I had it working, I realize that code was based on your script, and then I realized I had this feature already available 😛


    I thought of sending my version to you, with the ability to change the folder and the name changer (if the name of the script have illegal characters it will make an error)


    Instead I just kept it myself, and now someone asked for it, I thought of publishing it.



    Of course you can modify your code with my changes :)

    ]]>

  4. Anonymous says:

    < ![CDATA[

    Lukas Morawietz​, I am testing with your import script, and it always says the file can’t be read (error 3)


    Do it work for you?

    ]]>

  5. Anonymous says:

    < ![CDATA[

    Yes, it works for me.


    You can try


    a) use another file manager to select the file (e.g. the Android default app (seems to be the gallery or sth similar) doesn’t work, it always returns null to lightning)


    b) if the file is on a sdcard, move it to internal storage


    c) I assume you did sth like that already: restart everything, check if the file is a plain text file, …

    ]]>

  6. Anonymous says:

    < ![CDATA[

    Lukas Morawietz arg, I didn’t remember the file manager of lollipop seems to return a different data.


    Thanks, it’s working now 🙂



    I edited the script with the ability to save the flags and the name. Maybe you want to edit your import script to get the name too (anyway it works with the flags 🙂

    ]]>

  7. Anonymous says:

    < ![CDATA[

    The Name is already restored, if the file is named like the script…

    ]]>

  8. Anonymous says:

    < ![CDATA[

    As I see it, a backup should contain also scripts not anymore in the editor… I think I’ll replace the rest with your code (when I have the time). 

    ]]>

  9. Anonymous says:

    < ![CDATA[

    Lukas Morawietz​ as I said, if the name contains illegal characters it makes an error when saving.


    That’s why I format the name removing those characters.


    Also, in case for some reason you have two scripts with the same name (improbable, but who knows) it attach the id at the beginning, so every file is unique.



    Oh, I want to mention. I’m saving the scripts as .js to be able to get syntax highlighting when opening from custom editor. Your importer don’t allow those files, only .txt


    Just to mention (I already changed text/ * with * / * )

    ]]>

  10. Anonymous says:

    < ![CDATA[

    If you want to Change the MIME type, use file/*


    But:


    text/* should allow any text file with any file extension, including .js

    ]]>

  11. Anonymous says:

    < ![CDATA[

    I have to confirm this. Seems to be an android bug. js files are not recognized

    ]]>

  12. Anonymous says:

    < ![CDATA[

    And file/ is also not working. Android seems to ignore standard mime type handling

    ]]>

  13. Anonymous says:

    < ![CDATA[

    Actually I figured out, that Android has no MIME type for js at all, so the only way is to use * / * (without spaces, f*ck that google syntax) then there should be probably another test if the file is a script file. 

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *