Page 1 of 1

Sunday Trick for Gamers - or other List sorting needs...

Posted: 24 Oct 2010 17:26
by SkyFrontier
This is a H.A.W.X list of unlockable planes:

Code: Select all

A-10A Thunderbolt II - Beat Mission 16
A-6A Intruder - Attain Level 07
A-7B Corsair II - Attain Level 03
AV-8B Harrier II - Attain Level 08
EA-6B Prowler - Attain Level 13
EF-111A RAVEN - Attain Level 04
Eurofighter Typhoon - Beat Mission 14
F-117 Nighthawk - Beat Mission 13
F-14A Tomcat - Beat Mission 08
F-14B Bombcat - Beat Mission 12
F-14D SuperTomcat - Attain Level 24
F-15 Active - Beat Mission 04
F-15C Eagle - Beat Mission 10
F-15E StrikeEagle - Attain Level 25
F-16A Fighting Falcon - Beat Mission 09
F-16C Fighting Falcon - Attain Level 30
F-2 - Attain Level 06
F-20 Tigershark - Attain Level 11
F-22 Raptor - Beat Mission 17
F-4G AdvancedWildWeasel - Beat Mission 02
F-5A Freedom Fighter - Attain Level 05
F-5E Tiger II - Attain Level 15
F35 JSF - Beat Mission 19
FA-18 RC - Attain Level 12
FA-18C Hornet - Attain Level 27
FA-18E SuperHornet - Beat Mission 11
Jaguar - Attain Level 22
Mig-25 Foxbat - Attain Level 02
Mig-29 Fulcrum - Beat Mission 03
Mig-33 SuperFulcrum - Beat Mission 07
MIRAGE 2000 C - Attain Level 09
MIRAGE 2000-5 - Attain Level 23
MIRAGE 5 - Beat Mission 06
MIRAGE F1 - Attain Level 14
MIRAGE III - Attain Level 21
MIRAGE IV P - Attain Level 16
Rafale C - Beat Mission 15
Saab-35 Draken - Create a Ubisoft account and unlock _under Extras - Exclusive Content
Saab-39 Gripen - Attain Level 33
Su-25 Frogfoot - Beat Mission 01
Su-27 Flanker - Beat Mission 05
Su-32 FN - Attain Level 26
Su-34 Fullback - Attain Level 32
Su-35 SuperFlanker - Attain Level 34
Su-37 Terminator - Attain Level 36
Su-47 Berkut - Attain Level 40
X-29 - Attain Level 31
XA-20 Razorback - Create a Ubisoft account and unlock _under Extras - Exclusive Content
YF-12A - Attain Level 17
YF-17 Cobra - Beat Mission 18
YF-23 Black Widow II - Attain Level 35
-but you want to have it sorted by missions/unlock procedures!
Here's how:
-copy the list to the clipboard;
-execute this script and chose FILES on dialog:

Code: Select all

/*	Batch New Items
	
	v0.01.0000	2009.01.18	XY v7.80.0032
		+ first "new" release
*/
"Batch New Items... : BatchNewItems"
	global $XYS_name;
	sub _ensureXY;
	// files or folders ?
	$is_file = confirm("Do you want to create files, or folders ?<br><br>OK = Files<br>Cancel = Folders");
	$type = ($is_file) ? 'file' : 'dir';
	// ask for new items' names
	$names = input("$XYS_name: Enter new ".(($is_file) ? "files" : "folders")."' names",,<clipboard>, m);
 	// get last 2 bytes
	substr $check, $names, -2;
	// and make sure it ends with a CRLF
	$names = $names . (($check == <crlf>) ? "" : <crlf>);
	// remove empty lines
	regexreplace $names, $names, "(\r\n){2,}", <crlf>;
	// turn into a script
	regexreplace $script, $names, "(.+?)\r\n", "new ""$1"", $type; ";
	// and load it up!
	load $script,,s;

-
-
" [ Batch New Items ]"
-
"_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 Batch New Items : 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><br>$CJ_tmp";
	load *;
"Change&log of Batch New Items : _AutoChangelog"
	global $CJ_tmp;
	sub _ensureXY;
	$CJ_tmp = "_AutoChangelogHTML";
	sub _callCommonJacky;
	load *;
"- : _sep"
"Chec&k for updates of Batch New Items... : _CheckForAutoUpdates"
	global $CJ_tmp;
	sub _ensureXY;
	$CJ_tmp = "_CheckForAutoUpdates";
	sub _callCommonJacky;
	load *;
"&Install Batch New Items 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="Batch New Items"
	version="0.01.0000"
	requiredXY="7.80.0032"
	requiredCJ="0.01.0004"
	CJoptional=1
	Url="http://88.191.26.34/XYscripts/download/"
-now, select the created files and set them an extension (on List, right click > rename special > set extension...);
-cool. Now, select the files again and execute this little one:

Code: Select all

   rename r, "(.+) - (.+)\.(.{3,4}) > $2 - $1.$3";
-done. If you want to get rid of the extensions, again select the files and leave empty the box for extension (on List, right click > rename special > set extension...) - or edit the list via your fav text editor.

Of course you can use this trick on other lists with similar structure, but c'mon... it's a lazy sunday! (Now, I just need to stop my boring data mining task and find some time to play... :evil: )
Hint: ensure the input list has no conflicting characters like usual "* / \ < > : " ? | ".

Have a nice day!
(is there any text editor around which can perform such task? I believe the regex-supported ones could do the trick, but - no time to search and test for now...)

Re: Sunday Trick for Gamers - or other List sorting needs...

Posted: 24 Oct 2010 17:46
by SkyFrontier
-and yes, I'm wondering on how I could make the whole process easier and do the whole stuff reading <clipboard> - I can't see a way to apply regexRename (rename r) to items listed on clipboard... :oops:

Re: Sunday Trick for Gamers - or other List sorting needs...

Posted: 24 Oct 2010 21:51
by SkyFrontier
:idea: Concept (not working):

Code: Select all

   $a = "<clipboard>";
   regexreplace($a, "(.+) - (.+)\.(.{3,4})", "$2 - $1.$3");
   copytext $a;
   status "Done!";
   text $a, , , ,w;
Ripoff code (not working, too):

Code: Select all

"Swap Names on Lists from Clipboard"
   $hay = "<clipboard>";
   
   $pattern = '(.+) - (.+)\.(.{3,4}) > $2 - $1.$3';

   $results = '';

   $i = 0;
   $lines = GetToken("$hay", 'count', "<crlf>");
   while ($i < $lines) {
      $i++;
      $line = GetToken("$hay", "$i", "<crlf>");
      $match = RegexReplace("$line", ".*?$pattern", "$1<crlf>");   //Put a CRLF after each line (and strip leading chars)
      if (Compare("$line", "$match")) { //If line was changed...
         $j = 0;
         $matches = GetToken("$match", 'count', "<crlf>");
         while ($j < $matches) {
            $j++;
            $group = GetToken("$match", "$j", "<crlf>");
            if (Compare("$group", "<crlf>") && Compare("$group", "")) {   //If not CRLF/empty...
               $groupMatch = RegexReplace("$group", "^$pattern$|^.*$", "$1");   //If line matches line use it, else replace with nothing.
               if (Compare("$group", "$groupMatch") == 0) {   //If line was not changed....
                  $results = "$results$groupMatch<crlf><crlf>";
               }
            }
         }
      }
   }

     Text "$results", , , ,w; //wordwrapped!
Any help is welcome... :|