31 lines
1.2 KiB
C#
31 lines
1.2 KiB
C#
using Svg;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
|
|
namespace McsrGraphImageDownloader;
|
|
|
|
internal class Program {
|
|
[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 = 20;
|
|
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<SvgDocument>(new MemoryStream(Encoding.UTF8.GetBytes(svgText!)));
|
|
using (var bitmap = svg.Draw(1920, 1080)) {
|
|
bitmap.Save(outputFilename);
|
|
}
|
|
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, Path.GetFullPath(outputFilename), SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
|
|
|
|
await Task.Delay(TimeSpan.FromMinutes(15));
|
|
}
|
|
}
|
|
}
|