#define SHOW_ON_ONE_SCREEN using Svg; using System.Runtime.InteropServices; using System.Text; using System.Text.Json; namespace McsrGraphImageDownloader; internal class Program { #if SHOW_ON_ONE_SCREEN private const int screenToShowItOn = 0; // must be >= 0 and < amount_of_screens, will be clamped if necessary [ComImport] [Guid("B92B56A9-8B55-4E14-9A89-0199BBB6F93B")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] private interface IDesktopWallpaper { void SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID, [MarshalAs(UnmanagedType.LPWStr)] string wallpaper); [return: MarshalAs(UnmanagedType.LPWStr)] string GetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string monitorID); void GetMonitorDevicePathAt(uint monitorIndex, [MarshalAs(UnmanagedType.LPWStr)] out string monitorID); uint GetMonitorDevicePathCount(); // Remaining methods omitted since not needed } #endif [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni); public const int SPI_SETDESKWALLPAPER = 0x14; public const int SPIF_UPDATEINIFILE = 1; public const int SPIF_SENDCHANGE = 2; private const string outputFilename = "mcsrChart.png"; private static async Task Main(string[] args) { using var hc = new HttpClient(); while (true) { var svgJson = await hc.GetStringAsync("https://mcsr.ghxx.dev/api/chart"); var svgText = JsonDocument.Parse(svgJson).RootElement.GetProperty("data").GetString(); var svg = SvgDocument.Open(new MemoryStream(Encoding.UTF8.GetBytes(svgText!))); using (var bitmap = svg.Draw(1920, 1080)) { bitmap.Save(outputFilename); } #if SHOW_ON_ONE_SCREEN Type type = Type.GetTypeFromCLSID(new Guid("C2CF3110-460E-4FC1-B9D0-8A1C0C9CC4BD"))!; var wallpaper = (IDesktopWallpaper)Activator.CreateInstance(type)!; uint monitorCount = wallpaper.GetMonitorDevicePathCount(); Console.WriteLine($"Monitor count: {monitorCount}"); var monitorIndex = Math.Clamp(screenToShowItOn, 0, monitorCount - 1); wallpaper.GetMonitorDevicePathAt(monitorIndex, out string? monitorId); wallpaper.SetWallpaper(monitorId, Path.GetFullPath(outputFilename)); Console.WriteLine($"Wallpaper set for monitor {monitorIndex} only."); #else SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Path.GetFullPath(outputFilename), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); #endif await Task.Delay(TimeSpan.FromMinutes(15)); } } }