Browse Source

Import initiale - v1.0.0
Cette première version permet la détection de l'encodage, du EOL et le réencodage avec des options en entrée du programme.

Aryx 3 years ago
commit
8e9735cf5f

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+obj
+bin

+ 34 - 0
DetectEncoding.sln

@@ -0,0 +1,34 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.40629.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DetectEncoding", "DetectEncoding\DetectEncoding.csproj", "{82D05B7B-F006-4142-9E32-EBBB67D04875}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextEncodingDetect", "E:\CSharp\Projects\Ext\text-encoding-detect\TextEncodingDetect-C#\TextEncodingDetect\TextEncodingDetect.csproj", "{9E3C3CE1-23DD-4A1B-B927-92D6BE3011A2}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AryxDevLibrary", "..\..\AryxDevLibrary\AryxDevLibrary.csproj", "{E7DED023-F57F-4715-BC8D-752B60B6A203}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{82D05B7B-F006-4142-9E32-EBBB67D04875}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{82D05B7B-F006-4142-9E32-EBBB67D04875}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{82D05B7B-F006-4142-9E32-EBBB67D04875}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{82D05B7B-F006-4142-9E32-EBBB67D04875}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9E3C3CE1-23DD-4A1B-B927-92D6BE3011A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9E3C3CE1-23DD-4A1B-B927-92D6BE3011A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9E3C3CE1-23DD-4A1B-B927-92D6BE3011A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9E3C3CE1-23DD-4A1B-B927-92D6BE3011A2}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E7DED023-F57F-4715-BC8D-752B60B6A203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E7DED023-F57F-4715-BC8D-752B60B6A203}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E7DED023-F57F-4715-BC8D-752B60B6A203}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E7DED023-F57F-4715-BC8D-752B60B6A203}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+EndGlobal

+ 2 - 0
DetectEncoding.sln.DotSettings.user

@@ -0,0 +1,2 @@
+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
+	<s:Boolean x:Key="/Default/CodeStyle/LiveTemplatesUseVar/PreferVar/@EntryValue">False</s:Boolean></wpf:ResourceDictionary>

BIN
DetectEncoding.v12.suo


+ 73 - 0
DetectEncoding/DetectEncoding.csproj

@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.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>{82D05B7B-F006-4142-9E32-EBBB67D04875}</ProjectGuid>
+    <OutputType>Exe</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>DetectEncoding</RootNamespace>
+    <AssemblyName>DetectEncoding</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </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.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="business\parsing\ProgramParser.cs" />
+    <Compile Include="constant\EnumAppEncoding.cs" />
+    <Compile Include="constant\EnumEOL.cs" />
+    <Compile Include="dto\OutputConf.cs" />
+    <Compile Include="dto\ProgramArgs.cs" />
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\..\..\AryxDevLibrary\AryxDevLibrary.csproj">
+      <Project>{e7ded023-f57f-4715-bc8d-752b60b6a203}</Project>
+      <Name>AryxDevLibrary</Name>
+    </ProjectReference>
+    <ProjectReference Include="E:\CSharp\Projects\Ext\text-encoding-detect\TextEncodingDetect-C#\TextEncodingDetect\TextEncodingDetect.csproj">
+      <Project>{9e3c3ce1-23dd-4a1b-b927-92d6be3011a2}</Project>
+      <Name>TextEncodingDetect</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Folder Include="utils\" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- 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>

+ 6 - 0
DetectEncoding/DetectEncoding.csproj.user

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
+    <StartArguments>-e UNIX -f "E:\CSharp\Données accessoires\FileEncoding\UTF8-NOBOM.txt" -c ANSI</StartArguments>
+  </PropertyGroup>
+</Project>

+ 316 - 0
DetectEncoding/Program.cs

@@ -0,0 +1,316 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Text;
+using AryxDevLibrary.utils;
+using AryxDevLibrary.utils.cliParser;
+using AutoIt.Common;
+using DetectEncoding.business.parsing;
+using DetectEncoding.constant;
+using DetectEncoding.dto;
+
+namespace DetectEncoding
+{
+    class Program
+    {
+        static void Main(string[] args)
+        {
+            ProgramParser argParser = new ProgramParser();
+            try
+            {
+
+                ShowHeaderApp();
+
+                ProgramArgs objArgs = argParser.ParseDirect(args);
+
+
+                Console.WriteLine(" InputFile: {0}", objArgs.InputFileName);
+                var result = DetectEncodingBis(objArgs.InputFileName);
+
+
+
+                if (result != TextEncodingDetect.Encoding.None)
+                {
+
+                    EnumAppEncoding inEncTransType = FromTextEncoding(result);
+
+
+                    var resultEol = DetectEol(objArgs.InputFileName, inEncTransType);
+
+
+                    OutputConf outConf = new OutputConf
+                    {
+                        InputEncoding = inEncTransType
+                    };
+
+                    Console.Write(" Encoding: {0}", result);
+
+
+                    if (resultEol == EnumEOL.DOS)
+                    {
+                        Console.WriteLine("; Dos");
+                    }
+                    else if (resultEol == EnumEOL.UNIX)
+                    {
+                        Console.WriteLine("; Unix");
+                    }
+
+                    if (!objArgs.IsConvertMode || inEncTransType == null)
+                    {
+                        return;
+                    }
+
+
+                    outConf.OutputEncoding = objArgs.OutputEncoding;
+                    outConf.OutputFileName = objArgs.OutputFileName;
+                    outConf.OutputEol = objArgs.OutputEol;
+
+                    if (outConf.InputEncoding != null)
+                    {
+                        SetDefaultValueForConverter(objArgs.InputFileName, outConf);
+
+                        Console.WriteLine(" Output : Encoding: {0}; {1}", outConf.OutputEncoding.Libelle, outConf.OutputEol);
+
+                        outConf.InputEol = resultEol;
+                        ConvertFile(objArgs.InputFileName, outConf);
+
+                    }
+
+                }
+
+# if DEBUG
+                //Console.ReadLine();
+# endif
+
+            }
+            catch (CliParsingException e)
+            {
+
+# if DEBUG
+                Console.Write(e);
+# else
+                Console.Write(e.Message);
+# endif
+                argParser.ShowSyntax();
+
+            }
+
+        }
+
+        private static void ShowHeaderApp()
+        {
+            var dft = Console.ForegroundColor;
+
+            Console.ForegroundColor = ConsoleColor.White;
+
+            Console.WriteLine(" Encoding Detector with reencoding !");
+            Console.WriteLine(" ===================================");
+            Console.WriteLine(" by Aryx - Wolfaryx informatique - 2018");
+            Console.WriteLine("");
+            Console.ResetColor();
+
+            Console.WriteLine("");
+            Console.WriteLine(" Encoding detection based on work from AutoIt Consulting :");
+            Console.WriteLine(" https://github.com/AutoItConsulting/text-encoding-detect");
+
+
+
+            Console.WriteLine("");
+            Console.ResetColor();
+        }
+
+        private static void ConvertFile(string inputFileName, OutputConf outConf)
+        {
+
+
+
+            ToFile(inputFileName, outConf.InputEncoding, outConf.OutputEncoding, outConf.OutputEol, outConf.OutputFileName);
+        }
+
+        private static void SetDefaultValueForConverter(string inputFileName, OutputConf outConf)
+        {
+            if (outConf.OutputEncoding == null)
+            {
+                outConf.OutputEncoding = outConf.InputEncoding;
+            }
+
+            if (outConf.OutputEol.Equals(EnumEOL.NONE))
+            {
+                outConf.OutputEol = outConf.InputEol;
+            }
+
+            if (outConf.OutputFileName == null)
+            {
+                FileInfo fI = new FileInfo(inputFileName);
+                outConf.OutputFileName = fI.Name.Replace(fI.Extension, "") + "-Out" + fI.Extension;
+            }
+        }
+
+
+        private static EnumAppEncoding FromTextEncoding(TextEncodingDetect.Encoding result)
+        {
+            if (TextEncodingDetect.Encoding.Ansi.Equals(result))
+            {
+                return EnumAppEncoding.ANSI;
+            }
+
+            if (TextEncodingDetect.Encoding.Ascii.Equals(result))
+            {
+                return EnumAppEncoding.ASCII;
+            }
+
+            if (TextEncodingDetect.Encoding.Utf8Bom.Equals(result))
+            {
+                return EnumAppEncoding.UTF8_BOM;
+            }
+            if (TextEncodingDetect.Encoding.Utf8Nobom.Equals(result))
+            {
+                return EnumAppEncoding.UTF8_NOBOM;
+            }
+
+            if (TextEncodingDetect.Encoding.Utf16BeBom.Equals(result))
+            {
+                return EnumAppEncoding.UTF16BE_BOM;
+            }
+            if (TextEncodingDetect.Encoding.Utf16BeNoBom.Equals(result))
+            {
+                return EnumAppEncoding.UTF16BE_NOBOM;
+            }
+
+            if (TextEncodingDetect.Encoding.Utf16LeBom.Equals(result))
+            {
+                return EnumAppEncoding.UTF16LE_BOM;
+            }
+            if (TextEncodingDetect.Encoding.Utf16LeNoBom.Equals(result))
+            {
+                return EnumAppEncoding.UTF16LE_NOBOM;
+            }
+            return null;
+        }
+
+        private static EnumEOL DetectEol(string filename, EnumAppEncoding inEncoding)
+        {
+            EnumEOL enumRet = EnumEOL.UNIX;
+
+            String s;
+            using (StreamReader sr = GetStreamReaderFromEAppEncoding(filename, inEncoding))
+            {
+
+
+                if (sr.BaseStream.Length < 2)
+                {
+                    return enumRet;
+                }
+                //ensure file is not so small
+
+                int n1 = 0;
+                int c = 0;
+                int p = 0;
+                while (sr.Peek() >= 0)
+                {
+                    p++;
+
+                    if (p > 1)
+                    {
+                        n1 = c;
+                    }
+
+
+                    c = sr.Read();
+
+
+
+                    if (c == 10 && p > 1) //if (s1 == 13 && s2 == 10) //if sure its windows format
+                    {
+                        //file is end with CR-LF or LF ...
+                        if (n1 == 13)
+                        {
+                            enumRet = EnumEOL.DOS;
+                        } //file is end with CR-LF (Windows EOL format)
+                        else
+                        {
+                            enumRet = EnumEOL.UNIX;
+                        } //file is end with just LF, (UNIX/OSX format)
+                    }
+
+                }
+
+
+
+
+            }
+
+            return enumRet;
+        }
+
+
+
+
+
+        public static TextEncodingDetect.Encoding DetectEncodingBis(string filename)
+        {
+            var textDetect = new TextEncodingDetect();
+
+            byte[] array = File.ReadAllBytes(filename);
+            TextEncodingDetect.Encoding encoding = textDetect.DetectEncoding(array, array.Length - 1);
+            return encoding;
+
+
+        }
+
+
+        private static void ToFile(string inputFileName, EnumAppEncoding inputEncoding, EnumAppEncoding outputEncoding, EnumEOL outputEol, string outputFileName)
+        {
+
+
+            String eolChar = "\r\n";
+            if (outputEol == EnumEOL.UNIX)
+            {
+                eolChar = "\n";
+            }
+
+            using (StreamReader sr = GetStreamReaderFromEAppEncoding(inputFileName, inputEncoding))
+            {
+                using (StreamWriter sw = GetStreamWriterFromEAppEncoding(outputFileName, outputEncoding))
+                {
+                    String line = null;
+                    while ((line = sr.ReadLine()) != null)
+                    {
+
+                        sw.Write(line + eolChar);
+
+                    }
+                }
+            }
+
+        }
+
+        private static StreamReader GetStreamReaderFromEAppEncoding(string inputFileName, EnumAppEncoding inputEncoding)
+        {
+            return new StreamReader(inputFileName, inputEncoding.CsEncoding);
+        }
+
+        private static StreamWriter GetStreamWriterFromEAppEncoding(string outFileName, EnumAppEncoding encoding)
+        {
+            if (encoding.Equals(EnumAppEncoding.UTF8_NOBOM) || encoding.Equals(EnumAppEncoding.UTF8_BOM))
+            {
+                return new StreamWriter(File.Open(outFileName, FileMode.Create), new UTF8Encoding(encoding.OptionWithUtf8Bom));
+            }
+
+            if (encoding.Equals(EnumAppEncoding.UTF16BE_NOBOM) || encoding.Equals(EnumAppEncoding.UTF16BE_BOM))
+            {
+                return new StreamWriter(File.Open(outFileName, FileMode.Create), new UnicodeEncoding(true, encoding.OptionWithUtf8Bom));
+            }
+
+            if (encoding.Equals(EnumAppEncoding.UTF16LE_NOBOM) || encoding.Equals(EnumAppEncoding.UTF16LE_BOM))
+            {
+                return new StreamWriter(File.Open(outFileName, FileMode.Create), new UnicodeEncoding(false, encoding.OptionWithUtf8Bom));
+            }
+
+            return new StreamWriter(File.Open(outFileName, FileMode.Create), encoding.CsEncoding);
+        }
+    }
+}

+ 36 - 0
DetectEncoding/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// Les informations générales relatives à un assembly dépendent de 
+// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
+// associées à un assembly.
+[assembly: AssemblyTitle("DetectEncoding")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DetectEncoding")]
+[assembly: AssemblyCopyright("Copyright ©  2018")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly 
+// aux composants COM.  Si vous devez accéder à un type dans cet assembly à partir de 
+// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
+[assembly: ComVisible(false)]
+
+// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
+[assembly: Guid("baae3dd9-4246-40f0-a653-496ef1eb0c19")]
+
+// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
+//
+//      Version principale
+//      Version secondaire 
+//      Numéro de build
+//      Révision
+//
+// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut 
+// en utilisant '*', comme indiqué ci-dessous :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 139 - 0
DetectEncoding/business/parsing/ProgramParser.cs

@@ -0,0 +1,139 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using AryxDevLibrary.utils.cliParser;
+using DetectEncoding.constant;
+using DetectEncoding.dto;
+
+namespace DetectEncoding.business.parsing
+{
+    public class ProgramParser : CliParser<ProgramArgs>
+    {
+        private readonly Option _optionFile = new Option()
+        {
+            ShortOpt = "f",
+            LongOpt = "file",
+            Description = "chemin du fichier à analyser",
+            HasArgs = true,
+            IsMandatory = true,
+            Name = "OptionFile"
+        };
+
+        private readonly Option _optionTargetEnc = new Option()
+        {
+            ShortOpt = "c",
+            LongOpt = "convert-to",
+            Description = "Convertie l'encodage du fichier analysé dans un encodage cible : UTF8, UTF8_NOBOM, ANSI. La conversion en se fait que si l'encodage source a été détecté.",
+            HasArgs = true,
+            IsMandatory = false,
+            Name = "TargetEnc"
+        };
+
+        private readonly Option _optionTargetEOL = new Option()
+        {
+            ShortOpt = "e",
+            LongOpt = "end-of-line-to",
+            Description = "Convertie le caractère de fin de ligne : DOS, UNIX. La conversion en se fait que si l'encodage source a été détecté.",
+            HasArgs = true,
+            IsMandatory = false,
+            Name = "TargetEol"
+        };
+
+        private readonly Option _optionOutputFile = new Option()
+        {
+            ShortOpt = "o",
+            LongOpt = "output-file",
+            Description = "Fichier cible pour la conversion. Si omis, le fichier se présentera sous la forme [Nom fichier input]-Conv[Extension fichier input].",
+            HasArgs = true,
+            IsMandatory = false,
+            Name = "OutputFile"
+        };
+
+
+
+        public ProgramParser()
+        {
+            AddOption(_optionFile);
+            AddOption(_optionTargetEnc);
+            AddOption(_optionTargetEOL);
+            AddOption(_optionOutputFile);
+        }
+
+
+        public override ProgramArgs ParseDirect(string[] args)
+        {
+            return Parse(args, ParseTrt);
+        }
+
+        private ProgramArgs ParseTrt(Dictionary<string, Option> arg)
+        {
+            ProgramArgs p = new ProgramArgs();
+            p.OutputEol = EnumEOL.NONE;
+
+            string fileUrl = GetSingleOptionValue(_optionFile.Name, arg);
+            string fullPath = Path.GetFullPath(fileUrl);
+            if (!File.Exists(fullPath))
+            {
+                throw new CliParsingException(String.Format("Le fichier {0} n'existe pas", fullPath));
+            }
+            p.InputFileName = fullPath;
+
+            if (HasOption(_optionTargetEOL.Name, arg) || HasOption(_optionTargetEnc.Name, arg) ||
+                HasOption(_optionOutputFile.Name, arg))
+            {
+                p.IsConvertMode = true;
+            }
+
+            if (HasOption(_optionTargetEOL.Name, arg))
+            {
+                string eolInput = GetSingleOptionValue(_optionTargetEOL.Name, arg).ToUpper();
+                if ("DOS".Equals(eolInput))
+                {
+                    p.OutputEol = EnumEOL.DOS;
+                }
+                else if ("UNIX".Equals(eolInput))
+                {
+                    p.OutputEol = EnumEOL.UNIX;
+                }
+            }
+
+            if (HasOption(_optionTargetEnc.Name, arg))
+            {
+                string encodingInput = GetSingleOptionValue(_optionTargetEnc.Name, arg).ToUpper();
+                if ("UTF8".Equals(encodingInput) || "UTF-8".Equals(encodingInput) || "UTF8BOM".Equals(encodingInput) || EnumAppEncoding.UTF8_BOM.Libelle.Equals(encodingInput))
+                {
+                    p.OutputEncoding = EnumAppEncoding.UTF8_BOM;
+                }
+                if ("UTF8NOBOM".Equals(encodingInput) | "UTF-8-NOBOM".Equals(encodingInput) || EnumAppEncoding.UTF8_NOBOM.Libelle.Equals(encodingInput))
+                {
+                    p.OutputEncoding = EnumAppEncoding.UTF8_NOBOM;
+                }
+                else if ("ANSI".Equals(encodingInput) || EnumAppEncoding.ANSI.Libelle.Equals(encodingInput))
+                {
+                    p.OutputEncoding = EnumAppEncoding.ANSI;
+                }
+                else if (EnumAppEncoding.UTF16BE_BOM.Libelle.Equals(encodingInput))
+                {
+                    p.OutputEncoding = EnumAppEncoding.UTF16BE_BOM;
+                }
+                else if (EnumAppEncoding.UTF16LE_BOM.Libelle.Equals(encodingInput))
+                {
+                    p.OutputEncoding = EnumAppEncoding.UTF16LE_BOM;
+                }
+            }
+
+            if (HasOption(_optionOutputFile.Name, arg))
+            {
+                p.OutputFileName = GetSingleOptionValue(_optionOutputFile.Name, arg);
+            }
+
+
+            return p;
+
+
+        }
+    }
+}

+ 56 - 0
DetectEncoding/constant/EnumAppEncoding.cs

@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DetectEncoding.constant
+{
+    public class EnumAppEncoding
+    {
+
+        public static readonly EnumAppEncoding UTF8_BOM = new EnumAppEncoding("UTF8_BOM", Encoding.UTF8, true);
+        public static readonly EnumAppEncoding UTF8_NOBOM = new EnumAppEncoding("UTF8_NOBOM", Encoding.UTF8, false);
+        public static readonly EnumAppEncoding ANSI = new EnumAppEncoding("ANSI", Encoding.Default, false);
+
+        public static readonly EnumAppEncoding UTF16LE_BOM = new EnumAppEncoding("UTF16LE", Encoding.Unicode, true);
+        public static readonly EnumAppEncoding UTF16BE_BOM = new EnumAppEncoding("UTF16BE", Encoding.Unicode, true);
+
+        public static readonly EnumAppEncoding UTF16LE_NOBOM = new EnumAppEncoding("UTF16LE_NOBOM", Encoding.Unicode, false);
+        public static readonly EnumAppEncoding UTF16BE_NOBOM = new EnumAppEncoding("UTF16BE_NOBOM", Encoding.Unicode, false);
+
+        public static readonly EnumAppEncoding ASCII = new EnumAppEncoding("ASCII", Encoding.ASCII, false);
+
+
+
+        public static IEnumerable<EnumAppEncoding> Values
+        {
+            get
+            {
+                yield return UTF8_BOM;
+                yield return UTF8_NOBOM;
+                yield return ANSI;
+                yield return UTF16LE_BOM;
+                yield return UTF16BE_BOM;
+                yield return UTF16LE_NOBOM;
+                yield return UTF16BE_NOBOM;
+                yield return ASCII;
+
+            }
+        }
+
+        public string Libelle { get; private set; }
+        public Encoding CsEncoding { get; private set; }
+        public bool OptionWithUtf8Bom { get; private set; }
+
+
+
+        private EnumAppEncoding(string libelle, Encoding csEncoding, bool optionWithBom)
+        {
+            Libelle = libelle;
+            CsEncoding = csEncoding;
+            OptionWithUtf8Bom = optionWithBom;
+
+        }
+
+    }
+}

+ 18 - 0
DetectEncoding/constant/EnumEOL.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace DetectEncoding.constant
+{
+    public enum EnumEOL
+    {
+        NONE,
+
+        DOS,
+
+        UNIX
+
+    }
+
+}

+ 30 - 0
DetectEncoding/dto/OutputConf.cs

@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.AccessControl;
+using System.Text;
+using DetectEncoding.constant;
+
+namespace DetectEncoding.dto
+{
+    public class OutputConf
+    {
+
+        public EnumAppEncoding InputEncoding { get; set; }
+
+        public EnumEOL InputEol { get; set; }
+
+        public EnumAppEncoding OutputEncoding { get; set; }
+
+        public EnumEOL OutputEol { get; set; }
+
+        public string OutputFileName { get; set; }
+
+        public OutputConf()
+        {
+            InputEol = EnumEOL.NONE;
+            OutputEol = EnumEOL.NONE;
+        }
+
+    }
+}

+ 22 - 0
DetectEncoding/dto/ProgramArgs.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using DetectEncoding.constant;
+
+namespace DetectEncoding.dto
+{
+    public class ProgramArgs
+    {
+
+        public string InputFileName { get; set; }
+
+        public bool IsConvertMode { get; set; }
+
+        public EnumAppEncoding OutputEncoding { get; set; }
+
+        public EnumEOL OutputEol { get; set; }
+
+        public string OutputFileName { get; set; }
+    }
+}