update database, added unneccery switches

This commit is contained in:
2023-05-14 22:52:02 +03:00
parent 41781f5a13
commit 8c3e643a92
8 changed files with 76 additions and 10 deletions

View File

@@ -2,17 +2,27 @@ using System.Diagnostics;
using System;
using Serilog;
using LiteDB;
using Runas.Properties;
using CommandLine;
namespace Runas
{
class Program
{
public static LiteDatabase data = new (Resources.fu);
static void AddToDB(CLI cli)
{
var dt = cli.runas? data.GetCollection<Prog>("runas") : data.GetCollection<Prog>("justrun");
data.BeginTrans();
Prog prg = new(cli.FileName.Split("\\")[^1].Split(".")[0], cli.FileName, null);
dt.Insert(prg);
data.Commit();
}
public static bool DoRun(string program)
{
Process[] process = Process.GetProcessesByName(program);
Log.Information($"{program}:{process.Length > 0}");
return (process.Length > 0);
return (process.Length > 0 && !program.Contains("autohotkey",StringComparison.OrdinalIgnoreCase));
}
static void RunMe(Prog prog, bool verb = false)
@@ -40,7 +50,6 @@ namespace Runas
}
static void Main(string[] args)
{
var data = new LiteDatabase(@"Resources/fu");
Log.Logger = new LoggerConfiguration().WriteTo.File(
$"{Environment.CurrentDirectory}/Logs/{DateTime.Now:yyyy-MM-dd}.log",
@@ -48,6 +57,12 @@ namespace Runas
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}[{Level: u3}] {Message:lj}{NewLine}",
rollingInterval: RollingInterval.Hour)
.CreateLogger();
if (args.Length > 0)
{
CommandLine.Parser.Default.ParseArguments<CLI>(args).WithParsed(AddToDB);
}
else
{
foreach(var item in data.GetCollection<Prog>("justrun").FindAll()) {
RunMe(item);
}
@@ -55,6 +70,7 @@ namespace Runas
{
RunMe(item, true);
}
}
return;
}
}

View File

@@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2023-05-11T19:02:51.2552640Z;True|2023-05-11T21:49:12.2969130+03:00;False|2023-05-11T21:48:40.4117297+03:00;True|2023-05-11T21:11:39.1970156+03:00;True|2023-05-11T21:02:42.5394263+03:00;False|2023-05-11T20:58:37.6065421+03:00;True|2023-05-11T20:55:06.7668117+03:00;True|2023-05-11T20:54:31.1716996+03:00;False|2023-05-11T20:54:11.4960753+03:00;False|2023-05-11T20:54:01.8520808+03:00;False|2023-05-11T20:53:38.3458613+03:00;True|2023-05-11T20:37:33.5354276+03:00;False|2023-05-11T20:36:12.3336164+03:00;True|2023-05-10T06:20:47.8093947+03:00;True|2023-05-10T06:17:42.4993268+03:00;True|2023-05-10T06:12:44.8925775+03:00;True|2023-05-10T06:09:03.5233096+03:00;True|2023-05-10T06:04:13.8322513+03:00;True|2023-04-15T16:50:27.2494025+03:00;True|2023-04-13T12:15:40.8121486+03:00;True|2023-04-13T12:14:39.0698838+03:00;True|2023-04-13T11:56:25.1667689+03:00;True|2023-01-28T18:03:25.0217787+02:00;True|2023-01-16T23:36:26.1406639+02:00;True|2023-01-16T23:32:30.2672510+02:00;True|2023-01-16T23:23:32.8409530+02:00;True|2023-01-16T23:17:50.9710950+02:00;</History>
<History>True|2023-05-14T19:39:49.2543796Z;True|2023-05-14T19:35:43.0205073+03:00;True|2023-05-14T19:28:27.2649657+03:00;True|2023-05-14T19:12:49.2306386+03:00;True|2023-05-14T19:11:40.8831355+03:00;True|2023-05-11T22:02:51.2552640+03:00;True|2023-05-11T21:49:12.2969130+03:00;False|2023-05-11T21:48:40.4117297+03:00;True|2023-05-11T21:11:39.1970156+03:00;True|2023-05-11T21:02:42.5394263+03:00;False|2023-05-11T20:58:37.6065421+03:00;True|2023-05-11T20:55:06.7668117+03:00;True|2023-05-11T20:54:31.1716996+03:00;False|2023-05-11T20:54:11.4960753+03:00;False|2023-05-11T20:54:01.8520808+03:00;False|2023-05-11T20:53:38.3458613+03:00;True|2023-05-11T20:37:33.5354276+03:00;False|2023-05-11T20:36:12.3336164+03:00;True|2023-05-10T06:20:47.8093947+03:00;True|2023-05-10T06:17:42.4993268+03:00;True|2023-05-10T06:12:44.8925775+03:00;True|2023-05-10T06:09:03.5233096+03:00;True|2023-05-10T06:04:13.8322513+03:00;True|2023-04-15T16:50:27.2494025+03:00;True|2023-04-13T12:15:40.8121486+03:00;True|2023-04-13T12:14:39.0698838+03:00;True|2023-04-13T11:56:25.1667689+03:00;True|2023-01-28T18:03:25.0217787+02:00;True|2023-01-16T23:36:26.1406639+02:00;True|2023-01-16T23:32:30.2672510+02:00;True|2023-01-16T23:23:32.8409530+02:00;True|2023-01-16T23:17:50.9710950+02:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

View File

@@ -10,8 +10,9 @@
namespace Runas.Properties {
using System;
using System.IO;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
@@ -19,7 +20,7 @@ namespace Runas.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
@@ -60,11 +61,22 @@ namespace Runas.Properties {
}
}
/// <summary>
/// Looks up a localized resource of type System.Byte[].
/// </summary>
internal static Stream fu {
get {
var t = ResourceManager.GetObject("fu", resourceCulture);
MemoryStream obj = new MemoryStream((byte[])(t));
return obj;
}
}
/// <summary>
/// Looks up a localized string similar to {
/// &quot;AutoHotKey&quot;: [
/// &quot;C:\\Program Files\\AutoHotkey\\AutoHotkey.exe&quot;,
/// &quot;D:\\Drive\\טוויקים למחשב\\myscript 3.0\\myscript 2.0.ahk&quot;
/// &quot;C:\\Users\\Saret\\Programming\\AHK\\myscript\\myscript 2.0.ahk&quot;
/// ],
/// &quot;Lightshot&quot;: [
/// &quot;C:\\Program Files (x86)\\Skillbrains\\lightshot\\Lightshot.exe&quot;
@@ -74,7 +86,7 @@ namespace Runas.Properties {
/// &quot;C:\\Program Files (x86)\\ASUS\\ATK Package\\ATK Hotkey\\AsusNbKeys.exe&quot;
/// ],
/// &quot;HControl&quot;: [
/// &quot;C:\\Program Files (x86)\\ASUS\ [rest of string was truncated]&quot;;.
/// &quot;C:\\Program Files (x86)\ [rest of string was truncated]&quot;;.
/// </summary>
internal static string progs {
get {

View File

@@ -118,6 +118,9 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="fu" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\fu;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="progs" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\progs.json;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>

View File

@@ -0,0 +1,11 @@
{
"profiles": {
"Profile 1": {
"commandName": "Project"
},
"Profile 2": {
"commandName": "Project",
"commandLineArgs": "-f \"C:\\Program Files (x86)\\WinDirStat\\windirstat.exe\""
}
}
}

View File

@@ -24,11 +24,12 @@
<ItemGroup>
<EmbeddedResource Include="Resources\fu">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="LiteDB" Version="5.0.16" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
@@ -52,6 +53,7 @@
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

View File

@@ -2,6 +2,10 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>C:\Users\Saret\Programming\C#\Runas\Runas\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
<ActiveDebugProfile>Profile 1</ActiveDebugProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Update="Properties\Resources.resx">

18
Runas/cli.cs Normal file
View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommandLine;
namespace Runas
{
internal class CLI
{
[Option('f',"file", Required=false, HelpText="add full name of the file")]
public string FileName { get; set; }
[Option('a', "argm", Required = false, HelpText ="argument for the file")]
public string Arguments { get; set; }
[Option("runas", Default =false,Required =false)]
public bool runas { get; set; }
}
}