1
0
mirror of https://github.com/xCryptic/MegaKeep.git synced 2024-11-22 01:52:30 +01:00
see README for changes
This commit is contained in:
Cryptic 2019-11-05 19:00:01 -05:00
parent 2a696c57df
commit 8a37cc9fdc
2 changed files with 121 additions and 52 deletions

View File

@ -52,6 +52,77 @@ namespace MegaKeep
await Task.Run(() => Work(lines)); await Task.Run(() => Work(lines));
} }
private string Login(string user, string pass)
{
Process login = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-login.bat",
Arguments = user + " \"" + pass + "\""
}
};
Log("Logging in to " + user + "...");
login.Start();
var result = login.StandardOutput.ReadToEnd();
login.WaitForExit();
if (login.HasExited)
return result;
else
return "Unable to exit the process";
}
private string Logout()
{
Process logout = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-logout.bat"
}
};
// the process doesn't exit, just return failed
var result = "Failed to exit the process";
// 10 attempts to logout
for (var i = 0; i < 10; i++)
{
logout.Start();
logout.WaitForExit();
if (logout.HasExited)
{
var res = logout.StandardOutput.ReadToEnd();
if (res == "Logging out..." + Environment.NewLine)
{
// success
result = "Success";
break;
}
else
{
Log("Unable to log out (Attempt #" + (i + 1) + ")");
result = res;
}
}
}
return result;
}
private void Work(string[] lines) private void Work(string[] lines)
{ {
// loop through every line // loop through every line
@ -61,69 +132,59 @@ namespace MegaKeep
var user = info[0]; var user = info[0];
var pass = info[1]; var pass = info[1];
var restart = false; /* NOTE
* the for loop's purpose is in case the account is already
* logged into mega. this can happen if the user closes out
* of megakeep before the cycle ends or because the user
* is actively using megacmd
*/
Log("Logging in to " + user + "..."); for (var i = 0; i < 2; i++)
Process login = new Process
{ {
StartInfo = var loginResult = Login(user, pass);
if (loginResult == "")
{ {
UseShellExecute = false, // login was successful
RedirectStandardOutput = true, Log("Login succeeded. Logging out...");
RedirectStandardError = true,
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-login.bat",
Arguments = user + " \"" + pass + "\""
} }
}; else if (loginResult.Contains("Login failed"))
login.Start();
var result = login.StandardOutput.ReadToEnd();
login.WaitForExit();
if (login.HasExited)
{
if (result.Contains("Login failed"))
{ {
Log("Failed: " + result); Log("Failed: " + loginResult);
continue; // just move on to the next account break; // just move on to the next account
} }
else if (result.Contains("Already logged in")) else if (loginResult.Contains("Already logged in"))
{ {
Log("Already logged in. Logging out and restarting..."); Log("Already logged in. Logging out...");
restart = true;
} }
}
// wait a sec Thread.Sleep(2000);
Thread.Sleep(1500);
Process logout = new Process var logout = Logout();
{
StartInfo = if (logout == "Success")
{ {
UseShellExecute = false, Log("Logged out");
RedirectStandardOutput = true,
RedirectStandardError = true, Thread.Sleep(2000);
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-logout.bat" // we don't want to login to the same account again
// so we're going to break out of the loop
if (loginResult == "")
break;
} }
}; else
logout.Start();
logout.WaitForExit();
if (logout.HasExited)
Log(logout.StandardOutput.ReadToEnd());
if (restart)
{
this.Invoke((MethodInvoker) delegate
{ {
btnRun.PerformClick(); /* NOTE
}); * I've never had this happen before.
return; * however if this done happen,
* the loop will be ended since there's no
* point in continuing if logging out doesn't work
*/
Log("Unable to logout. Error: " + logout);
return;
}
} }
} }
@ -151,7 +212,7 @@ namespace MegaKeep
{ {
var time = "[" + DateTime.Now.ToString("hh:mm:ss tt") + "] "; var time = "[" + DateTime.Now.ToString("hh:mm:ss tt") + "] ";
txtLog.Text += time + txt + Environment.NewLine; txtLog.AppendText(time + txt + Environment.NewLine);
}); });
} }

View File

@ -1,7 +1,7 @@
MegaKeep MegaKeep
======== ========
![MegaKeep](https://i.imgur.com/jnLYBvm.png) ![MegaKeep](https://i.imgur.com/43lLYFx.png)
This program will allow you to login to all of your mega accounts to avoid deletion due to inactivity. This program will allow you to login to all of your mega accounts to avoid deletion due to inactivity.
@ -22,9 +22,17 @@ When making a pull request, please provide a thorough explanation of what you ad
## Version History ## Version History
v1.0 v1.0
- Initial Release - Initial Release
v1.1 v1.1
- Fixed the UI freezing (via Task) - Fixed the UI freezing (via Task)
- Added timestamps to logging - Added timestamps to logging
- Added log saving - Added log saving
v2.0
- Rewrote the base code for the program
- The program will no longer completely restart if an account is already logged in
- The log now automatically scrolls down with the log instead of jumping to the top