diff --git a/.gitignore b/.gitignore index 3529ad9..c1dfb74 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,10 @@ Thumbs.db *.cache *.ilk *.log -[Bb]in +Bin/* +!Bin/QRCoder.dll +bin/* +!bin/QRCoder.dll [Dd]ebug*/ *.lib *.sbr diff --git a/SharpProxy/SharpProxy.csproj b/SharpProxy/SharpProxy.csproj index 3859005..18514b9 100644 --- a/SharpProxy/SharpProxy.csproj +++ b/SharpProxy/SharpProxy.csproj @@ -53,6 +53,9 @@ main.ico + + bin\QRCoder.dll + diff --git a/SharpProxy/bin/QRCoder.dll b/SharpProxy/bin/QRCoder.dll new file mode 100644 index 0000000..6bf2420 Binary files /dev/null and b/SharpProxy/bin/QRCoder.dll differ diff --git a/SharpProxy/frmMain.Designer.cs b/SharpProxy/frmMain.Designer.cs index bea1166..44a8445 100644 --- a/SharpProxy/frmMain.Designer.cs +++ b/SharpProxy/frmMain.Designer.cs @@ -38,6 +38,9 @@ private void InitializeComponent() this.label3 = new System.Windows.Forms.Label(); this.cmbIPAddress = new System.Windows.Forms.ComboBox(); this.chkRewriteHostHeaders = new System.Windows.Forms.CheckBox(); + this.picQRCode = new System.Windows.Forms.PictureBox(); + this.label4 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.picQRCode)).BeginInit(); this.SuspendLayout(); // // btnStart @@ -115,6 +118,7 @@ private void InitializeComponent() this.cmbIPAddress.Name = "cmbIPAddress"; this.cmbIPAddress.Size = new System.Drawing.Size(189, 21); this.cmbIPAddress.TabIndex = 8; + this.cmbIPAddress.SelectedIndexChanged += new System.EventHandler(this.cmbIPAddress_SelectedIndexChanged); // // chkRewriteHostHeaders // @@ -128,11 +132,32 @@ private void InitializeComponent() this.chkRewriteHostHeaders.Text = "&Rewrite host headers (IIS Express)"; this.chkRewriteHostHeaders.UseVisualStyleBackColor = true; // + // picQRCode + // + this.picQRCode.BackColor = System.Drawing.Color.White; + this.picQRCode.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.picQRCode.Location = new System.Drawing.Point(216, 25); + this.picQRCode.Name = "picQRCode"; + this.picQRCode.Size = new System.Drawing.Size(131, 131); + this.picQRCode.TabIndex = 10; + this.picQRCode.TabStop = false; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(219, 9); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(51, 13); + this.label4.TabIndex = 11; + this.label4.Text = "QR Code"; + // // frmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(212, 185); + this.ClientSize = new System.Drawing.Size(375, 192); + this.Controls.Add(this.label4); + this.Controls.Add(this.picQRCode); this.Controls.Add(this.chkRewriteHostHeaders); this.Controls.Add(this.cmbIPAddress); this.Controls.Add(this.label3); @@ -149,6 +174,7 @@ private void InitializeComponent() this.Text = "SharpProxy"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmMain_FormClosing); this.Shown += new System.EventHandler(this.frmMain_Shown); + ((System.ComponentModel.ISupportInitialize)(this.picQRCode)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -165,6 +191,8 @@ private void InitializeComponent() private System.Windows.Forms.Label label3; private System.Windows.Forms.ComboBox cmbIPAddress; private System.Windows.Forms.CheckBox chkRewriteHostHeaders; + private System.Windows.Forms.PictureBox picQRCode; + private System.Windows.Forms.Label label4; } } diff --git a/SharpProxy/frmMain.cs b/SharpProxy/frmMain.cs index 73cb3aa..85d426b 100644 --- a/SharpProxy/frmMain.cs +++ b/SharpProxy/frmMain.cs @@ -10,6 +10,7 @@ using System.Net.Sockets; using System.Linq; using System.IO; +using QRCoder; namespace SharpProxy { @@ -17,6 +18,9 @@ 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"); @@ -113,6 +117,7 @@ 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) @@ -120,6 +125,7 @@ private void btnStop_Click(object sender, EventArgs e) ProxyThreadListener.Stop(); toggleButtons(); + picQRCode.Image = null; } private void showError(string msg) @@ -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(); + } } }