Location of a script question (version-detection)

degrassi

New member
I am finishing up a script that will automatically check for new versions of a script when it is run. If others may be interested in this, where would something like this live?

Is this the appropriate forum since it isn't particularly useful without some other script to work with?

Thanks

[edit]
To keep the downloadable script in the first post, I'm editing this with the script info.

In order to use this script, do the following steps:

Include the script in your file:
import <ver.ash>

Then, in your file, add two variables. One will designate the current version of the file
and the other will be what post number to look for on the kolmafia site.

For instance, in this script, the versions used look like:
string VER_VERSION = "1.0"; // version of the version script.
string VER_VERSION_PAGE = "1462";

The post number (1462, above) can be found by going to the post with the script on kolmafia.us
and looking at the URL. It should look something like:
http://kolmafia.us/index.php/topic,1462.0.html

Just take the number after "topic".

Then, to use the script, you'll do something like:

boolean current = check_version(VER_VERSION,VER_VERSION_PAGE);

if (!current)
{
print("A newer version of the ver.ash script is available.");
print("For current version go to: " + version_url(VER_VERSION_PAGE));
}

Replace VER_VERSION and VER_VERSION_PAGE with your appropriate variables, and then put
whatever message is appropriate for the version message.

Now, on the post with your script, be sure to add a line that looks something like:
[current version: 1.0]

You're done!

When you change the versions of your script, you'll need to do two things:

Change the version number inside your script (like the VER_VERSION in this script)
Edit the post with the new version to say "[current version: 1.1]" or whatever is appropriate.

Note: because the version numbers are all handled as strings, there's nothing stopping you from
more interesting build numbers like "[current version: 1.2b (the b is for balloon)]". Just be
sure to match it inside your script.
 

Attachments

  • ver.ash
    3.5 KB · Views: 73

degrassi

New member
I edited the above post to add the script with some usage details. It isn't heavily tested yet, but works OK on the couple of scripts I've played with. I'll test some more in the next day or two.
 
[quote author=degrassi link=topic=1462.msg6769#msg6769 date=1200959278]
Then, to use the script, you'll do something like:

boolean current = check_version(VER_VERSION,VER_VERSION_PAGE);

if (!current)
{
print("A newer version of the ver.ash script is available.");
print("For current version go to: " + version_url(VER_VERSION_PAGE));
}

[/quote]

Just an opinion, but I think that it would be more suitable to do this:

Code:
void main()
{	
if (!check_version(VER_VERSION,VER_VERSION_PAGE))
	{
        if( user_confirm( "A newer version of the ver.ash script is available. Update first?") )
                {
                 cli_execute("abort For current version go to: " + version_url(VER_VERSION_PAGE) );
                }
                else
                {
                 print("For current version go to: " + version_url(VER_VERSION_PAGE) );
                }
        }
//continue execution
}

This would give the user the chance to decide whether or not to update before the script is ran. This prompt I would put at the very beginning so if the user is the type to start the script then go get a bag of popcorn they wont be mad because the script waited on them and their session timed out.

By the way, I really like this idea, and may use it in the future in some of my scripts.
 

degrassi

New member
I simply did the version print() text as an example more than anything. In a real script, I think your idea is superior, and will snag it for any biggish scripts I put together and post.

I don't know that I'd want to interrupt a script if the versioning script itself was updated, but it's worth thinking about since it isn't something that's likely to update often.
 
[quote author=degrassi link=topic=1462.msg6787#msg6787 date=1201042317]
I simply did the version print() text as an example more than anything. In a real script, I think your idea is superior, and will snag it for any biggish scripts I put together and post.

I don't know that I'd want to interrupt a script if the versioning script itself was updated, but it's worth thinking about since it isn't something that's likely to update often.
[/quote]

Hmm, Well I just duplicated what you wrote, another "something like" sample pointing out the often forgotten user_confirm function in kolmafia which would seem quite useful in this situation, I do agree that I wouldn't want to stop a script if the versioning system were updated and not the primary script itself. On the other hand I know of a few scripts that get updated a lot, and the updates then to be important. Might even want to print the url before asking to update now so the user can look to see if the update is important or not. ???
 

degrassi

New member
I think you're right - the sample should be more like what someone would use (which user_confirm() is superior in most cases). I'll change it here soon.

Also, I'm toying with a way of importing a short "what changed" line into the versioning so that you could not only say that there was a version change, but pass onto the script a short description. Some sort of short "release note" or similar.

In thinking about what you wrote, I wonder if it would be useful to handle a user_confirm() wrapper in the version script itself that would remember what the user said. This way if someone said they wanted to continue without updating, they wouldn't be re-prompted until the version changed again. I don't think this would be terribly hard to implement, and would save users from having to go "nah, not this time" over and over again if they didn't care to update it yet.
 

zarqon

Well-known member
I don't say this often, but this script is hot. Great idea.

EDIT: I worked this into my Wossname script, it works great. Thanks for the code/idea!
 
That creates a new problem

I normally update if I have time, but if I don't I wont. If I am never prompted again, I never will update because I will forget. Other people are different, so who knows what the best plan for the individual might be? Adding another prompt asking if they want prompted again could be a solution, but then again, 2 prompts every time I run a script would be annoying so maybe only have the second prompt happen once? But maybe after the first time prompted, I looked at the page for the update, and decided I didn't want to update, but since I said to remind me....you know the rest

Some solutions just create new problems. This one will take some thought to decide which is the lessor of the evils.
 

macman104

Member
Chekc every week if they decline the first time, and use a property to determien when to ask them next? If the property doesnt' exist, prompt them?
 
Top