Shoutbox

[suggestion] Remove all files before import option in ScriptInfo.xml - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [suggestion] Remove all files before import option in ScriptInfo.xml (/showthread.php?tid=83009)

[suggestion] Remove all files before import option in ScriptInfo.xml by roflmao456 on 04-07-2008 at 03:34 AM

right now i have a script that installs into the same folder.

i recoded the script and changed the JS file names..
when someone that has a lower version of the script imports the new version, the older version's files are still there and they conflict with each other (using same functions, etc)

i'm wondering if there could be an extra option in the ScriptInfo.xml such as <RemoveFiles> instead of

quote:
Originally posted by MeEtc
just put in an empty file with same name


you can see what i mean if you install WLMini Music Player 2.1.7a and then the beta after.
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by -dt- on 04-07-2008 at 04:20 AM

quote:
Originally posted by roflmao456
right now i have a script that installs into the same folder.

i recoded the script and changed the JS file names..
when someone that has a lower version of the script imports the new version, the older version's files are still there and they conflict with each other (using same functions, etc)

i'm wondering if there could be an extra option in the ScriptInfo.xml such as <RemoveFiles> instead of
quote:
Originally posted by MeEtc
just put in an empty file with same name


you can see what i mean if you install WLMini Music Player 2.1.7a and then the beta after.


Music Now playing does

code:
    //uninstalls the old players 
    var OldFiles = [
        "iTunesClass.js",
        "WinampClass.js",
        "wmpClass.js",
        "jetAudioClass.js",
        "players\\MusicMonkey.player.js",
        "showConfig.txt"
    ];
   
   
    for(file in OldFiles){
        var name = MsgPlus.ScriptFilesPath + "\\" + OldFiles[file];
        if(fso.FileExists(name)){ fso.GetFile(name).Delete(true);}
    }


to delete old files

currently it does that on every OnEvent_Initialize though :( *wishes there was a onimport event*
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by markee on 04-07-2008 at 11:18 AM

quote:
Originally posted by -dt-
currently it does that on every OnEvent_Initialize though (Smilie) *wishes there was a onimport event*


quote:
Originally posted by scripting documentation
MessengerStart
[boolean] Specifies the reason for the event to occur. If this parameter is true, the event was generated during the startup of Messenger. If it is false, the event was generated after the script was imported, enabled, or restarted.

That would at least cut it down to when the script is initialised while messenger is running... 8-)
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by -dt- on 04-07-2008 at 11:29 AM

quote:
Originally posted by markee
quote:
Originally posted by -dt-
currently it does that on every OnEvent_Initialize though (Smilie) *wishes there was a onimport event*


quote:
Originally posted by scripting documentation
MessengerStart
[boolean] Specifies the reason for the event to occur. If this parameter is true, the event was generated during the startup of Messenger. If it is false, the event was generated after the script was imported, enabled, or restarted.

That would at least cut it down to when the script is initialised while messenger is running... 8-)
but what happens if the script is imported :/ MessengerStart wouldnt be true then since messenger has already started
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by markee on 04-07-2008 at 11:35 AM

code:
if(!MessengerStart){

//code that first only on an import as messenger has already been started
//it is possible to import a script without being logged in, but who really does that?

}

EDIT: You could also just check if the first one exists, if it does thn it will cycle through the rest (unless they relate to different versions, and then you need one from each version).
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by roflmao456 on 04-08-2008 at 02:11 AM

the code that -dt- posted doesn't unload the file unfortunately.

plus the files are loaded in alphabetical order so errors might come first and stop/intercept the script


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by Spunky on 04-08-2008 at 11:30 AM

Maybe an option to put in xml which files are to be replaced with what or deleted etc...


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by roflmao456 on 04-08-2008 at 12:44 PM

quote:
Originally posted by SpunkyLoveMuff
Maybe an option to put in xml which files are to be replaced with what or deleted etc...
(Y)
maybe something like
code:
<ScriptInfo>
<Information>
<Description>lol.</Description>
<Version>1</Version>
<Name>testscript</Name>
</Information>
<Import>
<RemoveFile>blah.js</RemoveFile>
<RemoveFile>lol.js</RemoveFile>
</Import>

</ScriptInfo>


or
code:
<ScriptInfo>
<Information>
<Description>lol.</Description>
<Version>1</Version>
<Name>testscript</Name>
</Information>
<Import>
<RemoveScript>testscript</RemoveScript>
</Import>

</ScriptInfo>


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by mynetx on 04-08-2008 at 03:46 PM

WLMStatus did change some file names as well from 1.1.7 to 1.1.8. In fact, I'm using a combined solution:
For JS files, the new plsc pack contains the files to be deleted, but with blank content (empty files). This causes the old JS code not to be run upon initialize, but there are still the empty JS files. Then the code does contain a list of obsolete files which are deleted in a Cleanup helper function.


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by L. Coyote on 04-08-2008 at 06:46 PM

I suggested this months ago, and since I don't think it got a good response (I can't really remember), I made my own extra script for that.

Basically, I remove all files and sub-folders that are not in two lists (one for files another for folders), plus I use a "lock" file for Polygamy compatibility.

The problem with the XML file, which I can now see, is that you have to think of all version upgrades. If you changed files in version 1.0, then in version 2.0 and finally settled for another file in version 3.0, you have to make sure the commands in the XML file don't mess different upgrades.

Instead of setting a "RemoveFile", I think the idea is to have a flag tag like "RemoveNonListed" (or some similar name, to express that the engine must remove all files that are not listed in the package being imported). That way, you don't have to write down each filename, you won't miss one and you won't misspell one.


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by mynetx on 04-08-2008 at 10:15 PM

Thanks for that idea, indeed it's a good one. As long as the list is able to be extended on runtime, in case that a script (such as WLMStatus) stores runtime config files or temp files in the script folder...


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by felipEx on 04-08-2008 at 10:49 PM

maybe Patchou have to delete all js files (*.js) or rename them (as .txt for example) before importing the new ones, that could be easier :P


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by markee on 04-09-2008 at 09:03 AM

I think a solution like mynetx made is best as a temporary fix, include blank .js files, delete them and also the .js file that deletes them also gets removed (this can be made through a try/catch statement globally so that initialize doesn't look for a non-existant function in the future).

As for deleting files, well I think we need to be able to make lists of some kind.  My scripts (like many others) need to keep text files and xml files, however some other xml files or text files should be updated/removed.  The same thing goes for folders.

Maybe a better solution would be something like the following...

code:
<ScriptInfo>
<Information>
<Description>lol.</Description>
<Version>1</Version>
<Name>testscript</Name>
</Information>
<Import>
    <RemoveFolder>folder1\subfolder</RemoveFolder> <!-- Removes the folder "subfolder" -->
    <RemoveFile>folder2\*.png</RemoveFile> <!-- Removes all .PNG files from folder1 -->
    <RemoveFile>old_ui.xml</RemoveFile> <!-- Removes the file "old_ui.xml" from the script's root directory -->
    <RemoveFolder>folder*\*< RemoveFolder> <!-- Removes all subfolders in "folder1" and "folder2" and any other folder that starts with "folder" -->
</Import>
</ScriptInfo>

If I was asking for a lot then I would want regex compatibility, but * as a wildcard is good enough i guess....
RE: [suggestion] Remove all files before import option in ScriptInfo.xml by Matti on 04-09-2008 at 01:31 PM

I have to agree here.

I had an awful hard time to make such system for Countdown Live 2.0, since the script structure completely changed. Removing files in the Images folder is very easy, but script files are lots harder. Even with the actions taken, a script restart is still required in order to unload the obsolete script files. Luckily this should only be done once. :P

Patchou really needs to implement something so we can control what should be removed. :)
* Matti thinks this thread should be in the Scripts forum rather than the General Talk... 8-)


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by roflmao456 on 07-23-2010 at 07:00 PM

*revives my old thread*
Perhaps this should be in Plus! 5? :P


RE: [suggestion] Remove all files before import option in ScriptInfo.xml by whiz on 07-23-2010 at 07:32 PM

My workaround is a list of files that should be there, and then everything else is removed.

But having a proper way of specifying obsolete files would be great for Plus! 5.


RE: RE: [suggestion] Remove all files before import option in ScriptInfo.xml by CookieRevised on 07-26-2010 at 08:17 AM

quote:
Originally posted by L. Coyote
I suggested this months ago, and since I don't think it got a good response (I can't really remember), I made my own extra script for that.
It has in fact been suggested years ago, and again when the new update system was created.

The response back then, IIRC, was something in the line of "you're not supposed to change your script file names, so choose the file names wisely".


* CookieRevised slaps himself for not reading the posting date....


-------

quote:
Originally posted by L. Coyote
Instead of setting a "RemoveFile", I think the idea is to have a flag tag like "RemoveNonListed" (or some similar name, to express that the engine must remove all files that are not listed in the package being imported). That way, you don't have to write down each filename, you won't miss one and you won't misspell one.
quote:
Originally posted by whiz
My workaround is a list of files that should be there, and then everything else is removed.

Which will also delete any user generated file, (or script generated file), which is a major big no-no.... That would be a realy bad choice imo. I don't want any script to remove any files I have put in the scripting directory (like comment files, backups, a link to the thread, the actual plsc, etc).

A "RemoveFile" is far safer and better than "RemoveNonListed".

Also, I'm personaly not a fan of using wildcards, like markee suggested, in the "RemoveFile" attribute, for the same reasons above.

If you want to remove files you, as the script creater, knows what exact files were created/needed by the previous version. So no need for wildcards. Yes, it makes the "RemoveFile" list a bit longer, but it is far more safer and the user will not accidently loose any files because the script developper thinks he needed to remove all the existing files with <RemoveFile>*</RemoveFile>.

;)

---------------

PS: in fact, I have no trouble manually deleting script files from scripts which are currently running though. The only thing you need to look out for when doing it manually is that the scripting editor isn't opened with the script you want to delete files from (goes only for JS files).

You can include the files you want to remove as null files (0 bytes long), and in the initialization of the script remove them (if they exist).
This even works when the scripting editor is opened (as long as you press "ok" to let Plus! close and re-open Messenger).