Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Now you can enter your login/password or anything ASF requires to ope…
Browse files Browse the repository at this point in the history
…rate correctly. v0.3
  • Loading branch information
alvr committed Jun 25, 2016
1 parent 74b26a5 commit 048eb81
Show file tree
Hide file tree
Showing 14 changed files with 383 additions and 95 deletions.
106 changes: 106 additions & 0 deletions ASFui/ASFProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.VisualBasic;

namespace ASFui
{
[SuppressMessage("ReSharper", "InconsistentNaming")]
public class ASFProcess
{
private Process ASF;
private readonly RichTextBox output;
private Thread outputThread;

public ASFProcess(RichTextBox rtb)
{
ASF = new Process();
output = rtb;

var ASFInfo = new ProcessStartInfo()
{
Arguments = "--server",
CreateNoWindow = true,
Domain = "",
FileName = Properties.Settings.Default.ASFBinary,
LoadUserProfile = false,
Password = null,
RedirectStandardError = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
StandardErrorEncoding = Encoding.UTF8,
StandardOutputEncoding = Encoding.UTF8,
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden
};

ASF.StartInfo = ASFInfo;
}

private void PrintOutput()
{
var sb = new StringBuilder();
int s;
while ((s = ASF.StandardOutput.Read()) != 0)
{
sb.Append(Convert.ToChar(s));
if(s == '\n')
{
output.AppendText(sb.ToString());
output.SelectionStart = output.Text.Length;
output.ScrollToCaret();
sb.Clear();
}

if (sb.ToString().EndsWith("\"android:\"):") || sb.ToString().EndsWith("login:") ||
sb.ToString().EndsWith("+1234567890):") || sb.ToString().EndsWith("mobile:") ||
sb.ToString().EndsWith("email:") || sb.ToString().EndsWith("PIN:") ||
sb.ToString().EndsWith("app:") || sb.ToString().EndsWith("hostname:"))
{
output.AppendText(sb + " ");
var result = Interaction.InputBox(sb.ToString(), @"Enter necessary input");
ASF.StandardInput.WriteLine(result);
ASF.StandardInput.Flush();
output.AppendText(result + Environment.NewLine);
sb.Clear();
}
else if(sb.ToString().EndsWith("password:"))
{
var Password = new Password(ASF, sb.ToString());
Password.ShowDialog();
sb.Clear();
}
}
}

public void Start()
{
ASF.Start();
outputThread = new Thread(PrintOutput);
outputThread.Start();
}

public void Stop()
{
if (ASF == null)
{
return;
}

if (ASF.HasExited)
{
ASF.Close();
}
else
{
ASF.Kill();
}

outputThread.Abort();
ASF = null;
}
}
}
29 changes: 0 additions & 29 deletions ASFui/ASFui.Designer.cs

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

44 changes: 12 additions & 32 deletions ASFui/ASFui.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
Expand All @@ -11,6 +10,7 @@ namespace ASFui
public partial class ASFui : Form
{
private bool _asfRunning;
private ASFProcess _asf;

public ASFui()
{
Expand All @@ -37,7 +37,6 @@ public ASFui()
Environment.Exit(-2);
}
InitializeComponent();
ASFProcess.StartInfo.FileName = Properties.Settings.Default.ASFBinary;
}

private void ASFui_Resize(object sender, EventArgs e)
Expand All @@ -50,33 +49,9 @@ private void ASFui_Resize(object sender, EventArgs e)
private void ASFui_FormClosing(object sender, FormClosingEventArgs e)
{
if (!_asfRunning || !Properties.Settings.Default.IsLocal) return;
ASFProcess.Kill();
ASFProcess.CancelOutputRead();
BackgroundWorker.CancelAsync();
_asf.Stop();
}

private void BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
if (!Properties.Settings.Default.IsLocal) return;
ASFProcess.Start();
ASFProcess.BeginOutputReadLine();
ASFProcess.WaitForExit();
}

private void ASFProcess_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
rtbOutput.AppendText(e.Data + Environment.NewLine);
rtbOutput.SelectionStart = rtbOutput.Text.Length;
rtbOutput.ScrollToCaret();
}

private void ASFProcess_ErrorDataReceived(object sender, DataReceivedEventArgs e)
{
rtbOutput.AppendText(e.Data + Environment.NewLine);
rtbOutput.SelectionStart = rtbOutput.Text.Length;
rtbOutput.ScrollToCaret();
}


private void GetBotList()
{
cbBotList.Items.Clear();
Expand All @@ -98,7 +73,11 @@ private void BtnStart_Click(object sender, EventArgs e)
{
btnStart.Enabled = false;
rtbOutput.AppendText(@"Starting ASF..." + Environment.NewLine);
BackgroundWorker.RunWorkerAsync();
if (Properties.Settings.Default.IsLocal)
{
_asf = new ASFProcess(rtbOutput);
_asf.Start();
}
btnStop.Enabled = true;
btnClear.Enabled = true;
cbBotList.Enabled = true;
Expand All @@ -114,9 +93,10 @@ private void BtnStop_Click(object sender, EventArgs e)
{
btnStop.Enabled = false;
rtbOutput.AppendText("Stopping ASF..." + Environment.NewLine);
BackgroundWorker.CancelAsync();
Util.SendCommand("exit");
ASFProcess.CancelOutputRead();
if (Properties.Settings.Default.IsLocal)
{
_asf.Stop();
}
DisableElements();
tsslCommandOutput.Text = @"Stopped ASF server.";
}
Expand Down
15 changes: 12 additions & 3 deletions ASFui/ASFui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -77,6 +78,7 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand All @@ -95,16 +97,20 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ASFProcess.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ASFProcess.cs" />
<Compile Include="ASFui.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ASFui.Designer.cs">
<DependentUpon>ASFui.cs</DependentUpon>
</Compile>
<Compile Include="Client.cs" />
<Compile Include="Password.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Password.Designer.cs">
<DependentUpon>Password.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
Expand All @@ -123,6 +129,9 @@
<EmbeddedResource Include="ASFui.resx">
<DependentUpon>ASFui.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Password.resx">
<DependentUpon>Password.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
Expand Down
6 changes: 0 additions & 6 deletions ASFui/ASFui.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="BackgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="TrayIcon.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>274, 17</value>
</metadata>
Expand All @@ -129,7 +126,4 @@
<metadata name="StatusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>491, 17</value>
</metadata>
<metadata name="ASFProcess.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>174, 17</value>
</metadata>
</root>
2 changes: 1 addition & 1 deletion ASFui/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<userSettings>
<ASFui.Properties.Settings>
<setting name="ASFBinary" serializeAs="String">
<value>ASF.exe</value>
<value />
</setting>
<setting name="IsLocal" serializeAs="String">
<value>True</value>
Expand Down
Loading

0 comments on commit 048eb81

Please sign in to comment.