From efc0889d788319a38006b0e195a93b63451ba542 Mon Sep 17 00:00:00 2001 From: Cryptic Date: Mon, 18 Jan 2021 22:22:03 -0500 Subject: [PATCH] Cleaned code, Updated .Net Framework and Updated Readme thanks to the contributors jogerj & CrazyOldWizard --- MegaKeep/App.config | 12 +++--- MegaKeep/MegaKeep.cs | 46 +++++++++++------------ MegaKeep/MegaKeep.csproj | 3 +- MegaKeep/Properties/Resources.Designer.cs | 2 +- MegaKeep/Properties/Settings.Designer.cs | 2 +- README.md | 7 ++++ 6 files changed, 40 insertions(+), 32 deletions(-) diff --git a/MegaKeep/App.config b/MegaKeep/App.config index 703ff62..9e40778 100644 --- a/MegaKeep/App.config +++ b/MegaKeep/App.config @@ -1,18 +1,18 @@ - + - -
+ +
- + - + - \ No newline at end of file + diff --git a/MegaKeep/MegaKeep.cs b/MegaKeep/MegaKeep.cs index 3c8151c..86ad5bb 100644 --- a/MegaKeep/MegaKeep.cs +++ b/MegaKeep/MegaKeep.cs @@ -12,24 +12,23 @@ namespace MegaKeep { private string _local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); private string[] commandlineArgs = { }; - public MegaKeep() - { - InitializeComponent(); - } + public MegaKeep(string[] args) { InitializeComponent(); - if (args.Length > 0) + + if (args.Length == 0) + return; + + commandlineArgs = args; + var txtFileIndex = Array.IndexOf(args, "--txtFile") + 1; + var txtFile = args[txtFileIndex]; + + if (File.Exists(txtFile)) { - 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; - } + Properties.Settings.Default.Location = txtFile; + Properties.Settings.Default.Save(); + txtPath.Text = txtFile; } } @@ -40,7 +39,7 @@ namespace MegaKeep // first make sure megacmd is found if (!File.Exists(_local + "\\MEGAcmd\\mega-login.bat")) { - Log("mega-login.bat was not found, please install it to the default dirctory: https://mega.nz/cmd"); + Log("mega-login.bat was not found, please install it to the default directory: https://mega.nz/cmd"); return; } @@ -67,7 +66,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. + + if (commandlineArgs.Contains("--cli")) // if running in cli mode, closes window after running work this.Close(); } @@ -86,7 +86,7 @@ namespace MegaKeep } }; - Log("Logging in to " + user + "..."); + Log("Logging into " + user + "..."); login.Start(); var result = login.StandardOutput.ReadToEnd(); @@ -95,7 +95,7 @@ namespace MegaKeep if (login.HasExited) return result; else - return "Unable to exit the process"; + return "Unable to exit the process"; } private string Logout() @@ -127,7 +127,6 @@ namespace MegaKeep if (res == "Logging out..." + Environment.NewLine) { - // success result = "Success"; break; } @@ -148,6 +147,7 @@ namespace MegaKeep foreach (var line in lines) { var info = line.Split(':'); + // check line format if (info.Length != 2) { @@ -155,6 +155,7 @@ namespace MegaKeep Log("Colon (:) seperator not found. Error: " + line); continue; } + var user = info[0]; var pass = info[1]; @@ -174,7 +175,7 @@ namespace MegaKeep // login was successful Log("Login succeeded. Logging out..."); } - else if (loginResult.Contains("Login failed")) + else if (loginResult.Contains("Failed")) { Log("Failed: " + loginResult); break; // just move on to the next account @@ -234,7 +235,7 @@ namespace MegaKeep private void Log(string txt) { - this.Invoke((MethodInvoker) delegate + this.Invoke((MethodInvoker)delegate { var time = "[" + DateTime.Now.ToString("hh:mm:ss tt") + "] "; @@ -246,9 +247,8 @@ namespace MegaKeep { // if started with arg "--cli" simulate button click in UI if (commandlineArgs.Contains("--cli")) - { btnRun.PerformClick(); - } + txtPath.Text = Properties.Settings.Default.Location; } diff --git a/MegaKeep/MegaKeep.csproj b/MegaKeep/MegaKeep.csproj index c990a28..6a78bdb 100644 --- a/MegaKeep/MegaKeep.csproj +++ b/MegaKeep/MegaKeep.csproj @@ -8,10 +8,11 @@ WinExe MegaKeep MegaKeep - v4.6.2 + v4.7.2 512 true true + AnyCPU diff --git a/MegaKeep/Properties/Resources.Designer.cs b/MegaKeep/Properties/Resources.Designer.cs index e64dd1b..2586048 100644 --- a/MegaKeep/Properties/Resources.Designer.cs +++ b/MegaKeep/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace MegaKeep.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", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { diff --git a/MegaKeep/Properties/Settings.Designer.cs b/MegaKeep/Properties/Settings.Designer.cs index 5ac1b95..1cd4795 100644 --- a/MegaKeep/Properties/Settings.Designer.cs +++ b/MegaKeep/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace MegaKeep.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); diff --git a/README.md b/README.md index 420eeb4..457e779 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,13 @@ You must have MEGAcmd installed and running on your machine. You can download th Create a text file (.txt) of all your mega accounts and passwords in a `user:pass` format with one account per line. Then locate that file and run the program. +## Command Line + +You are also able to start the program via command line. + +`--cli` will auto-click the run button and run whatever file is already loaded +`--txtFile "C:\path\to\txtfile.txt"` will load the text file into the program + ## Contributing When making a pull request, please provide a thorough explanation of what you added/fixed. Suggestions are welcome in the form of issues.