mirror of
https://github.com/xCryptic/MegaKeep.git
synced 2024-11-22 01:52:30 +01:00
v2
see README for changes
This commit is contained in:
parent
2a696c57df
commit
8a37cc9fdc
@ -52,19 +52,8 @@ namespace MegaKeep
|
|||||||
await Task.Run(() => Work(lines));
|
await Task.Run(() => Work(lines));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Work(string[] lines)
|
private string Login(string user, string pass)
|
||||||
{
|
{
|
||||||
// loop through every line
|
|
||||||
foreach (var line in lines)
|
|
||||||
{
|
|
||||||
var info = line.Split(':');
|
|
||||||
var user = info[0];
|
|
||||||
var pass = info[1];
|
|
||||||
|
|
||||||
var restart = false;
|
|
||||||
|
|
||||||
Log("Logging in to " + user + "...");
|
|
||||||
|
|
||||||
Process login = new Process
|
Process login = new Process
|
||||||
{
|
{
|
||||||
StartInfo =
|
StartInfo =
|
||||||
@ -78,27 +67,20 @@ namespace MegaKeep
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Log("Logging in to " + user + "...");
|
||||||
|
|
||||||
login.Start();
|
login.Start();
|
||||||
var result = login.StandardOutput.ReadToEnd();
|
var result = login.StandardOutput.ReadToEnd();
|
||||||
login.WaitForExit();
|
login.WaitForExit();
|
||||||
|
|
||||||
if (login.HasExited)
|
if (login.HasExited)
|
||||||
{
|
return result;
|
||||||
if (result.Contains("Login failed"))
|
else
|
||||||
{
|
return "Unable to exit the process";
|
||||||
Log("Failed: " + result);
|
|
||||||
continue; // just move on to the next account
|
|
||||||
}
|
|
||||||
else if (result.Contains("Already logged in"))
|
|
||||||
{
|
|
||||||
Log("Already logged in. Logging out and restarting...");
|
|
||||||
restart = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait a sec
|
private string Logout()
|
||||||
Thread.Sleep(1500);
|
{
|
||||||
|
|
||||||
Process logout = new Process
|
Process logout = new Process
|
||||||
{
|
{
|
||||||
StartInfo =
|
StartInfo =
|
||||||
@ -111,21 +93,100 @@ namespace MegaKeep
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 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.Start();
|
||||||
logout.WaitForExit();
|
logout.WaitForExit();
|
||||||
|
|
||||||
if (logout.HasExited)
|
if (logout.HasExited)
|
||||||
Log(logout.StandardOutput.ReadToEnd());
|
{
|
||||||
|
var res = logout.StandardOutput.ReadToEnd();
|
||||||
|
|
||||||
if (restart)
|
if (res == "Logging out..." + Environment.NewLine)
|
||||||
{
|
{
|
||||||
this.Invoke((MethodInvoker) delegate
|
// success
|
||||||
|
result = "Success";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
btnRun.PerformClick();
|
Log("Unable to log out (Attempt #" + (i + 1) + ")");
|
||||||
});
|
result = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Work(string[] lines)
|
||||||
|
{
|
||||||
|
// loop through every line
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
var info = line.Split(':');
|
||||||
|
var user = info[0];
|
||||||
|
var pass = info[1];
|
||||||
|
|
||||||
|
/* 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
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (var i = 0; i < 2; i++)
|
||||||
|
{
|
||||||
|
var loginResult = Login(user, pass);
|
||||||
|
|
||||||
|
if (loginResult == "")
|
||||||
|
{
|
||||||
|
// login was successful
|
||||||
|
Log("Login succeeded. Logging out...");
|
||||||
|
}
|
||||||
|
else if (loginResult.Contains("Login failed"))
|
||||||
|
{
|
||||||
|
Log("Failed: " + loginResult);
|
||||||
|
break; // just move on to the next account
|
||||||
|
}
|
||||||
|
else if (loginResult.Contains("Already logged in"))
|
||||||
|
{
|
||||||
|
Log("Already logged in. Logging out...");
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
|
var logout = Logout();
|
||||||
|
|
||||||
|
if (logout == "Success")
|
||||||
|
{
|
||||||
|
Log("Logged out");
|
||||||
|
|
||||||
|
Thread.Sleep(2000);
|
||||||
|
|
||||||
|
// 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
|
||||||
|
{
|
||||||
|
/* NOTE
|
||||||
|
* I've never had this happen before.
|
||||||
|
* 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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log("Finished");
|
Log("Finished");
|
||||||
File.WriteAllLines(Environment.CurrentDirectory + "\\" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-log.txt", txtLog.Lines);
|
File.WriteAllLines(Environment.CurrentDirectory + "\\" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-log.txt", txtLog.Lines);
|
||||||
@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
README.md
10
README.md
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user