Browse Source

Import: MojibakeCorrecting

HOME 11 months ago
parent
commit
4926954ae3

+ 144 - 0
MojibakeCorrecting/MainForm.cs

@@ -0,0 +1,144 @@
+//Target:Winform
+//Ref:System
+//Ref:System.Drawing
+//Ref:System.Windows.Forms
+
+using System;
+using System.Diagnostics;
+using System.Drawing;
+using System.Reflection;
+using System.Text;
+using System.Windows.Forms;
+
+[assembly: AssemblyTitle("Mojibake correcting for filename and file content")]
+[assembly: AssemblyProduct("Mojibake correcting")]
+[assembly: AssemblyCopyright("Copyright © V 2016")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
+
+namespace MojibakeCorrecting
+{
+    internal static class ShutUpDesigener
+    {
+        public static T AddControl<T>(this Control me, T toAdd) where T : Control
+        {
+            me.Controls.Add(toAdd);
+            return toAdd;
+        }
+
+        public static T AddItem<T>(this ToolStrip me, T toAdd) where T : ToolStripItem
+        {
+            me.Items.Add(toAdd);
+            return toAdd;
+        }
+    }
+
+    public class MainForm : Form
+    {
+        private MainForm()
+        {
+            InitUi();
+        }
+
+        private void InitUi()
+        {
+            ClientSize = new Size(640, 480);
+
+            Text = Application.ProductName;
+
+            var tcMain = new TabControl { Dock = DockStyle.Fill };
+            Controls.Add(tcMain);
+
+            //var tpFileName = new TabPage("File name");
+            //tcMain.TabPages.Add(tpFileName);
+
+            //var tpFileContent = new TabPage("File content");
+            //tcMain.TabPages.Add(tpFileContent);
+
+            var tpEncodingDetect = new TabPage("Encoding Detect");
+            tcMain.TabPages.Add(tpEncodingDetect);
+            {
+                //instance && conf
+
+                var toolbar = new ToolStrip { Dock = DockStyle.Top, RenderMode = ToolStripRenderMode.System, GripStyle = ToolStripGripStyle.Hidden };
+
+                toolbar.AddItem(new ToolStripLabel("From:"));
+                var tbcbF = toolbar.AddItem(new ToolStripComboBox { ComboBox = { DisplayMember = "DisplayName", ValueMember = "CodePage", DropDownStyle = ComboBoxStyle.DropDownList, DataSource = Encoding.GetEncodings(), Width = 200 } }).ComboBox;
+
+                toolbar.AddItem(new ToolStripLabel("To:"));
+                var tbcbT = toolbar.AddItem(new ToolStripComboBox { ComboBox = { DisplayMember = "DisplayName", ValueMember = "CodePage", DropDownStyle = ComboBoxStyle.DropDownList, DataSource = Encoding.GetEncodings(), Width = 200 } }).ComboBox;
+                var tbtnC = toolbar.AddItem(new ToolStripButton("MConv") { ToolTipText = "Manual convert" });
+                var tbckA = toolbar.AddItem(new ToolStripButton("AOChg") { ToolTipText = "Auto convert on changed" });
+                var tbtnR = toolbar.AddItem(new ToolStripButton("Reset") { ToolTipText = "Reset controls" });
+
+                var split = new SplitContainer { Dock = DockStyle.Fill, Orientation = Orientation.Horizontal };
+                var txtOrig = new TextBox { Multiline = true, Dock = DockStyle.Fill };
+                var txtResu = new TextBox { Multiline = true, Dock = DockStyle.Fill, ReadOnly = true };
+
+                //fucking resharper
+
+                Debug.Assert(tbcbF != null, "cb is null");
+                Debug.Assert(tbcbT != null, "cb is null");
+
+                //event
+
+                tbckA.Click += delegate
+                {
+                    tbckA.Checked = !tbckA.Checked;
+                    tbtnC.Enabled = !tbckA.Checked;
+                };
+
+                var actConv = new Action(() =>
+                {
+                    var enc = Encoding.GetEncoding((int)tbcbF.SelectedValue);
+                    var dec = Encoding.GetEncoding((int)tbcbT.SelectedValue);
+                    txtResu.Text = dec.GetString(enc.GetBytes(txtOrig.Text));
+                });
+
+                var actChkConv = new Action(() => { if (tbckA.Checked) actConv(); });
+
+                var actReset = new Action(() =>
+                {
+                    var def = Encoding.Default.CodePage;
+                    tbcbF.SelectedValue = def;
+                    tbcbT.SelectedValue = def;
+                    txtOrig.Clear();
+                    txtResu.Clear();
+                });
+
+                tbcbF.SelectedIndexChanged += delegate { actChkConv(); };
+                tbcbT.SelectedIndexChanged += delegate { actChkConv(); };
+                txtOrig.TextChanged += delegate { actChkConv(); };
+
+                tbtnC.Click += delegate { actConv(); };
+
+                tbtnR.Click += delegate { actReset(); };
+
+                //put
+
+                tpEncodingDetect.Controls.Add(split);
+                split.Panel1.Controls.Add(txtOrig);
+                split.Panel2.Controls.Add(txtResu);
+
+                tpEncodingDetect.Controls.Add(toolbar);
+
+                //init
+                Shown += delegate
+                {
+                    actReset();
+                };
+            }
+        }
+
+        /// <summary>
+        /// 应用程序的主入口点。
+        /// </summary>
+        [STAThread]
+        private static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+            Application.Run(new MainForm());
+        }
+    }
+}

+ 120 - 0
MojibakeCorrecting/MainForm.resx

@@ -0,0 +1,120 @@
+<?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=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>
+</root>

+ 66 - 0
MojibakeCorrecting/MojibakeCorrecting.csproj

@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{261D52DE-F168-41D2-AD50-78B5B1D801E3}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>MojibakeCorrecting</RootNamespace>
+    <AssemblyName>MojibakeCorrecting</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Windows.Forms" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="MainForm.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="Properties\" />
+  </ItemGroup>
+  <ItemGroup>
+    <EmbeddedResource Include="MainForm.resx">
+      <DependentUpon>MainForm.cs</DependentUpon>
+    </EmbeddedResource>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PostBuildEvent>if $(ConfigurationName) == Release if not exist $(TargetDir)Packed md $(TargetDir)Packed
+if $(ConfigurationName) == Release $(SolutionDir)packages\ILRepack.2.0.10\tools\ILRepack /ndebug /out:$(TargetDir)Packed\$(TargetFileName) $(TargetPath)</PostBuildEvent>
+  </PropertyGroup>
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 4 - 0
MojibakeCorrecting/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="ILRepack" version="2.0.10" targetFramework="net461" />
+</packages>

+ 2 - 0
StrangeTools.sln

@@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotLoader", "DotLoader\DotL
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TcpTunnel", "TcpTunnel\TcpTunnel.csproj", "{9FA46C6F-A981-4303-8256-EC9B6536BFE5}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MojibakeCorrecting", "MojibakeCorrecting\MojibakeCorrecting.csproj", "{261D52DE-F168-41D2-AD50-78B5B1D801E3}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU