Skip to content

Commit 14a6df5

Browse files
committed
1.2.0
Logging implemented
1 parent 8563499 commit 14a6df5

18 files changed

+232
-57
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ mono_crash.*
2323
[Rr]eleases/
2424
x64/
2525
x86/
26+
Debug_x64/
27+
Debug_x86/
28+
Release_x64/
29+
Release_x86/
2630
[Aa][Rr][Mm]/
2731
[Aa][Rr][Mm]64/
2832
bld/
@@ -351,3 +355,5 @@ MigrationBackup/
351355

352356
# Ionide (cross platform F# VS Code tools) working folder
353357
.ionide/
358+
Source/Debug_x64/de/HDRProfile.resources.dll
359+
Source/Debug_x64/HDRProfile.exe

Source/Debug_x64/HDRProfile.exe

15.5 KB
Binary file not shown.
512 Bytes
Binary file not shown.
12.5 KB
Binary file not shown.

Source/HDRProfile/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<system:String x:Key="DonateLink">https://paypal.me/pools/c/8vksshrMln</system:String>
1414
<system:String x:Key="InfoLink">https://sourceforge.net/projects/hdr-profile</system:String>
15-
<system:String x:Key="Version">1.1.0</system:String>
15+
<system:String x:Key="Version">1.2.0</system:String>
1616
<SolidColorBrush x:Key="ButtonBackground" Color="#FF0086F5"/>
1717
<SolidColorBrush x:Key="AccentColor" Color="#FFFF581A"/>
1818
<SolidColorBrush x:Key="AccentColor2" Color="#4C87B3"/>

Source/HDRProfile/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ protected override void OnStartup(StartupEventArgs e)
2323
if (mutex.WaitOne(TimeSpan.Zero, true))
2424
{
2525
mutex.ReleaseMutex();
26+
2627
}
2728
else
2829
{

Source/HDRProfile/HDRProfile.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<ApplicationManifest>app.manifest</ApplicationManifest>
6161
</PropertyGroup>
6262
<ItemGroup>
63+
<Reference Include="CodectoryCore.Logging">
64+
<HintPath>..\Externals\CodectoryCore.Logging.dll</HintPath>
65+
</Reference>
6366
<Reference Include="CodectoryCore.UI.Wpf, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
6467
<SpecificVersion>False</SpecificVersion>
6568
<HintPath>..\Release\CodectoryCore.UI.Wpf.dll</HintPath>
@@ -87,6 +90,7 @@
8790
<Private>True</Private>
8891
</Reference>
8992
<Reference Include="System.ServiceModel" />
93+
<Reference Include="System.Windows.Forms" />
9094
<Reference Include="System.Windows.Interactivity">
9195
<HintPath>..\Externals\System.Windows.Interactivity.dll</HintPath>
9296
</Reference>

Source/HDRProfile/HDRProfileHandler.cs

Lines changed: 133 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using CodectoryCore.UI.Wpf;
1+
using CodectoryCore.Logging;
2+
using CodectoryCore.UI.Wpf;
23
using Hardcodet.Wpf.TaskbarNotification;
34
using Microsoft.Win32;
45
using System;
@@ -23,9 +24,12 @@ namespace HDRProfile
2324
{
2425
public class HDRProfileHandler : BaseViewModel
2526
{
27+
28+
public static Logs Logs = new Logs($"{System.AppDomain.CurrentDomain.BaseDirectory}HDRProfile.log", "HDRPProfile", true);
29+
2630
Dictionary<ApplicationItem, bool> _lastApplicationStates = new Dictionary<ApplicationItem, bool>();
2731

28-
private string SettingsPath => $"{System.AppDomain.CurrentDomain.BaseDirectory}\\HDRProfile_Settings.xml";
32+
private string SettingsPath => $"{System.AppDomain.CurrentDomain.BaseDirectory}HDRProfile_Settings.xml";
2933
TaskbarIcon TrayMenu;
3034
readonly object _accessLock = new object();
3135

@@ -77,7 +81,7 @@ private void Initialize()
7781
{
7882
if (Initialized)
7983
return;
80-
84+
Logs.Add("Initializing...", false);
8185
ProcessWatcher = new ProcessWatcher();
8286
HDRSwitcherHandler = new HDRController();
8387
LoadSettings();
@@ -86,53 +90,89 @@ private void Initialize()
8690
SwitchTrayIcon(Settings.StartMinimizedToTray);
8791
ShowView = !Settings.StartMinimizedToTray;
8892
Initialized = true;
93+
Logs.Add("Initialized", false);
94+
8995
}
9096
}
9197

9298
private void LoadSettings()
9399
{
100+
Logs.Add("Loading settings..", false);
94101
try
95102
{
96103
Settings = HDRProfileSettings.ReadSettings(SettingsPath);
97104
}
98-
catch (Exception)
105+
catch (Exception ex)
99106
{
107+
Logs.Add("Failed to load settings", false);
108+
Logs.AddException(ex);
100109
Settings = new HDRProfileSettings();
101-
Settings.SaveSettings(SettingsPath);
110+
SaveSettings();
111+
Logs.Add("Created new settings file", false);
112+
102113
}
114+
103115
Settings.ApplicationItems.CollectionChanged += ApplicationItems_CollectionChanged;
104116
settings.PropertyChanged += Settings_PropertyChanged;
117+
Logs.LoggingEnabled = Settings.Logging;
105118
foreach (var application in Settings.ApplicationItems)
106119
{
107120
ProcessWatcher.AddProcess(application);
108121
application.PropertyChanged += ApplicationItem_PropertyChanged;
109122
}
110-
123+
Logs.Add("Settings loaded", false);
111124
}
112125

113126
private void InitializeTrayMenu()
114127
{
115-
TrayMenu = new TaskbarIcon();
116-
TrayMenu.Visibility = Visibility.Hidden;
117-
TrayMenu.ToolTipText = Locale_Texts.HDRProfile;
118-
TrayMenu.Icon = Locale_Texts.Logo;
119-
ContextMenu contextMenu = new ContextMenu();
120-
MenuItem close = new MenuItem()
128+
Logs.Add("Initializing tray menu", false);
129+
try
121130
{
122-
Header = Locale_Texts.Shutdown
123-
};
124-
close.Click += (o, e) => Shutdown();
131+
TrayMenu = new TaskbarIcon();
132+
TrayMenu.Visibility = Visibility.Hidden;
133+
TrayMenu.ToolTipText = Locale_Texts.HDRProfile;
134+
TrayMenu.Icon = Locale_Texts.Logo;
135+
ContextMenu contextMenu = new ContextMenu();
136+
MenuItem close = new MenuItem()
137+
{
138+
Header = Locale_Texts.Shutdown
139+
};
140+
close.Click += (o, e) => Shutdown();
125141

126-
MenuItem open = new MenuItem()
127-
{
128-
Header = Locale_Texts.Open
129-
};
130-
open.Click += (o, e) => SwitchTrayIcon(false);
142+
MenuItem open = new MenuItem()
143+
{
144+
Header = Locale_Texts.Open
145+
};
146+
open.Click += (o, e) => SwitchTrayIcon(false);
147+
148+
149+
MenuItem activateHDR = new MenuItem()
150+
{
151+
Header = Locale_Texts.ActivateHDR
152+
};
153+
activateHDR.Click += (o,e) => HDRController.SetHDR(true);
154+
155+
MenuItem deactivateHDR = new MenuItem()
156+
{
157+
Header = Locale_Texts.DeactivateHDR
158+
};
159+
deactivateHDR.Click += (o, e) => HDRController.SetHDR(false);
131160

132-
contextMenu.Items.Add(open);
133-
contextMenu.Items.Add(close);
134-
TrayMenu.ContextMenu = contextMenu;
135-
TrayMenu.TrayLeftMouseDown += TrayMenu_TrayLeftMouseDown;
161+
contextMenu.Items.Add(open);
162+
contextMenu.Items.Add(activateHDR);
163+
contextMenu.Items.Add(deactivateHDR);
164+
contextMenu.Items.Add(close);
165+
166+
TrayMenu.ContextMenu = contextMenu;
167+
TrayMenu.TrayLeftMouseDown += TrayMenu_TrayLeftMouseDown;
168+
Logs.Add("Tray menu initialized", false);
169+
170+
}
171+
catch (Exception ex)
172+
{
173+
Logs.AddException(ex);
174+
throw ex;
175+
}
136176
}
137177

138178
private void CreateRelayCommands()
@@ -156,14 +196,16 @@ private void Settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
156196
Tools.SetAutoStart(Locale_Texts.HDRProfile, System.Reflection.Assembly.GetEntryAssembly().Location, settings.AutoStart);
157197
if (e.PropertyName.Equals(nameof(Settings.HDRMode)))
158198
UpdateHDRMode();
159-
Settings.SaveSettings(SettingsPath);
199+
Logs.LoggingEnabled = Settings.Logging;
200+
SaveSettings();
160201
}
161202
}
162203

163204

164205

165206
private void TrayMenu_TrayLeftMouseDown(object sender, RoutedEventArgs e)
166207
{
208+
Logs.Add("Open app from Tray", false);
167209
SwitchTrayIcon(false);
168210
ShowView = true;
169211

@@ -172,14 +214,23 @@ private void TrayMenu_TrayLeftMouseDown(object sender, RoutedEventArgs e)
172214

173215
private void StartApplication(ApplicationItem application)
174216
{
175-
HDRController.SetHDR(true);
176-
System.Threading.Thread.Sleep(3000);
177-
Process process = new Process();
178-
process.StartInfo = new ProcessStartInfo(application.ApplicationFilePath);
179-
process.Start();
180-
Stopwatch stopwatch = new Stopwatch();
181-
stopwatch.Start();
182-
System.Threading.Thread.Sleep(3000);
217+
Logs.Add($"Start application {application.ApplicationName}", false);
218+
try
219+
{
220+
HDRController.SetHDR(true);
221+
System.Threading.Thread.Sleep(3000);
222+
Process process = new Process();
223+
process.StartInfo = new ProcessStartInfo(application.ApplicationFilePath);
224+
process.Start();
225+
Stopwatch stopwatch = new Stopwatch();
226+
stopwatch.Start();
227+
System.Threading.Thread.Sleep(3000);
228+
}
229+
catch (Exception ex)
230+
{
231+
Logs.AddException(ex);
232+
throw ex;
233+
}
183234
}
184235

185236

@@ -191,10 +242,12 @@ private void Closing()
191242
{
192243
if (Settings.CloseToTray)
193244
{
245+
Logs.Add($"Minimizing to tray...", false);
194246
SwitchTrayIcon(true);
195247
}
196248
else
197249
{
250+
Logs.Add($"Shutting down...", false);
198251
Shutdown();
199252
}
200253
}
@@ -208,31 +261,36 @@ private void Shutdown()
208261

209262
public void Start()
210263
{
211-
if (Started)
212-
return;
213264
lock (_accessLock)
214265
{
266+
if (Started)
267+
return;
268+
Logs.Add($"Starting process watcher...", false);
215269
ProcessWatcher.OneProcessIsRunningChanged += ProcessWatcher_RunningOrFocusedChanged;
216270
ProcessWatcher.OneProcessIsFocusedChanged += ProcessWatcher_RunningOrFocusedChanged;
217-
218271
Started = true;
219272
ProcessWatcher.Start();
273+
Logs.Add($"Process watcher started", false);
274+
220275
}
221276
}
222277

223278
public void Stop()
224279
{
225-
if (!Started)
226-
return;
227280
lock (_accessLock)
228281
{
282+
if (!Started)
283+
return;
284+
Logs.Add($"Stopping process watcher...", false);
229285

230286
ProcessWatcher.OneProcessIsRunningChanged -= ProcessWatcher_RunningOrFocusedChanged;
231287
ProcessWatcher.OneProcessIsFocusedChanged -= ProcessWatcher_RunningOrFocusedChanged;
232288

233289
ProcessWatcher.Stop();
234290
HDRSwitcherHandler.DeactivateHDR();
235291
Started = false;
292+
Logs.Add($"Process watcher stopped", false);
293+
236294
}
237295

238296
}
@@ -253,6 +311,7 @@ private void ApplicationItems_CollectionChanged(object sender, NotifyCollectionC
253311
case NotifyCollectionChangedAction.Add:
254312
foreach (var applicationItem in e.NewItems)
255313
{
314+
Logs.Add($"Application added: {((ApplicationItem)applicationItem).ApplicationName}", false);
256315
ProcessWatcher.AddProcess(((ApplicationItem)applicationItem));
257316
((ApplicationItem)applicationItem).PropertyChanged += ApplicationItem_PropertyChanged;
258317
}
@@ -261,20 +320,37 @@ private void ApplicationItems_CollectionChanged(object sender, NotifyCollectionC
261320
case NotifyCollectionChangedAction.Remove:
262321
foreach (var applicationItem in e.OldItems)
263322
{
323+
Logs.Add($"Application removed: {((ApplicationItem)applicationItem).ApplicationName}", false);
264324
ProcessWatcher.RemoveProcess(((ApplicationItem)applicationItem));
265325
((ApplicationItem)applicationItem).PropertyChanged -= ApplicationItem_PropertyChanged;
266326

267327
}
268328
break;
269329

270330
}
331+
332+
SaveSettings();
333+
}
334+
}
335+
336+
private void SaveSettings()
337+
{
338+
Logs.Add("Saving settings..", false);
339+
try
340+
{
271341
Settings.SaveSettings(SettingsPath);
342+
Logs.Add("Settings saved", false);
343+
272344
}
345+
catch (Exception ex)
346+
{
347+
Logs.AddException(ex);
348+
}
273349
}
274350

275351
private void ApplicationItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
276352
{
277-
Settings.SaveSettings(SettingsPath);
353+
SaveSettings();
278354
}
279355

280356
private void AddAplication()
@@ -306,13 +382,25 @@ private void UpdateHDRMode()
306382
{
307383
lock (_accessLock)
308384
{
309-
if ((Settings.HDRMode == HDRMode.Running && ProcessWatcher.OneProcessIsRunning) || Settings.HDRMode == HDRMode.Focused && ProcessWatcher.OneProcessIsFocused)
385+
try
386+
{
387+
Logs.Add($"Updating HDR mode to {Settings.HDRMode}...", false);
388+
389+
if ((Settings.HDRMode == HDRMode.Running && ProcessWatcher.OneProcessIsRunning) || Settings.HDRMode == HDRMode.Focused && ProcessWatcher.OneProcessIsFocused)
390+
{
391+
HDRSwitcherHandler.ActivateHDR();
392+
CheckIfRestartIsNecessary((IDictionary<ApplicationItem, bool>)ProcessWatcher.Applications);
393+
}
394+
else if (Settings.HDRMode != HDRMode.None)
395+
HDRSwitcherHandler.DeactivateHDR();
396+
Logs.Add($"HDR mode updated to {Settings.HDRMode}", false);
397+
398+
}
399+
catch (Exception ex)
310400
{
311-
HDRSwitcherHandler.ActivateHDR();
312-
CheckIfRestartIsNecessary((IDictionary<ApplicationItem, bool>)ProcessWatcher.Applications);
401+
Logs.AddException(ex);
402+
throw ex;
313403
}
314-
else if (Settings.HDRMode != HDRMode.None)
315-
HDRSwitcherHandler.DeactivateHDR();
316404
}
317405
}
318406

@@ -330,13 +418,13 @@ private void CheckIfRestartIsNecessary(IDictionary<ApplicationItem, bool> applic
330418
else if (_lastApplicationStates.ContainsKey(applicationState.Key) && applicationState.Value && !_lastApplicationStates[applicationState.Key])
331419
RestartProcess(applicationState.Key);
332420
}
333-
334421
_lastApplicationStates.Clear();
335422
_lastApplicationStates = newLastStates;
336423
}
337424

338425
private void RestartProcess(ApplicationItem application)
339426
{
427+
Logs.Add($"Restarting application {application.ApplicationName}", false);
340428
Process.GetProcessesByName(application.ApplicationName).ToList().ForEach(p => p.Kill());
341429
Process proc = new Process();
342430
StartApplication(application);

Source/HDRProfile/HDRProfileHandlerView.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
<RowDefinition />
8383
<RowDefinition Height="30"/>
8484
</Grid.RowDefinitions>
85-
<local:HDRProfileSettingsView Grid.Row="0" DataContext="{Binding ElementName=MainWindow , Path=DataContext.Settings}" Margin="10,10,10,0" Grid.Column="0" Grid.ColumnSpan="4" VerticalAlignment="Top" Height="107"/>
85+
<local:HDRProfileSettingsView Grid.Row="0" DataContext="{Binding ElementName=MainWindow , Path=DataContext.Settings}" Margin="10" Grid.Column="0" Grid.ColumnSpan="4"/>
8686

8787
<Button Grid.Column="3" Grid.Row="1" Content="{x:Static local:Locale_Texts.Shutdown}" Command="{Binding ShutdownCommand}" Margin="5,5,10,5" RenderTransformOrigin="0.914,0.566" HorizontalAlignment="Right" Width="113" Height="20" VerticalAlignment="Bottom"/>
8888
<TextBlock Text="{Binding Mode=OneWay, Source={StaticResource Version}, StringFormat= V\{0\} }" Width="Auto" Margin="10,5,5,5" Grid.Row="1" Grid.Column="0" Height="13" HorizontalAlignment="Right" />

0 commit comments

Comments
 (0)