-Found a hardcoded legacy code - fixed.
-Added a way to easily set a predefined path for the script to work, thus avoiding initial browsing for the main app's dir.
, too - useful to test localization patches...
Scratched v2 in favor of this.
-now it lists similar base-named folders to inform user on what names *not* to use, prior to chose a category name.
-additional error-checking code to stop script if it detects potential name collision that would lead to unwanted effects.
-better warnings, rephrasing.
-improved preview of what will happen and to show who's who, now and after the changes if they are accepted by user.
-better ending status messages that will tell the user what is what, and keeps the last used "themes" folder selected in list.
Code: Select all
"'Themes' Folders Switcher, v3 - FINAL|:steps"
inputfolder $mpath, "c:\", "Please indicate your main application's path<crlf>which contains the target 'Themes' folder:"; //disable this to get no prompts on main app's path.
// goto "c:\path\"; $mpath = "<curpath>"; //enable this to get no prompts regarding main app's path; optional - disable the next command.
goto $mpath;
$ini = "$mpath\z_ThemesHandler.ini"; IF (exists($ini) == 0)
{
new $ini, file;
echo "$ini<crlf>was not present and it has been created!<crlf>It is STRONGLY recommended that you set it up now.<crlf>Please click 'OK' to proceed.";
sub "_SETUP";
}
elseif
{
selfilter """z_ThemesHandler.ini""";
$size=report("{Size}",1);
IF (($size) == 0) {
$cnfrm = confirm("The program requires a basic setup which was not completed thus far.<crlf><crlf>Please click 'OK' to config it now<crlf> or 'Cancel' to end this script.")?"YES":"NO");
IF ($cnfrm == YES) { sub "_SETUP" }
ELSE ($cnfrm == NO) { sub "_NOP" }
}
$th = getkey("Default", "1_ThemesDEF", "$ini");
$base = getkey("Path", "2_Path", "$ini");
$ini = getkey("ini", "2_INI", "$ini");
$tback = getkey("Old", "1_ThemesOLD", "$ini");
$tfut = getkey("Current", "1_ThemesCUR", "$ini");
$answer = confirm("New '$th' main folder will be<crlf>'$tback'.<crlf>Current '$th' folder will be renamed as<crlf>'$tfut'<crlf>and stored for future fast switches.<crlf><crlf>Please click 'OK' to continue or 'Cancel' to choose another folder.")?"_YES":"_NO";
IF ($answer == _YES) { }
ELSE ($answer == _NO) { sub "_NON" }
$tback = getkey("Old", "1_ThemesOLD", "$ini");
$tt = getkey("Default", "1_ThemesDEF", "$ini");
selfilter """$tt""";
$tc = getinfo("CountSelected");
IF (($tc) != 1) { status "Fatal error detected: '$th' not present.", BF0000, stop; end 1, "Folder '$th' is not available and it's crucial to your app.<crlf>Please check what's wrong and fix it!<crlf><crlf>This script will now be stopped.<crlf><crlf>Have a nice day! ^^"; }
// #485; //refresh list - avoid surprises on list...
selfilter """$tt""";
rename r, "$tt > themeTMP";
// #485; //refresh list - see what's going on...
$tback = getkey("Old", "1_ThemesOLD", "$ini");
selfilter """$tback""";
rename r, "$tback > $tt";
// #485; //refresh list - see what's going on...
$ct = getkey("Current", "1_ThemesCUR", "$ini");
selfilter """themeTMP""";
rename r, "themeTMP > $ct";
setkey "$mpath", "Path", "1_Path", "$ini";
setkey "$tback", "Current", "1_ThemesCUR", "$ini";
//could raise potential bug: setkey "Themes", "Default", "1_ThemesDEF", "$ini";
$nt = getkey("Default", "1_ThemesDEF", "$ini");
setkey "$nt", "Default", "1_ThemesDEF", "$ini";
setkey "$ct", "Old", "1_ThemesOLD", "$ini";
#485; //refresh list - to display updated .ini...
echo "'$tback' is your new '$nt' folder!";
status "'$tback' is now '$nt'!";
"_NON"
$ini = "<curpath>\z_ThemesHandler.ini";
$tnn = getkey("Default", "1_ThemesDEF", "$ini");
$resp = confirm("Please click 'OK' to select another folder which will be set<crlf>as current '$tnn' folder or 'Cancel' to end this script.")?"_YO":"_NOP";
IF ($resp == _YO) { sub "_YO"; }
ELSE ($resp == _NO) { sub "_NOP"; }
"_NOP"
// msg "Operation canceled by user.<crlf>Have a nice day! ^^";
// status text, [color RRGGBB], [icon=ready|progress|alert|stop]
status "Operation canceled by user.", BF0000, alert;
end 1;
"_SETUP"
$ini = "<curpath>\z_ThemesHandler.ini";
input $th, "Please enter the default 'Themes' folder name:", "Themes";
$c2r = "$th _";
replace $c2r, $c2r, "$th _", "$th _"; replace $c2r, $c2r, " ", "";
selfilter "$th";
$rep = get("SelectedItemsNames", "<crlf>");
$ct = input("Set the category name for the current '$th' folder:", "('$c2r' will be auto-prepended)<crlf><crlf>Currently on list (you should REALLY avoid using them):<crlf>$rep", "ALT", "S");
$sug = replace ("$ini", "z_ThemesHandler.ini", "");
$cr1 = "$th $ct";
replace $cr1, $cr1, "$th $ct", "$th _$ct"; replace $cr1, $cr1, " ", "";
selfilter """$cr1""";
$ex = getinfo("CountSelected");
IF ($ex == 1) { status "Error: '$cr1' would crash script.", BF0000, stop; end 1, "~~~~~~~~~~---------~~~~~~~~~~<crlf> ~~~~~~~-WARNING-~~~~~~~<crlf>~~~~~~~~~~---------~~~~~~~~~~<crlf><crlf>Setup has detected that a file of same name<crlf>already exists and it could lead to several problems.<crlf><crlf>Please run the script again and pay attention to the list<crlf>presented list during setup and avoid duplicates.<crlf><crlf>Fatal error detected: '$cr1' would be<crlf>duplicated and could crash either the script or the operation.<crlf>Have a nice day! ^^<crlf><crlf>~~~~~~~~~~---------~~~~~~~~~~"; }
ELSE ($ex != 1) { }
// setting "AllowRecursion", 0;
inputfolder $old, "$sug", "Now, please select the folder that will replace current '$th' folder in future category swaps:<crlf>(current '$th' will be named: '$cr1')";
$old = replace ("$old", "$sug", "");
setkey "<curpath>", "Path", "2_Path", "$ini";
setkey "$ini", "ini", "2_INI", "$ini";
//test: ::$th = 1; $ct = ab; $y = "$th $ct"; replace $crr, $y, "$th $ct", "$th_$ct"; echo $crr;
//test OK: ::$th = 1; $ct = ab; $y = "$th $ct"; replace $crr, $y, "$th $ct", "$ct _$th"; replace $crr, $crr, " ", ""; echo $crr;
$crr = "$th $ct";
replace $crr, $crr, "$th $ct", "$th _$ct"; replace $crr, $crr, " ", "";
setkey "$crr", "Current", "1_ThemesCUR", "$ini";
setkey "$th", "Default", "1_ThemesDEF", "$ini";
setkey "$old", "Old", "1_ThemesOLD", "$ini";
#485; //refresh list - to display updated .ini; generates a bug if not present (runs setup a 2nd time)...
"_YO"
$ini = "<curpath>\z_ThemesHandler.ini";
$tnow = getkey("Current", "1_ThemesCUR", "$ini");
$ty = getkey("Default", "1_ThemesDEF", "$ini");
$tback = getkey("Old", "1_ThemesOLD", "$ini");
inputfolder $oldy, "<curpath>", "Replacement for '$ty' in next category swap:<crlf>(previous choice would be: $tback;<crlf>current '$ty' folder is: $tnow)";
$oldy = replace ("$oldy", "<curpath>\", "");
setkey "$oldy", "Old", "1_ThemesOLD", "$ini";