Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ Thumbs.db
*.cache
*.ilk
*.log
[Bb]in
Bin/*
!Bin/QRCoder.dll
bin/*
!bin/QRCoder.dll
[Dd]ebug*/
*.lib
*.sbr
Expand Down
3 changes: 3 additions & 0 deletions SharpProxy/SharpProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<ApplicationIcon>main.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="QRCoder">
<HintPath>bin\QRCoder.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down
Binary file added SharpProxy/bin/QRCoder.dll
Binary file not shown.
30 changes: 29 additions & 1 deletion SharpProxy/frmMain.Designer.cs

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

21 changes: 21 additions & 0 deletions SharpProxy/frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
using System.Net.Sockets;
using System.Linq;
using System.IO;
using QRCoder;

namespace SharpProxy
{
public partial class frmMain : Form
{
private const int MIN_PORT = 1;
private const int MAX_PORT = 65535;
private const int PIXELS_PER_MODULE = 4;

private QRCodeGenerator qrCodeGenerator = new QRCodeGenerator();

public static readonly string CommonDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "SharpProxy");
public static readonly string ConfigInfoPath = Path.Combine(CommonDataPath, "config.txt");
Expand Down Expand Up @@ -113,13 +117,15 @@ private void btnStart_Click(object sender, EventArgs e)
ProxyThreadListener = new ProxyThread(externalPort, internalPort, chkRewriteHostHeaders.Checked);

toggleButtons();
showQRCode();
}

private void btnStop_Click(object sender, EventArgs e)
{
ProxyThreadListener.Stop();

toggleButtons();
picQRCode.Image = null;
}

private void showError(string msg)
Expand Down Expand Up @@ -215,5 +221,20 @@ private void txtPorts_KeyPress(object sender, KeyPressEventArgs e)
btnStart_Click(null, null);
}
}

private void showQRCode ()
{
string data = String.Format("http://{0}:{1}", cmbIPAddress.Text, txtExternalPort.Text);

QRCode qrCode = new QRCode(qrCodeGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.M));

picQRCode.Image = qrCode.GetGraphic(PIXELS_PER_MODULE);
}

private void cmbIPAddress_SelectedIndexChanged (object sender, EventArgs e)
{
if (btnStop.Enabled)
showQRCode();
}
}
}