Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion DevelopmentTransferUtility/Common/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

/// <summary>
Expand Down Expand Up @@ -189,7 +192,8 @@ public string GetUsage()
" --hiddenimport - Признак импорта в скрытом режиме (без показа окна утилиты импорта).\n" +
" --importfolders - Список импортируемых папок (используется как фильтр при импорте).\n" +
" --skipautoadded - Игнорировать автоматически выбранные элементы (используется только при экспорте).\n" +
" --help - Вывести справку по параметрам командной строки.\n";
" --utf8 - Конвертировать файлы в UTF-8.\n" +
" --help - Вывести справку по параметрам командной строки.\n";
}
}
}
43 changes: 39 additions & 4 deletions DevelopmentTransferUtility/Common/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,21 @@ private static void TransformFolderToPackage(ICommandLineOptions options, string
/// Обработать экспорт.
/// </summary>
/// <param name="options">Ключи командной строки.</param>
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
{
Expand All @@ -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))
Expand All @@ -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);
}
}

Expand All @@ -280,18 +295,38 @@ private static void ProcessImport(ICommandLineOptions options)
/// <param name="args">Параметры командной строки.</param>
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;
switch (options.Mode.ToLower())
{
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);
Expand Down
85 changes: 85 additions & 0 deletions DevelopmentTransferUtility/Common/FilesToUtf8.cs
Original file line number Diff line number Diff line change
@@ -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;
}

}
}
7 changes: 6 additions & 1 deletion DevelopmentTransferUtility/Common/ICommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,10 @@ internal interface ICommandLineOptions
/// Не экспортировать автоматически выбранные элементы.
/// </summary>
bool SkipAutoAddedElements { get; set; }

/// <summary>
/// Конвертировать файлы в UTF-8
/// </summary>
bool convertToUTF8 { get; set; }
}
}
}
3 changes: 2 additions & 1 deletion DevelopmentTransferUtility/DevelopmentTransferUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
<Compile Include="Common\ConnectionParams.cs" />
<Compile Include="Common\ConnectionManager.cs" />
<Compile Include="Common\DeleteProcessor.cs" />
<Compile Include="Common\FilesToUtf8.cs" />
<Compile Include="Common\ImportFilter.cs" />
<Compile Include="Common\TransferDevelopmentRunner.cs" />
<Compile Include="Common\EventTextParser.cs" />
Expand Down Expand Up @@ -262,4 +263,4 @@
<RemoveDir Directories="$(SolutionDir).vs" />
<RemoveDir Directories="$(ProjectDir)$(BaseIntermediateOutputPath)" />
</Target>
</Project>
</Project>