diff --git a/README.md b/README.md index bf0f276..5d0984d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/SevenConverter/Forms/Main.cs b/SevenConverter/Forms/Main.cs index ba25d00..15713cb 100644 --- a/SevenConverter/Forms/Main.cs +++ b/SevenConverter/Forms/Main.cs @@ -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)) { @@ -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, diff --git a/SevenConverter/Properties/AssemblyInfo.cs b/SevenConverter/Properties/AssemblyInfo.cs index 346d773..83acaf8 100644 --- a/SevenConverter/Properties/AssemblyInfo.cs +++ b/SevenConverter/Properties/AssemblyInfo.cs @@ -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")] \ No newline at end of file +[assembly: AssemblyVersion("1.5.6.0")] +[assembly: AssemblyFileVersion("1.5.6.0")] \ No newline at end of file diff --git a/SevenConverter/Utils/Tools.cs b/SevenConverter/Utils/Tools.cs index 65d8239..959acee 100644 --- a/SevenConverter/Utils/Tools.cs +++ b/SevenConverter/Utils/Tools.cs @@ -1,4 +1,6 @@ -using System.Reflection; +using System; +using System.Reflection; +using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; @@ -6,11 +8,34 @@ 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;