update database, added unneccery switches
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user