Skip to content

Instantly share code, notes, and snippets.

@rfox90
Created July 8, 2015 01:24
Show Gist options
  • Save rfox90/5de38c01dc3ab3596f9e to your computer and use it in GitHub Desktop.
Save rfox90/5de38c01dc3ab3596f9e to your computer and use it in GitHub Desktop.
Sharex Recovery
#!/usr/bin/perl -w
#I use sharex to form my own version of imgur, files get uploaded with a random string on my domain
#
#I accidentally deleted the webserver copy, so used the local cache to re-create it with this
use XML::Simple;
use Data::Dumper;
use File::Copy;
use File::Find::Rule;
use Data::Dumper;
#Sharex keeps a History.xml file in its Directory "My Documents/Sharex" I use a copy of this that's modified to be valid xml
my $ref = XMLin("History-back.xml");
#XMLIN is cool but it's hard to know what we are getting
#Let's understand the nesting
foreach (keys %$ref){
print "\n".$_."\n";
}
my $items = $ref->{HistoryItem};
#I care about newer uploads first
my @reverseItems = reverse @$items;
foreach my $item (@reverseItems) {
my $filename = $item->{Filename};
#Remove extention
$filename =~ s/\.[a-z]+$//;
print $filename."\n";
#Sharex stores local cache in Screenshots
my @files = File::Find::Rule->file()
->name($filename.".*")
->in( './Screenshots' );
print Dumper(@files);
if(scalar(@files) == 0) {
print "Couldnt find a file so next\n";
next;
}
if(scalar(@files) >1) {
print "Couldnt find a single file so next\n";
next;
}
my $newfilename = $item->{URL};
#Remove domains from the original URL
$newfilename =~ s/http\:\/\/ahref\.co\.uk\///;
$newfilename =~ s/http\:\/\/vps\.ahref\.co\.uk\///;
#Copy to new folder structure
print $newfilename . "\n";
copy($files[0],"./".$newfilename);
#Re-upload to webserver
}
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment