Skip to content

Commit

Permalink
Merge pull request #195 from Ordisoftware/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Ordisoftware authored Nov 11, 2019
2 parents e767bcd + c07aa10 commit bad7c77
Show file tree
Hide file tree
Showing 14 changed files with 535 additions and 112 deletions.
3 changes: 3 additions & 0 deletions Project/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@
<setting name="AutoLockSessionTimeOut" serializeAs="String">
<value>30</value>
</setting>
<setting name="LockSessionMediaStop" serializeAs="String">
<value>False</value>
</setting>
</Ordisoftware.HebrewCalendar.Properties.Settings>
</userSettings>
<startup>
Expand Down
3 changes: 3 additions & 0 deletions Project/Hebrew Calendar (vs2017).csproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<Compile Include="Dependencies\GenericParsing\ParserState.cs" />
<Compile Include="Dependencies\GenericParsing\ParsingException.cs" />
<Compile Include="Dependencies\VietnameseCalendar\VietnameseCalendar.cs" />
<Compile Include="Source\Forms\Boxes\LockSessionForm.MediaStop.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Source\Forms\Boxes\LockSessionForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
4 changes: 2 additions & 2 deletions Project/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("3.8.0.0")]
[assembly: AssemblyFileVersion("3.8.0.0")]
[assembly: AssemblyVersion("3.9.0.0")]
[assembly: AssemblyFileVersion("3.9.0.0")]
12 changes: 12 additions & 0 deletions Project/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Project/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,8 @@
<Setting Name="AutoLockSessionTimeOut" Type="System.Int32" Scope="User">
<Value Profile="(Default)">30</Value>
</Setting>
<Setting Name="LockSessionMediaStop" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
18 changes: 16 additions & 2 deletions Project/Source/Enums/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,25 @@ static public readonly Dictionary<string, string> ExitApplication
{ "fr", "Quitter l'application ?" }
};

static public readonly Dictionary<string, string> ShutdownComputer
= new Dictionary<string, string>()
{
{ "en", "Shutdown the computer?" },
{ "fr", "Arrêter l'ordinateur ?" }
};

static public readonly Dictionary<string, string> LockSessionError
= new Dictionary<string, string>()
{
{ "en", "Shutdown the computer?" },
{ "fr", "Arrêter l'ordinateur ?" }
};

static public readonly Dictionary<string, string> CantExitApplicationWhileGenerating
= new Dictionary<string, string>()
{
{ "en", "Can't close while generating." },
{ "fr", "Impossible de quitter durant la génération." }
{ "en", "Lock Session Error: {0}" },
{ "fr", "Erreur de verrouillage de session : {0}" }
};

static public readonly Dictionary<string, string> NoNewVersionAvailable
Expand Down
50 changes: 49 additions & 1 deletion Project/Source/Forms/Boxes/LockSessionForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions Project/Source/Forms/Boxes/LockSessionForm.MediaStop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/// <license>
/// This file is part of Ordisoftware Hebrew Calendar.
/// Copyright 2016-2019 Olivier Rogier.
/// See www.ordisoftware.com for more information.
/// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
/// If a copy of the MPL was not distributed with this file, You can obtain one at
/// https://mozilla.org/MPL/2.0/.
/// If it is not possible or desirable to put the notice in a particular file,
/// then You may include the notice in a location(such as a LICENSE file in a
/// relevant directory) where a recipient would be likely to look for such a notice.
/// You may add additional accurate notices of copyright ownership.
/// </license>
/// <created> 2019-11 </created>
/// <edited> 2019-11 </edited>
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Ordisoftware.HebrewCalendar
{

public partial class LockSessionForm : Form
{

[DllImport("user32.dll", SetLastError = true)]
private static extern uint SendInput(uint numberOfInputs, INPUT[] inputs, int sizeOfInputStructure);

[StructLayout(LayoutKind.Sequential)]
internal struct INPUT
{
public uint Type;
public MOUSEKEYBDHARDWAREINPUT Data;
}

[StructLayout(LayoutKind.Explicit)]
internal struct MOUSEKEYBDHARDWAREINPUT
{
[FieldOffset(0)]
public HARDWAREINPUT Hardware;
[FieldOffset(0)]
public KEYBDINPUT Keyboard;
[FieldOffset(0)]
public MOUSEINPUT Mouse;
}

[StructLayout(LayoutKind.Sequential)]
internal struct KEYBDINPUT
{
public ushort Vk;
public ushort Scan;
public uint Flags;
public uint Time;
public IntPtr ExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
internal struct MOUSEINPUT
{
public int X;
public int Y;
public uint MouseData;
public uint Flags;
public uint Time;
public IntPtr ExtraInfo;
}

[StructLayout(LayoutKind.Sequential)]
internal struct HARDWAREINPUT
{
public uint Msg;
public ushort ParamL;
public ushort ParamH;
}

private void MediaStop()
{
if ( !EditMediaStop.Checked ) return;
INPUT input = new INPUT
{
Type = 1
};
input.Data.Keyboard = new KEYBDINPUT()
{
Vk = 0xB3,
Scan = 0,
Flags = 0,
Time = 0,
ExtraInfo = IntPtr.Zero,
};
INPUT[] inputs = new INPUT[] { input };
SendInput(1, inputs, Marshal.SizeOf(typeof(INPUT)));
}

}

}
64 changes: 61 additions & 3 deletions Project/Source/Forms/Boxes/LockSessionForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
/// <created> 2019-11 </created>
/// <edited> 2019-11 </edited>
using System;
using System.IO;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using Ordisoftware.Core;
using Microsoft.Win32;

namespace Ordisoftware.HebrewCalendar
{
Expand Down Expand Up @@ -45,12 +48,44 @@ private LockSessionForm()
private void LockSessionForm_Load(object sender, EventArgs e)
{
LabelMessage.Text = string.Format(LabelMessage.Text, Program.Settings.AutoLockSessionTimeOut);
int width = LabelMessage.Width + LabelMessage.Left + LabelMessage.Left + 5;
if ( width > Width )
Width = width;
ActionHibernate.Left = ActionStandby.Left + ActionStandby.Width + 5;
ActionShutdown.Left = ActionHibernate.Left + ActionHibernate.Width + 5;
ActionHibernate.Enabled = CanHibernate();
ActionStandby.Enabled = CanStandby();
CenterToScreen();
Timer.Start();
Timer_Tick(null, null);
}

private bool CanStandby()
{
return true;
}

private bool CanHibernate()
{
try
{
using ( RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Power") )
if ( key != null )
{
var value = key.GetValue("HibernateEnabled", 0);
return value == null ? false : (bool)value;
}
}
catch
{
return File.Exists(@"C:\hiberfil.sys");
}
return false;
}

private void LockSessionForm_FormClosed(object sender, FormClosedEventArgs e)
{
Timer.Stop();
Instance = null;
}

Expand All @@ -62,22 +97,45 @@ private void Timer_Tick(object sender, EventArgs e)
LockSession();
}

private void ActionCancel_Click(object sender, EventArgs e)
{
Close();
}

private void ActionOk_Click(object sender, EventArgs e)
{
LockSession();
}

private void ActionCancel_Click(object sender, EventArgs e)
private void ActionShutdown_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
if ( !DisplayManager.QueryYesNo(Translations.ShutdownComputer.GetLang()) ) return;
Close();
MediaStop();
Program.RunShell("shutdown", "/s /t 0");
MainForm.Instance.SessionEnding(null, null);
}

private void ActionHibernate_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
Close();
MediaStop();
Application.SetSuspendState(PowerState.Hibernate, false, false);
}

private void ActionStandby_Click(object sender, LinkLabelLinkClickedEventArgs e)
{
Close();
MediaStop();
Application.SetSuspendState(PowerState.Suspend, false, false);
}

private void LockSession()
{
Timer.Enabled = false;
MediaStop();
Close();
if ( !LockWorkStation() )
MessageBox.Show("Lock Session Error: " + Marshal.GetLastWin32Error());
MessageBox.Show(Translations.LockSessionError.GetLang(Marshal.GetLastWin32Error()));
}

}
Expand Down
Loading

0 comments on commit bad7c77

Please sign in to comment.