Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!C:Perl\bin\perl.exe
- # Version: 4 - Dec 1st, 2013
- # Version: 3 - Oct 30th, 2013
- # Version: 2 - Oct 6th, 2013
- #
- # Reads Fuzzie's html post to find the current version of mods
- # Generates a tab separated file that can be loaded into a spreadsheet program
- # Will also read a old version of its output file to compare to
- # Will also try to determine the version from the mod files in mods directory.
- # Marks New column New, if it is different then the old version number
- # Marks Match column Yes, if the file version matches the mod version
- # Requires Perl to be installed. Top line of this script must be path to your Perl executable.
- #
- # Steps to use:
- # 1. Save Fuzzie's 1st post as an html file, set $htmlFile to the html file name
- # 2. Edit $oldFile line, set it to old file, if you have one
- # 3. Set $modDir to your mod dir, maybe expanded %APPDATA%/.minecraft/mods
- # 4. Run the program
- # 5. Add $trans variables for files that don't match, already done
- # 6. Load the results in a spreadsheet program
- # 7. Update your mods marked with as New in the spreadsheet or log
- use strict;
- use warnings;
- use File::Path;
- use FileHandle;
- use Data::Dumper;
- my %trans;
- #########################################
- #### User edit this section
- my $oldFile = "modlist_2013.11.06_21.57.39.txt";
- my $htmlFile = "Fuzzzie's 1.6.4 Mod List.htm";
- my $modDir = "C:/Users/Bruce/AppData/Roaming/.minecraft/mods"; # more typical modDir
- #my $modDir = "C:/Users/Bruce/Minecraft/Minecraft_1.6.4_ver_3/data/.minecraft/mods";
- #my $modDir = "C:/Users/Bruce/Downloads";
- # Some mod names don't match well to their file names
- #$trans{"Html Name"} = "File Name";
- $trans{"Energy Manipulation"} = "EM";
- $trans{"Better World Generation 4"} = "BWG4";
- $trans{"Nuclear Control"} = "IC2NuclearControl";
- $trans{"Extra Utilities"} = "extrautils";
- $trans{"Rei's Minimap"} = "ReiMinimap";
- $trans{"Barrels Mod"} = "Barrels";
- $trans{"Extra Bees/Trees"} = "binnie-mods";
- $trans{"Carpenter Blocks"} = "Carpenter's Blocks";
- $trans{"Mo Creatures"} = "DrZharks MoCreatures Mod";
- $trans{"Forestry"} = "forestry-A";
- $trans{"NBTEdit"} = "Forge_NBTEdit";
- $trans{"Iron Chests 2"} = "ironchest-universal";
- $trans{"NEI Mystcraft Plugin"} = "MystNEI-Plugin";
- $trans{"Wireless Redstone CBE"} = "WR-CBE";
- $trans{"Zan's Minimap"} = "ZansMinimap";
- $trans{"TreeCapitator"} = "TreeCapitator.Forge";
- $trans{"MrCrayfish's Furniture"} = "FurnitureMod";
- $trans{"BiblioWoods BoP"} = "BiblioWoods[BiomesOPlenty]";
- $trans{"Buildcraft"} = "buildcraft-A";
- $trans{"Additional Buildcraft Objects"} = "buildcraft-Z-additional-buildcraft-objects";
- $trans{"NEI Plugin Pack"} = "NEIPlugins";
- $trans{"Immibis's Peripheral"} = "immibis-peripherals";
- $trans{"Tinkers Construct"} = "TConstruct";
- $trans{"MFFS Classic"} = "MFFS";
- $trans{"IndustrialCraft 2 Experimental"} = "industrialcraft-2_";
- $trans{"RotartyCraft"} = "RotaryCraft";
- $trans{"Applied Energistics"} = "appeng";
- $trans{"Applied Energistics Dev"} = "appeng";
- $trans{"Universal Electricity Basic Components"} = "Basic_Components";
- $trans{"Darkguardsman Mods"} = "Dark-AssemblyLine";
- $trans{"Gravitation Suite"} = "mod_zGraviSuite";
- $trans{"GregTech Addon"} = "gregtechmod";
- $trans{"Advanced Solar Panels"} = "mod_AdvancedSolarPanels";
- $trans{"Project: Red"} = "ProjectRedBase";
- $trans{"Metallurgy 3"} = "Metallurgy";
- $trans{"Steve's Carts 2"} = "Steve's Carts";
- $trans{"Thaumcraft 4"} = "Thaumcraft";
- $trans{"Minechem 4"} = "Minechem";
- #########################################
- my $debug = 0;
- my $data = {};
- my $date = GetDateTime();
- my $outFile = "modlist_$date.txt";
- my $logFile = "minecraft_fuz_mod_ver.log";
- my $LOG = OpenOutRef($logFile);
- print "Creating $logFile\n";
- ReadOldFile($oldFile,$data);
- ReadHtmlFile($htmlFile,$data);
- ReadModDir($modDir,$data);
- Compare($data);
- WriteData($outFile,$data);
- #print $LOG "-----------------------------------\n";
- #print $LOG Dumper($data);
- print $LOG "-----------------------------------\n";
- print $LOG "old count = $data->{oldCnt}\n";
- print $LOG "new count = $data->{newCnt}\n";
- print $LOG "diff count = $data->{difCnt}\n";
- print $LOG "file count = $data->{fileCnt}\n";
- print $LOG "-----------------------------------\n";
- close($LOG);
- exit 0;
- #############################################################################
- sub ReadModDir {
- my ($modDir, $data) = @_;
- if ( -d $modDir ) {
- print $LOG "Reading dir : $modDir\n";
- my @files = ReadDir($modDir);
- foreach my $file ( @files ) {
- if ( $file =~ /(.+)\.(zip|jar)$/ ) {
- print $LOG "File : $file\n" if ($debug==3);
- $data->{fileCnt}++;
- my $fileNameVar1 = $1;
- my $fileNameVar2 = $1;
- $fileNameVar1 =~ s/^\[[\w\.]+\]//; # remove starting minecraft version
- $fileNameVar1 =~ s/^[\d\.]+//; # remove starting minecraft version
- $fileNameVar1 =~ s/[-_\.\[\]\s\']+//g;
- #print $LOG " file changed : $fileNameVar1\n";
- my $gotMatch = 0;
- foreach my $mod ( @{$data->{mod}} ) {
- next if ( $mod->{done} );
- my $modName = $mod->{name};
- #print $LOG " modname = $modName\n";
- if ( defined($trans{$modName}) ) {
- $modName = $trans{$modName};
- #print $LOG " changed modName = $modName\n";
- }
- $modName =~ s/[-_\.\[\]\s\']+//g;
- if ( $fileNameVar1 =~ /^$modName/i ) {
- $gotMatch = 1;
- $mod->{done} = 1;
- print $LOG " found match $modName\n" if ($debug==3);
- my @letterMod = split(//,$modName);
- my @letterFile = split(//,$fileNameVar2);
- my $j = 0;
- my $fileModName;
- for(my $i=0; $i <= $#letterMod; $i++) {
- while ( $letterFile[$j] !~ /$letterMod[$i]/i ) {
- $fileModName .= $letterFile[$j];
- #print $LOG " $i $j N $letterMod[$i] fileModName = $fileModName\n";
- $j++
- }
- if ( $letterFile[$j] =~ /$letterMod[$i]/i ) {
- $fileModName .= $letterFile[$j];
- #print $LOG " $i $j Y $letterMod[$i] fileModName = $fileModName\n";
- $j++
- }
- }
- $fileModName =~ s/\[/\\[/g;
- if ( $fileNameVar2 =~ /$fileModName(.+)/ ) {
- my $v = $1;
- $v =~ s/^[-_\s]+//;
- $v =~ s/[\[\]]+//g;
- my $name = $mod->{name};
- $data->{fileVer}{$name} = $v;
- print $LOG " fileVer = $v\n" if ($debug==3);
- }
- }
- last if ($gotMatch);
- }
- if ( !$gotMatch ) {
- if ( $fileNameVar2 =~ /(.+)(\d+\..+)/ ) {
- my($m,$v) = ($1,$2);
- $v =~ s/^[-_\s]+//;
- $v =~ s/[\[\]]+//g;
- $m =~ s/_v$//;
- $m =~ s/\bv//;
- $m =~ s/(\[|\.)$//;
- my $mod = {};
- $mod->{name} = $m;
- $data->{fileVer}{$m} = $v;
- $mod->{version} = "unknown";
- $mod->{new} = "";
- $mod->{credit} = "";
- $mod->{download} = "";
- $mod->{thread} = "";
- $mod->{done} = 1;
- push(@{$data->{mod}}, $mod);
- }
- }
- }
- }
- #print $LOG "-----------------------------------\n";
- }
- else {
- print $LOG "Error can't find dir : $modDir\n";
- exit 1;
- }
- }
- #############################################################################
- # Read the old file
- sub ReadOldFile {
- my ($oldFile, $data) = @_;
- my $old;
- $data->{oldCnt} = 0;;
- if ( -e $oldFile ) {
- my $OLD = OpenInRef($oldFile);
- print $LOG "Reading $oldFile\n";
- my @line = <$OLD>;
- close($OLD);
- foreach my $line ( @line ) {
- next if ( $line =~ /^#/ );
- my ($order,$name,$oldVer,$new,$oldFileVer,$match,$credit,$download,$thread) = split(/\t/,$line);
- $data->{old}{$name} = $oldVer;
- $data->{oldCnt}++;
- }
- print $LOG "-----------------------------------\n";
- }
- else {
- print $LOG "Warning unable to find oldFile = $oldFile\n";
- }
- }
- #############################################################################
- # Read the html file
- sub ReadHtmlFile {
- my($htmlFile,$data) = @_;
- if ( !-e $htmlFile ) {
- print $LOG "Error can't find html file : $htmlFile\n";
- exit 1;
- }
- $data->{newCnt} = 0;
- my($name,$version,$credit,$download,$thread);
- my $i = 0;
- my $INFILE = OpenInRef($htmlFile);
- print $LOG "Reading file : $htmlFile\n";
- my @line = <$INFILE>;
- close($INFILE);
- foreach my $line ( @line ) {
- chomp($line);
- #print $LOG "line $i : $line\n";
- # <font color="#0000CD"><div style="text-align: left;">CodeChickenCore</div>
- if ( $i==0 && $line =~ /color=\"\#(0000CD|FF0000)\"><div style=\"text-align: left;\">(.+)<\/div>/ ) {
- $name = $2;
- print $LOG "\nmod=$name\n" if ($debug==2);
- ($version,$credit,$download,$thread) = ("","","","");
- $i=1;
- }
- elsif ( $i==1 && $line =~ /<td class=\"cms_table_grid_td\"><div style=\"text-align: center;\">(.+)<\/div>/ ) {
- $version = $1;
- print $LOG "version=$version\n" if ($debug==2);
- $i=2;
- }
- elsif ( $i==2 && $line =~ /<font color=\"#FF8C00\">(.+)<\/font>/ ) {
- $credit = $1;
- $credit =~ s/<\/div>//;
- $credit =~ s/<div.+>//;
- print $LOG "credit=$credit\n" if ($debug==2);
- $i=3;
- }
- elsif ( $i==3 && $line =~ /a href=\"(\S+)\" target=\"_blank\">Download/ ) {
- $download = $1;
- print $LOG "download=$download\n" if ($debug==2);
- $i=4;
- }
- elsif ( $i==4 && $line =~ /a href=\"(\S+)\" target=\"_blank\">(Thread|Website)/ ) {
- $thread = $1;
- print $LOG "thread=$thread\n" if ($debug==2);
- $i=5;
- }
- elsif ( $i > 1 && $line =~ /<\/tr>/ ) {
- my $mod = {};
- $mod->{name} = $name;
- $mod->{version} = $version;
- $mod->{new} = "";
- $mod->{credit} = $credit;
- $mod->{download} = $download;
- $mod->{thread} = $thread;
- $mod->{done} = 0;
- $data->{fileVer}{$name} = "";
- $data->{newCnt}++;
- push(@{$data->{mod}}, $mod);
- $i=0;
- }
- elsif ( $line =~ /<\/td>/ && $i==1) {
- $version = "unknown";
- $i=2;
- }
- elsif ( $line =~ /<\/table>/ ) {
- $data->{div}{$name} = 1;
- }
- }
- print $LOG "-----------------------------------\n" if ($debug==2);
- }
- #############################################################################
- sub Compare {
- my ($data) = @_;
- $data->{difCnt} = 0;
- if ( $data->{oldCnt} ) {
- print $LOG "Comparing old to new\n";
- foreach my $mod ( @{$data->{mod}} ) {
- my $name = $mod->{name};
- my $version = $mod->{version};
- if ( defined($data->{old}{name}) ) {
- if ( $data->{old}{$name} ne $version ) {
- print $LOG " $name - new version\n";
- $mod->{new} = "New";
- $data->{difCnt}++;
- }
- }
- else {
- $mod->{new} = "New";
- $data->{difCnt}++;
- }
- }
- print $LOG "-----------------------------------\n";
- }
- }
- #############################################################################
- # Write the output file
- sub WriteData {
- my ($outFile,$data) = @_;
- my $j = 0;
- my $OUTFILE = OpenOutRef($outFile);
- print $LOG "Creating $outFile\n";
- print $OUTFILE "#Order\tMod\tNew\tVersion\tFile Version\tMatch\tCredit\tDownload\tThread\n";
- foreach my $mod ( @{$data->{mod}} ) {
- $j++;
- my $name = $mod->{name};
- my $fv1 = $mod->{version};
- my $fv = $data->{fileVer}{$name};
- my $fv2 = $fv;
- $fv1 =~ s/[\s\.\-]+//g;
- $fv2 =~ s/[\s\.\-]+//g;
- my $match = "";
- if ( $fv2 =~ /$fv1/ ) {
- $match = "Yes";
- }
- print $OUTFILE "$j\t$name\t$mod->{new}\t$mod->{version}\t$fv\t$match\t$mod->{credit}\t$mod->{download}\t$mod->{thread}\n";
- if ( defined($data->{div}{$name}) ) {
- $j++;
- print $OUTFILE "$j\n";
- }
- }
- close($OUTFILE);
- }
- #############################################################################
- sub OpenOutRef {
- my ($outFile) = (@_);
- my $OUTFILE = FileHandle->new;
- if ( $OUTFILE->open("> $outFile") == 0 ) {
- print "Error unable to open out file: $outFile\n";
- exit(1);
- }
- return $OUTFILE;
- }
- sub OpenInRef {
- my ($inFile) = (@_);
- my $INFILE = FileHandle->new;
- if ( $INFILE->open("< $inFile") == 0 ) {
- print $LOG "Error unable to open in file: $inFile\n";
- exit(1);
- }
- return $INFILE;
- }
- #############################################################################
- sub ReadDir {
- my($dir)= @_;
- if ( opendir(DIR, $dir) ) {
- my @file = readdir(DIR);
- closedir(DIR);
- return @file;
- }
- else {
- print $LOG "Error: Unable to open directory $dir\n $!";
- exit(1);
- }
- }
- #############################################################################
- sub GetDateTime {
- my ($sec,$min,$hour,$day,$month,$yr19,@rest) = localtime(time);
- my $year = $yr19+1900;
- $month++;
- my $date = sprintf("%4d.%02d.%02d_%02d.%02d.%02d",$year,$month,$day,$hour,$min,$sec);
- return $date;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement