Last active
October 12, 2017 18:28
-
-
Save leonard84/33f8463e497935dbfb74032e67ff1188 to your computer and use it in GitHub Desktop.
Saves all Pictures from the Windows Spotlight into My Documents/spotter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Check-Header | |
{ | |
param( | |
$path | |
) | |
# Hexidecimal signatures for expected files | |
$jpg = 'FFD8FFE0'; | |
# Get content of each file (up to 4 bytes) for analysis | |
([Byte[]] $fileheader = Get-Content -Path $path -TotalCount 4 -Encoding Byte) | | |
ForEach-Object { | |
if(("{0:X}" -f $_).length -eq 1) | |
{ | |
$HeaderAsHexString += "0{0:X}" -f $_ | |
} | |
else | |
{ | |
$HeaderAsHexString += "{0:X}" -f $_ | |
} | |
} | |
# Validate file header | |
@($jpg) -contains $HeaderAsHexString | |
} | |
$storepath = "$([Environment]::GetFolderPath("MyDocuments"))\spotter" | |
md -force $storepath | Out-Null | |
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
Get-ChildItem "$env:localappdata\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets" | | |
Foreach-Object { | |
# Use SHA1 hash of file to prevent duplicates | |
$hash = Get-FileHash -Algorithm SHA1 $_.fullName | |
$target = "$storepath\$($hash.Hash).jpg" | |
if (!(Test-Path $target)) { | |
if (Check-Header $_.fullName) { | |
$img = [System.Drawing.Image]::Fromfile($_.fullName); | |
if ($img.Size.Width -ge 1920) { | |
echo "Found new $($_.name)" | |
Copy-Item $_.fullName "$target" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment