2020-02-20 23:08:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using MahApps.Metro.Controls;
|
|
|
|
|
using Microsoft.VisualBasic;
|
|
|
|
|
using PInvoke;
|
2020-03-10 04:11:11 +00:00
|
|
|
|
using SharpDX.DXGI;
|
2020-01-07 13:50:11 +00:00
|
|
|
|
using Wabbajack.Lib;
|
2020-02-20 23:08:12 +00:00
|
|
|
|
using static PInvoke.User32;
|
|
|
|
|
using static PInvoke.Gdi32;
|
2020-01-07 13:50:11 +00:00
|
|
|
|
|
|
|
|
|
namespace Wabbajack.Util
|
|
|
|
|
{
|
2020-02-20 23:08:12 +00:00
|
|
|
|
// Much of the GDI code here is taken from : https://github.com/ModOrganizer2/modorganizer/blob/master/src/envmetrics.cpp
|
|
|
|
|
// Thanks to MO2 for being good citizens and supporting OSS code
|
2020-01-07 13:50:11 +00:00
|
|
|
|
public static class SystemParametersConstructor
|
|
|
|
|
{
|
2020-02-20 23:08:12 +00:00
|
|
|
|
private static List<(int Width, int Height, bool IsPrimary)> GetDisplays()
|
|
|
|
|
{
|
|
|
|
|
// Needed to make sure we get the right values from this call
|
|
|
|
|
SetProcessDPIAware();
|
|
|
|
|
unsafe
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var col = new List<(int Width, int Height, bool IsPrimary)>();
|
|
|
|
|
|
|
|
|
|
EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero,
|
|
|
|
|
delegate(IntPtr hMonitor, IntPtr hdcMonitor, RECT* lprcMonitor, void *dwData)
|
|
|
|
|
{
|
|
|
|
|
MONITORINFOEX mi = new MONITORINFOEX();
|
|
|
|
|
mi.cbSize = Marshal.SizeOf(mi);
|
|
|
|
|
bool success = GetMonitorInfo(hMonitor, (MONITORINFO*)&mi);
|
|
|
|
|
if (success)
|
|
|
|
|
{
|
|
|
|
|
col.Add(((mi.Monitor.right - mi.Monitor.left), (mi.Monitor.bottom - mi.Monitor.top), mi.Flags == 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}, IntPtr.Zero);
|
|
|
|
|
return col;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-07 13:50:11 +00:00
|
|
|
|
public static SystemParameters Create()
|
|
|
|
|
{
|
2020-02-20 23:08:12 +00:00
|
|
|
|
var (width, height, _) = GetDisplays().First(d => d.IsPrimary);
|
2020-03-10 04:11:11 +00:00
|
|
|
|
|
|
|
|
|
using var f = new Factory1();
|
|
|
|
|
var video_memory = f.Adapters1.Select(a =>
|
|
|
|
|
Math.Max(a.Description.DedicatedSystemMemory, (long)a.Description.DedicatedVideoMemory)).Max();
|
|
|
|
|
var memory = Common.Utils.GetMemoryStatus();
|
2020-01-07 13:50:11 +00:00
|
|
|
|
return new SystemParameters
|
|
|
|
|
{
|
2020-02-20 23:08:12 +00:00
|
|
|
|
ScreenWidth = width,
|
2020-03-10 04:11:11 +00:00
|
|
|
|
ScreenHeight = height,
|
|
|
|
|
VideoMemorySize = video_memory,
|
2020-03-19 02:10:55 +00:00
|
|
|
|
SystemMemorySize = (long)memory.ullTotalPhys,
|
2020-01-07 13:50:11 +00:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|