Skip to content

Commit d89798e

Browse files
committed
Inital Release
1 parent 7d808de commit d89798e

15 files changed

Lines changed: 3112 additions & 2 deletions

MegaKeep.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.28307.489
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MegaKeep", "MegaKeep\MegaKeep.csproj", "{B6BF9080-54BD-458E-A302-5AFD20A385EF}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{B6BF9080-54BD-458E-A302-5AFD20A385EF}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {2A488EE8-A60F-44C9-81C7-603260A509BD}
24+
EndGlobalSection
25+
EndGlobal

MegaKeep/App.config

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
5+
<section name="MegaKeep.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
6+
</sectionGroup>
7+
</configSections>
8+
<startup>
9+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
10+
</startup>
11+
<userSettings>
12+
<MegaKeep.Properties.Settings>
13+
<setting name="Location" serializeAs="String">
14+
<value />
15+
</setting>
16+
</MegaKeep.Properties.Settings>
17+
</userSettings>
18+
</configuration>

MegaKeep/MegaKeep.Designer.cs

Lines changed: 143 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MegaKeep/MegaKeep.cs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Threading;
5+
using System.Windows.Forms;
6+
7+
namespace MegaKeep
8+
{
9+
public partial class MegaKeep : Form
10+
{
11+
private string _local = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
12+
13+
public MegaKeep()
14+
{
15+
InitializeComponent();
16+
}
17+
18+
private void btnRun_Click(object sender, EventArgs e)
19+
{
20+
txtLog.Clear();
21+
22+
// first make sure megacmd is found
23+
if (!File.Exists(_local + "\\MEGAcmd\\mega-login.bat"))
24+
{
25+
Log("mega-login.bat was not found, please install it to the default dirctory: https://mega.nz/cmd");
26+
return;
27+
}
28+
29+
// then check to make sure the file exists
30+
if (!File.Exists(txtPath.Text))
31+
{
32+
MessageBox.Show("The file could not be found");
33+
return;
34+
}
35+
36+
Log("Loading file...");
37+
38+
// then try to read the text file's contents
39+
string[] lines;
40+
try
41+
{
42+
lines = File.ReadAllLines(txtPath.Text);
43+
}
44+
catch (Exception ex)
45+
{
46+
Log("Error: " + ex.ToString());
47+
return;
48+
}
49+
50+
// loop through every line
51+
foreach (var line in lines)
52+
{
53+
var info = line.Split(':');
54+
var user = info[0];
55+
var pass = info[1];
56+
57+
var restart = false;
58+
59+
Log("Logging in to " + user + "...");
60+
61+
Process login = new Process
62+
{
63+
StartInfo =
64+
{
65+
UseShellExecute = false,
66+
RedirectStandardOutput = true,
67+
RedirectStandardError = true,
68+
CreateNoWindow = true,
69+
FileName = _local + "\\MEGAcmd\\mega-login.bat",
70+
Arguments = user + " \"" + pass + "\""
71+
}
72+
};
73+
74+
login.Start();
75+
var result = login.StandardOutput.ReadToEnd();
76+
login.WaitForExit();
77+
78+
if (login.HasExited)
79+
{
80+
if (result.Contains("Login failed"))
81+
{
82+
Log("Failed: " + result);
83+
continue; // just move on to the next account
84+
}
85+
else if (result.Contains("Already logged in"))
86+
{
87+
Log("Already logged in. Logging out and restarting...");
88+
restart = true;
89+
}
90+
}
91+
92+
// wait a sec
93+
Thread.Sleep(1500);
94+
95+
Process logout = new Process
96+
{
97+
StartInfo =
98+
{
99+
UseShellExecute = false,
100+
RedirectStandardOutput = true,
101+
RedirectStandardError = true,
102+
CreateNoWindow = true,
103+
FileName = _local + "\\MEGAcmd\\mega-logout.bat"
104+
}
105+
};
106+
107+
logout.Start();
108+
logout.WaitForExit();
109+
110+
if (logout.HasExited)
111+
Log(logout.StandardOutput.ReadToEnd());
112+
113+
if (restart)
114+
{
115+
btnRun.PerformClick();
116+
return;
117+
}
118+
}
119+
120+
Log("Finished");
121+
}
122+
123+
private void btnLocate_Click(object sender, EventArgs e)
124+
{
125+
OpenFileDialog openFile = new OpenFileDialog();
126+
127+
openFile.Multiselect = false;
128+
openFile.Title = "Mega Keepalive";
129+
openFile.Filter = "Text Files (*.txt)|*.txt";
130+
131+
if (openFile.ShowDialog() == DialogResult.OK)
132+
{
133+
txtPath.Text = openFile.FileName;
134+
}
135+
}
136+
137+
private void Log(string txt)
138+
{
139+
txtLog.Text += txt + Environment.NewLine;
140+
}
141+
142+
private void MegaKeep_Load(object sender, EventArgs e)
143+
{
144+
txtPath.Text = Properties.Settings.Default.Location;
145+
}
146+
147+
private void txtPath_TextChanged(object sender, EventArgs e)
148+
{
149+
Properties.Settings.Default.Location = txtPath.Text;
150+
Properties.Settings.Default.Save();
151+
}
152+
}
153+
}

0 commit comments

Comments
 (0)