mirror of
https://github.com/wabbajack-tools/wabbajack.git
synced 2024-08-30 18:42:17 +00:00
FilePickerVM and SystemParametersConstructor porting
This commit is contained in:
parent
761b5195fb
commit
26aabf413c
@ -12,6 +12,7 @@ using Wabbajack.Common;
|
|||||||
using Wabbajack.Lib;
|
using Wabbajack.Lib;
|
||||||
using Wabbajack.Lib.Extensions;
|
using Wabbajack.Lib.Extensions;
|
||||||
using Wabbajack.Paths;
|
using Wabbajack.Paths;
|
||||||
|
using Wabbajack.Paths.IO;
|
||||||
|
|
||||||
namespace Wabbajack
|
namespace Wabbajack
|
||||||
{
|
{
|
||||||
@ -139,11 +140,11 @@ namespace Wabbajack
|
|||||||
switch (t.Type)
|
switch (t.Type)
|
||||||
{
|
{
|
||||||
case PathTypeOptions.Either:
|
case PathTypeOptions.Either:
|
||||||
return t.Path.Exists;
|
return t.Path.FileExists() || t.Path.DirectoryExists();
|
||||||
case PathTypeOptions.File:
|
case PathTypeOptions.File:
|
||||||
return t.Path.IsFile;
|
return t.Path.FileExists();
|
||||||
case PathTypeOptions.Folder:
|
case PathTypeOptions.Folder:
|
||||||
return t.Path.IsDirectory;
|
return t.Path.DirectoryExists();
|
||||||
case PathTypeOptions.Off:
|
case PathTypeOptions.Off:
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -252,15 +253,15 @@ namespace Wabbajack
|
|||||||
execute: () =>
|
execute: () =>
|
||||||
{
|
{
|
||||||
AbsolutePath dirPath;
|
AbsolutePath dirPath;
|
||||||
dirPath = TargetPath.Exists ? TargetPath.Parent : TargetPath;
|
dirPath = TargetPath.FileExists() ? TargetPath.Parent : TargetPath;
|
||||||
var dlg = new CommonOpenFileDialog
|
var dlg = new CommonOpenFileDialog
|
||||||
{
|
{
|
||||||
Title = PromptTitle,
|
Title = PromptTitle,
|
||||||
IsFolderPicker = PathType == PathTypeOptions.Folder,
|
IsFolderPicker = PathType == PathTypeOptions.Folder,
|
||||||
InitialDirectory = (string)dirPath,
|
InitialDirectory = dirPath.ToString(),
|
||||||
AddToMostRecentlyUsedList = false,
|
AddToMostRecentlyUsedList = false,
|
||||||
AllowNonFileSystemItems = false,
|
AllowNonFileSystemItems = false,
|
||||||
DefaultDirectory = (string)dirPath,
|
DefaultDirectory = dirPath.ToString(),
|
||||||
EnsureFileExists = true,
|
EnsureFileExists = true,
|
||||||
EnsurePathExists = true,
|
EnsurePathExists = true,
|
||||||
EnsureReadOnly = false,
|
EnsureReadOnly = false,
|
||||||
|
@ -4,20 +4,29 @@ using System.Linq;
|
|||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using PInvoke;
|
using PInvoke;
|
||||||
using Silk.NET.Core.Native;
|
using Silk.NET.Core.Native;
|
||||||
using Silk.NET.DXGI;
|
using Silk.NET.DXGI;
|
||||||
using Wabbajack.Common;
|
using Wabbajack.Common;
|
||||||
|
using Wabbajack.Installer;
|
||||||
using Wabbajack.Lib;
|
using Wabbajack.Lib;
|
||||||
using static PInvoke.User32;
|
using static PInvoke.User32;
|
||||||
|
using UnmanagedType = System.Runtime.InteropServices.UnmanagedType;
|
||||||
|
|
||||||
namespace Wabbajack.Util
|
namespace Wabbajack.Util
|
||||||
{
|
{
|
||||||
// Much of the GDI code here is taken from : https://github.com/ModOrganizer2/modorganizer/blob/master/src/envmetrics.cpp
|
// 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
|
// Thanks to MO2 for being good citizens and supporting OSS code
|
||||||
public static class SystemParametersConstructor
|
public class SystemParametersConstructor
|
||||||
{
|
{
|
||||||
private static IEnumerable<(int Width, int Height, bool IsPrimary)> GetDisplays()
|
private readonly ILogger<SystemParametersConstructor> _logger;
|
||||||
|
|
||||||
|
public SystemParametersConstructor(ILogger<SystemParametersConstructor> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
private IEnumerable<(int Width, int Height, bool IsPrimary)> GetDisplays()
|
||||||
{
|
{
|
||||||
// Needed to make sure we get the right values from this call
|
// Needed to make sure we get the right values from this call
|
||||||
SetProcessDPIAware();
|
SetProcessDPIAware();
|
||||||
@ -43,7 +52,7 @@ namespace Wabbajack.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SystemParameters Create()
|
public SystemParameters Create()
|
||||||
{
|
{
|
||||||
var (width, height, _) = GetDisplays().First(d => d.IsPrimary);
|
var (width, height, _) = GetDisplays().First(d => d.IsPrimary);
|
||||||
|
|
||||||
@ -93,7 +102,7 @@ namespace Wabbajack.Util
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Utils.ErrorThrow(e);
|
_logger.LogError(e, "While getting SystemParameters");
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@ -103,7 +112,7 @@ namespace Wabbajack.Util
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var memory = Utils.GetMemoryStatus();
|
var memory = GetMemoryStatus();
|
||||||
return new SystemParameters
|
return new SystemParameters
|
||||||
{
|
{
|
||||||
ScreenWidth = width,
|
ScreenWidth = width,
|
||||||
@ -113,5 +122,36 @@ namespace Wabbajack.Util
|
|||||||
SystemPageSize = (long)memory.ullTotalPageFile - (long)memory.ullTotalPhys
|
SystemPageSize = (long)memory.ullTotalPageFile - (long)memory.ullTotalPhys
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[return: MarshalAs(UnmanagedType.Bool)]
|
||||||
|
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
||||||
|
static extern bool GlobalMemoryStatusEx([In, Out] MEMORYSTATUSEX lpBuffer);
|
||||||
|
|
||||||
|
public static MEMORYSTATUSEX GetMemoryStatus()
|
||||||
|
{
|
||||||
|
var mstat = new MEMORYSTATUSEX();
|
||||||
|
GlobalMemoryStatusEx(mstat);
|
||||||
|
return mstat;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
|
||||||
|
public class MEMORYSTATUSEX
|
||||||
|
{
|
||||||
|
public uint dwLength;
|
||||||
|
public uint dwMemoryLoad;
|
||||||
|
public ulong ullTotalPhys;
|
||||||
|
public ulong ullAvailPhys;
|
||||||
|
public ulong ullTotalPageFile;
|
||||||
|
public ulong ullAvailPageFile;
|
||||||
|
public ulong ullTotalVirtual;
|
||||||
|
public ulong ullAvailVirtual;
|
||||||
|
public ulong ullAvailExtendedVirtual;
|
||||||
|
public MEMORYSTATUSEX()
|
||||||
|
{
|
||||||
|
dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user