Skip to content

Instantly share code, notes, and snippets.

@hassanselim0
Last active August 7, 2020 21:32
Show Gist options
  • Save hassanselim0/14d6c8314c238b5cfaaf429c396d6cb4 to your computer and use it in GitHub Desktop.
Save hassanselim0/14d6c8314c238b5cfaaf429c396d6cb4 to your computer and use it in GitHub Desktop.
Copy Windows Spotlight Lockscreens Images
// This script requires ScriptCS (https://github.com/scriptcs/scriptcs) but you can modify it and build it as a C# App
// You run this from inside the target folder (where images are copied to), or pass the target path as a script parameter
// You can also have an "_exceptions.txt" file with images to exclude, so they wont be copied again
#r WindowsBase
#r System.Xaml
#r PresentationCore
if (Env.ScriptArgs.Count > 0)
Directory.SetCurrentDirectory(Env.ScriptArgs[0]);
var srcDir = Environment.ExpandEnvironmentVariables(@"%LOCALAPPDATA%\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets");
var tarDir = @".";
var srcFiles = Directory.GetFiles(srcDir);
var tarFiles = new List<string>();
var except = Enumerable.Empty<string>();
if (File.Exists("_exceptions.txt"))
except = File.ReadAllLines("_exceptions.txt").Select(f => Path.Combine(srcDir, f));
foreach (var f in srcFiles.Except(except))
{
var tarFile = Path.Combine(tarDir, Path.GetFileName(f) + ".jpg");
if (!File.Exists(tarFile))
{
File.Copy(f, tarFile);
tarFiles.Add(tarFile);
}
}
using System.Windows.Media.Imaging;
foreach (var f in tarFiles)
{
try
{
using (var stream = File.OpenRead(f))
{
var frame = BitmapFrame.Create(stream);
if (frame.PixelWidth >= 1280 && frame.PixelHeight >= 720) continue;
if (frame.PixelWidth >= 720 && frame.PixelHeight >= 1280)
{
stream.Close();
File.Move(f, Path.Combine(tarDir, "Phone", Path.GetFileName(f)));
continue;
}
}
}
catch { }
File.Delete(f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment