From 138a6a1bacdf00ac176ef60fa3ca4b5db5b22952 Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 15:14:54 +0300 Subject: [PATCH 1/8] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=81?= =?UTF-8?q?=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C=20=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DevelopmentTransferUtility/Common/EntryPoint.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/DevelopmentTransferUtility/Common/EntryPoint.cs b/DevelopmentTransferUtility/Common/EntryPoint.cs index 6d8247f..47e637c 100644 --- a/DevelopmentTransferUtility/Common/EntryPoint.cs +++ b/DevelopmentTransferUtility/Common/EntryPoint.cs @@ -243,7 +243,16 @@ private static void ProcessExport(ICommandLineOptions options) if (NeedExportDevelopment(options)) ExportDevelopment(options, developmentFileName); - TransformPackageToFolder(options, developmentFileName); + TransformPackageToFolder(options, developmentFileName); + + if(options.convertToUTF8) + { + Console.Write("Конвертация в UTF-8.. "); + filestoutf8.convert(options.DevelopmentFolderName); + Console.Write("Done"); + Console.WriteLine(); + } + } finally { @@ -280,10 +289,13 @@ private static void ProcessImport(ICommandLineOptions options) /// Параметры командной строки. public static void Main(string[] args) { - bool needCloseApplicationWindow = false; + + bool needCloseApplicationWindow = false; + try { var options = new CommandLineOptions(); + if (Parser.Default.ParseArguments(args, options)) { needCloseApplicationWindow = options.CloseWindow; From f7519250d62200eaa7df19a608d54f0f8d4dac5c Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 15:18:28 +0300 Subject: [PATCH 2/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=BF=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B2=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DevelopmentTransferUtility/Common/CommandLineOptions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DevelopmentTransferUtility/Common/CommandLineOptions.cs b/DevelopmentTransferUtility/Common/CommandLineOptions.cs index dc60474..8f9a08d 100644 --- a/DevelopmentTransferUtility/Common/CommandLineOptions.cs +++ b/DevelopmentTransferUtility/Common/CommandLineOptions.cs @@ -156,6 +156,9 @@ internal class CommandLineOptions : ICommandLineOptions [Option("skipautoadded", Required = false, DefaultValue = false)] public bool SkipAutoAddedElements { get; set; } + [Option("utf8", Required =false,DefaultValue =false)] + public bool convertToUTF8 { get; set; } + #endregion /// @@ -189,7 +192,8 @@ public string GetUsage() " --hiddenimport - Признак импорта в скрытом режиме (без показа окна утилиты импорта).\n" + " --importfolders - Список импортируемых папок (используется как фильтр при импорте).\n" + " --skipautoadded - Игнорировать автоматически выбранные элементы (используется только при экспорте).\n" + - " --help - Вывести справку по параметрам командной строки.\n"; + " --utf8 - Конвертировать файлы в UTF-8.\n" + + " --help - Вывести справку по параметрам командной строки.\n"; } } } From 920755f87c56d8bd9ab9b48ad7e56ec444a7e596 Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 15:19:33 +0300 Subject: [PATCH 3/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D0=BF=D1=86=D0=B8=D1=8F=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B2=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DevelopmentTransferUtility/Common/ICommandLineOptions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DevelopmentTransferUtility/Common/ICommandLineOptions.cs b/DevelopmentTransferUtility/Common/ICommandLineOptions.cs index a83ddb6..a87dcb8 100644 --- a/DevelopmentTransferUtility/Common/ICommandLineOptions.cs +++ b/DevelopmentTransferUtility/Common/ICommandLineOptions.cs @@ -114,5 +114,10 @@ internal interface ICommandLineOptions /// Не экспортировать автоматически выбранные элементы. /// bool SkipAutoAddedElements { get; set; } + + /// + /// Конвертировать файлы в UTF-8 + /// + bool convertToUTF8 { get; set; } } -} \ No newline at end of file +} From 7e560991fa6e38dde940904f1867ee4c27205a70 Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 15:21:11 +0300 Subject: [PATCH 4/8] =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B2=20UTF-8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/FilesToUtf8.cs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 DevelopmentTransferUtility/Common/FilesToUtf8.cs diff --git a/DevelopmentTransferUtility/Common/FilesToUtf8.cs b/DevelopmentTransferUtility/Common/FilesToUtf8.cs new file mode 100644 index 0000000..661f234 --- /dev/null +++ b/DevelopmentTransferUtility/Common/FilesToUtf8.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NpoComputer.DevelopmentTransferUtility.Common +{ + static class filestoutf8 + { + + static public void convert(string fpath) + { + + string[] files = Directory.GetFiles(fpath, "*", SearchOption.AllDirectories); + + foreach (string f in files) + { + convertfile(f); + + } + + } + + static private void convertfile(string file) + { + var t = File.ReadAllText(file, Encoding.Default); + + File.WriteAllText(file, t, Encoding.UTF8); + } + } +} From 75b69e87912727ceda90c3cc36a671640b3c25b5 Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 15:23:48 +0300 Subject: [PATCH 5/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DevelopmentTransferUtility/DevelopmentTransferUtility.csproj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DevelopmentTransferUtility/DevelopmentTransferUtility.csproj b/DevelopmentTransferUtility/DevelopmentTransferUtility.csproj index 7cdb2f9..922a7cd 100644 --- a/DevelopmentTransferUtility/DevelopmentTransferUtility.csproj +++ b/DevelopmentTransferUtility/DevelopmentTransferUtility.csproj @@ -96,6 +96,7 @@ + @@ -262,4 +263,4 @@ - \ No newline at end of file + From 8e2c6b720f2a03fa51194d33a85dcbf04446d052 Mon Sep 17 00:00:00 2001 From: infectormp Date: Wed, 13 Mar 2019 17:04:34 +0300 Subject: [PATCH 6/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=82=D0=B8=D0=BF=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлен тип разработки --type "all" при указании которого будет выгружена вся разработка (standard + routes + wizards) --- .../Common/EntryPoint.cs | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/DevelopmentTransferUtility/Common/EntryPoint.cs b/DevelopmentTransferUtility/Common/EntryPoint.cs index 47e637c..f409122 100644 --- a/DevelopmentTransferUtility/Common/EntryPoint.cs +++ b/DevelopmentTransferUtility/Common/EntryPoint.cs @@ -233,10 +233,13 @@ private static void TransformFolderToPackage(ICommandLineOptions options, string /// Обработать экспорт. /// /// Ключи командной строки. - private static void ProcessExport(ICommandLineOptions options) + private static void ProcessExport(ICommandLineOptions options, string processType="") { string tempFolder; string developmentFileName = GetDevelopmentFileName(options, out tempFolder); + + if (!string.IsNullOrEmpty(processType)) + options.Type = processType; try { @@ -245,14 +248,6 @@ private static void ProcessExport(ICommandLineOptions options) TransformPackageToFolder(options, developmentFileName); - if(options.convertToUTF8) - { - Console.Write("Конвертация в UTF-8.. "); - filestoutf8.convert(options.DevelopmentFolderName); - Console.Write("Done"); - Console.WriteLine(); - } - } finally { @@ -303,7 +298,24 @@ public static void Main(string[] args) { default: case "export": - ProcessExport(options); + if (options.Type == "all") + { + ProcessExport(options, "standard"); + ProcessExport(options, "routes"); + ProcessExport(options, "wizards"); + } + + else + ProcessExport(options); + + if (options.convertToUTF8) + { + Console.Write("Конвертация в UTF-8.. "); + filestoutf8.convert(options.DevelopmentFolderName); + Console.Write("Done"); + Console.WriteLine(); + } + break; case "import": ProcessImport(options); From 8d97105de3ac5691781f0557c637afba0c3ca598 Mon Sep 17 00:00:00 2001 From: infectormp Date: Fri, 15 Mar 2019 13:32:59 +0300 Subject: [PATCH 7/8] Update EntryPoint.cs --- DevelopmentTransferUtility/Common/EntryPoint.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/DevelopmentTransferUtility/Common/EntryPoint.cs b/DevelopmentTransferUtility/Common/EntryPoint.cs index f409122..120ae85 100644 --- a/DevelopmentTransferUtility/Common/EntryPoint.cs +++ b/DevelopmentTransferUtility/Common/EntryPoint.cs @@ -266,6 +266,14 @@ private static void ProcessImport(ICommandLineOptions options) string developmentFileName = GetDevelopmentFileName(options, out tempFolder); try { + if( options.convertToUTF8) + { + Console.Write("Конвертация в 1251.."); + Options.DevelopmentFolderName = filestoutf8.import(options.DevelopmentFolderName); + Console.Write("Done"); + Console.WriteLine(); + } + TransformFolderToPackage(options, developmentFileName); if (NeedImportDevelopment(options)) @@ -275,6 +283,9 @@ private static void ProcessImport(ICommandLineOptions options) { if (NeedImportDevelopment(options)) Directory.Delete(tempFolder, true); + + if (options.convertToUTF8) + Directory.Delete(options.DevelopmentFolderName, true); } } @@ -311,7 +322,7 @@ public static void Main(string[] args) if (options.convertToUTF8) { Console.Write("Конвертация в UTF-8.. "); - filestoutf8.convert(options.DevelopmentFolderName); + filestoutf8.export(options.DevelopmentFolderName); Console.Write("Done"); Console.WriteLine(); } From 0285f0f0650e5c74e6c1bb3a805665e3055b2476 Mon Sep 17 00:00:00 2001 From: infectormp Date: Fri, 15 Mar 2019 13:37:38 +0300 Subject: [PATCH 8/8] Update FilesToUtf8.cs --- .../Common/FilesToUtf8.cs | 72 ++++++++++++++++--- 1 file changed, 62 insertions(+), 10 deletions(-) diff --git a/DevelopmentTransferUtility/Common/FilesToUtf8.cs b/DevelopmentTransferUtility/Common/FilesToUtf8.cs index 661f234..7b8df95 100644 --- a/DevelopmentTransferUtility/Common/FilesToUtf8.cs +++ b/DevelopmentTransferUtility/Common/FilesToUtf8.cs @@ -9,25 +9,77 @@ namespace NpoComputer.DevelopmentTransferUtility.Common { static class filestoutf8 { - - static public void convert(string fpath) + static public void export(string folder_path) { + convertToUTF8(folder_path); + } + static public string import(string folder_path) + { + string tmp_path = createTmpDir(); + + if (string.IsNullOrEmpty(tmp_path)) + return ""; - string[] files = Directory.GetFiles(fpath, "*", SearchOption.AllDirectories); + ConvertTo1251(folder_path, tmp_path); + + return tmp_path; + } + + static public void convertToUTF8(string fpath) + { + convert(fpath, Encoding.Default, Encoding.UTF8); + } + + static public void convert(string fpath_src, string fpath_dest, Encoding src, Encoding dest) + { + if (string.IsNullOrEmpty(fpath_dest)) + fpath_dest = fpath_src; + + string[] files = Directory.GetFiles(fpath_src, "*", SearchOption.AllDirectories); foreach (string f in files) - { - convertfile(f); - - } + convertfile(f, f.Replace(fpath_src, fpath_dest), src, dest); } - static private void convertfile(string file) + static private void convert(string fpath, Encoding src, Encoding dest) { - var t = File.ReadAllText(file, Encoding.Default); + convert(fpath, fpath, src,dest); + } + + static private void convertfile(string filesrc, string filedest, Encoding src, Encoding dest) + { + + var t = File.ReadAllText(filesrc, src); - File.WriteAllText(file, t, Encoding.UTF8); + FileInfo fi = new FileInfo(filedest); + + Directory.CreateDirectory(fi.DirectoryName); + + File.WriteAllText(filedest, t, dest); + } + + static public void ConvertTo1251(string pathSrc, string pathDest) + { + convert(pathSrc,pathDest, Encoding.UTF8, Encoding.Default); + } + + static private string createTmpDir() + { + string tmp_path = Path.GetTempPath() + Guid.NewGuid(); + + try + { + Directory.CreateDirectory(tmp_path); + } + + catch(Exception e) + { + tmp_path = ""; + } + + return tmp_path; } + } }