Browse Source

Merge remote-tracking branch 'upstream/master'

Conflicts:
	shadowsocks-csharp/View/QRCodeForm.cs
pull/37/head
wzxjohn 10 years ago
parent
commit
78bc6f448c
3 changed files with 37 additions and 24 deletions
  1. +0
    -1
      shadowsocks-csharp/Controller/PACServer.cs
  2. +0
    -1
      shadowsocks-csharp/Controller/PolipoRunner.cs
  3. +37
    -22
      shadowsocks-csharp/View/QRCodeForm.cs

+ 0
- 1
shadowsocks-csharp/Controller/PACServer.cs View File

@@ -15,7 +15,6 @@ namespace Shadowsocks.Controller
{
private static int PORT = 8090;
private static string PAC_FILE = "pac.txt";
public bool openOnLan;
Socket _listener;
FileSystemWatcher watcher;


+ 0
- 1
shadowsocks-csharp/Controller/PolipoRunner.cs View File

@@ -12,7 +12,6 @@ namespace Shadowsocks.Controller
class PolipoRunner
{
private Process _process;
public bool openOnLan;
public void Start(Configuration configuration)
{


+ 37
- 22
shadowsocks-csharp/View/QRCodeForm.cs View File

@@ -25,35 +25,50 @@ namespace Shadowsocks.View
private void GenQR(string ssconfig)
{
string qrText = ssconfig;
QRCode4CS.QRCode qrCoded = new QRCode4CS.QRCode(6, QRErrorCorrectLevel.L);
qrCoded.AddData(qrText);
qrCoded.Make();
int blockSize = 5;
Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));
for (int row = 0; row < qrCoded.GetModuleCount(); row++)
QRCode4CS.Options options = new QRCode4CS.Options();
options.Text = qrText;
QRCode4CS.QRCode qrCoded = null;
bool success = false;
foreach (var level in new QRErrorCorrectLevel[]{QRErrorCorrectLevel.H, QRErrorCorrectLevel.Q, QRErrorCorrectLevel.M, QRErrorCorrectLevel.L})
{
for (int col = 0; col < qrCoded.GetModuleCount(); col++)
for (int i = 3; i < 10; i++)
{
bool isDark = qrCoded.IsDark(row, col);
if (isDark)
try
{
for (int y = 0; y < blockSize; y++)
{
int myCol = (blockSize * (col - 1)) + (y + blockSize);
for (int x = 0; x < blockSize; x++)
{
drawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.Black);
}
}
options.TypeNumber = i;
options.CorrectLevel = level;
qrCoded = new QRCode4CS.QRCode(options);
qrCoded.Make();
success = true;
break;
}
catch
{
qrCoded = null;
continue;
}
else
}
if (success)
break;
}
if (qrCoded == null)
{
return;
}
int blockSize = Math.Max(200 / qrCoded.GetModuleCount(), 1);
Bitmap drawArea = new Bitmap((qrCoded.GetModuleCount() * blockSize), (qrCoded.GetModuleCount() * blockSize));
using (Graphics g = Graphics.FromImage(drawArea))
{
g.Clear(Color.White);
using (Brush b = new SolidBrush(Color.Black))
{
for (int row = 0; row < qrCoded.GetModuleCount(); row++)
{
for (int y = 0; y < blockSize; y++)
for (int col = 0; col < qrCoded.GetModuleCount(); col++)
{
int myCol = (blockSize * (col - 1)) + (y + blockSize);
for (int x = 0; x < blockSize; x++)
if (qrCoded.IsDark(row, col))
{
drawArea.SetPixel((blockSize * (row - 1)) + (x + blockSize), myCol, Color.White);
g.FillRectangle(b, blockSize * row, blockSize * col, blockSize, blockSize);
}
}
}


Loading…
Cancel
Save