Skip to content

Commit

Permalink
Switch to .NET 6.0 (Long Term Support). Fix some errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
EJocys committed Jan 15, 2023
1 parent a2dc94f commit e1fe7d0
Show file tree
Hide file tree
Showing 27 changed files with 2,463 additions and 687 deletions.
470 changes: 277 additions & 193 deletions Cleanup_Solution.ps1

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion FocusLogger/Common/DataItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ public class DataItem : ISettingsItem, INotifyPropertyChanged
public bool IsActive { get => _IsActive; set => SetProperty(ref _IsActive, value); }
bool _IsActive;

public bool IsSame(DataItem item)
public bool NonPath { get => _IsError; set => SetProperty(ref _IsError, value); }
bool _IsError;

public bool IsSame(DataItem item)
{
return
item.ProcessId == ProcessId &&
Expand Down
11 changes: 9 additions & 2 deletions FocusLogger/Controls/DataListControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,17 @@
x:Name="ProcessPathColumn"
Width="Auto"
x:FieldModifier="public"
Binding="{Binding ProcessPath}"
EditingElementStyle="{StaticResource TextBoxCell}"
ElementStyle="{StaticResource TextBlockCell}"
Header="Path" />
Header="Path">
<DataGridTextColumn.Binding>
<MultiBinding Converter="{StaticResource _MainDataGridFormattingConverter}">
<Binding RelativeSource="{RelativeSource Self}" />
<Binding RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="ProcessPath" />
</MultiBinding>
</DataGridTextColumn.Binding>
</DataGridTextColumn>
</DataGrid.Columns>
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
Expand Down
32 changes: 29 additions & 3 deletions FocusLogger/Controls/DataListControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using JocysCom.ClassLibrary.ComponentModel;
using JocysCom.ClassLibrary.Controls;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -29,8 +30,8 @@ object _MainDataGridFormattingConverter_Convert(object[] values, Type targetType
{
var sender = (FrameworkElement)values[0];
var template = (FrameworkElement)values[1];
var cell = (DataGridCell)(template ?? sender).Parent;
var value = values[2];
var cell = (DataGridCell)(template ?? sender).Parent;
var item = (DataItem)cell.DataContext;
if (cell.Column == IsActiveImageColumn)
{
Expand Down Expand Up @@ -61,6 +62,11 @@ object _MainDataGridFormattingConverter_Convert(object[] values, Type targetType
value = string.Format("{0:HH:mm:ss:fff}", item.Date);
cell.Opacity = 0.5;
}
if (cell.Column == ProcessPathColumn)
{
if (item.NonPath)
cell.Opacity = 0.3;
}
// Other.
return value;
}
Expand Down Expand Up @@ -101,9 +107,27 @@ public void UpdateFromProcess(DataItem item)
using (var process = Process.GetProcessById(item.ProcessId))
{
item.ProcessName = process.ProcessName;
if (item.ProcessId == 0)
{
item.ProcessPath = "System Idle Process";
item.NonPath = true;
}
if (item.ProcessId > 0)
{
item.ProcessPath = process.MainModule?.FileName;
try
{
item.ProcessPath = process.MainModule?.FileName;
}
catch (Exception ex)
{
const int E_FAIL = unchecked((int)0x80004005); // -2147467259
item.ProcessPath = $"Error: {ex.Message}";
item.NonPath = true;
// If Win32 Acccess is denied exception, then...
if (ex is Win32Exception && ex.HResult == E_FAIL)
item.ProcessPath += " Run as Administrator";

}
}
}
}
Expand All @@ -123,8 +147,8 @@ private void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
if (MainWindow.IsClosing)
return;
_Timer.Start();
UpdateInfo();
_Timer.Start();
}

DataItem oldActiveItem = new DataItem();
Expand All @@ -144,6 +168,7 @@ public void UpdateInfo()
// Get window which or child window of which receives keyboard input.
var activeHandle = NativeMethods.GetActiveWindow();
var activeItem = GetItemFromHandle(activeHandle, true);
// If active window changed then...
if (!activeItem.IsSame(oldActiveItem))
{
oldActiveItem = activeItem;
Expand All @@ -153,6 +178,7 @@ public void UpdateInfo()
// Get foreground window.
var foregroundHandle = NativeMethods.GetForegroundWindow();
var foregroundItem = GetItemFromHandle(foregroundHandle);
// If foreground window changed then...
if (!foregroundItem.IsSame(oldForegroundItem))
{
oldForegroundItem = foregroundItem;
Expand Down
2 changes: 1 addition & 1 deletion FocusLogger/Documents/Step2_app_sign.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@ECHO OFF
COPY /Y "..\bin\Debug\publish\JocysCom.FocusLogger.exe" "JocysCom.FocusLogger.exe"
COPY /Y "..\bin\Release\publish\JocysCom.FocusLogger.exe" "JocysCom.FocusLogger.exe"
CALL:SIG "JocysCom.FocusLogger.exe"
echo.
pause
Expand Down
10 changes: 7 additions & 3 deletions FocusLogger/JocysCom.FocusLogger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
<Authors>Jocys.com</Authors>
<Company>Jocys.com</Company>
<Product>Focus Logger</Product>
<Description>Find out which process or program is taking the window focus. In game, mouse and keyboard could start temporary stop responding if other program takes the focus. This tools could help to find out which program steals the focus.</Description>
<Description>Find out which process or program is taking the window focus. In game, mouse and keyborad could start temporary stop responding if other program takes the focus. This tools could help to find out which program steals the focus.</Description>
<ApplicationIcon>App.ico</ApplicationIcon>
<Version>1.0.9</Version>
<Version>1.1.6</Version>
<RepositoryUrl>https://github.com/JocysCom/FocusLogger</RepositoryUrl>
<PackageProjectUrl>https://www.jocys.com</PackageProjectUrl>
<Copyright>Copyright © Jocys.com 2021</Copyright>
Expand All @@ -22,6 +22,10 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>embedded</DebugType>
</PropertyGroup>

<ItemGroup>
<None Remove="App.ico" />
<None Remove="Resources\BuildDate.txt" />
Expand Down
18 changes: 18 additions & 0 deletions FocusLogger/JocysCom/ComponentModel/BindingListInvoked.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -115,6 +116,23 @@ protected override void OnAddingNew(AddingNewEventArgs e)
Invoke((Action<AddingNewEventArgs>)base.OnAddingNew, e);
}

//public void FixLeak()
//{
// var flags = BindingFlags.Instance | BindingFlags.NonPublic;
// var fi = GetType().BaseType.BaseType.GetField("onListChanged", flags);
// var d = (Delegate)fi.GetValue(this);
// if (d != null)
// {
// if (d.Target is System.Windows.Data.BindingListCollectionView view)
// {
// view.DetachFromSourceCollection();
// var vfi = view.GetType().BaseType.GetField("_currentItem", flags);
// vfi.SetValue(view, null);
// fi.SetValue(this, null);
// }
// }
//}

#endregion
}
}
31 changes: 15 additions & 16 deletions FocusLogger/JocysCom/Configuration/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace JocysCom.ClassLibrary.Configuration
{
public partial class AssemblyInfo
{

public AssemblyInfo()
{
Assembly =
Expand All @@ -34,13 +33,6 @@ public static AssemblyInfo Entry
}
}

public static string ExpandPath(string path)
{
path = Environment.ExpandEnvironmentVariables(path);
path = JocysCom.ClassLibrary.Text.Helper.Replace(path, Entry, false);
return path;
}

public AssemblyInfo(string strValFile)
{
Assembly = Assembly.LoadFile(strValFile);
Expand Down Expand Up @@ -131,7 +123,10 @@ public string RunMode
get
{
if (_RunMode == null)
_RunMode = SettingsParser.Current.Parse("RunMode", "");
// TODO: Standardize configuration provider XML, JSON, INI, Registry, etc...
// https://docs.microsoft.com/en-us/dotnet/core/extensions/configuration-providers
//_RunMode = SettingsParser.Current.Parse("RunMode", "");
return "";
return _RunMode;
}
}
Expand All @@ -154,7 +149,7 @@ public string GetTitle(bool showBuild = true, bool showRunMode = true, bool show
default: break; // General Availability (GA) - Gold
}
}

var haveRunMode = !string.IsNullOrEmpty(RunMode);
// If run mode is not specified then assume live.
var nonLive = haveRunMode && string.Compare(RunMode, "LIVE", true) != 0;
Expand Down Expand Up @@ -262,7 +257,7 @@ out AnswerCount
/// This means that compiling assemblies under the same conditions (permalink)
/// would produce byte-for-byte equivalent binaries.
/// </remarks>
public static DateTime GetBuildDateTime(string filePath, TimeZoneInfo tzi = null)
public static DateTime GetBuildDateTime(string filePath)
{
// Constants related to the Windows PE file format.
const int PE_HEADER_OFFSET = 60; // 0x3C
Expand Down Expand Up @@ -364,9 +359,11 @@ public string AssemblyPath
{
get
{
string codeBase = Assembly.Location;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
var codeBase = Assembly.Location;
if (string.IsNullOrEmpty(codeBase))
return codeBase;
var uri = new UriBuilder(codeBase);
var path = Uri.UnescapeDataString(uri.Path);
return path;
}
}
Expand Down Expand Up @@ -395,7 +392,9 @@ string GetAttribute<T>(Func<T, string> value) where T : Attribute
: value.Invoke(attribute);
}

public string GetAppDataPath(bool userLevel, string format, params object[] args)


public string GetAppDataPath(bool userLevel = false, string format = "", params object[] args)
{
// Get writable application folder.
var specialFolder = userLevel
Expand All @@ -411,7 +410,7 @@ public string GetAppDataPath(bool userLevel, string format, params object[] args
return path;
}

public FileInfo GetAppDataFile(bool userLevel, string format, params object[] args)
public FileInfo GetAppDataFile(bool userLevel = false, string format = "", params object[] args)
{
var path = GetAppDataPath(userLevel, format, args);
return new FileInfo(path);
Expand Down
Loading

0 comments on commit e1fe7d0

Please sign in to comment.