Skip to content

Commit 3f7876b

Browse files
committed
1.7.15
[New] - added "Close program action"
1 parent 69bdebc commit 3f7876b

File tree

12 files changed

+249
-12
lines changed

12 files changed

+249
-12
lines changed

LICENSE

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ software for all its users. We, the Free Software Foundation, use the
1818
GNU General Public License for most of our software; it applies also to
1919
any other work released this way by its authors. You can apply it to
2020
your programs, too.
21-
F
21+
2222
When we speak of free software, we are referring to freedom, not
2323
price. Our General Public Licenses are designed to make sure that you
2424
have the freedom to distribute copies of free software (and charge for
@@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
631631
state the exclusion of warranty; and each file should have at least
632632
the "copyright" line and a pointer to where the full notice is found.
633633

634-
AutoHDR
635-
Copyright (C) 2021 2021
634+
AutoHDR - Profile-based setting changed on application events
635+
Copyright (C) 2021 Heiko Thome
636636

637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671671
may consider it more useful to permit linking proprietary applications with
672672
the library. If this is what you want to do, use the GNU Lesser General
673673
Public License instead of this License. But first, please read
674-
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
674+
<http://www.gnu.org/philosophy/why-not-lgpl.html>.

Source/HDRProfile/AutoHDR.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,13 @@
180180
<Reference Include="PresentationFramework" />
181181
</ItemGroup>
182182
<ItemGroup>
183+
<Compile Include="Profiles\Actions\CloseProgramAction.cs" />
183184
<Compile Include="Theming\ThemeResourceDirectory.cs" />
184185
<Compile Include="Theming\Theme.cs" />
185186
<Compile Include="UWP\WWAHostHandler.cs" />
187+
<Compile Include="Views\CloseProgramActionView.xaml.cs">
188+
<DependentUpon>CloseProgramActionView.xaml</DependentUpon>
189+
</Compile>
186190
<Compile Include="WinAPIFunctions.cs" />
187191
<Compile Include="Windows\UI.cs" />
188192
<Page Include="App.xaml">
@@ -283,6 +287,10 @@
283287
<Generator>MSBuild:Compile</Generator>
284288
<SubType>Designer</SubType>
285289
</Page>
290+
<Page Include="Views\CloseProgramActionView.xaml">
291+
<Generator>MSBuild:Compile</Generator>
292+
<SubType>Designer</SubType>
293+
</Page>
286294
<Page Include="Views\RunProgramActionView.xaml">
287295
<Generator>MSBuild:Compile</Generator>
288296
<SubType>Designer</SubType>

Source/HDRProfile/AutoHDRDaemon.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,13 +715,13 @@ private void ShowInfo()
715715
private void ShowLogs()
716716
{
717717
if (DialogService != null)
718-
DialogService.ShowDialogModal(_logsStorage, new System.Drawing.Size(600, 1000));
718+
DialogService.ShowDialogModal(_logsStorage, new System.Drawing.Size(700, 1000));
719719
}
720720

721721
private void ShowLicense()
722722
{
723723
if (DialogService != null)
724-
DialogService.ShowDialogModal(new AutoHDRLicense(), new System.Drawing.Size(600, 1000));
724+
DialogService.ShowDialogModal(new AutoHDRLicense(), new System.Drawing.Size(700, 1000));
725725
}
726726

727727

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
using AutoHDR.ProjectResources;
2+
using CodectoryCore.Logging;
3+
using CodectoryCore.UI.Wpf;
4+
using Microsoft.Win32;
5+
using Newtonsoft.Json;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics;
9+
using System.Drawing;
10+
using System.IO;
11+
using System.Linq;
12+
using System.Runtime.Serialization;
13+
using System.Text;
14+
using System.Threading.Tasks;
15+
16+
namespace AutoHDR.Profiles.Actions
17+
{
18+
[JsonObject(MemberSerialization.OptIn)]
19+
public class CloseProgramAction : ProfileActionBase
20+
{
21+
public override string ActionTypeName => ProjectResources.Locale_Texts.CloseProgram;
22+
23+
24+
private string _processName = "";
25+
26+
[JsonProperty]
27+
public string ProcessName { get => _processName; set { _processName = value; OnPropertyChanged(); } }
28+
29+
private bool _force = false;
30+
31+
[JsonProperty]
32+
public bool Force { get => _force; set { _force = value; OnPropertyChanged(); } }
33+
34+
35+
36+
public override string ActionDescription => $"{Locale_Texts.Close} {ProcessName}";
37+
38+
public RelayCommand GetFileCommand { get; private set; }
39+
40+
41+
public CloseProgramAction()
42+
{
43+
44+
}
45+
46+
public override ActionEndResult RunAction(params object[] parameter)
47+
{
48+
try
49+
{
50+
51+
Process[] runningProcesses = Process.GetProcesses();
52+
foreach (Process process in runningProcesses)
53+
{
54+
if (process.ProcessName == ProcessName)
55+
try
56+
{
57+
CallNewLog(new LogEntry($"Closing {ProcessName}..."));
58+
59+
bool result = process.CloseMainWindow();
60+
if (!result)
61+
62+
process.Close();
63+
}
64+
catch (Exception ex)
65+
{
66+
throw new Exception($"Closing {ProcessName} failed", ex);
67+
}
68+
if (!process.HasExited)
69+
{
70+
if (Force)
71+
{
72+
CallNewLog(new LogEntry($"Killing {ProcessName}..."));
73+
try
74+
{
75+
process.Kill();
76+
CallNewLog(new LogEntry($"Process {ProcessName} killed.."));
77+
78+
}
79+
catch (Exception ex)
80+
{
81+
throw new Exception($"Killing {ProcessName} failed", ex);
82+
}
83+
}
84+
}
85+
else
86+
CallNewLog(new LogEntry($"Process {ProcessName} closed."));
87+
88+
89+
}
90+
return new ActionEndResult(true);
91+
}
92+
catch (Exception ex)
93+
{
94+
CallNewLog(new CodectoryCore.Logging.LogEntry($"{ ex.Message }\r\n{ ex.StackTrace}", CodectoryCore.Logging.LogEntryType.Error));
95+
return new ActionEndResult(false, ex.Message, ex);
96+
}
97+
}
98+
}
99+
}

Source/HDRProfile/ProjectResources/Locale_Texts.Designer.cs

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/HDRProfile/ProjectResources/Locale_Texts.de.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@
189189
<data name="ChooseUWPApplication" xml:space="preserve">
190190
<value>UWP App auswählen...</value>
191191
</data>
192+
<data name="Close" xml:space="preserve">
193+
<value>Beenden</value>
194+
</data>
195+
<data name="CloseProgram" xml:space="preserve">
196+
<value>Programm beenden</value>
197+
</data>
192198
<data name="ColorDepth" xml:space="preserve">
193199
<value>Farbtiefe [bit]</value>
194200
</data>
@@ -240,6 +246,9 @@
240246
<data name="FilePath" xml:space="preserve">
241247
<value>Dateipfad</value>
242248
</data>
249+
<data name="ForceKill" xml:space="preserve">
250+
<value>Beenden erzwingen</value>
251+
</data>
243252
<data name="GlobalAutoHDR" xml:space="preserve">
244253
<value>Automatischer HDR-Modus für alle Monitore verwenden</value>
245254
</data>
@@ -309,6 +318,9 @@
309318
<data name="Priority" xml:space="preserve">
310319
<value>Priorität</value>
311320
</data>
321+
<data name="ProcessName" xml:space="preserve">
322+
<value>Prozessname</value>
323+
</data>
312324
<data name="Profile" xml:space="preserve">
313325
<value>Profil</value>
314326
</data>

Source/HDRProfile/ProjectResources/Locale_Texts.resx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@
195195
<data name="ChooseUWPApplication" xml:space="preserve">
196196
<value>Choose UWP app...</value>
197197
</data>
198+
<data name="Close" xml:space="preserve">
199+
<value>Close</value>
200+
</data>
201+
<data name="CloseProgram" xml:space="preserve">
202+
<value>Close program</value>
203+
</data>
198204
<data name="ColorDepth" xml:space="preserve">
199205
<value>Color depth [bit]</value>
200206
</data>
@@ -249,6 +255,9 @@
249255
<data name="FilePath" xml:space="preserve">
250256
<value>File path</value>
251257
</data>
258+
<data name="ForceKill" xml:space="preserve">
259+
<value>Force closing</value>
260+
</data>
252261
<data name="GitHub" xml:space="preserve">
253262
<value>GitHub</value>
254263
</data>
@@ -910,8 +919,8 @@ to attach them to the start of each source file to most effectively
910919
state the exclusion of warranty; and each file should have at least
911920
the "copyright" line and a pointer to where the full notice is found.
912921

913-
{one line to give the program's name and a brief idea of what it does.}
914-
Copyright (C) {year} {name of author}
922+
AutoHDR - Profile-based setting changed on application events
923+
Copyright (C) 2021 Heiko Thome
915924

916925
This program is free software: you can redistribute it and/or modify
917926
it under the terms of the GNU General Public License as published by
@@ -1001,6 +1010,9 @@ Public License instead of this License. But first, please read
10011010
<data name="Priority" xml:space="preserve">
10021011
<value>Priority</value>
10031012
</data>
1013+
<data name="ProcessName" xml:space="preserve">
1014+
<value>Process name</value>
1015+
</data>
10041016
<data name="Profile" xml:space="preserve">
10051017
<value>Profile</value>
10061018
</data>

Source/HDRProfile/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,5 @@
5252
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5353
// indem Sie "*" wie unten gezeigt eingeben:
5454
// [assembly: AssemblyVersion("1.0.*")]
55-
[assembly: AssemblyVersion("1.7.14.0")]
56-
[assembly: AssemblyFileVersion("1.7.14.0")]
55+
[assembly: AssemblyVersion("1.7.15.0")]
56+
[assembly: AssemblyFileVersion("1.7.15.0")]

Source/HDRProfile/Views/AutoHDRLicenseView.xaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
xmlns:pres="clr-namespace:AutoHDR.ProjectResources"
88
xmlns:info="clr-namespace:AutoHDR.Info"
99
xmlns:local="clr-namespace:AutoHDR.Views"
10-
mc:Ignorable="d" MinWidth="300" MinHeight="600" >
10+
mc:Ignorable="d" MinWidth="600" MinHeight="600" >
1111

1212
<i:Interaction.Triggers>
1313
<i:EventTrigger EventName="Loaded">
@@ -42,7 +42,15 @@
4242
<TextBlock Grid.Row="1" Text="{x:Static pres:Locale_Texts.License}" HorizontalAlignment="Left" Margin="5,15,0,0" FontSize="20" VerticalAlignment="Top"/>
4343
<Border Style="{StaticResource RoundedBorder}" Grid.Row="2" BorderBrush="{DynamicResource AccentBrush}" BorderThickness="1" Margin="5" >
4444
<ScrollViewer>
45-
<TextBlock Text="{x:Static pres:Locale_Texts.LicenseContent}" TextAlignment="Center"/>
45+
<Grid Margin="17,0,0,0">
46+
<Grid.ColumnDefinitions>
47+
<ColumnDefinition Width="*"/>
48+
<ColumnDefinition Width="Auto"/>
49+
<ColumnDefinition Width="*"/>
50+
</Grid.ColumnDefinitions>
51+
<Label Grid.Column="1" Content="{x:Static pres:Locale_Texts.LicenseContent}"/>
52+
53+
</Grid>
4654
</ScrollViewer>
4755
</Border>
4856

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<UserControl x:Class="AutoHDR.Views.CloseProgramActionView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="clr-namespace:AutoHDR.Views"
7+
xmlns:root="clr-namespace:AutoHDR"
8+
xmlns:pres="clr-namespace:AutoHDR.ProjectResources"
9+
xmlns:prflActns="clr-namespace:AutoHDR.Profiles.Actions"
10+
mc:Ignorable="d"
11+
d:DataContext="{d:DesignInstance Type=prflActns:CloseProgramAction, IsDesignTimeCreatable=False}">
12+
13+
<Grid VerticalAlignment="Top">
14+
<Grid.ColumnDefinitions>
15+
<ColumnDefinition Width="Auto"/>
16+
<ColumnDefinition Width="*"/>
17+
18+
<ColumnDefinition Width="Auto"/>
19+
</Grid.ColumnDefinitions>
20+
<Grid.RowDefinitions>
21+
<RowDefinition Height="Auto"/>
22+
<RowDefinition Height="Auto"/>
23+
</Grid.RowDefinitions>
24+
25+
<Label Grid.Row="0" Grid.Column="0" Margin="5" Content="{x:Static pres:Locale_Texts.ProcessName}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
26+
<Label Grid.Row="1" Grid.Column="0" Margin="5" Content="{x:Static pres:Locale_Texts.ForceKill}" HorizontalAlignment="Left" VerticalAlignment="Top"/>
27+
28+
<TextBox Grid.Row="0" Grid.ColumnSpan="2" Grid.Column="1" Margin="5" Text="{Binding ProcessName}" />
29+
<CheckBox Grid.Row="1" Grid.Column="1" VerticalContentAlignment="Center" HorizontalContentAlignment="Left" IsChecked="{Binding Force, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="5,0,0,0" />
30+
</Grid>
31+
</UserControl>

0 commit comments

Comments
 (0)