Skip to content

Commit

Permalink
Merge pull request #14 from fediachov/master
Browse files Browse the repository at this point in the history
Prevents power sleep on converting
  • Loading branch information
RadiumByte authored Apr 16, 2020
2 parents 3e81f3c + dbf4131 commit ed76cf6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Automatically rename a file when matching names.
- Getting file information.
- Play one or more files.
- Prevents power sleep on converting.

## Video conversion

Expand Down
4 changes: 4 additions & 0 deletions SevenConverter/Forms/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ private void BtnStart_Click(object sender, EventArgs e)

if (listSoruceFiles.Items.Count > 0)
{
Tools.PreventSleep();

if (!String.IsNullOrEmpty(tbDestFilePath.Text)
&& !Directory.Exists(tbDestFilePath.Text))
{
Expand Down Expand Up @@ -158,6 +160,8 @@ private void BtnStart_Click(object sender, EventArgs e)
// done!
if (result)
SystemSounds.Exclamation.Play();

Tools.AllowSleep();
}
else
MessageBox.Show(Properties.strings.FolderDoesNotExist,
Expand Down
4 changes: 2 additions & 2 deletions SevenConverter/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.5.0")]
[assembly: AssemblyFileVersion("1.5.5.0")]
[assembly: AssemblyVersion("1.5.6.0")]
[assembly: AssemblyFileVersion("1.5.6.0")]
27 changes: 26 additions & 1 deletion SevenConverter/Utils/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
using System.Reflection;
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;

namespace SevenConverter.Utils
{
public static class Tools
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern ExecutionState SetThreadExecutionState(ExecutionState esFlags);

[FlagsAttribute]
private enum ExecutionState : uint
{
EsAwaymodeRequired = 0x00000040,
EsContinuous = 0x80000000,
EsDisplayRequired = 0x00000002,
EsSystemRequired = 0x00000001
}

public static void PreventSleep()
{
SetThreadExecutionState(ExecutionState.EsContinuous | ExecutionState.EsSystemRequired);
}

public static void AllowSleep()
{
SetThreadExecutionState(ExecutionState.EsContinuous);
}

public static string GetProgramVersion()
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}


public static void ShowPanel(Control toggleControl, Panel panel, bool show, int height)
{
panel.Left = toggleControl.Left + toggleControl.Width;
Expand Down

0 comments on commit ed76cf6

Please sign in to comment.