Browse Source

import FileCharsetConvert

HOME 3 months ago
parent
commit
82ced41b3a

+ 11 - 0
FileCharsetConvert/FileCharsetConvert.csproj

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

+ 263 - 0
FileCharsetConvert/MainForm.Designer.cs

@@ -0,0 +1,263 @@
+namespace FileCharsetConvert
+{
+    partial class MainForm
+    {
+        /// <summary>
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows 窗体设计器生成的代码
+
+        /// <summary>
+        /// 设计器支持所需的方法 - 不要
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            ColumnHeader columnHeader1;
+            ColumnHeader columnHeader3;
+            label2 = new Label();
+            proc = new ProgressBar();
+            btnApplySelection = new Button();
+            cmbInEnc = new ComboBox();
+            btnScan = new Button();
+            label1 = new Label();
+            btnSelectFolder = new Button();
+            txtFolder = new TextBox();
+            lvMain = new ListView();
+            chkSubDir = new CheckBox();
+            txtFlt = new TextBox();
+            label3 = new Label();
+            cmbOutEnc = new ComboBox();
+            label4 = new Label();
+            dlgFolder = new FolderBrowserDialog();
+            columnHeader1 = new ColumnHeader();
+            columnHeader3 = new ColumnHeader();
+            SuspendLayout();
+            // 
+            // columnHeader1
+            // 
+            columnHeader1.Text = "文件名(双击预览)";
+            columnHeader1.Width = 427;
+            // 
+            // columnHeader3
+            // 
+            columnHeader3.Text = "状态";
+            columnHeader3.Width = 64;
+            // 
+            // label2
+            // 
+            label2.AutoSize = true;
+            label2.Location = new Point(14, 86);
+            label2.Margin = new Padding(4, 0, 4, 0);
+            label2.Name = "label2";
+            label2.Size = new Size(44, 17);
+            label2.TabIndex = 18;
+            label2.Text = "读编码";
+            // 
+            // proc
+            // 
+            proc.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            proc.Location = new Point(14, 154);
+            proc.Margin = new Padding(4, 4, 4, 4);
+            proc.Name = "proc";
+            proc.Size = new Size(584, 14);
+            proc.TabIndex = 17;
+            // 
+            // btnApplySelection
+            // 
+            btnApplySelection.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            btnApplySelection.Location = new Point(511, 103);
+            btnApplySelection.Margin = new Padding(4, 4, 4, 4);
+            btnApplySelection.Name = "btnApplySelection";
+            btnApplySelection.Size = new Size(88, 33);
+            btnApplySelection.TabIndex = 7;
+            btnApplySelection.Text = "应用选中";
+            btnApplySelection.UseVisualStyleBackColor = true;
+            btnApplySelection.Click += btnApplySelection_Click;
+            // 
+            // cmbInEnc
+            // 
+            cmbInEnc.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            cmbInEnc.DisplayMember = "DisplayName";
+            cmbInEnc.FormattingEnabled = true;
+            cmbInEnc.Location = new Point(65, 82);
+            cmbInEnc.Margin = new Padding(4, 4, 4, 4);
+            cmbInEnc.Name = "cmbInEnc";
+            cmbInEnc.Size = new Size(438, 25);
+            cmbInEnc.TabIndex = 5;
+            // 
+            // btnScan
+            // 
+            btnScan.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            btnScan.Location = new Point(511, 47);
+            btnScan.Margin = new Padding(4, 4, 4, 4);
+            btnScan.Name = "btnScan";
+            btnScan.Size = new Size(88, 33);
+            btnScan.TabIndex = 4;
+            btnScan.Text = "扫描";
+            btnScan.UseVisualStyleBackColor = true;
+            btnScan.Click += btnScan_Click;
+            // 
+            // label1
+            // 
+            label1.AutoSize = true;
+            label1.Location = new Point(14, 13);
+            label1.Margin = new Padding(4, 0, 4, 0);
+            label1.Name = "label1";
+            label1.Size = new Size(44, 17);
+            label1.TabIndex = 12;
+            label1.Text = "文件夹";
+            // 
+            // btnSelectFolder
+            // 
+            btnSelectFolder.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            btnSelectFolder.Location = new Point(511, 6);
+            btnSelectFolder.Margin = new Padding(4, 4, 4, 4);
+            btnSelectFolder.Name = "btnSelectFolder";
+            btnSelectFolder.Size = new Size(88, 33);
+            btnSelectFolder.TabIndex = 1;
+            btnSelectFolder.Text = "浏览";
+            btnSelectFolder.UseVisualStyleBackColor = true;
+            btnSelectFolder.Click += btnSelectFolder_Click;
+            // 
+            // txtFolder
+            // 
+            txtFolder.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtFolder.Location = new Point(65, 8);
+            txtFolder.Margin = new Padding(4, 4, 4, 4);
+            txtFolder.Name = "txtFolder";
+            txtFolder.Size = new Size(438, 23);
+            txtFolder.TabIndex = 0;
+            // 
+            // lvMain
+            // 
+            lvMain.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
+            lvMain.Columns.AddRange(new ColumnHeader[] { columnHeader1, columnHeader3 });
+            lvMain.FullRowSelect = true;
+            lvMain.Location = new Point(14, 177);
+            lvMain.Margin = new Padding(4, 4, 4, 4);
+            lvMain.Name = "lvMain";
+            lvMain.Size = new Size(584, 438);
+            lvMain.TabIndex = 8;
+            lvMain.UseCompatibleStateImageBehavior = false;
+            lvMain.View = View.Details;
+            lvMain.MouseDoubleClick += lvMain_MouseDoubleClick;
+            // 
+            // chkSubDir
+            // 
+            chkSubDir.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+            chkSubDir.AutoSize = true;
+            chkSubDir.Location = new Point(405, 47);
+            chkSubDir.Margin = new Padding(4, 4, 4, 4);
+            chkSubDir.Name = "chkSubDir";
+            chkSubDir.Size = new Size(99, 21);
+            chkSubDir.TabIndex = 3;
+            chkSubDir.Text = "包含子文件夹";
+            chkSubDir.UseVisualStyleBackColor = true;
+            // 
+            // txtFlt
+            // 
+            txtFlt.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            txtFlt.Location = new Point(65, 44);
+            txtFlt.Margin = new Padding(4, 4, 4, 4);
+            txtFlt.Name = "txtFlt";
+            txtFlt.Size = new Size(319, 23);
+            txtFlt.TabIndex = 2;
+            txtFlt.Text = "*.txt;*.cs;*.aspx";
+            // 
+            // label3
+            // 
+            label3.AutoSize = true;
+            label3.Location = new Point(14, 48);
+            label3.Margin = new Padding(4, 0, 4, 0);
+            label3.Name = "label3";
+            label3.Size = new Size(32, 17);
+            label3.TabIndex = 21;
+            label3.Text = "过滤";
+            // 
+            // cmbOutEnc
+            // 
+            cmbOutEnc.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+            cmbOutEnc.DisplayMember = "DisplayName";
+            cmbOutEnc.FormattingEnabled = true;
+            cmbOutEnc.Location = new Point(65, 119);
+            cmbOutEnc.Margin = new Padding(4, 4, 4, 4);
+            cmbOutEnc.Name = "cmbOutEnc";
+            cmbOutEnc.Size = new Size(438, 25);
+            cmbOutEnc.TabIndex = 6;
+            // 
+            // label4
+            // 
+            label4.AutoSize = true;
+            label4.Location = new Point(14, 123);
+            label4.Margin = new Padding(4, 0, 4, 0);
+            label4.Name = "label4";
+            label4.Size = new Size(44, 17);
+            label4.TabIndex = 18;
+            label4.Text = "写编码";
+            // 
+            // dlgFolder
+            // 
+            dlgFolder.RootFolder = Environment.SpecialFolder.MyComputer;
+            // 
+            // MainForm
+            // 
+            AutoScaleDimensions = new SizeF(7F, 17F);
+            AutoScaleMode = AutoScaleMode.Font;
+            ClientSize = new Size(612, 633);
+            Controls.Add(label3);
+            Controls.Add(txtFlt);
+            Controls.Add(chkSubDir);
+            Controls.Add(label4);
+            Controls.Add(label2);
+            Controls.Add(proc);
+            Controls.Add(btnApplySelection);
+            Controls.Add(cmbOutEnc);
+            Controls.Add(cmbInEnc);
+            Controls.Add(btnScan);
+            Controls.Add(label1);
+            Controls.Add(btnSelectFolder);
+            Controls.Add(txtFolder);
+            Controls.Add(lvMain);
+            Margin = new Padding(4, 4, 4, 4);
+            Name = "MainForm";
+            Text = "文件编码转换";
+            ResumeLayout(false);
+            PerformLayout();
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.ProgressBar proc;
+        private System.Windows.Forms.Button btnApplySelection;
+        private System.Windows.Forms.ComboBox cmbInEnc;
+        private System.Windows.Forms.Button btnScan;
+        private System.Windows.Forms.Label label1;
+        private System.Windows.Forms.Button btnSelectFolder;
+        private System.Windows.Forms.TextBox txtFolder;
+        private System.Windows.Forms.ListView lvMain;
+        private System.Windows.Forms.CheckBox chkSubDir;
+        private System.Windows.Forms.TextBox txtFlt;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.ComboBox cmbOutEnc;
+        private System.Windows.Forms.Label label4;
+        private System.Windows.Forms.FolderBrowserDialog dlgFolder;
+    }
+}
+

+ 76 - 0
FileCharsetConvert/MainForm.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.IO;
+using System.Diagnostics;
+
+namespace FileCharsetConvert;
+
+public partial class MainForm : Form
+{
+    public MainForm()
+    {
+        InitializeComponent();
+        cmbInEnc.DataSource = Encoding.GetEncodings();
+        cmbOutEnc.DataSource = Encoding.GetEncodings();
+    }
+
+    private void btnSelectFolder_Click(object sender, EventArgs e)
+    {
+        if (dlgFolder.ShowDialog() == DialogResult.OK)
+            txtFolder.Text = dlgFolder.SelectedPath;
+    }
+
+    private void btnScan_Click(object sender, EventArgs e)
+    {
+        List<string> ScanResult = new List<string>();
+
+        foreach (var item in txtFlt.Text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
+        {
+            ScanResult.AddRange(Directory.GetFiles(txtFolder.Text, item,
+                chkSubDir.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
+        }
+
+        var FileList = ScanResult.Distinct().ToList();
+
+        lvMain.Items.Clear();
+        foreach (var item in FileList)
+        {
+            var lvi = new ListViewItem();
+            lvi.Text = item;
+            lvi.SubItems.Add("未转换");
+
+            lvMain.Items.Add(lvi);
+
+        }
+
+    }
+
+    private void btnApplySelection_Click(object sender, EventArgs e)
+    {
+        foreach (ListViewItem item in lvMain.SelectedItems)
+        {
+            File.WriteAllText(item.Text,
+                File.ReadAllText(item.Text, ((EncodingInfo)cmbInEnc.SelectedItem).GetEncoding()),
+                ((EncodingInfo)cmbOutEnc.SelectedItem).GetEncoding());
+            item.SubItems[1].Text = "已转换";
+        }
+    }
+
+    private void lvMain_MouseDoubleClick(object sender, MouseEventArgs e)
+    {
+        if (lvMain.SelectedItems.Count != 0)
+        {
+            string filename = Path.GetTempFileName() + "-" + Path.GetFileName(lvMain.SelectedItems[0].Text) + ".txt";
+            File.WriteAllText(filename,
+                File.ReadAllText(lvMain.SelectedItems[0].Text, ((EncodingInfo)cmbInEnc.SelectedItem).GetEncoding()),
+                ((EncodingInfo)cmbOutEnc.SelectedItem).GetEncoding());
+            Process.Start(new ProcessStartInfo() { FileName = filename, UseShellExecute = true });
+        }
+    }
+}

+ 129 - 0
FileCharsetConvert/MainForm.resx

@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!--
+    Microsoft ResX Schema 
+
+    Version 2.0
+
+    The primary goals of this format is to allow a simple XML format
+    that is mostly human readable. The generation and parsing of the
+    various data types are done through the TypeConverter classes
+    associated with the data types.
+
+    Example:
+
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+
+    There are any number of "resheader" rows that contain simple
+    name/value pairs.
+
+    Each data row contains a name, and value. The row also contains a
+    type or mimetype. Type corresponds to a .NET class that support
+    text/value conversion through the TypeConverter architecture.
+    Classes that don't support this are serialized and stored with the
+    mimetype set.
+
+    The mimetype is used for serialized objects, and tells the
+    ResXResourceReader how to depersist the object. This is currently not
+    extensible. For a given mimetype the value must be set accordingly:
+
+    Note - application/x-microsoft.net.object.binary.base64 is the format
+    that the ResXResourceWriter will generate, however the reader can
+    read any of the formats listed below.
+
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="columnHeader1.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+  <metadata name="columnHeader3.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+  <metadata name="dlgFolder.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>

+ 19 - 0
FileCharsetConvert/Program.cs

@@ -0,0 +1,19 @@
+using System.Text;
+
+namespace FileCharsetConvert;
+
+internal static class Program
+{
+    /// <summary>
+    ///  The main entry point for the application.
+    /// </summary>
+    [STAThread]
+    static void Main()
+    {
+        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
+        // To customize application configuration such as set high DPI settings or default font,
+        // see https://aka.ms/applicationconfiguration.
+        ApplicationConfiguration.Initialize();
+        Application.Run(new MainForm());
+    }
+}

+ 7 - 1
StrangeTools.sln

@@ -42,7 +42,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleIcon", "ConsoleIcon\
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConnectionStat-net7", "ConnectionStat\ConnectionStat-net7.csproj", "{F5E85481-3D66-4613-8A38-9FB863248D18}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SubtitleFontCollection", "SubtitleFontCollection\SubtitleFontCollection.csproj", "{4DF53F11-E296-4E40-83AB-B91B51750B81}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SubtitleFontCollection", "SubtitleFontCollection\SubtitleFontCollection.csproj", "{4DF53F11-E296-4E40-83AB-B91B51750B81}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FileCharsetConvert", "FileCharsetConvert\FileCharsetConvert.csproj", "{50E8583A-2B8B-44C0-A397-95A0BD1B0807}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -122,6 +124,10 @@ Global
 		{4DF53F11-E296-4E40-83AB-B91B51750B81}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{4DF53F11-E296-4E40-83AB-B91B51750B81}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{4DF53F11-E296-4E40-83AB-B91B51750B81}.Release|Any CPU.Build.0 = Release|Any CPU
+		{50E8583A-2B8B-44C0-A397-95A0BD1B0807}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{50E8583A-2B8B-44C0-A397-95A0BD1B0807}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{50E8583A-2B8B-44C0-A397-95A0BD1B0807}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{50E8583A-2B8B-44C0-A397-95A0BD1B0807}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE