Modules - Added activation mechanism and conditions

This commit is contained in:
SpoinkyNL committed 2020-08-16 23:44:59 +02:00
1 parent 12456519d5
commit 6a32ecc3a4
17 files changed
+357 -149

No files matched your search

@@ -1,4 +1,5 @@
using System.Diagnostics;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract.DataModels.Attributes;
using Artemis.Plugins.Modules.General.Utilities;
@@ -16,7 +17,7 @@ namespace Artemis.Plugins.Modules.General.DataModel.Windows
ProcessName = process.ProcessName;
// Accessing MainModule requires admin privileges, this way does not
ProgramLocation = WindowUtilities.GetProcessFilename(process);
ProgramLocation = process.GetProcessFilename();
}
public string WindowTitle { get; set; }
@@ -12,9 +12,28 @@ namespace Artemis.Plugins.Modules.General
{
public class GeneralModule : ProfileModule<GeneralDataModel>
{
public override IEnumerable<ModuleViewModel> GetViewModels()
public override void EnablePlugin()
{
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsDataModel = true;
DataModel.TestTimeList.Add(new TimeDataModel { CurrentTime = DateTime.Now.AddDays(1), CurrentTimeUTC = DateTime.UtcNow.AddDays(1) });
DataModel.TestTimeList.Add(new TimeDataModel { CurrentTime = DateTime.Now.AddDays(2), CurrentTimeUTC = DateTime.UtcNow.AddDays(2) });
DataModel.TestTimeList.Add(new TimeDataModel { CurrentTime = DateTime.Now.AddDays(3), CurrentTimeUTC = DateTime.UtcNow.AddDays(3) });
DataModel.TestTimeList.Add(new TimeDataModel { CurrentTime = DateTime.Now.AddDays(4), CurrentTimeUTC = DateTime.UtcNow.AddDays(4) });
}
public override void DisablePlugin()
{
}
public override void ModuleActivated()
{
}
public override void ModuleDeactivated()
{
return new List<ModuleViewModel> {new GeneralViewModel(this)};
}
public override void Update(double deltaTime)
@@ -26,20 +45,9 @@ namespace Artemis.Plugins.Modules.General
base.Update(deltaTime);
}
public override void EnablePlugin()
{
DisplayName = "General";
DisplayIcon = "AllInclusive";
ExpandsDataModel = true;
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(1), CurrentTimeUTC = DateTime.UtcNow.AddDays(1)});
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(2), CurrentTimeUTC = DateTime.UtcNow.AddDays(2)});
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(3), CurrentTimeUTC = DateTime.UtcNow.AddDays(3)});
DataModel.TestTimeList.Add(new TimeDataModel {CurrentTime = DateTime.Now.AddDays(4), CurrentTimeUTC = DateTime.UtcNow.AddDays(4)});
}
public override void DisablePlugin()
public override IEnumerable<ModuleViewModel> GetViewModels()
{
return new List<ModuleViewModel> { new GeneralViewModel(this) };
}
#region Open windows
@@ -1,7 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
namespace Artemis.Plugins.Modules.General.Utilities
{
@@ -14,33 +12,11 @@ namespace Artemis.Plugins.Modules.General.Utilities
return (int) processId;
}
public static string GetProcessFilename(Process p)
{
var capacity = 2000;
var builder = new StringBuilder(capacity);
var ptr = OpenProcess(ProcessAccessFlags.QueryLimitedInformation, false, p.Id);
if (!QueryFullProcessImageName(ptr, 0, builder, ref capacity)) return string.Empty;
return builder.ToString();
}
[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("kernel32.dll")]
private static extern bool QueryFullProcessImageName([In] IntPtr hProcess, [In] int dwFlags, [Out] StringBuilder lpExeName, ref int lpdwSize);
[DllImport("kernel32.dll")]
private static extern IntPtr OpenProcess(ProcessAccessFlags processAccess, bool bInheritHandle, int processId);
[Flags]
private enum ProcessAccessFlags : uint
{
QueryLimitedInformation = 0x00001000
}
}
}