mirror of
https://github.com/xCryptic/MegaKeep.git
synced 2024-11-22 01:52:30 +01:00
Added ability to run via command line with arguments "--cli" and can set file path with "--txtFile" #5 (#6)
This commit is contained in:
parent
10a4d09007
commit
b76965bf63
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
@ -10,11 +11,27 @@ namespace MegaKeep
|
||||
public partial class MegaKeep : Form
|
||||
{
|
||||
private string _local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
||||
|
||||
private string[] commandlineArgs = { };
|
||||
public MegaKeep()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
public MegaKeep(string[] args)
|
||||
{
|
||||
InitializeComponent();
|
||||
if (args.Length > 0)
|
||||
{
|
||||
commandlineArgs = args;
|
||||
var txtFileIndex = Array.IndexOf(args, "--txtFile") + 1;
|
||||
var txtFile = args[txtFileIndex];
|
||||
if (File.Exists(txtFile))
|
||||
{
|
||||
Properties.Settings.Default.Location = txtFile;
|
||||
Properties.Settings.Default.Save();
|
||||
txtPath.Text = txtFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void btnRun_ClickAsync(object sender, EventArgs e)
|
||||
{
|
||||
@ -50,6 +67,8 @@ namespace MegaKeep
|
||||
|
||||
// run the processes in a task so it doesn't freeze the ui
|
||||
await Task.Run(() => Work(lines));
|
||||
if (commandlineArgs.Contains("--cli"))// if running in cli mode, closes window after running work.
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private string Login(string user, string pass)
|
||||
@ -225,6 +244,11 @@ namespace MegaKeep
|
||||
|
||||
private void MegaKeep_Load(object sender, EventArgs e)
|
||||
{
|
||||
// if started with arg "--cli" simulate button click in UI
|
||||
if (commandlineArgs.Contains("--cli"))
|
||||
{
|
||||
btnRun.PerformClick();
|
||||
}
|
||||
txtPath.Text = Properties.Settings.Default.Location;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MegaKeep
|
||||
@ -9,11 +10,31 @@ namespace MegaKeep
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new MegaKeep());
|
||||
CommandArgs(args);
|
||||
Application.Run(new MegaKeep(args)); //passes args to new start method
|
||||
}
|
||||
|
||||
// sets the path to the text file passed via command line.
|
||||
static void CommandArgs(string[] args)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
{
|
||||
var txtFileIndex = Array.IndexOf(args, "--txtFile") + 1;
|
||||
if(args[txtFileIndex] != null)
|
||||
{
|
||||
var txtFile = args[txtFileIndex];
|
||||
if (File.Exists(txtFile))
|
||||
{
|
||||
Properties.Settings.Default.Location = txtFile;
|
||||
Properties.Settings.Default.Save();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user