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";
}
}
}
diff --git a/DevelopmentTransferUtility/Common/EntryPoint.cs b/DevelopmentTransferUtility/Common/EntryPoint.cs
index 6d8247f..120ae85 100644
--- a/DevelopmentTransferUtility/Common/EntryPoint.cs
+++ b/DevelopmentTransferUtility/Common/EntryPoint.cs
@@ -233,17 +233,21 @@ 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
{
if (NeedExportDevelopment(options))
ExportDevelopment(options, developmentFileName);
- TransformPackageToFolder(options, developmentFileName);
+ TransformPackageToFolder(options, developmentFileName);
+
}
finally
{
@@ -262,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))
@@ -271,6 +283,9 @@ private static void ProcessImport(ICommandLineOptions options)
{
if (NeedImportDevelopment(options))
Directory.Delete(tempFolder, true);
+
+ if (options.convertToUTF8)
+ Directory.Delete(options.DevelopmentFolderName, true);
}
}
@@ -280,10 +295,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;
@@ -291,7 +309,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.export(options.DevelopmentFolderName);
+ Console.Write("Done");
+ Console.WriteLine();
+ }
+
break;
case "import":
ProcessImport(options);
diff --git a/DevelopmentTransferUtility/Common/FilesToUtf8.cs b/DevelopmentTransferUtility/Common/FilesToUtf8.cs
new file mode 100644
index 0000000..7b8df95
--- /dev/null
+++ b/DevelopmentTransferUtility/Common/FilesToUtf8.cs
@@ -0,0 +1,85 @@
+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 export(string folder_path)
+ {
+ convertToUTF8(folder_path);
+ }
+ static public string import(string folder_path)
+ {
+ string tmp_path = createTmpDir();
+
+ if (string.IsNullOrEmpty(tmp_path))
+ return "";
+
+ 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, f.Replace(fpath_src, fpath_dest), src, dest);
+
+ }
+
+ static private void convert(string fpath, Encoding src, Encoding dest)
+ {
+ convert(fpath, fpath, src,dest);
+ }
+
+ static private void convertfile(string filesrc, string filedest, Encoding src, Encoding dest)
+ {
+
+ var t = File.ReadAllText(filesrc, src);
+
+ 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;
+ }
+
+ }
+}
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
+}
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
+