Skip to content

Commit

Permalink
Inital Release
Browse files Browse the repository at this point in the history
  • Loading branch information
maybecryptic committed May 30, 2019
1 parent 7d808de commit d89798e
Show file tree
Hide file tree
Showing 15 changed files with 3,112 additions and 2 deletions.
25 changes: 25 additions & 0 deletions MegaKeep.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.489
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MegaKeep", "MegaKeep\MegaKeep.csproj", "{B6BF9080-54BD-458E-A302-5AFD20A385EF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2A488EE8-A60F-44C9-81C7-603260A509BD}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions MegaKeep/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="MegaKeep.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<userSettings>
<MegaKeep.Properties.Settings>
<setting name="Location" serializeAs="String">
<value />
</setting>
</MegaKeep.Properties.Settings>
</userSettings>
</configuration>
143 changes: 143 additions & 0 deletions MegaKeep/MegaKeep.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 153 additions & 0 deletions MegaKeep/MegaKeep.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows.Forms;

namespace MegaKeep
{
public partial class MegaKeep : Form
{
private string _local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

public MegaKeep()
{
InitializeComponent();
}

private void btnRun_Click(object sender, EventArgs e)
{
txtLog.Clear();

// 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");
return;
}

// then check to make sure the file exists
if (!File.Exists(txtPath.Text))
{
MessageBox.Show("The file could not be found");
return;
}

Log("Loading file...");

// then try to read the text file's contents
string[] lines;
try
{
lines = File.ReadAllLines(txtPath.Text);
}
catch (Exception ex)
{
Log("Error: " + ex.ToString());
return;
}

// 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
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-login.bat",
Arguments = user + " \"" + pass + "\""
}
};

login.Start();
var result = login.StandardOutput.ReadToEnd();
login.WaitForExit();

if (login.HasExited)
{
if (result.Contains("Login failed"))
{
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
Thread.Sleep(1500);

Process logout = new Process
{
StartInfo =
{
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
FileName = _local + "\\MEGAcmd\\mega-logout.bat"
}
};

logout.Start();
logout.WaitForExit();

if (logout.HasExited)
Log(logout.StandardOutput.ReadToEnd());

if (restart)
{
btnRun.PerformClick();
return;
}
}

Log("Finished");
}

private void btnLocate_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();

openFile.Multiselect = false;
openFile.Title = "Mega Keepalive";
openFile.Filter = "Text Files (*.txt)|*.txt";

if (openFile.ShowDialog() == DialogResult.OK)
{
txtPath.Text = openFile.FileName;
}
}

private void Log(string txt)
{
txtLog.Text += txt + Environment.NewLine;
}

private void MegaKeep_Load(object sender, EventArgs e)
{
txtPath.Text = Properties.Settings.Default.Location;
}

private void txtPath_TextChanged(object sender, EventArgs e)
{
Properties.Settings.Default.Location = txtPath.Text;
Properties.Settings.Default.Save();
}
}
}
Loading

0 comments on commit d89798e

Please sign in to comment.