first commit

This commit is contained in:
liushuming
2026-02-27 08:52:30 +08:00
commit ce677db88b
13 changed files with 533 additions and 0 deletions

76
client/Reader/MainForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,76 @@
namespace Reader
{
partial class MainForm
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.txtFolder = new System.Windows.Forms.TextBox();
this.btnBrowse = new System.Windows.Forms.Button();
this.btnRead = new System.Windows.Forms.Button();
this.dgv = new System.Windows.Forms.DataGridView();
((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit();
this.SuspendLayout();
// txtFolder
this.txtFolder.Location = new System.Drawing.Point(12, 30);
this.txtFolder.Name = "txtFolder";
this.txtFolder.Size = new System.Drawing.Size(360, 23);
// btnBrowse
this.btnBrowse.Location = new System.Drawing.Point(378, 28);
this.btnBrowse.Name = "btnBrowse";
this.btnBrowse.Size = new System.Drawing.Size(75, 25);
this.btnBrowse.Text = "浏览文件夹";
this.btnBrowse.UseVisualStyleBackColor = true;
this.btnBrowse.Click += new System.EventHandler(this.btnBrowse_Click);
// btnRead
this.btnRead.Location = new System.Drawing.Point(378, 170);
this.btnRead.Name = "btnRead";
this.btnRead.Size = new System.Drawing.Size(75, 27);
this.btnRead.Text = "开始读取";
this.btnRead.UseVisualStyleBackColor = true;
this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
// dgv
this.dgv.AllowUserToAddRows = false;
this.dgv.AllowUserToDeleteRows = false;
this.dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dgv.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
new System.Windows.Forms.DataGridViewTextBoxColumn() { Name = "colFile", HeaderText = "文件名" },
new System.Windows.Forms.DataGridViewTextBoxColumn() { Name = "colUpload", HeaderText = "上传信息" },
new System.Windows.Forms.DataGridViewTextBoxColumn() { Name = "colDownload", HeaderText = "下载信息" },
new System.Windows.Forms.DataGridViewTextBoxColumn() { Name = "colTime", HeaderText = "暗码写入时间" }
});
this.dgv.Location = new System.Drawing.Point(12, 62);
this.dgv.Name = "dgv";
this.dgv.ReadOnly = true;
this.dgv.RowTemplate.Height = 25;
this.dgv.Size = new System.Drawing.Size(441, 100);
// MainForm
this.ClientSize = new System.Drawing.Size(465, 209);
this.Controls.Add(this.txtFolder);
this.Controls.Add(this.btnBrowse);
this.Controls.Add(this.dgv);
this.Controls.Add(this.btnRead);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "Reader - 读取暗码";
((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox txtFolder;
private System.Windows.Forms.Button btnBrowse;
private System.Windows.Forms.Button btnRead;
private System.Windows.Forms.DataGridView dgv;
}
}

98
client/Reader/MainForm.cs Normal file
View File

@@ -0,0 +1,98 @@
using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Reader
{
public partial class MainForm : Form
{
private static readonly HttpClient http = new HttpClient();
private const string ServerUrl = "http://localhost:5000";
public MainForm()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
using var fbd = new FolderBrowserDialog();
if (fbd.ShowDialog() == DialogResult.OK)
{
txtFolder.Text = fbd.SelectedPath;
}
}
private async void btnRead_Click(object sender, EventArgs e)
{
var folder = txtFolder.Text;
if (string.IsNullOrWhiteSpace(folder) || !Directory.Exists(folder))
{
MessageBox.Show("请选择有效的文件夹。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
dgv.Rows.Clear();
var files = Directory.GetFiles(folder, "*", SearchOption.AllDirectories);
var shaList = new System.Collections.Generic.List<string>();
var fileMap = new System.Collections.Generic.Dictionary<string, string>();
foreach (var f in files)
{
try
{
var sha = await Task.Run(() => ComputeSha256(f));
shaList.Add(sha);
fileMap[sha] = f;
}
catch { }
}
if (shaList.Count == 0)
{
MessageBox.Show("没有找到文件。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
var payload = new { shas = shaList };
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var resp = await http.PostAsync(ServerUrl + "/read", content);
if (!resp.IsSuccessStatusCode)
{
MessageBox.Show("读取失败: " + await resp.Content.ReadAsStringAsync(), "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
var text = await resp.Content.ReadAsStringAsync();
using var doc = JsonDocument.Parse(text);
var root = doc.RootElement;
var data = root.GetProperty("data");
foreach (var sha in shaList)
{
var fileName = Path.GetFileName(fileMap[sha]);
if (data.TryGetProperty(sha, out var item) && item.ValueKind != JsonValueKind.Null)
{
var up = item.GetProperty("upload_code").GetString() ?? "";
var down = item.GetProperty("download_code").GetString() ?? "";
var created = item.GetProperty("created_at").GetString() ?? "";
dgv.Rows.Add(fileName, up, down, created);
}
else
{
dgv.Rows.Add(fileName, "无", "无", "无");
}
}
}
private static string ComputeSha256(string filePath)
{
using var sha = SHA256.Create();
using var stream = File.OpenRead(filePath);
var hash = sha.ComputeHash(stream);
var sb = new StringBuilder();
foreach (var b in hash) sb.Append(b.ToString("x2"));
return sb.ToString();
}
}
}

17
client/Reader/Program.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Windows.Forms;
namespace Reader
{
static class Program
{
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>