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

95
client/Writer/MainForm.Designer.cs generated Normal file
View File

@@ -0,0 +1,95 @@
namespace Writer
{
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.txtFile = new System.Windows.Forms.TextBox();
this.btnBrowse = new System.Windows.Forms.Button();
this.txtUpload = new System.Windows.Forms.TextBox();
this.txtDownload = new System.Windows.Forms.TextBox();
this.lblFile = new System.Windows.Forms.Label();
this.lblUpload = new System.Windows.Forms.Label();
this.lblDownload = new System.Windows.Forms.Label();
this.btnWrite = new System.Windows.Forms.Button();
this.SuspendLayout();
// txtFile
this.txtFile.Location = new System.Drawing.Point(12, 30);
this.txtFile.Name = "txtFile";
this.txtFile.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);
// txtUpload
this.txtUpload.Location = new System.Drawing.Point(12, 80);
this.txtUpload.Name = "txtUpload";
this.txtUpload.Size = new System.Drawing.Size(441, 23);
// txtDownload
this.txtDownload.Location = new System.Drawing.Point(12, 130);
this.txtDownload.Name = "txtDownload";
this.txtDownload.Size = new System.Drawing.Size(441, 23);
// labels
this.lblFile.AutoSize = true;
this.lblFile.Location = new System.Drawing.Point(12, 12);
this.lblFile.Name = "lblFile";
this.lblFile.Size = new System.Drawing.Size(59, 15);
this.lblFile.Text = "目标文件";
this.lblUpload.AutoSize = true;
this.lblUpload.Location = new System.Drawing.Point(12, 62);
this.lblUpload.Name = "lblUpload";
this.lblUpload.Size = new System.Drawing.Size(83, 15);
this.lblUpload.Text = "上传暗码(上传)";
this.lblDownload.AutoSize = true;
this.lblDownload.Location = new System.Drawing.Point(12, 112);
this.lblDownload.Name = "lblDownload";
this.lblDownload.Size = new System.Drawing.Size(83, 15);
this.lblDownload.Text = "下载暗码(下载)";
// btnWrite
this.btnWrite.Location = new System.Drawing.Point(378, 170);
this.btnWrite.Name = "btnWrite";
this.btnWrite.Size = new System.Drawing.Size(75, 27);
this.btnWrite.Text = "开始写入";
this.btnWrite.UseVisualStyleBackColor = true;
this.btnWrite.Click += new System.EventHandler(this.btnWrite_Click);
// MainForm
this.ClientSize = new System.Drawing.Size(465, 209);
this.Controls.Add(this.txtFile);
this.Controls.Add(this.btnBrowse);
this.Controls.Add(this.txtUpload);
this.Controls.Add(this.txtDownload);
this.Controls.Add(this.lblFile);
this.Controls.Add(this.lblUpload);
this.Controls.Add(this.lblDownload);
this.Controls.Add(this.btnWrite);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "Writer - 写入暗码";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.TextBox txtFile;
private System.Windows.Forms.Button btnBrowse;
private System.Windows.Forms.TextBox txtUpload;
private System.Windows.Forms.TextBox txtDownload;
private System.Windows.Forms.Label lblFile;
private System.Windows.Forms.Label lblUpload;
private System.Windows.Forms.Label lblDownload;
private System.Windows.Forms.Button btnWrite;
}
}

72
client/Writer/MainForm.cs Normal file
View File

@@ -0,0 +1,72 @@
using System;
using System.IO;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Writer
{
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 ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
txtFile.Text = ofd.FileName;
}
}
private async void btnWrite_Click(object sender, EventArgs e)
{
var file = txtFile.Text;
if (string.IsNullOrWhiteSpace(file) || !File.Exists(file))
{
MessageBox.Show("请选择有效的文件。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
var upload = txtUpload.Text ?? string.Empty;
var download = txtDownload.Text ?? string.Empty;
try
{
var sha = await Task.Run(() => ComputeSha256(file));
var payload = new { sha = sha, upload_code = upload, download_code = download };
var content = new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json");
var resp = await http.PostAsync(ServerUrl + "/write", content);
if (resp.IsSuccessStatusCode)
{
MessageBox.Show("写入暗码成功", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("写入失败: " + await resp.Content.ReadAsStringAsync(), "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
MessageBox.Show("发生错误: " + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
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/Writer/Program.cs Normal file
View File

@@ -0,0 +1,17 @@
using System;
using System.Windows.Forms;
namespace Writer
{
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>