Skip to content

Commit c8cba43

Browse files
author
RandomEngy
committed
Some refactoring, and marking thread as working during encodes to prevent system from going in to sleep mode.
1 parent 0cd7d80 commit c8cba43

9 files changed

Lines changed: 55 additions & 7 deletions

File tree

VidCoder/IListItemConverter.cs renamed to VidCoder/Utilities/ListSynchronizer/IListItemConverter.cs

File renamed without changes.

VidCoder/MultiSelectorBehaviors.cs renamed to VidCoder/Utilities/ListSynchronizer/MultiSelectorBehaviors.cs

File renamed without changes.

VidCoder/TwoListSynchronizer.cs renamed to VidCoder/Utilities/ListSynchronizer/TwoListSynchronizer.cs

File renamed without changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.InteropServices;
6+
using VidCoder.Services;
7+
8+
namespace VidCoder
9+
{
10+
[Flags]
11+
public enum EXECUTION_STATE : uint
12+
{
13+
ES_SYSTEM_REQUIRED = 0x00000001,
14+
ES_DISPLAY_REQUIRED = 0x00000002,
15+
// Legacy flag, should not be used.
16+
// ES_USER_PRESENT = 0x00000004,
17+
ES_CONTINUOUS = 0x80000000,
18+
}
19+
20+
public static class SystemSleepManagement
21+
{
22+
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
23+
private static extern EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE esFlags);
24+
25+
public static void PreventSleep()
26+
{
27+
DispatchService.BeginInvoke(() =>
28+
{
29+
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED);
30+
});
31+
}
32+
33+
public static void AllowSleep()
34+
{
35+
DispatchService.BeginInvoke(() =>
36+
{
37+
SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
38+
});
39+
}
40+
}
41+
}

VidCoder/VidCoder.csproj

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@
194194
<Compile Include="Converters\DoubleDisplayConverter.cs" />
195195
<Compile Include="Converters\PercentDisplayConverter.cs" />
196196
<Compile Include="EnumStringConverter.cs" />
197-
<Compile Include="IListItemConverter.cs" />
197+
<Compile Include="Utilities\ListSynchronizer\IListItemConverter.cs" />
198198
<Compile Include="Model\Logger.cs" />
199-
<Compile Include="MultiSelectorBehaviors.cs" />
199+
<Compile Include="Utilities\ListSynchronizer\MultiSelectorBehaviors.cs" />
200200
<Compile Include="Settings.cs" />
201-
<Compile Include="TwoListSynchronizer.cs" />
201+
<Compile Include="Utilities\ListSynchronizer\TwoListSynchronizer.cs" />
202+
<Compile Include="Utilities\SystemSleepManagement.cs" />
202203
<Compile Include="ViewModel\AboutDialogViewModel.cs" />
203204
<Compile Include="ViewModel\DataModels\AdvancedChoices.cs" />
204205
<Compile Include="ViewModel\DataModels\ColumnViewModel.cs" />
@@ -222,7 +223,7 @@
222223
<Compile Include="View\ScanMultipleDialog.xaml.cs">
223224
<DependentUpon>ScanMultipleDialog.xaml</DependentUpon>
224225
</Compile>
225-
<Compile Include="WpfSystemIcons.cs" />
226+
<Compile Include="Utilities\WpfSystemIcons.cs" />
226227
<Compile Include="View\ExceptionDialog.xaml.cs">
227228
<DependentUpon>ExceptionDialog.xaml</DependentUpon>
228229
</Compile>
@@ -251,7 +252,7 @@
251252
<Compile Include="Converters\FramerateDisplayConverter.cs" />
252253
<Compile Include="Converters\InverseBoolConverter.cs" />
253254
<Compile Include="Converters\VisibilityConverter.cs" />
254-
<Compile Include="DisplayConversions.cs" />
255+
<Compile Include="Utilities\DisplayConversions.cs" />
255256
<Compile Include="DragDrop\DragDropHelper.cs" />
256257
<Compile Include="DragDrop\DraggedAdorner.cs" />
257258
<Compile Include="DragDrop\IDragItem.cs" />
@@ -276,7 +277,7 @@
276277
<Compile Include="Services\UpdateService.cs" />
277278
<Compile Include="Services\WindowLauncher.cs" />
278279
<Compile Include="Services\WindowManager.cs" />
279-
<Compile Include="Utilities.cs" />
280+
<Compile Include="Utilities\Utilities.cs" />
280281
<Compile Include="ViewModel\ChapterMarkersDialogViewModel.cs" />
281282
<Compile Include="ViewModel\CharCode.cs" />
282283
<Compile Include="ViewModel\ChoosePresetNameViewModel.cs" />

VidCoder/ViewModel/MainViewModel.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,9 +1153,15 @@ public bool Encoding
11531153
set
11541154
{
11551155
this.encoding = value;
1156-
if (!value)
1156+
1157+
if (value)
1158+
{
1159+
SystemSleepManagement.PreventSleep();
1160+
}
1161+
else
11571162
{
11581163
this.EncodeSpeedDetailsAvailable = false;
1164+
SystemSleepManagement.AllowSleep();
11591165
}
11601166

11611167
this.NotifyPropertyChanged("PauseVisible");

0 commit comments

Comments
 (0)