add qrcode form
This commit is contained in:
@@ -116,6 +116,14 @@ namespace Shadowsocks.Controller
|
||||
}
|
||||
}
|
||||
|
||||
public string GetQRCodeForCurrentServer()
|
||||
{
|
||||
Server server = GetCurrentServer();
|
||||
string parts = server.method + ":" + server.password + "@" + server.server + ":" + server.server_port;
|
||||
string base64 = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(parts));
|
||||
return "ss://" + base64;
|
||||
}
|
||||
|
||||
private void updateSystemProxy()
|
||||
{
|
||||
if (config.enabled)
|
||||
|
||||
@@ -1,28 +1,37 @@
|
||||
<!doctype html>
|
||||
<script src="jquery.min.js">
|
||||
</script>
|
||||
<script src="qrcode.min.js">
|
||||
<html>
|
||||
<head>
|
||||
<script>
|
||||
__QRCODELIB__
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
padding: 10px;
|
||||
margin: 0;
|
||||
html, body, table, div {
|
||||
padding: 0px;
|
||||
margin: 0 !important;
|
||||
}
|
||||
div#qrcode {
|
||||
margin: 10px !important;
|
||||
}
|
||||
#qrcode {
|
||||
width:300px;
|
||||
height:300px;
|
||||
}
|
||||
</style>
|
||||
<div id="qrcode"></div>
|
||||
</head>
|
||||
<body>
|
||||
<div id="qrcode" name="qrcode"></div>
|
||||
<script type="text/javascript">
|
||||
function genCode(code) {
|
||||
new QRCode("qrcode", {
|
||||
text: code,
|
||||
width: 300,
|
||||
height: 300,
|
||||
width: 200,
|
||||
height: 200,
|
||||
colorDark : "#000000",
|
||||
colorLight : "#ffffff",
|
||||
correctLevel : QRCode.CorrectLevel.H
|
||||
});
|
||||
}
|
||||
</script>
|
||||
genCode("__SSURL__");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Binary file not shown.
+45
@@ -104,5 +104,50 @@ namespace Shadowsocks.Properties {
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to <!doctype html>
|
||||
///<html>
|
||||
///<head>
|
||||
///<script>
|
||||
/// __QRCODELIB__
|
||||
///</script>
|
||||
///<style>
|
||||
/// body {
|
||||
/// padding: 10px;
|
||||
/// margin: 0;
|
||||
/// }
|
||||
/// #qrcode {
|
||||
/// width:300px;
|
||||
/// height:300px;
|
||||
/// }
|
||||
///</style>
|
||||
///</head>
|
||||
///<body>
|
||||
///<div id="qrcode" name="qrcode"></div>
|
||||
///<script type="text/javascript">
|
||||
/// function genCode(code) {
|
||||
/// new QRCode("qrcode", {
|
||||
/// text: code,
|
||||
/// width: 300,
|
||||
/// height: 300,
|
||||
/// colorDark : "#000000",
|
||||
/// colorLig [rest of string was truncated]";.
|
||||
/// </summary>
|
||||
internal static string qrcode {
|
||||
get {
|
||||
return ResourceManager.GetString("qrcode", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Byte[].
|
||||
/// </summary>
|
||||
internal static byte[] qrcode_min_js {
|
||||
get {
|
||||
object obj = ResourceManager.GetObject("qrcode_min_js", resourceCulture);
|
||||
return ((byte[])(obj));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,4 +130,10 @@
|
||||
<data name="proxy_pac_txt" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\proxy.pac.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name="qrcode" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\qrcode.htm;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312</value>
|
||||
</data>
|
||||
<data name="qrcode_min_js" type="System.Resources.ResXFileRef, System.Windows.Forms">
|
||||
<value>..\Data\qrcode.min.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
+12
-3
@@ -63,6 +63,7 @@
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.ServerGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.ServersListBox = new System.Windows.Forms.ListBox();
|
||||
this.QRCodeItem = new System.Windows.Forms.MenuItem();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.panel1.SuspendLayout();
|
||||
this.panel3.SuspendLayout();
|
||||
@@ -287,6 +288,7 @@
|
||||
this.ServersItem,
|
||||
this.menuItem4,
|
||||
this.editPACFileItem,
|
||||
this.QRCodeItem,
|
||||
this.aboutItem,
|
||||
this.menuItem3,
|
||||
this.quitItem});
|
||||
@@ -329,18 +331,18 @@
|
||||
//
|
||||
// aboutItem
|
||||
//
|
||||
this.aboutItem.Index = 4;
|
||||
this.aboutItem.Index = 5;
|
||||
this.aboutItem.Text = "About...";
|
||||
this.aboutItem.Click += new System.EventHandler(this.AboutItem_Click);
|
||||
//
|
||||
// menuItem3
|
||||
//
|
||||
this.menuItem3.Index = 5;
|
||||
this.menuItem3.Index = 6;
|
||||
this.menuItem3.Text = "-";
|
||||
//
|
||||
// quitItem
|
||||
//
|
||||
this.quitItem.Index = 6;
|
||||
this.quitItem.Index = 7;
|
||||
this.quitItem.Text = "&Quit";
|
||||
this.quitItem.Click += new System.EventHandler(this.Quit_Click);
|
||||
//
|
||||
@@ -394,6 +396,12 @@
|
||||
this.ServersListBox.TabIndex = 5;
|
||||
this.ServersListBox.SelectedIndexChanged += new System.EventHandler(this.ServersListBox_SelectedIndexChanged);
|
||||
//
|
||||
// QRCodeItem
|
||||
//
|
||||
this.QRCodeItem.Index = 4;
|
||||
this.QRCodeItem.Text = "Show &QRCode...";
|
||||
this.QRCodeItem.Click += new System.EventHandler(this.QRCodeItem_Click);
|
||||
//
|
||||
// ConfigForm
|
||||
//
|
||||
this.AcceptButton = this.OKButton;
|
||||
@@ -461,6 +469,7 @@
|
||||
private System.Windows.Forms.MenuItem menuItem4;
|
||||
private System.Windows.Forms.TextBox RemarksTextBox;
|
||||
private System.Windows.Forms.Label label6;
|
||||
private System.Windows.Forms.MenuItem QRCodeItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,5 +302,10 @@ namespace Shadowsocks.View
|
||||
{
|
||||
IPTextBox.Focus();
|
||||
}
|
||||
|
||||
private void QRCodeItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
new QRCodeForm(controller.GetQRCodeForCurrentServer()).Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
namespace Shadowsocks.View
|
||||
{
|
||||
partial class QRCodeForm
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.QRCodeWebBrowser = new System.Windows.Forms.WebBrowser();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// QRCodeWebBrowser
|
||||
//
|
||||
this.QRCodeWebBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.QRCodeWebBrowser.Location = new System.Drawing.Point(0, 0);
|
||||
this.QRCodeWebBrowser.MinimumSize = new System.Drawing.Size(20, 20);
|
||||
this.QRCodeWebBrowser.Name = "QRCodeWebBrowser";
|
||||
this.QRCodeWebBrowser.ScriptErrorsSuppressed = true;
|
||||
this.QRCodeWebBrowser.ScrollBarsEnabled = false;
|
||||
this.QRCodeWebBrowser.Size = new System.Drawing.Size(184, 182);
|
||||
this.QRCodeWebBrowser.TabIndex = 0;
|
||||
//
|
||||
// QRCodeForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(184, 182);
|
||||
this.Controls.Add(this.QRCodeWebBrowser);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.MaximizeBox = false;
|
||||
this.Name = "QRCodeForm";
|
||||
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
|
||||
this.Load += new System.EventHandler(this.QRCodeForm_Load);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.WebBrowser QRCodeWebBrowser;
|
||||
}
|
||||
}
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
using Shadowsocks.Properties;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Shadowsocks.View
|
||||
{
|
||||
public partial class QRCodeForm : Form
|
||||
{
|
||||
private string code;
|
||||
|
||||
public QRCodeForm(string code)
|
||||
{
|
||||
this.code = code;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private string QRCodeHTML(string ssURL)
|
||||
{
|
||||
string html = Resources.qrcode;
|
||||
string qrcodeLib;
|
||||
|
||||
byte[] qrcodeGZ = Resources.qrcode_min_js;
|
||||
byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M
|
||||
int n;
|
||||
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(qrcodeGZ),
|
||||
CompressionMode.Decompress, false))
|
||||
{
|
||||
n = input.Read(buffer, 0, buffer.Length);
|
||||
if (n == 0)
|
||||
{
|
||||
throw new IOException("can not decompress qrcode lib");
|
||||
}
|
||||
qrcodeLib = System.Text.Encoding.UTF8.GetString(buffer, 0, n);
|
||||
}
|
||||
string result = html.Replace("__QRCODELIB__", qrcodeLib);
|
||||
return result.Replace("__SSURL__", ssURL);
|
||||
}
|
||||
|
||||
private void QRCodeForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
QRCodeWebBrowser.DocumentText = QRCodeHTML(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+120
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -79,8 +79,10 @@
|
||||
<Reference Include="Microsoft.VisualBasic" />
|
||||
<Reference Include="Microsoft.VisualBasic.PowerPacks.Vs, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="3rd\SimpleJson.cs" />
|
||||
@@ -106,6 +108,12 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Controller\ShadowsocksController.cs" />
|
||||
<Compile Include="Controller\SystemProxy.cs" />
|
||||
<Compile Include="View\QRCodeForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Include="View\QRCodeForm.Designer.cs">
|
||||
<DependentUpon>QRCodeForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="View\ConfigForm.resx">
|
||||
<DependentUpon>ConfigForm.cs</DependentUpon>
|
||||
<SubType>Designer</SubType>
|
||||
@@ -120,9 +128,13 @@
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="View\QRCodeForm.resx">
|
||||
<DependentUpon>QRCodeForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
<None Include="app.config" />
|
||||
<None Include="Data\polarssl.dll.gz" />
|
||||
<None Include="Data\polipo.exe.gz" />
|
||||
<None Include="Data\qrcode.min.js.gz" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
@@ -135,6 +147,7 @@
|
||||
<None Include="Data\proxy.pac.txt.gz" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Data\qrcode.htm" />
|
||||
<Content Include="shadowsocks.ico" />
|
||||
<None Include="Data\polipo_config.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user