common-jacky

Discuss and share scripts and script files...
Post Reply
jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

common-jacky

Post by jacky »

UPDATE: Latest info on February 9, 2009 :

:arrow: The latest version of the script is 0.01.0006 and can be downloaded from here. Requires XY 7.90.0075
common-jacky.xys
v0.01.0007
(46.1 KiB) Downloaded 237 times
:arrow: _ShowHTML: when specified, $CJ_height was set actually to $CJ_width, fixed.

:arrow: _ShowHTML: when a form is auto-added (because $CJ_convert_vars==1 or $CJ_unrar_html==1) then besides the action (xys:$XYS_name) now the id is also set (cj_form)

:arrow: _ShowHTML: added $CJ_form_extra to add other stuff to form id="cj_form" (e.g. JS events, ...)

:arrow: _ShowHTML: added $CJ_js to add javascript code. When not empty, a block <script> is added, so the JS code must be set directly in $CJ_js
Additionally, a few functions are also added:
- scrollToId(id) : scroll to element of specified id
- hasClass(id,class) : returns true/false whether element of specified id has specified class or not
- addClass(id,class) : adds specified class to element of specified id (if not there already)
- removeClass(id,class) : removes specified class from element of specified id
- removeElement(id) : removes element of specified id (from page)
- addInput(name, value) : adds to element(/form) id="cj_form" a new input type=hidden with specified name/value
To simply add those (without extra JS code), simply do something like $CJ_js = '//'; (cause it's still JS code!)

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

UPDATE: Latest info on January 18, 2009 :

:arrow: The latest version of the script is 0.01.0004 and can be downloaded from here. Requires XY 7.90.0030

:arrow: _makeRelative: when $CJ_is_folder==1 and the path couldn't be made relative, it would be returned with an added/trailing "\", fixed

:arrow: _ShowHTML: when $CJ_css_buttons==1 the div #buttons could hide the end of the content of the page, fixed.

:arrow: added _getDateFromNumber and _getNumberFromDate to work with dates

:arrow: Minor changes to avoid recursion warnings better

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

:arrow: The latest version of the script is 0.01.0002 and can be downloaded from here. Requires XY 7.90.0030

Okay, so this isn't really a script per-se in that it cannot do anything on its own, as I've mentioned before it's more of a "library" I use for scripts I might be needing/using in various other scripts, you know those that do stuff ;)

Of course it's not ideal to do such a thing when we don't have user-functions - also I'm not a programmer so don't expect anything too big please ;) - but I couldn't wait as I was already copy/pasting the same stuff in many different scripts and that was worse to maintain. I'll try to describe what this script can do used for and how it works, but feel free to ask anything you want or report any bugs you find, as I'm sure I left some in there. (And for people familiar with Office Space, I'm not entirely sure I didn't mess up one of those "Monday detail" 8))

Okay so before anything, all the scripts in here assume/require the two following global variables to be defined :
- $XYS_name must be the "public/display" name for the script, used in messages and stuff
- $XYS_file must be the path/file of the calling script file, so you'll get that by doing a simple: self $XYS_file, file;

:arrow: Misc Stuff

Code: Select all

_makeRelative
This is to convert a path/name into relative form. Obviously can be used based on <xypath> to get a path usable through XY's relative path support, but you can also define the reference path to any other path, should you want to.
Before:
$CJ_path must be the full path/name of an item
$CJ_is_folder must be set to 1 when $CJ_path is a folder (to get ".." instead of "..\..\Program Files")
$CJ_ref_path will be the reference path, defaults to <xypath> if empty/unset

After:
$CJ_path will be the "new" path, converted to relative syntax if possible

Code: Select all

_makeUnrelative
This does just the opposite, take a relative path, the reference path, and make it back to a full path
Before:
$CJ_path : the relative path to an item
$CJ_ref_path : the reference path, defaults to <xypath> if empty/unset

After:
$CJ_path : the "new" full path

:arrow: Show self-changelog
This is just a couple of scripts to do the exact same thing: show the changelog of the calling script. How does it work? It will read the file and show the "changelog" which must be the first thing in the XYS file, as a multi-line comments. Also it will try to get the version number of the script, from the Internal INI section, more about that below on the XYAU part...

Code: Select all

_AutoChangelog
Will be shown in a simple text-window. In lines beginning with 2 tabulations the 2 tabs will be replaced by 2 blanks; then in lines beginning with one tabulation it'll be removed, and all occurences of the script's name (i.e. $XYS_name) will be replaced by "Changelog of $XYS_name v$ver" (where $ver is the Internal version number)

Code: Select all

_AutoChangelogHTML
Same but in an HTML window. One more "requirement" would be that the first line includes the script's name ($XYS_name) and nothing else, to make a nice title...

:arrow: XYplorer Automatic Updater integration
As I said before and recently demonstrated by Pagat, XYAU can be used to check for updates an any script, pretty much. To do so you'll need to have an INI section [Internal] in your script file, with the following:
version : the version number of the script, xx.xx.xxxx
Url : "root" of the URLs used to get updates. Will be used with "$XYS_name.txt" for versions info, "$XYS_name.xys" for the latest (beta) script file, and "$XYS_name.official.xys" for the latest (official) script file

The TXT must returned a few version numbers and nothing else: "a.aa.aaaa-b.bb.bbbb-c.cc.cccc-d.dd.dddd" (no quotes, obviously)
aaaa is the required XY version for the script in its latest version working with the last official version of XY
bbbb is the last version of the script working with the latest official XY, and can be downloaded as $XYS_name.official.xys
cccc is the required XY version for the latest version of the script (can be a BETA version of XY)
dddd is the last version of the script, and can be downloaded as $XYS_name.xys

I know not everyone can set up such a thing, or that it can be a PITA to maintain, but that's also why I have this idea for a "scripts library" I'm working on, it's not quite done yet, but hopefully it will be some day ;) and it will then take care of all that automatically :D

Code: Select all

_CheckForAutoUpdates
Launch XYAU to check for updates of the calling script

Code: Select all

_InstallInXYAU
Install support of the calling script inside XYAU. If already installed, asks whether to remove it.

Code: Select all

_getXyauState
Returns the current state of integration of the calling script in XYAU, to be shown on some About box or something...
After:
$CJ_tmp : contains the text ready to be shown indicating whether or not support in XYAU is installed, and if so whether or not there's auto-check for updates enabled

:arrow: Common Settings
Yeah, another silly idea of mine, but since I have a few script requiring to unrar/unzip files, I got tired of having to define for each of them how to do so. So I thought maybe those settings could be saved inside a "shared" INI file(say common-jacky.ini) and define once for all scripts. Of course, each script can still define its own specific settings in its own INI, and if it works it can all be done through CJ :)

Note: Yeah, I called it unrar even though it's meant to do both unzip & unrar, please don't ask :)

The idea is: it will look for 2 settings (actually 3, more on that just right after) : unrar (path/name.exe) and args (command-line arguments) First inside the calling script's INI file, that is the script file ($XYS_file) but with .ini instead of .xys obviously. In other words, in your script file it should be "$base.ini" with a self $base, base;
If both are found, we're done. If one is missing (or both) CK will look inside its own INI file. Meaning you can have the unrar in CJ.ini, but the arguments in your own INI. Also means you can have unrar & arguments in CJ.ini for most scripts, but some would have their own different args in their own INI (e.g. with overwriting enabled, which you don't want shared).
Lastly, CJ comes with a few "presets" so people can just chose in a list instead of having to know what arguments to use. ATM they are stored inside CJ itself, I thought about using CJ.ini but that wasn't good, so I just did that instead. A better choice might have been another INI file (e.g. presents.ini or something), maybe that should be changed later on... not sure yet?

Settings are saved in the script's INI under [CommonJacky] or shared in CJ's INI under [CommonSettings] and are :
- UnRAR : path to unrar.exe (might be relative syntax to <xypath> or use "?:\" syntax, in the later case it will be returned converted unless $CJ_unrar_norelative is enabled
- UnRAR_Use : what preset to use, or 99 for manual (this one is never returned, it's internal business)
- UnRAR_Args : the manual arguments (it should include placeholders %zip% for file, and %dest% for destination, and be quoted in the args, i.e. replaced by non-quoted strings)

I hope I'm clear, if not maybe you'll make sense of it anyways, or just ask away and I'll try to explain it better.

Code: Select all

_getUnrarSettings
Call it to load settings to use to extract ZIP/RAR files
Before:
$CJ_unrar_norelative : Set it to 1 to disable auto-conversion of "?:\" in $CJ_unrar

After:
$CJ_unrar : path/name to use to launch the app (can be relative syntax, "?:\" already converted to running drive (in <xypath>) unless asked otherwise with $CJ_unrar_norelative
$CJ_unrar_args : the arguments for the command-line (%zip% for the ZIP/RAR file, %dest% for the destination folder)

Code: Select all

_setUnrarSettings
Wall it to show an HTML window asking user to define the settings to use to extract ZIP/RAR files for calling script. That can also be done embedded in your own configuration window if you use CJ's _ShowHTML -- see below

Code: Select all

_saveUnrarSettings
This one should only be called when doing the embedded with _ShowHTML, and be called when the user pressed the "Ok/Save" button, so that the new settings are saved (!)

:arrow: HTML stuff
I'm sure there are unlimited genius stuff that can be made with the html() function, and when I first thought of how I could use it myself, I came up with this to take car of some common task. Note that depending what you're trying/willing to do, this might not suit you.

Code: Select all

_ShowHTML
Shows an HTML page, adding CSS stuff to look nice, and possibly turning all resulting values into global vars automatically...
Before:
$CJ_html : the HTML code to be shown on the page, don't need to bother with <html> stuff and whatnot, will be added automatically. Start directly with your content instead.
$CJ_css : any extra CSS to be added inside the <style> tag if you want to
$CJ_title : title of the HTML window (defaults to $XYS_name)
$CJ_width : width of window (defaults to 725)
$CJ_height : height of window (defaults to 500)
$CJ_scroll_id : the id of the element to scroll to on page load, useful after a refresh for instance
$CJ_css_buttons : set to 1 to add CSS for a <div id="buttons"> that will be always visible at the bottom of the screen. IE doesn't like "position: fixed" but this should work fine in IE, and I wanted to have my Ok/Cancel buttons visible all the time on my "config window", looks much better that way I feel. (PS: like the auto scroll thing, it will require javascript, but it should always be enabled I guess since were on a local "page"...)

$CJ_form_extra : when a form is added ($CJ_convert_vars==1 || $CJ_unrar_html==1) both action (xys:$XYS_name) and id (cj_form) are set. Use this variable to add other stuff - e.g. onSubmit="submitting();"

$CJ_js : additional javascript code to be included, no need to use <script> tags. If not empty, then a few javascript functions are added:
- scrollToId(id) : scroll to element of specified id
- hasClass(id,class) : returns true/false whether element of specified id has specified class or not
- addClass(id,class) : adds specified class to element of specified id (if not there already)
- removeClass(id,class) : removes specified class from element of specified id
- removeElement(id) : removes element of specified id (from page)
- addInput(name, value) : adds to element(/form) id="cj_form" a new input type=hidden with specified name/value

$CJ_convert_vars : set to 1 to see content put inside a <form> and every results (from input field) sent be put into global vars $CJ_HTML_xxxx So for instance an <input type=text name=foobar> will have the text typed set into $CJ_HTML_foobar

$CJ_unrar_html : set to 1 to have the string %CJ_UNRAR_HTML% replaced in $CJ_html by the code to take care of the common unrar settings (using <h3> titles for app & args) -- When done, it means CJ_html will be put inside a <form> (like when $CJ_convert_vars is enabled) and CJ will add and take care of some new settings/input values on the form. If $CJ_convert_vars is enabled, those will NOT be turned into global vars. They will also be stripped from $CJ_html
Also, the calling script needs to:
- call _saveUnrarSettings to have the settings saved when "Ok/Save" was pressed, otherwise they're lost/not applied
- check for $CJ_unrar_reload and if it was been set to 1 simply reload the HTML page (with entered values), as it means an button was clicked (e.g. Browse to unrar.exe) and while CJ took care of its action (and set $CJ_scroll_id, see below), the page still needs to be "refreshed" now.

After:
$CJ_html : what the html function returned (untouched, unless $CJ_unrar_html is enabled, then unrar stuff are removed)
$CJ_unrar_reload : when set to 1 the calling scripts needs to "refresh" the page, as described above
$CJ_scroll_id : when "refreshing" ($CJ_unrar_reload==1) this is set to the id to get back in the page where the user clicked -- leave as is to auto-scroll back, or overwrite/unset to change/disable as you wish
$CJ_HTML_xxxx : the vars from the form values when $CJ_convert_vars is enabled

:arrow: Dates

Code: Select all

_getNumberFromDate
Will convert a date into a number (of days), thus allowing to add/remove days to/from a date

Before:
$CJ_date must be the date, format dd-mm-yyyy (separator doesn't matter actually, so dd/mm.yyyy is fine too)

After:
$CJ_day_number will be the day number for the given date

Code: Select all

_getDateFromNumber
Will convert a "day number" into the corresponding date

Before:
$CJ_day_number must be the day number to get the date of

After:
$CJ_date will be the date, formatted dd-mm-yyyy

:arrow: Template

Yeah, so here's a little template I'd use to create a new script, which includes the changelog-comment, the Internal INI section and an example of how to use/launch scripts in common-jacky... Also there's some _ensureXY script, which is just something I use to make sure the running XY is compatible with the script, and it uses the Internal section to know which XY is needed (requiredXY), much like the _callCommonJacky uses requiredCJ to ensure that the required version of common-jacky.xys is installed...

You don't have to use all that of course, it's just an example! ;)

Code: Select all

/*	ScriptName
	
	v0.01.0000	yyyy.mm.dd	XY v7.80.0032
		+ first release
*/
"&Do something... : DoSomething"
	sub _ensureXY;
	msg "This should probably do something...";
-
-
" [ ScriptName ]"
-
"_ensureXY"
	global $XYS_name, $XYS_file;
	self $XYS_file, file;
	getkey $XYS_name, "name", "Internal", $XYS_file;
	getkey $xyreq, "requiredXY", "Internal", $XYS_file;
	end (compare(<xyver>, $xyreq, v) >= 0),,1;
	msg "WARNING: This version of $XYS_name requires XYplorer v$xyreq in order to work properly.<br><br>You are currently running an older version (<xyver>), are you sure you want to continue anyway ?<br><br>Note that this might lead to errors / unexpected results.", 1;
"&About ScriptName : About"
	global $XYS_name, $CJ_tmp;
	sub _ensureXY;
	self $file, file;
	self $path, path;
	self $base, base;
	getkey $curver, "version", "Internal", $file;
	getkey $xyreq, "requiredXY", "Internal", $file;
	status "$XYS_name: version $curver";
	//
	$CJ_tmp = "_getXyauState";
	sub _callCommonJacky;
	$CJ_tmp = ($CJ_tmp == "_getXyauState") ? "Unable to get XYplorer Automatic Updater integration state -- requires common-jacky.xys" : $CJ_tmp;
	//
	msg "$XYS_name -- version $curver<br>Requires XYplorer $xyreq (Running: <xyver>)<br><br>This script: $file<br>Configuration: $path\$base.ini<br><br>$CJ_tmp";
	load *;
"Change&log of ScriptName : _AutoChangelog"
	global $CJ_tmp;
	sub _ensureXY;
	$CJ_tmp = "_AutoChangelogHTML";
	sub _callCommonJacky;
	load *;
"&Edit Configuration File... : _EditINI"
	sub _ensureXY;
	self $path, path;
	self $base, base;
	open "$path\$base.ini";
"- : _sep"
"Chec&k for updates of ScriptName... : _CheckForAutoUpdates"
	global $CJ_tmp;
	sub _ensureXY;
	$CJ_tmp = "_CheckForAutoUpdates";
	sub _callCommonJacky;
	load *;
"&Install ScriptName support in XYplorer Automatic Updater... : _InstallInXYAU"
	global $CJ_tmp;
	sub _ensureXY;
	$CJ_tmp = "_InstallInXYAU";
	sub _callCommonJacky;
	load *;
"_callCommonJacky"
	global $CJ_tmp;
	self $file, file;
	self $path, path;
	getkey $cj_req, "requiredCJ", "Internal", $file;
	getkey $cj_ver, "version", "Internal", "common-jacky.xys";
	end $cj_ver == "", ($CJ_tmp == '_getXyauState') ? '' : "In order to accomplish the desired operation, you need to have the ""library"" common-jacky.xys installed -- Please download the script file and put it in the same folder as this script file ($path\).", 1;
	end (compare($cj_ver, $cj_req, v) == -1), "In order to accomplish the desired operation, you need to have the ""library"" common-jacky.xys v$cj_req or more installed, your current version is v$cj_ver -- Please update to the latest version.", 1;
	load "common-jacky", "$CJ_tmp";
-
"Show &Full Menu... : ShowFullMenu"
	load *,*;
"Show Standard &Menu... : _ShowMenu"
	load *;
-
"Cancel : nothing"
"_nothing"
"_settings"
	[Internal]
	name="ScriptName"
	version="0.01.0000"
	requiredXY="7.80.0032"
	requiredCJ="0.01.0004"
	CJoptional=1
	Url="http://88.191.26.34/XYscripts/download/"
:arrow: That's all, folks!

Yep, that's it. Any questions/comments/ideas are welcome of course, and feel free to have a look inside my own scripts to see how it works if that above wasn't clear (enough) (and you find my code to be clearer).

Have fun!
Last edited by jacky on 26 Sep 2010 19:31, edited 3 times in total.
Proud XYplorer Fanatic

Pagat
Posts: 306
Joined: 09 Oct 2007 21:23
Location: Austria

Re: common-jacky

Post by Pagat »

woa! common-jacky is evolving pretty fast and pretty good! Well done :)

I have to check if i can use some of your new stuff for my QuickGoTo script. Thanks for that great work!

Pagat
Posts: 306
Joined: 09 Oct 2007 21:23
Location: Austria

Re: common-jacky

Post by Pagat »

jacky wrote:The TXT must returned a few version numbers and nothing else: "a.aa.aaaa-b.bb.bbbb-c.cc.cccc-d.dd.dddd" (no quotes, obviously)
aaaa is the required XY version for the script in its latest version working with the last official version of XY
bbbb is the last version of the script working with the latest official XY, and can be downloaded as $XYS_name.official.xys
cccc is the required XY version for the latest version of the script (can be a BETA version of XY)
dddd is the last version of the script, and can be downloaded as $XYS_name.xys
So i'm not sure if i understood this completely. Let me summarize:
Right now the latest official version of XY is 7.90.0000. Therefore aaaa is set to 7.90.0000. bbbb should be set to the latest version of my script that is compatible with XY 7.90.0000.
dddd is the latest version of my script (for QuickGoto that's 0.01.0006) and cccc is the version of XY that is needed to run that script (In my case it was the beta where Don added the html function, i think that was 7.90.0030).

Right?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: common-jacky

Post by jacky »

Yep, except for one little thing :
Pagat wrote:Right now the latest official version of XY is 7.90.0000. Therefore aaaa is set to 7.90.0000. bbbb should be set to the latest version of my script that is compatible with XY 7.90.0000.
Not necessarily, bbbb should indeed be the latest version of your script that will work with the latest official XY (so work with 7.90.0010 actually), but aaaa only need to be the version of XY that that script requires, which isn't always the last official.
Quick example: imagine you have a script with one version (0.01.0000) requiring 7.80.0032 and the next (0.01.0001) requiring 7.90.0030; then the txt file should be "7.80.0032-0.01.0000-7.90.0030-0.01.0001"
Proud XYplorer Fanatic

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: common-jacky

Post by jacky »

:arrow: The latest version of the script is 0.01.0004 and can be downloaded from here. Requires XY 7.90.0030

:arrow: _makeRelative: when $CJ_is_folder==1 and the path couldn't be made relative, it would be returned with an added/trailing "\", fixed

:arrow: _ShowHTML: when $CJ_css_buttons==1 the div #buttons could hide the end of the content of the page, fixed.

:arrow: added _getDateFromNumber and _getNumberFromDate to work with dates

:arrow: Minor changes to avoid recursion warnings better
Proud XYplorer Fanatic

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: common-jacky

Post by jacky »

:arrow: The latest version of the script is 0.01.0006 and can be downloaded from here. Requires XY 7.90.0075

:arrow: _ShowHTML: when specified, $CJ_height was set actually to $CJ_width, fixed.

:arrow: _ShowHTML: when a form is auto-added (because $CJ_convert_vars==1 or $CJ_unrar_html==1) then besides the action (xys:$XYS_name) now the id is also set (cj_form)

:arrow: _ShowHTML: added $CJ_form_extra to add other stuff to form id="cj_form" (e.g. JS events, ...)

:arrow: _ShowHTML: added $CJ_js to add javascript code. When not empty, a block <script> is added, so the JS code must be set directly in $CJ_js
Additionally, a few functions are also added:
- scrollToId(id) : scroll to element of specified id
- hasClass(id,class) : returns true/false whether element of specified id has specified class or not
- addClass(id,class) : adds specified class to element of specified id (if not there already)
- removeClass(id,class) : removes specified class from element of specified id
- removeElement(id) : removes element of specified id (from page)
- addInput(name, value) : adds to element(/form) id="cj_form" a new input type=hidden with specified name/value
To simply add those (without extra JS code), simply do something like $CJ_js = '//'; (cause it's still JS code!)
Proud XYplorer Fanatic

Post Reply