You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

QRCodeForm.cs 1.6 kB

10 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Shadowsocks.Properties;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. namespace Shadowsocks.View
  12. {
  13. public partial class QRCodeForm : Form
  14. {
  15. private string code;
  16. public QRCodeForm(string code)
  17. {
  18. this.code = code;
  19. InitializeComponent();
  20. }
  21. private string QRCodeHTML(string ssURL)
  22. {
  23. string html = Resources.qrcode;
  24. string qrcodeLib;
  25. byte[] qrcodeGZ = Resources.qrcode_min_js;
  26. byte[] buffer = new byte[1024 * 1024]; // builtin pac gzip size: maximum 1M
  27. int n;
  28. using (GZipStream input = new GZipStream(new MemoryStream(qrcodeGZ),
  29. CompressionMode.Decompress, false))
  30. {
  31. n = input.Read(buffer, 0, buffer.Length);
  32. if (n == 0)
  33. {
  34. throw new IOException("can not decompress qrcode lib");
  35. }
  36. qrcodeLib = System.Text.Encoding.UTF8.GetString(buffer, 0, n);
  37. }
  38. string result = html.Replace("__QRCODELIB__", qrcodeLib);
  39. return result.Replace("__SSURL__", ssURL);
  40. }
  41. private void QRCodeForm_Load(object sender, EventArgs e)
  42. {
  43. QRCodeWebBrowser.DocumentText = QRCodeHTML(code);
  44. }
  45. }
  46. }