commit
ac83679e8e
@ -0,0 +1,20 @@
|
||||
*.bak
|
||||
*.suo
|
||||
*.db-shm
|
||||
*.db-wal
|
||||
*.user
|
||||
.vs
|
||||
obj
|
||||
Obj
|
||||
bin
|
||||
Bin
|
||||
debug
|
||||
Debug
|
||||
release
|
||||
Release
|
||||
Logs
|
||||
logs
|
||||
node_modules
|
||||
temp
|
||||
~$*
|
||||
log.txt
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,189 @@
|
||||
using Microsoft.Web.WebView2.Core;
|
||||
using Microsoft.Web.WebView2.WinForms;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace PhotoCollector
|
||||
{
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public static JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
private CVRHelper _cvrHelper = new CVRHelper();
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private async void MainForm_Shown(object sender, EventArgs e)
|
||||
{
|
||||
InitCVR();
|
||||
InitWebViewAsync();
|
||||
}
|
||||
|
||||
private async void InitWebViewAsync()
|
||||
{
|
||||
var browserExecutableFolder = Path.Combine(AppContext.BaseDirectory, "webview");
|
||||
var userDataFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), Application.ProductName);
|
||||
var env = await CoreWebView2Environment.CreateAsync(browserExecutableFolder, userDataFolder);
|
||||
this.webView21.NavigationCompleted += WebView21_NavigationCompleted;
|
||||
this.webView21.CoreWebView2InitializationCompleted += WebView21_CoreWebView2InitializationCompleted;
|
||||
await this.webView21.EnsureCoreWebView2Async(env);
|
||||
}
|
||||
|
||||
private void CoreWebView2_PermissionRequested(object? sender, CoreWebView2PermissionRequestedEventArgs e)
|
||||
{
|
||||
if (e.PermissionKind == CoreWebView2PermissionKind.Camera)
|
||||
{
|
||||
e.State = CoreWebView2PermissionState.Allow;
|
||||
}
|
||||
}
|
||||
|
||||
private void WebView21_CoreWebView2InitializationCompleted(object? sender, CoreWebView2InitializationCompletedEventArgs e)
|
||||
{
|
||||
var webView = sender as WebView2;
|
||||
webView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false;
|
||||
webView.CoreWebView2.Settings.IsPinchZoomEnabled = false;
|
||||
webView.CoreWebView2.Settings.IsBuiltInErrorPageEnabled = false;
|
||||
#if !DEBUG
|
||||
webView.CoreWebView2.Settings.AreBrowserAcceleratorKeysEnabled = false;
|
||||
webView.CoreWebView2.Settings.IsStatusBarEnabled = false;
|
||||
#endif
|
||||
webView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested;
|
||||
webView.CoreWebView2.Settings.UserAgent = $"{webView.CoreWebView2.Settings.UserAgent}|{AppContext.BaseDirectory}";
|
||||
webView.CoreWebView2.WebMessageReceived += CoreWebView2_WebMessageReceived;
|
||||
webView.CoreWebView2.Navigate("https://localhost:7235/");
|
||||
}
|
||||
|
||||
private void CoreWebView2_WebMessageReceived(object? sender, CoreWebView2WebMessageReceivedEventArgs e)
|
||||
{
|
||||
var messages = JsonSerializer.Deserialize<Dictionary<string, string>>(e.WebMessageAsJson);
|
||||
var command = messages["command"].ToString();
|
||||
if (command == "folder")
|
||||
{
|
||||
this.folderBrowserDialog1.SelectedPath = messages["path"];
|
||||
if (this.folderBrowserDialog1.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
this.webView21.ExecuteScriptAsync($"onfolderSelected({JsonSerializer.Serialize(folderBrowserDialog1.SelectedPath, jsonSerializerOptions)})");
|
||||
}
|
||||
}
|
||||
else if (command == "read")
|
||||
{
|
||||
var file = messages["file"];
|
||||
var base64 = string.Empty;
|
||||
var code = 0;
|
||||
var message = string.Empty;
|
||||
if (File.Exists(file))
|
||||
{
|
||||
var meta = file + ".meta";
|
||||
if (File.Exists(meta))
|
||||
{
|
||||
if (FileMd5(file) == File.ReadAllText(meta))
|
||||
{
|
||||
base64 = Convert.ToBase64String(File.ReadAllBytes(file));
|
||||
}
|
||||
else
|
||||
{
|
||||
code = 3;
|
||||
message = "文件校验失败:{file}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
code = 2;
|
||||
message = "文件元数据缺失:{meta}";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
code = 1;
|
||||
message = $"文件不存在:{file}";
|
||||
}
|
||||
var args = JsonSerializer.Serialize(new
|
||||
{
|
||||
file,
|
||||
base64,
|
||||
code,
|
||||
message
|
||||
}, jsonSerializerOptions);
|
||||
this.webView21.ExecuteScriptAsync($"onFileReceived({args})");
|
||||
}
|
||||
else if (command == "save")
|
||||
{
|
||||
var file = messages["file"];
|
||||
File.WriteAllBytes(file, Convert.FromBase64String(messages["base64"].Split(',')[1]));
|
||||
File.WriteAllText(file + ".meta", FileMd5(file));
|
||||
this.webView21.ExecuteScriptAsync($"alert({JsonSerializer.Serialize(messages["file"])})");
|
||||
}
|
||||
}
|
||||
|
||||
private void WebView21_NavigationCompleted(object? sender, CoreWebView2NavigationCompletedEventArgs e)
|
||||
{
|
||||
if (!e.IsSuccess)
|
||||
{
|
||||
this.toolStripStatusLabel1.Text = e.WebErrorStatus.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitCVR()
|
||||
{
|
||||
this._cvrHelper.OnConnect = new Action<bool>(o =>
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
if (!this.IsHandleCreated || this.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
//this.Text = o ? "读卡器已连接" : "读卡器未连接";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}));
|
||||
});
|
||||
this._cvrHelper.OnRead = new Action<IdCardModel>(o =>
|
||||
{
|
||||
this.Invoke(new Action(() =>
|
||||
{
|
||||
if (!this.IsHandleCreated || this.IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
this.toolStripStatusLabel1.Text = o.Name;
|
||||
var param = JsonSerializer.Serialize(o, jsonSerializerOptions);
|
||||
this.webView21.ExecuteScriptAsync($"onRead({param})");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Text += ex.Message;
|
||||
this.Text += ex.StackTrace;
|
||||
this.Text += Environment.NewLine;
|
||||
}
|
||||
}));
|
||||
});
|
||||
this._cvrHelper.Start();
|
||||
}
|
||||
|
||||
public static string FileMd5(string file)
|
||||
{
|
||||
using var md5 = MD5.Create();
|
||||
using var stream = File.OpenRead(file);
|
||||
var hash = md5.ComputeHash(stream);
|
||||
stream.Dispose();
|
||||
return BitConverter.ToString(hash).Replace("-", "").ToLower();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
<root>
|
||||
<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=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>138, 17</value>
|
||||
</metadata>
|
||||
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>258, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -0,0 +1,16 @@
|
||||
namespace PhotoCollector
|
||||
{
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
https://go.microsoft.com/fwlink/?LinkID=208121.
|
||||
-->
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Any CPU</Platform>
|
||||
<PublishDir>bin\Release\net6.0-windows\publish\win-x64\</PublishDir>
|
||||
<PublishProtocol>FileSystem</PublishProtocol>
|
||||
<TargetFramework>net6.0-windows</TargetFramework>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<SelfContained>true</SelfContained>
|
||||
<PublishSingleFile>True</PublishSingleFile>
|
||||
<PublishReadyToRun>False</PublishReadyToRun>
|
||||
</PropertyGroup>
|
||||
</Project>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
0744e088ca453d89bdc6eb2ff732c9b161033baeb37cc56d9f77d8694bd1eb0d05f4cebc33fe3b148820af747e4377bb00f20e536674a66fa7380590ca7792c99e14b055abc74aae687aaf40aff3a1966db4a8e29e1fad4279dec343e78248a43a6a2d5c1ce792ddc59d969b722d6dc81211b36242c7ff707b31bc6a8a3c349541c0eed86da73a2cee520a8daf3803db56d0d4dc3ab2c78117f9956a9beb7fab1bdc9ad1864f6b20975fb31f4e5d8c57a0bbb5576e282bfbb4fdf9ee03d8506e3186da4f4f273043db8c3b5837e430c25a98fedbc6735368b9068e1ea84bd065e988565bb076061c3ca34741521516a6eb3057712ada68db90dcfc01738b2718aca9b5fc9186c033236a82e08837678abb4b661f82319239a047ec9f4ce27c0fe3b0a03bda9da311f6ab913fbf944af732b1d6efb61af8ad510f06011c96f7d3f466be1e7304d73d1e2c1f66e072e874b8294de9ae84c3330bfbf12ec9f0c2eb4993b8b04403833f04b6d25bd41a6989b5da7314522a1a5336d4562e3d3802df48ff35f635e1cfa00f10522881d4f4be9172f2788b5326963a62dc0a5eb6e2385b71defa2fe8e4e7a63248d5d1e8b19cb4d36f1d3f480f83806d2cc916b2887de9b25bc3185eea9c33585c68ab9dc9aa8667950c5752fca36ebded734c731c365a8b5359da8c08481dd535ebf63c647070f6094cbcb7157c6d19bb11e842c7eb15c16ec55bba6772cc437c659c0da977d84776e554bf8498e64b65aad167b025841f550e85302fa2a86ad8df8458c146272382e009b46e7f3f196b46f12a016b0e6cb0313e3587601911f2609665d466c652d544c2dcfeb7e24c83ed2fd2df461b6f265870129735870271f0ba7b095d1b9c1819678159ca35ac54a873a9743d13f16068021088a85a03fe97d8e488b590c9f367dfe9aa40a200aa7ea5f5e8d85fba0677dc758242fadd415ed8e67af58ca00d37145c179f8f12c378aeff639f6592bf8ae689ac89cf58e14ca2cacaa677ea0f90ed24c87166a8b19d740f0c1b8e4133ab08962f07423b876a1fd8564fb86fa07b5288e63d8e8bf8f5e06d0bd3428e0be12ae23344b950dabf35579078b9f769ff2bcf998c6f834188da60314fea43ef3534b6dfc79d5d8353cd91dcaae14a1224604208e57157345f4b31aed3ec2686ad0e5a5b18572b292ed0cc636b982f42f2da295cd0fcd178811929a1b5b2007954a016d0bf4d82755924514c464670a1727fccbcd578b7b6f62e8e8baea2986f2fd3326644e9290fdbb368c0c053d3d8ab3872517d4dd295c770a8938c26b811488d31443092ea9ebc6358e76328218fa5ee64434fe3eabefbc9c1e2d6a52607a6b7a9930baf8bca041e6be8b62b216d6987ebb9d4a3c7d89a201f9f1487abf8513a947a5baad53dbccbe73441c59d1bfeed4ddb92f3308cad5c0bf3cf
|
Binary file not shown.
@ -0,0 +1,8 @@
|
||||
<assembly
|
||||
xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
|
||||
<assemblyIdentity
|
||||
name='96.0.1054.29'
|
||||
version='96.0.1054.29'
|
||||
type='win32'/>
|
||||
<file name='msedge_elf.dll'/>
|
||||
</assembly>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
// This json file will contain a list of extensions that will be included
|
||||
// in the installer.
|
||||
|
||||
{
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue