summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF
diff options
context:
space:
mode:
authorsr55 <[email protected]>2016-04-19 21:52:27 +0100
committersr55 <[email protected]>2016-04-19 21:52:27 +0100
commit4284cf487665dd2013b8c95cf2195980ac8106df (patch)
tree9ed89bad39b89315a94adc7b09ad901d4af8f1ec /win/CS/HandBrakeWPF
parent5e299e96599e191345f303623baa6ceda01c0916 (diff)
WinGui: Some initial work to make the HandBrake.ApplicationServices library more portable.
Diffstat (limited to 'win/CS/HandBrakeWPF')
-rw-r--r--win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs1
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj2
-rw-r--r--win/CS/HandBrakeWPF/Services/PrePostActionService.cs1
-rw-r--r--win/CS/HandBrakeWPF/Utilities/SystemInfo.cs114
-rw-r--r--win/CS/HandBrakeWPF/Utilities/Win32.cs199
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs1
6 files changed, 318 insertions, 0 deletions
diff --git a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs
index 489b787b1..b89125674 100644
--- a/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs
+++ b/win/CS/HandBrakeWPF/Converters/Video/VideoEncoderConverter.cs
@@ -23,6 +23,7 @@ namespace HandBrakeWPF.Converters.Video
using EncodeTask = HandBrakeWPF.Services.Encode.Model.EncodeTask;
using OutputFormat = HandBrakeWPF.Services.Encode.Model.Models.OutputFormat;
+ using SystemInfo = HandBrake.ApplicationServices.Utilities.SystemInfo;
/// <summary>
/// Video Encoder Converter
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index 5869f24bb..358c1109c 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -253,6 +253,8 @@
<Compile Include="Utilities\Output\CsvHelper.cs" />
<Compile Include="Utilities\PropertyChangedBase.cs" />
<Compile Include="Utilities\DirectoryUtilities.cs" />
+ <Compile Include="Utilities\SystemInfo.cs" />
+ <Compile Include="Utilities\Win32.cs" />
<Compile Include="Utilities\Win7.cs" />
<Compile Include="ViewModels\AudioDefaultsViewModel.cs" />
<Compile Include="ViewModels\CountdownAlertViewModel.cs" />
diff --git a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
index 1d54d1e6f..4e3f4f30f 100644
--- a/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
+++ b/win/CS/HandBrakeWPF/Services/PrePostActionService.cs
@@ -20,6 +20,7 @@ namespace HandBrakeWPF.Services
using HandBrakeWPF.EventArgs;
using HandBrakeWPF.Services.Interfaces;
using HandBrakeWPF.Services.Queue.Interfaces;
+ using HandBrakeWPF.Utilities;
using HandBrakeWPF.ViewModels.Interfaces;
using EncodeCompletedEventArgs = HandBrakeWPF.Services.Encode.EventArgs.EncodeCompletedEventArgs;
diff --git a/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs b/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs
new file mode 100644
index 000000000..9ed362e32
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/SystemInfo.cs
@@ -0,0 +1,114 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="SystemInfo.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The System Information.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Management;
+ using System.Windows.Forms;
+
+ using HandBrake.ApplicationServices.Interop.HbLib;
+
+ using Microsoft.Win32;
+
+ /// <summary>
+ /// The System Information.
+ /// </summary>
+ public class SystemInfo
+ {
+ /// <summary>
+ /// Gets the total physical ram in a system
+ /// </summary>
+ /// <returns>The total memory in the system</returns>
+ public static ulong TotalPhysicalMemory
+ {
+ get
+ {
+ Win32.MEMORYSTATUSEX memStat = new Win32.MEMORYSTATUSEX { dwLength = 64 };
+ Win32.GlobalMemoryStatusEx(ref memStat);
+
+ ulong value = memStat.ullTotalPhys / 1024 / 1024;
+ return value;
+ }
+ }
+
+ /// <summary>
+ /// Gets the number of CPU Cores
+ /// </summary>
+ /// <returns>Object</returns>
+ public static object GetCpuCount
+ {
+ get
+ {
+ RegistryKey regKey = Registry.LocalMachine;
+ regKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
+ return regKey == null ? 0 : regKey.GetValue("ProcessorNameString");
+ }
+ }
+
+ /// <summary>
+ /// Gets the System screen size information.
+ /// </summary>
+ /// <returns>System.Windows.Forms.Scree</returns>
+ public static Screen ScreenBounds
+ {
+ get { return Screen.PrimaryScreen; }
+ }
+
+ /// <summary>
+ /// Gets the get gpu driver version.
+ /// </summary>
+ public static List<string> GetGPUInfo
+ {
+ get
+ {
+ List<string> gpuInfo = new List<string>();
+
+ try
+ {
+ ManagementObjectSearcher searcher =
+ new ManagementObjectSearcher("select * from " + "Win32_VideoController");
+
+ foreach (ManagementObject share in searcher.Get())
+ {
+ string gpu = string.Empty, version = string.Empty;
+
+ foreach (PropertyData PC in share.Properties)
+ {
+ if (!string.IsNullOrEmpty(PC.Name) && PC.Value != null)
+ {
+ if (PC.Name.Equals("DriverVersion")) version = PC.Value.ToString();
+ if (PC.Name.Equals("Name")) gpu = PC.Value.ToString();
+ }
+ }
+
+ if (string.IsNullOrEmpty(gpu))
+ {
+ gpu = "Unknown GPU";
+ }
+
+ if (string.IsNullOrEmpty(version))
+ {
+ version = "Unknown Driver Version";
+ }
+
+ gpuInfo.Add(string.Format("{0} - {1}", gpu, version));
+ }
+ }
+ catch (Exception)
+ {
+ // Do Nothing. We couldn't get GPU Information.
+ }
+
+ return gpuInfo;
+ }
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Utilities/Win32.cs b/win/CS/HandBrakeWPF/Utilities/Win32.cs
new file mode 100644
index 000000000..a65a5e09d
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Utilities/Win32.cs
@@ -0,0 +1,199 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="Win32.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Win32 API calls
+// </summary>
+// <auto-generated>Disable Stylecop for this file </auto-generated>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Utilities
+{
+ using System;
+ using System.Runtime.InteropServices;
+ using System.Windows.Threading;
+
+ /// <summary>
+ /// Win32 API calls
+ /// </summary>
+ public class Win32
+ {
+ /// <summary>
+ /// Used to force UI Thread.
+ /// </summary>
+ private static Action<Action> executor = action => action();
+
+ /// <summary>
+ /// Set the Forground Window
+ /// </summary>
+ /// <param name="hWnd">
+ /// The h wnd.
+ /// </param>
+ /// <returns>
+ /// A Boolean true when complete.
+ /// </returns>
+ [DllImport("user32.dll")]
+ public static extern bool SetForegroundWindow(int hWnd);
+
+ /// <summary>
+ /// Lock the workstation
+ /// </summary>
+ [DllImport("user32.dll")]
+ public static extern void LockWorkStation();
+
+ /// <summary>
+ /// Exit Windows
+ /// </summary>
+ /// <param name="uFlags">
+ /// The u flags.
+ /// </param>
+ /// <param name="dwReason">
+ /// The dw reason.
+ /// </param>
+ /// <returns>
+ /// an integer
+ /// </returns>
+ [DllImport("user32.dll")]
+ public static extern int ExitWindowsEx(int uFlags, int dwReason);
+
+ /// <summary>
+ /// Memory Status EX Struct
+ /// </summary>
+ public struct MEMORYSTATUSEX
+ {
+ public int dwLength;
+
+ public int dwMemoryLoad;
+
+ public ulong ullTotalPhys;
+
+ public ulong ullAvailPhys;
+
+ public ulong ullTotalPageFile;
+
+ public ulong ullAvailPageFile;
+
+ public ulong ullTotalVirtual;
+
+ public ulong ullAvailVirtual;
+
+ public ulong ullAvailExtendedVirtual;
+ }
+
+ /// <summary>
+ /// Get the System Memory information
+ /// </summary>
+ /// <param name="lpBuffer">
+ /// The lp buffer.
+ /// </param>
+ /// <returns>
+ /// A boolean.
+ /// </returns>
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
+
+ /// <summary>
+ /// Generate a Console Ctrl Event
+ /// </summary>
+ /// <param name="sigevent">
+ /// The sigevent.
+ /// </param>
+ /// <param name="dwProcessGroupId">
+ /// The dw process group id.
+ /// </param>
+ /// <returns>
+ /// Bool true is sucess
+ /// </returns>
+ [DllImport("kernel32.dll", SetLastError = true)]
+ public static extern bool GenerateConsoleCtrlEvent(ConsoleCtrlEvent sigevent, int dwProcessGroupId);
+
+ /// <summary>
+ /// Console Ctrl Event
+ /// </summary>
+ public enum ConsoleCtrlEvent
+ {
+ /// <summary>
+ /// Ctrl - C
+ /// </summary>
+ CTRL_C = 0,
+
+ /// <summary>
+ /// Ctrl - Break
+ /// </summary>
+ CTRL_BREAK = 1,
+
+ /// <summary>
+ /// Ctrl - Close
+ /// </summary>
+ CTRL_CLOSE = 2,
+ }
+
+ [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
+ private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
+
+ /// <summary>
+ /// Execution State
+ /// </summary>
+ [Flags]
+ public enum EXECUTION_STATE : uint
+ {
+ ES_SYSTEM_REQUIRED = 0x00000001,
+
+ ES_CONTINUOUS = 0x80000000,
+
+ ES_AWAYMODE_REQUIRED = 0x00000040
+ }
+
+ /// <summary>
+ /// Initializes static members of the <see cref="Win32"/> class.
+ /// </summary>
+ static Win32()
+ {
+ InitializeWithDispatcher();
+ }
+
+ /// <summary>
+ /// Prevent the system from sleeping
+ /// </summary>
+ public static void PreventSleep()
+ {
+ executor(
+ () => SetThreadExecutionState(
+ EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED
+ | EXECUTION_STATE.ES_AWAYMODE_REQUIRED));
+ }
+
+ /// <summary>
+ /// Allow the system to sleep.
+ /// </summary>
+ public static void AllowSleep()
+ {
+ executor(() => SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS));
+ }
+
+ /// <summary>
+ /// Initializes the framework using the current dispatcher.
+ /// </summary>
+ public static void InitializeWithDispatcher()
+ {
+ var dispatcher = Dispatcher.CurrentDispatcher;
+
+ SetUIThreadMarshaller(action =>
+ {
+ if (dispatcher.CheckAccess())
+ action();
+ else dispatcher.Invoke(action);
+ });
+ }
+
+ /// <summary>
+ /// Sets a custom UI thread marshaller.
+ /// </summary>
+ /// <param name="marshaller">The marshaller.</param>
+ public static void SetUIThreadMarshaller(Action<Action> marshaller)
+ {
+ executor = marshaller;
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
index c28eea1f8..a60be1aef 100644
--- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
@@ -31,6 +31,7 @@ namespace HandBrakeWPF.ViewModels
using Ookii.Dialogs.Wpf;
using Execute = Caliburn.Micro.Execute;
+ using SystemInfo = HandBrake.ApplicationServices.Utilities.SystemInfo;
/// <summary>
/// The Options View Model