[
  {
    "path": ".gitignore",
    "content": "## Ignore Visual Studio temporary files, build results, and\n## files generated by popular Visual Studio add-ons.\n##\n## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore\n\n# User-specific files\n*.rsuser\n*.suo\n*.user\n*.userosscache\n*.sln.docstates\n\n# User-specific files (MonoDevelop/Xamarin Studio)\n*.userprefs\n\n# Mono auto generated files\nmono_crash.*\n\n# Build results\n[Dd]ebug/\n[Dd]ebugPublic/\n[Rr]elease/\n[Rr]eleases/\nx64/\nx86/\n[Aa][Rr][Mm]/\n[Aa][Rr][Mm]64/\nbld/\n[Bb]in/\n[Oo]bj/\n[Ll]og/\n[Ll]ogs/\n\n# Visual Studio 2015/2017 cache/options directory\n.vs/\n# Uncomment if you have tasks that create the project's static files in wwwroot\n#wwwroot/\n\n# Visual Studio 2017 auto generated files\nGenerated\\ Files/\n\n# MSTest test Results\n[Tt]est[Rr]esult*/\n[Bb]uild[Ll]og.*\n\n# NUnit\n*.VisualState.xml\nTestResult.xml\nnunit-*.xml\n\n# Build Results of an ATL Project\n[Dd]ebugPS/\n[Rr]eleasePS/\ndlldata.c\n\n# Benchmark Results\nBenchmarkDotNet.Artifacts/\n\n# .NET Core\nproject.lock.json\nproject.fragment.lock.json\nartifacts/\n\n# StyleCop\nStyleCopReport.xml\n\n# Files built by Visual Studio\n*_i.c\n*_p.c\n*_h.h\n*.ilk\n*.meta\n*.obj\n*.iobj\n*.pch\n*.pdb\n*.ipdb\n*.pgc\n*.pgd\n*.rsp\n*.sbr\n*.tlb\n*.tli\n*.tlh\n*.tmp\n*.tmp_proj\n*_wpftmp.csproj\n*.log\n*.vspscc\n*.vssscc\n.builds\n*.pidb\n*.svclog\n*.scc\n\n# Chutzpah Test files\n_Chutzpah*\n\n# Visual C++ cache files\nipch/\n*.aps\n*.ncb\n*.opendb\n*.opensdf\n*.sdf\n*.cachefile\n*.VC.db\n*.VC.VC.opendb\n\n# Visual Studio profiler\n*.psess\n*.vsp\n*.vspx\n*.sap\n\n# Visual Studio Trace Files\n*.e2e\n\n# TFS 2012 Local Workspace\n$tf/\n\n# Guidance Automation Toolkit\n*.gpState\n\n# ReSharper is a .NET coding add-in\n_ReSharper*/\n*.[Rr]e[Ss]harper\n*.DotSettings.user\n\n# TeamCity is a build add-in\n_TeamCity*\n\n# DotCover is a Code Coverage Tool\n*.dotCover\n\n# AxoCover is a Code Coverage Tool\n.axoCover/*\n!.axoCover/settings.json\n\n# Visual Studio code coverage results\n*.coverage\n*.coveragexml\n\n# NCrunch\n_NCrunch_*\n.*crunch*.local.xml\nnCrunchTemp_*\n\n# MightyMoose\n*.mm.*\nAutoTest.Net/\n\n# Web workbench (sass)\n.sass-cache/\n\n# Installshield output folder\n[Ee]xpress/\n\n# DocProject is a documentation generator add-in\nDocProject/buildhelp/\nDocProject/Help/*.HxT\nDocProject/Help/*.HxC\nDocProject/Help/*.hhc\nDocProject/Help/*.hhk\nDocProject/Help/*.hhp\nDocProject/Help/Html2\nDocProject/Help/html\n\n# Click-Once directory\npublish/\n\n# Publish Web Output\n*.[Pp]ublish.xml\n*.azurePubxml\n# Note: Comment the next line if you want to checkin your web deploy settings,\n# but database connection strings (with potential passwords) will be unencrypted\n*.pubxml\n*.publishproj\n\n# Microsoft Azure Web App publish settings. Comment the next line if you want to\n# checkin your Azure Web App publish settings, but sensitive information contained\n# in these scripts will be unencrypted\nPublishScripts/\n\n# NuGet Packages\n*.nupkg\n# NuGet Symbol Packages\n*.snupkg\n# The packages folder can be ignored because of Package Restore\n**/[Pp]ackages/*\n# except build/, which is used as an MSBuild target.\n!**/[Pp]ackages/build/\n# Uncomment if necessary however generally it will be regenerated when needed\n#!**/[Pp]ackages/repositories.config\n# NuGet v3's project.json files produces more ignorable files\n*.nuget.props\n*.nuget.targets\n\n# Microsoft Azure Build Output\ncsx/\n*.build.csdef\n\n# Microsoft Azure Emulator\necf/\nrcf/\n\n# Windows Store app package directories and files\nAppPackages/\nBundleArtifacts/\nPackage.StoreAssociation.xml\n_pkginfo.txt\n*.appx\n*.appxbundle\n*.appxupload\n\n# Visual Studio cache files\n# files ending in .cache can be ignored\n*.[Cc]ache\n# but keep track of directories ending in .cache\n!?*.[Cc]ache/\n\n# Others\nClientBin/\n~$*\n*~\n*.dbmdl\n*.dbproj.schemaview\n*.jfm\n*.pfx\n*.publishsettings\norleans.codegen.cs\n\n# Including strong name files can present a security risk\n# (https://github.com/github/gitignore/pull/2483#issue-259490424)\n#*.snk\n\n# Since there are multiple workflows, uncomment next line to ignore bower_components\n# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)\n#bower_components/\n\n# RIA/Silverlight projects\nGenerated_Code/\n\n# Backup & report files from converting an old project file\n# to a newer Visual Studio version. Backup files are not needed,\n# because we have git ;-)\n_UpgradeReport_Files/\nBackup*/\nUpgradeLog*.XML\nUpgradeLog*.htm\nServiceFabricBackup/\n*.rptproj.bak\n\n# SQL Server files\n*.mdf\n*.ldf\n*.ndf\n\n# Business Intelligence projects\n*.rdl.data\n*.bim.layout\n*.bim_*.settings\n*.rptproj.rsuser\n*- [Bb]ackup.rdl\n*- [Bb]ackup ([0-9]).rdl\n*- [Bb]ackup ([0-9][0-9]).rdl\n\n# Microsoft Fakes\nFakesAssemblies/\n\n# GhostDoc plugin setting file\n*.GhostDoc.xml\n\n# Node.js Tools for Visual Studio\n.ntvs_analysis.dat\nnode_modules/\n\n# Visual Studio 6 build log\n*.plg\n\n# Visual Studio 6 workspace options file\n*.opt\n\n# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)\n*.vbw\n\n# Visual Studio LightSwitch build output\n**/*.HTMLClient/GeneratedArtifacts\n**/*.DesktopClient/GeneratedArtifacts\n**/*.DesktopClient/ModelManifest.xml\n**/*.Server/GeneratedArtifacts\n**/*.Server/ModelManifest.xml\n_Pvt_Extensions\n\n# Paket dependency manager\n.paket/paket.exe\npaket-files/\n\n# FAKE - F# Make\n.fake/\n\n# CodeRush personal settings\n.cr/personal\n\n# Python Tools for Visual Studio (PTVS)\n__pycache__/\n*.pyc\n\n# Cake - Uncomment if you are using it\n# tools/**\n# !tools/packages.config\n\n# Tabs Studio\n*.tss\n\n# Telerik's JustMock configuration file\n*.jmconfig\n\n# BizTalk build output\n*.btp.cs\n*.btm.cs\n*.odx.cs\n*.xsd.cs\n\n# OpenCover UI analysis results\nOpenCover/\n\n# Azure Stream Analytics local run output\nASALocalRun/\n\n# MSBuild Binary and Structured Log\n*.binlog\n\n# NVidia Nsight GPU debugger configuration file\n*.nvuser\n\n# MFractors (Xamarin productivity tool) working folder\n.mfractor/\n\n# Local History for Visual Studio\n.localhistory/\n\n# BeatPulse healthcheck temp database\nhealthchecksdb\n\n# Backup folder for Package Reference Convert tool in Visual Studio 2017\nMigrationBackup/\n\n# Ionide (cross platform F# VS Code tools) working folder\n.ionide/\n"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# SerialPortForWindowsTerminal\nSerial port for windows terminal, 让Windows Terminal支持串口的插件\n\n该插件为WindowsTerminal提供访问串口终端能力\n\n\n## 使用说明\n\n![截图](https://github.com/Zhou-zhi-peng/SerialPortForWindowsTerminal/blob/main/images/001.bmp?raw=true)\n![截图](https://github.com/Zhou-zhi-peng/SerialPortForWindowsTerminal/blob/main/images/002.bmp?raw=true)\n![截图](https://github.com/Zhou-zhi-peng/SerialPortForWindowsTerminal/blob/main/images/003.bmp?raw=true)\n\n\n## 配置说明：\n![使用说明](https://github.com/Zhou-zhi-peng/SerialPortForWindowsTerminal/blob/main/images/000.gif?raw=true)\n"
  },
  {
    "path": "SerialForWindowsTerminal.cpp",
    "content": "﻿// SerialForWindowsTerminal.cpp : 定义应用程序的入口点。\n//\n\n#include \"framework.h\"\n#include \"SerialForWindowsTerminal.h\"\n#include <vector>\n#include <string>\n#include <iostream>\n#include <boost/asio.hpp> \n#include <boost/asio/windows/stream_handle.hpp>\n\n#define MAX_LOADSTRING 100\n\n// 全局变量:\nHINSTANCE hInstance;\nINT_PTR CALLBACK    About(HWND, UINT, WPARAM, LPARAM);\nINT_PTR CALLBACK    SettingFunc(HWND, UINT, WPARAM, LPARAM);\n\n// 添加全局标志来跟踪Ctrl+A状态\nbool g_isCtrlAPressed = false;\n// 添加全局标志来控制程序退出\nbool g_shouldExit = false;\nstd::vector<uint8_t> g_lineBuffer;\n\nusing PortsArray = std::vector<std::pair<std::wstring, int>>;\n\nstatic PortsArray GetAllPorts(void)\n{\n    PortsArray ports;\n    HKEY hRegKey;\n    int nCount = 0;\n    if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L\"Hardware\\\\DeviceMap\\\\SerialComm\", 0, KEY_READ, &hRegKey) == ERROR_SUCCESS)\n    {\n        while (true)\n        {\n            TCHAR szName[MAX_PATH] = { 0 };\n            TCHAR szPort[MAX_PATH] = { 0 };\n            DWORD nValueSize = MAX_PATH - 1;\n            DWORD nDataSize = MAX_PATH - 1;\n            DWORD nType;\n\n            if (::RegEnumValue(hRegKey, nCount, szName, &nValueSize, NULL, &nType, (LPBYTE)szPort, &nDataSize) == ERROR_NO_MORE_ITEMS)\n            {\n                break;\n            }\n            std::wstring name(szName);\n            auto idx = name.find_last_of('\\\\');\n            if (idx != name.npos)\n            {\n                name = name.substr(idx + 1);\n            }\n            name += L\" (\";\n            name += szPort;\n            name += L\")\";\n            ports.push_back(std::make_pair(name, (int)std::wcstoul(szPort + 3, nullptr, 10)));\n            nCount++;\n        }\n        ::RegCloseKey(hRegKey);\n    }\n    return ports;\n}\n\nstatic void UpdatePortControl(HWND hDlg)\n{\n    auto allPorts = GetAllPorts();\n    auto hWndPort = GetDlgItem(hDlg, IDC_COMBO_PORT);\n    ComboBox_ResetContent(hWndPort);\n    for (auto port : allPorts)\n    {\n        auto index = ComboBox_AddString(hWndPort, port.first.c_str());\n        ComboBox_SetItemData(hWndPort, index, port.second);\n    }\n}\n\nstatic void CenterParentWindow(HWND hWnd)\n{\n    RECT rcDlg;\n    ::GetWindowRect(hWnd, &rcDlg);\n    RECT rcParent;\n    HWND hWndParent = GetParent(hWnd);\n    GetClientRect(hWndParent, &rcParent);\n    POINT ptParentInScreen;\n    ptParentInScreen.x = rcParent.left;\n    ptParentInScreen.y = rcParent.top;\n    ::ClientToScreen(hWndParent, (LPPOINT)&ptParentInScreen);\n    SetWindowPos(\n        hWnd,\n        NULL,\n        ptParentInScreen.x + (rcParent.right - rcParent.left - (rcDlg.right - rcDlg.left)) / 2,\n        ptParentInScreen.y + (rcParent.bottom - rcParent.top - (rcDlg.bottom - rcDlg.top)) / 2,\n        0,\n        0,\n        SWP_NOZORDER | SWP_NOSIZE);\n}\n\ntypedef struct\n{\n    DWORD Serial;\n    DWORD BaudRate;\n    DWORD WordLength;\n    DWORD StopBit;\n    DWORD Parity;\n    DWORD FlowControl;\n    DWORD EncodingFormat;  // 添加编码格式字段：0=UTF8, 1=GBK\n    DWORD EchoMode;        // 添加回显模式字段：0=关闭(字符模式), 1=开启(行模式)\n}SERIAL_CONFIG;\n\nstatic void WriteSerialConfig(const SERIAL_CONFIG& cfg)\n{\n    HKEY hKey;\n    if (ERROR_SUCCESS == ::RegCreateKey(HKEY_CURRENT_USER, L\"SOFTWARE\\\\SerialForWindowsTerminal\", &hKey))\n    {\n        DWORD dwSize = sizeof(DWORD);\n        DWORD dwType = REG_DWORD;\n\n        ::RegSetValueEx(hKey, L\"Serial\", 0, dwType, (CONST LPBYTE)&cfg.Serial, dwSize);\n        ::RegSetValueEx(hKey, L\"BaudRate\", 0, dwType, (CONST LPBYTE)&cfg.BaudRate, dwSize);\n        ::RegSetValueEx(hKey, L\"WordLength\", 0, dwType, (CONST LPBYTE)&cfg.WordLength, dwSize);\n        ::RegSetValueEx(hKey, L\"StopBit\", 0, dwType, (CONST LPBYTE)&cfg.StopBit, dwSize);\n        ::RegSetValueEx(hKey, L\"Parity\", 0, dwType, (CONST LPBYTE)&cfg.Parity, dwSize);\n        ::RegSetValueEx(hKey, L\"FlowControl\", 0, dwType, (CONST LPBYTE)&cfg.FlowControl, dwSize);\n        ::RegSetValueEx(hKey, L\"EncodingFormat\", 0, dwType, (CONST LPBYTE)&cfg.EncodingFormat, dwSize);\n        ::RegSetValueEx(hKey, L\"EchoMode\", 0, dwType, (CONST LPBYTE)&cfg.EchoMode, dwSize);  // 写入回显模式\n        ::RegCloseKey(hKey);\n    }\n}\n\nstatic void ToggleEncodingFormat(SERIAL_CONFIG& cfg)\n{\n    // 切换编码格式\n    cfg.EncodingFormat = (cfg.EncodingFormat == 0) ? 1 : 0;\n    \n    // 应用新的编码格式\n    if (cfg.EncodingFormat == 0) // UTF-8\n    {\n        SetConsoleOutputCP(CP_UTF8);\n        SetConsoleCP(CP_UTF8);\n        std::cout << \"\\033[32mConsole encoding: UTF-8\\033[0m\" << std::endl;\n    }\n    else // GBK\n    {\n        SetConsoleOutputCP(936);\n        SetConsoleCP(936);\n        std::cout << \"\\033[32mConsole encoding: GBK\\033[0m\" << std::endl;\n    }\n    \n    // 保存配置到注册表\n    WriteSerialConfig(cfg);\n}\n\nstatic SERIAL_CONFIG ReadSerialConfig()\n{\n    HKEY hKey;\n    SERIAL_CONFIG cfg;\n    cfg.Serial = 0;\n    cfg.BaudRate = 9600;\n    cfg.WordLength = 8;\n    cfg.StopBit = ONESTOPBIT;\n    cfg.Parity = NOPARITY;\n    cfg.FlowControl = 0;\n    cfg.EncodingFormat = 0;  // 默认使用UTF-8编码\n    cfg.EchoMode = 0;        // 默认关闭回显模式（字符模式）\n    if (ERROR_SUCCESS == ::RegOpenKeyEx(HKEY_CURRENT_USER, L\"SOFTWARE\\\\SerialForWindowsTerminal\", 0, KEY_READ, &hKey))\n    {\n        DWORD dwSize = sizeof(DWORD);\n        DWORD dwType = REG_DWORD;\n\n        ::RegQueryValueEx(hKey, L\"Serial\", 0, &dwType, (LPBYTE)&cfg.Serial, &dwSize);\n        ::RegQueryValueEx(hKey, L\"BaudRate\", 0, &dwType, (LPBYTE)&cfg.BaudRate, &dwSize);\n        ::RegQueryValueEx(hKey, L\"WordLength\", 0, &dwType, (LPBYTE)&cfg.WordLength, &dwSize);\n        ::RegQueryValueEx(hKey, L\"StopBit\", 0, &dwType, (LPBYTE)&cfg.StopBit, &dwSize);\n        ::RegQueryValueEx(hKey, L\"Parity\", 0, &dwType, (LPBYTE)&cfg.Parity, &dwSize);\n        ::RegQueryValueEx(hKey, L\"FlowControl\", 0, &dwType, (LPBYTE)&cfg.FlowControl, &dwSize);\n        ::RegQueryValueEx(hKey, L\"EncodingFormat\", 0, &dwType, (LPBYTE)&cfg.EncodingFormat, &dwSize);\n        ::RegQueryValueEx(hKey, L\"EchoMode\", 0, &dwType, (LPBYTE)&cfg.EchoMode, &dwSize);  // 读取回显模式\n        ::RegCloseKey(hKey);\n    }\n    return cfg;\n}\n\nstatic void ToggleEchoMode(SERIAL_CONFIG& cfg)\n{\n    // 切换回显模式\n    cfg.EchoMode = (cfg.EchoMode == 0) ? 1 : 0;\n    \n    // 清空行缓冲区\n    g_lineBuffer.clear();\n    \n    // 显示当前回显模式\n    std::cout << \"\\033[32mEcho mode: \" << (cfg.EchoMode == 0 ? \"Off\" : \"On\") << \"\\033[0m\" << std::endl;\n    \n    // 保存配置到注册表\n    WriteSerialConfig(cfg);\n}\n\nstatic boost::system::error_code InitializeSerialPort(boost::asio::serial_port& serialPort,const SERIAL_CONFIG& cfg, boost::system::error_code& ec)\n{\n    serialPort.set_option(boost::asio::serial_port::baud_rate(cfg.BaudRate), ec);\n    if (ec)\n        return ec;\n    serialPort.set_option(boost::asio::serial_port::character_size(cfg.WordLength), ec);\n    if (ec)\n        return ec;\n    switch (cfg.StopBit)\n    {\n    case 0:\n        serialPort.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::one), ec);\n        break;\n    case 1:\n        serialPort.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::onepointfive), ec);\n        break;\n    case 2:\n        serialPort.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::two), ec);\n        break;\n    default:\n        serialPort.set_option(boost::asio::serial_port::stop_bits(boost::asio::serial_port::stop_bits::one), ec);\n        break;\n    }\n    if (ec)\n        return ec;\n\n    switch (cfg.Parity)\n    {\n    case 0:\n        serialPort.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::none), ec);\n        break;\n    case 1:\n        serialPort.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::odd), ec);\n        break;\n    case 2:\n        serialPort.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::even), ec);\n        break;\n    default:\n        serialPort.set_option(boost::asio::serial_port::parity(boost::asio::serial_port::parity::none), ec);\n        break;\n    }\n    if (ec)\n        return ec;\n\n    switch (cfg.FlowControl)\n    {\n    case 0:\n        serialPort.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::none), ec);\n        break;\n    case 1:\n        serialPort.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::software), ec);\n        break;\n    case 2:\n        serialPort.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::hardware), ec);\n        break;\n    default:\n        serialPort.set_option(boost::asio::serial_port::flow_control(boost::asio::serial_port::flow_control::none), ec);\n        break;\n    }\n    \n    return ec;\n}\ntemplate <class TStream1, class TStream2>\nstatic void DoStreamToStream(TStream1& stream1, TStream2& stream2, std::vector<uint8_t>& buffer, SERIAL_CONFIG* pCfg = nullptr)\n{\n    stream1.async_read_some(\n        boost::asio::buffer(buffer.data(), buffer.size()),\n        [&stream1, &stream2, &buffer, pCfg](const boost::system::error_code& ec, std::size_t bytes_transferred)\n        {\n            if (ec)\n            {\n                std::cerr << \"\\033[31m\" << \"error : \" << ec.message() << \"\\033[0m\" << std::endl;\n            }\n            else\n            {\n                // 检查是否需要特殊处理键盘输入（仅当stream1是标准输入且有配置指针时）\n                bool skipWrite = false;\n                if (pCfg != nullptr)\n                {\n                    for (size_t i = 0; i < bytes_transferred; i++)\n                    {\n                        uint8_t ch = buffer[i];\n                        \n                        // 检查Ctrl+A (ASCII 1)\n                        if (ch == 1)\n                        {\n                            g_isCtrlAPressed = true;\n                            skipWrite = true;\n                            break;\n                        }\n                        \n                        // 如果Ctrl+A已按下，检查后续按键\n                        if (g_isCtrlAPressed)\n                        {\n                            g_isCtrlAPressed = false; // 重置标志\n                            skipWrite = true;\n                            \n                            // Ctrl+X: 退出程序\n                            if (ch == 24) // Ctrl+X\n                            {\n                                if (MessageBoxW(NULL, L\"确定要退出程序吗？\", L\"退出确认\", MB_YESNO | MB_ICONQUESTION) == IDYES)\n                                {\n                                    g_shouldExit = true;\n                                    // 通过取消所有异步操作来退出io_service\n                                    stream1.cancel();\n                                    stream2.cancel();\n                                    exit(0);\n                                }\n                            }\n                            // Ctrl+C: 切换编码格式\n                            else if (ch == 3) // Ctrl+C\n                            {\n                                ToggleEncodingFormat(*pCfg);\n                            }\n                            // Ctrl+E: 切换回显模式\n                            else if (ch == 5) // Ctrl+E\n                            {\n                                ToggleEchoMode(*pCfg);\n                            }\n                            break;\n                        }\n                    }\n                    \n                    // 如果是回显模式且不是特殊按键，进行行缓冲处理\n                    if (!skipWrite && pCfg->EchoMode == 1)\n                    {\n                        skipWrite = true; // 总是跳过直接写入，由行模式处理\n                        \n                        for (size_t i = 0; i < bytes_transferred; i++)\n                        {\n                            uint8_t ch = buffer[i];\n                            \n                            // 处理退格键\n                            if (ch == 8 || ch == 127) // Backspace或Delete\n                            {\n                                if (!g_lineBuffer.empty())\n                                {\n                                    g_lineBuffer.pop_back();\n                                    // 输出退格、空格、退格以清除屏幕上的字符\n                                    std::cout << \"\\b \\b\";\n                                }\n                                continue;\n                            }\n                            \n                            // 处理回车换行\n                            if (ch == '\\r' || ch == '\\n')\n                            {\n                                // 发送累积的行数据\n                                // if (!g_lineBuffer.empty())\n                                // {\n                                    // 添加回车换行\n                                    g_lineBuffer.push_back('\\r');\n                                    g_lineBuffer.push_back('\\n');\n                                    \n                                    // 写入串口\n                                    boost::asio::write(stream2, boost::asio::buffer(g_lineBuffer.data(), g_lineBuffer.size()));\n                                    \n                                    // 清空缓冲区\n                                    g_lineBuffer.clear();\n                                // }\n                                \n                                // 显示换行到终端\n                                std::cout << \"\\n\";\n                                continue;\n                            }\n                            \n                            // 普通字符，添加到缓冲区并回显\n                            g_lineBuffer.push_back(ch);\n                            std::cout << static_cast<char>(ch);\n                            std::cout.flush(); // 确保立即显示\n                        }\n                    }\n                }\n                \n                // 只有在不需要特殊处理且不是回显模式时才进行正常的数据流传输\n                if (!skipWrite && (pCfg == nullptr || pCfg->EchoMode == 0))\n                {\n                    boost::asio::async_write(\n                        stream2,\n                        boost::asio::const_buffer(buffer.data(), bytes_transferred),\n                        [&stream1, &stream2, &buffer, pCfg](const boost::system::error_code& ec, std::size_t bytes_transferred)\n                        {\n                            if (ec)\n                            {\n                                std::cerr << \"\\033[31m\" << \"error : \" << ec.message() << \"\\033[0m\" << std::endl;\n                            }\n                            else\n                            {\n                                DoStreamToStream(stream1, stream2, buffer, pCfg);\n                            }\n                        }\n                    );\n                }\n                else if (!g_shouldExit)\n                {\n                    // 继续监听输入\n                    DoStreamToStream(stream1, stream2, buffer, pCfg);\n                }\n            }\n        }\n    );\n}\n\nstatic boost::system::error_code DoWork(boost::asio::io_service& ioctx, boost::asio::serial_port& serialPort, SERIAL_CONFIG& cfg)\n{\n    boost::system::error_code ec;\n    boost::asio::windows::stream_handle stdinput(ioctx);\n    boost::asio::windows::stream_handle stdoutput(ioctx);\n    const auto kBufferSize = 1024;\n    std::vector<uint8_t> serialPortRecvBuffer;\n    std::vector<uint8_t> serialPortSendBuffer;\n    serialPortRecvBuffer.resize(kBufferSize);\n    serialPortSendBuffer.resize(kBufferSize);\n\n    auto conin = CreateFile(L\"CONIN$\", FILE_GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);\n    auto conout = CreateFile(L\"CONOUT$\", FILE_GENERIC_WRITE, FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);\n\n    if (stdinput.assign(conin, ec))\n        return ec;\n\n    if (stdoutput.assign(conout, ec))\n        return ec;\n\n    // 对于串口到输出的流，不需要特殊处理\n    DoStreamToStream(serialPort, stdoutput, serialPortRecvBuffer);\n    // 对于输入到串口的流，传递配置指针以支持快捷键处理\n    DoStreamToStream(stdinput, serialPort, serialPortSendBuffer, &cfg);\n    \n    // 重置退出标志\n    g_shouldExit = false;\n    \n    ioctx.run(ec);\n    return ec;\n}\n\nint wmain(int argc, const WCHAR* args[])\n{\n    boost::system::error_code ec;\n    boost::asio::io_service ioctx;\n    boost::asio::serial_port serialPort(ioctx);\n    hInstance = GetModuleHandle(nullptr);\n\n    DWORD consoleMode = 0;\n    auto conin = GetStdHandle(STD_INPUT_HANDLE);\n    auto conout = GetStdHandle(STD_OUTPUT_HANDLE);\n    GetConsoleMode(conin, &consoleMode);\n    consoleMode |= ENABLE_MOUSE_INPUT;\n    consoleMode &= ~ENABLE_ECHO_INPUT;\n    consoleMode &= ~ENABLE_PROCESSED_INPUT;\n    consoleMode &= ~ENABLE_LINE_INPUT;\n    consoleMode |= ENABLE_QUICK_EDIT_MODE;\n    consoleMode |= ENABLE_WINDOW_INPUT;\n    consoleMode |= ENABLE_VIRTUAL_TERMINAL_INPUT;\n    SetConsoleMode(conin, consoleMode);\n\n    GetConsoleMode(conout, &consoleMode);\n    SetConsoleMode(conout, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING | ENABLE_PROCESSED_OUTPUT);\n\n    while (true)\n    {\n        auto hWndParent = ::GetForegroundWindow();\n        if (hWndParent == nullptr)\n            hWndParent = GetConsoleWindow();\n        if (DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETTING_DIALOG), hWndParent, SettingFunc, 1) == IDOK)\n        {\n            ioctx.restart();\n            auto cfg = ReadSerialConfig();\n            auto portName = std::string(\"COM\") + std::to_string(cfg.Serial);\n            if (serialPort.open(portName, ec))\n            {\n                std::cerr << \"\\033[31m\" << \"can not open \" << portName << \"\\033[0m\" <<std::endl;\n                std::cerr << \"\\033[31m\" << \"error : \" << ec.message() << \"\\033[0m\" << std::endl;\n                continue;\n            }\n            if (InitializeSerialPort(serialPort, cfg, ec))\n            {\n                std::cerr << \"\\033[31m\" << \"can not initialize \" << portName << \"\\033[0m\" << std::endl;\n                std::cerr << \"\\033[31m\" << \"error : \" << ec.message() << \"\\033[0m\" << std::endl;\n                continue;\n            }\n            else\n            {\n                // 根据用户选择的编码格式设置控制台\n                if (cfg.EncodingFormat == 0) // UTF-8\n                {\n                    SetConsoleOutputCP(CP_UTF8);\n                    SetConsoleCP(CP_UTF8);\n                }\n                else // GBK\n                {\n                    SetConsoleOutputCP(936);  // 936是GBK的代码页\n                    SetConsoleCP(936);\n                }\n\n                    // 显示当前编码格式\n                    std::cout << \"\\033[36mVersion: v1.0.0\\033[0m\" << std::endl;\n                    std::cout << \"\\033[32mConsole encoding: \" << (cfg.EncodingFormat == 0 ? \"UTF-8\" : \"GBK\") << \"\\033[0m\" << std::endl;\n                    std::cout << \"\\033[32mEcho mode: \" << (cfg.EchoMode == 0 ? \"Off\" : \"On\") << \"\\033[0m\" << std::endl;\n                    std::cout << \"\\033[33mPress Ctrl+A then Ctrl+C to toggle encoding format\\033[0m\" << std::endl;\n                    std::cout << \"\\033[33mPress Ctrl+A then Ctrl+E to toggle echo mode\\033[0m\" << std::endl;\n                    std::cout << \"\\033[33mPress Ctrl+A then Ctrl+X to exit\\033[0m\" << std::endl;\n\n                    // 运行工作循环，传递配置\n                    DoWork(ioctx, serialPort, cfg);\n                    \n                    // 检查是否需要退出程序\n                    if (g_shouldExit)\n                    {\n                        break;\n                    }\n            }\n            break;\n        }\n        else\n        {\n            return ERROR_CANCELLED;\n        }\n    }\n    return ERROR_SUCCESS;\n}\n\n// “关于”框的消息处理程序。\nINT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\n{\n    UNREFERENCED_PARAMETER(lParam);\n    switch (message)\n    {\n    case WM_INITDIALOG:\n        CenterParentWindow(hDlg);\n        return (INT_PTR)TRUE;\n\n    case WM_COMMAND:\n        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)\n        {\n            EndDialog(hDlg, LOWORD(wParam));\n            return (INT_PTR)TRUE;\n        }\n        break;\n    }\n    return (INT_PTR)FALSE;\n}\n\nINT_PTR CALLBACK SettingFunc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\n{\n    UNREFERENCED_PARAMETER(lParam);\n    switch (message)\n    {\n    case WM_INITDIALOG:\n    {\n        CenterParentWindow(hDlg);\n        auto cfg = ReadSerialConfig();\n        auto hWndPort = GetDlgItem(hDlg, IDC_COMBO_PORT);\n        UpdatePortControl(hDlg);\n        auto portCount = ComboBox_GetCount(hWndPort);\n        if (cfg.Serial != 0)\n        {\n            for (int i = 0; i < portCount; ++i)\n            {\n                auto com = (int)ComboBox_GetItemData(hWndPort, i);\n                if (com == cfg.Serial)\n                {\n                    ComboBox_SetCurSel(hWndPort, i);\n                    break;\n                }\n            }\n        }\n        else\n        {\n            ComboBox_SetCurSel(hWndPort, 0);\n        }\n\n        auto hWndBaudRate = GetDlgItem(hDlg, IDC_COMBO_SPEED);\n        ComboBox_AddString(hWndBaudRate, L\"50\"); \n        ComboBox_AddString(hWndBaudRate, L\"75\");\n        ComboBox_AddString(hWndBaudRate, L\"100\");\n        ComboBox_AddString(hWndBaudRate, L\"105\");\n        ComboBox_AddString(hWndBaudRate, L\"300\");\n        ComboBox_AddString(hWndBaudRate, L\"600\");\n        ComboBox_AddString(hWndBaudRate, L\"1200\");\n        ComboBox_AddString(hWndBaudRate, L\"2400\");\n        ComboBox_AddString(hWndBaudRate, L\"4800\");\n        ComboBox_AddString(hWndBaudRate, L\"9600\");\n        ComboBox_AddString(hWndBaudRate, L\"19200\");\n        ComboBox_AddString(hWndBaudRate, L\"38400\");\n        ComboBox_AddString(hWndBaudRate, L\"57600\");\n        ComboBox_AddString(hWndBaudRate, L\"115200\");\n        ComboBox_AddString(hWndBaudRate, L\"128000\");\n        ComboBox_AddString(hWndBaudRate, L\"256000\");\n        ComboBox_SetText(hWndBaudRate, std::to_wstring(cfg.BaudRate).c_str());\n\n        auto hWndWordLength = GetDlgItem(hDlg, IDC_COMBO_WORD);\n        ComboBox_AddString(hWndWordLength, L\"4\");\n        ComboBox_AddString(hWndWordLength, L\"5\");\n        ComboBox_AddString(hWndWordLength, L\"6\");\n        ComboBox_AddString(hWndWordLength, L\"7\");\n        ComboBox_AddString(hWndWordLength, L\"8\");\n        ComboBox_AddString(hWndWordLength, L\"9\");\n        ComboBox_AddString(hWndWordLength, L\"10\");\n        ComboBox_SetCurSel(hWndWordLength, (int)(cfg.WordLength - 4));\n\n        auto hWndStopBit = GetDlgItem(hDlg, IDC_COMBO_STOP);\n        ComboBox_AddString(hWndStopBit, L\"1\");\n        ComboBox_AddString(hWndStopBit, L\"1.5\");\n        ComboBox_AddString(hWndStopBit, L\"2\");\n        ComboBox_SetCurSel(hWndStopBit, (int)(cfg.StopBit));\n\n        auto hWndParity = GetDlgItem(hDlg, IDC_COMBO_PARITY);\n        ComboBox_AddString(hWndParity, L\"无\");\n        ComboBox_AddString(hWndParity, L\"奇\");\n        ComboBox_AddString(hWndParity, L\"偶\");\n        ComboBox_SetCurSel(hWndParity, (int)(cfg.Parity));\n\n        auto hWndFlowControl = GetDlgItem(hDlg, IDC_COMBO_FLOW_CONTROL);\n        ComboBox_AddString(hWndFlowControl, L\"无\");\n        ComboBox_AddString(hWndFlowControl, L\"软件(Xon/Xoff)\");\n        ComboBox_AddString(hWndFlowControl, L\"硬件\");\n        ComboBox_SetCurSel(hWndFlowControl, (int)(cfg.FlowControl));\n\n        // 在WM_INITDIALOG处理部分，在FlowControl下拉框之后添加编码格式下拉框\n        auto hWndEncoding = GetDlgItem(hDlg, IDC_COMBO_ENCODING);\n        ComboBox_AddString(hWndEncoding, L\"UTF-8\");\n        ComboBox_AddString(hWndEncoding, L\"GBK\");\n        ComboBox_SetCurSel(hWndEncoding, (int)(cfg.EncodingFormat));\n\n        // 添加回显模式复选框\n        auto hWndEchoMode = GetDlgItem(hDlg, IDC_COMBO_ECHO);\n        ComboBox_AddString(hWndEchoMode, L\"关闭\");\n        ComboBox_AddString(hWndEchoMode, L\"开启\");\n        ComboBox_SetCurSel(hWndEchoMode, (int)(cfg.EchoMode));\n\n        return (INT_PTR)TRUE;\n    }\n    case WM_DEVICECHANGE:\n        UpdatePortControl(hDlg);\n        return (INT_PTR)TRUE;\n    case WM_COMMAND:\n        if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)\n        {\n            if (LOWORD(wParam) == IDOK)\n            {\n                SERIAL_CONFIG cfg = {0};\n                auto hWndPort = GetDlgItem(hDlg, IDC_COMBO_PORT);\n                auto hWndBaudRate = GetDlgItem(hDlg, IDC_COMBO_SPEED);\n                auto hWndWordLength = GetDlgItem(hDlg, IDC_COMBO_WORD);\n                auto hWndStopBit = GetDlgItem(hDlg, IDC_COMBO_STOP);\n                auto hWndParity = GetDlgItem(hDlg, IDC_COMBO_PARITY);\n                auto hWndFlowControl = GetDlgItem(hDlg, IDC_COMBO_FLOW_CONTROL);\n\n                WCHAR txtBuffer[32] = {0};\n                auto curSel = ComboBox_GetCurSel(hWndPort);\n                if (curSel >= 0)\n                {\n                    cfg.Serial = (DWORD)ComboBox_GetItemData(hWndPort, curSel);\n                }\n                else\n                {\n                    ComboBox_GetText(hWndPort, txtBuffer, 32);\n                    cfg.Serial = std::wcstoul(txtBuffer + 3, nullptr, 10);\n                }\n                ComboBox_GetText(hWndBaudRate, txtBuffer, 32);\n                cfg.BaudRate = std::wcstoul(txtBuffer, nullptr, 10);\n                cfg.WordLength = ComboBox_GetCurSel(hWndWordLength) + 4;\n                cfg.StopBit = ComboBox_GetCurSel(hWndStopBit);\n                cfg.Parity = ComboBox_GetCurSel(hWndParity);\n                cfg.FlowControl = ComboBox_GetCurSel(hWndFlowControl);\n                // 获取编码格式下拉框的当前选择\n                auto hWndEncoding = GetDlgItem(hDlg, IDC_COMBO_ENCODING);\n                cfg.EncodingFormat = ComboBox_GetCurSel(hWndEncoding);\n\n                // 获取回显模式复选框状态\n                auto hWndEchoMode = GetDlgItem(hDlg, IDC_COMBO_ECHO);\n                cfg.EchoMode = ComboBox_GetCurSel(hWndEchoMode);\n\n                WriteSerialConfig(cfg);\n            }\n            EndDialog(hDlg, LOWORD(wParam));\n            return (INT_PTR)TRUE;\n        }\n        break;\n    }\n    return (INT_PTR)FALSE;\n}"
  },
  {
    "path": "SerialForWindowsTerminal.h",
    "content": "#pragma once\n\n#include \"resource.h\"\n"
  },
  {
    "path": "SerialForWindowsTerminal.sln",
    "content": "﻿\nMicrosoft Visual Studio Solution File, Format Version 12.00\n# Visual Studio Version 16\nVisualStudioVersion = 16.0.31019.35\nMinimumVisualStudioVersion = 10.0.40219.1\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"SerialForWindowsTerminal\", \"SerialForWindowsTerminal.vcxproj\", \"{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug|x64 = Debug|x64\n\t\tDebug|x86 = Debug|x86\n\t\tRelease|x64 = Release|x64\n\t\tRelease|x86 = Release|x86\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Debug|x64.ActiveCfg = Debug|x64\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Debug|x64.Build.0 = Debug|x64\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Debug|x86.ActiveCfg = Debug|Win32\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Debug|x86.Build.0 = Debug|Win32\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Release|x64.ActiveCfg = Release|x64\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Release|x64.Build.0 = Release|x64\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Release|x86.ActiveCfg = Release|Win32\n\t\t{77CF1E9C-BB5B-4DD5-B18C-30D998DB8BC0}.Release|x86.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityGlobals) = postSolution\n\t\tSolutionGuid = {7BB5C9B7-34E8-4227-B1EB-22E406EEF0EA}\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "SerialForWindowsTerminal.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|x64\">\n      <Configuration>Debug</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|x64\">\n      <Configuration>Release</Configuration>\n      <Platform>x64</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <VCProjectVersion>16.0</VCProjectVersion>\n    <Keyword>Win32Proj</Keyword>\n    <ProjectGuid>{77cf1e9c-bb5b-4dd5-b18c-30d998db8bc0}</ProjectGuid>\n    <RootNamespace>SerialForWindowsTerminal</RootNamespace>\n    <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v142</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v142</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>true</UseDebugLibraries>\n    <PlatformToolset>v142</PlatformToolset>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <PlatformToolset>v142</PlatformToolset>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"Shared\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <LinkIncremental>false</LinkIncremental>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>D:\\boost_1_68_0\\</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalManifestDependencies>type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'</AdditionalManifestDependencies>\n      <AdditionalLibraryDirectories>D:\\boost_1_68_0\\Windows\\msvc14.1\\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n    <Manifest>\n      <EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>\n    </Manifest>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>C:\\local\\boost_1_68_0\\lib64-msvc-14.1;C:\\local\\boost_1_68_0</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalManifestDependencies>type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'</AdditionalManifestDependencies>\n      <AdditionalLibraryDirectories>C:\\local\\boost_1_68_0\\lib64-msvc-14.1;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>C:\\local\\boost_1_68_0</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalLibraryDirectories>C:\\local\\boost_1_68_0\\lib64-msvc-14.1;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <AdditionalManifestDependencies>type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'</AdditionalManifestDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|x64'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <SDLCheck>true</SDLCheck>\n      <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <ConformanceMode>true</ConformanceMode>\n      <AdditionalIncludeDirectories>C:\\local\\boost_1_68_0</AdditionalIncludeDirectories>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalLibraryDirectories>C:\\local\\boost_1_68_0\\lib64-msvc-14.1;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>\n      <AdditionalManifestDependencies>type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'</AdditionalManifestDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"framework.h\" />\n    <ClInclude Include=\"Resource.h\" />\n    <ClInclude Include=\"SerialForWindowsTerminal.h\" />\n    <ClInclude Include=\"targetver.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"SerialForWindowsTerminal.cpp\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"SerialForWindowsTerminal.rc\" />\n  </ItemGroup>\n  <ItemGroup>\n    <Image Include=\"SerialForWindowsTerminal.ico\" />\n    <Image Include=\"small.ico\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "SerialForWindowsTerminal.vcxproj.filters",
    "content": "﻿<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"源文件\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"头文件\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"资源文件\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"framework.h\">\n      <Filter>头文件</Filter>\n    </ClInclude>\n    <ClInclude Include=\"targetver.h\">\n      <Filter>头文件</Filter>\n    </ClInclude>\n    <ClInclude Include=\"Resource.h\">\n      <Filter>头文件</Filter>\n    </ClInclude>\n    <ClInclude Include=\"SerialForWindowsTerminal.h\">\n      <Filter>头文件</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"SerialForWindowsTerminal.cpp\">\n      <Filter>源文件</Filter>\n    </ClCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"SerialForWindowsTerminal.rc\">\n      <Filter>资源文件</Filter>\n    </ResourceCompile>\n  </ItemGroup>\n  <ItemGroup>\n    <Image Include=\"small.ico\">\n      <Filter>资源文件</Filter>\n    </Image>\n    <Image Include=\"SerialForWindowsTerminal.ico\">\n      <Filter>资源文件</Filter>\n    </Image>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "framework.h",
    "content": "﻿// header.h: 标准系统包含文件的包含文件，\n// 或特定于项目的包含文件\n//\n\n#pragma once\n\n#include \"targetver.h\"\n#define WIN32_LEAN_AND_MEAN             // 从 Windows 头文件中排除极少使用的内容\n// Windows 头文件\n#include <windows.h>\n#include <windowsx.h>\n\n// C 运行时头文件\n#include <stdlib.h>\n#include <malloc.h>\n#include <memory.h>\n#include <tchar.h>\n"
  },
  {
    "path": "resource.h",
    "content": "﻿//{{NO_DEPENDENCIES}}\n// Microsoft Visual C++ 生成的包含文件。\n// 供 SerialForWindowsTerminal.rc 使用\n//\n#define IDC_MYICON                      2\n#define IDD_SERIALFORWINDOWSTERMINAL_DIALOG 102\n#define IDS_APP_TITLE                   103\n#define IDD_ABOUTBOX                    103\n#define IDM_ABOUT                       104\n#define IDI_SERIALFORWINDOWSTERMINAL    107\n#define IDI_SMALL                       108\n#define IDC_SERIALFORWINDOWSTERMINAL    109\n#define IDR_MAINFRAME                   128\n#define IDD_SETTING_DIALOG              130\n#define IDC_COMBO1                      1002\n#define IDC_COMBO_PORT                  1002\n#define IDC_COMBO2                      1003\n#define IDC_COMBO_SPEED                 1003\n#define IDC_COMBO3                      1004\n#define IDC_COMBO_WORD                  1004\n#define IDC_COMBO4                      1005\n#define IDC_COMBO_STOP                  1005\n#define IDC_COMBO5                      1006\n#define IDC_COMBO_CHECK                 1006\n#define IDC_COMBO_PARITY                1006\n#define IDC_COMBO6                      1007\n#define IDC_COMBO_FLOW_CONTROL          1007\n#define IDC_COMBO_ENCODING              1008\n#define IDC_COMBO_FLOW_CONTROL2         1011\n#define IDC_COMBO_ECHO                  1011\n#define IDC_STATIC                      -1\n\n// Next default values for new objects\n// \n#ifdef APSTUDIO_INVOKED\n#ifndef APSTUDIO_READONLY_SYMBOLS\n#define _APS_NO_MFC                     1\n#define _APS_NEXT_RESOURCE_VALUE        131\n#define _APS_NEXT_COMMAND_VALUE         32771\n#define _APS_NEXT_CONTROL_VALUE         1010\n#define _APS_NEXT_SYMED_VALUE           110\n#endif\n#endif\n"
  },
  {
    "path": "targetver.h",
    "content": "﻿#pragma once\n\n// // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。\n// 如果希望为之前的 Windows 平台构建应用程序，在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并\n// 将 _WIN32_WINNT 宏设置为想要支持的平台。\n#include <SDKDDKVer.h>\n"
  }
]