User:Dart Raiden/Дублирующиеся строки: Difference between revisions
Dart Raiden (talk | contribs) No edit summary |
formatting |
||
| Line 9: | Line 9: | ||
Содержимое smf_sortcleaner.bat: | Содержимое smf_sortcleaner.bat: | ||
< | <pre style="overflow:auto;"> | ||
@echo off && cls | /* | ||
%WinDir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /out:"%~0.exe" %0 | @echo off && cls | ||
"%~0.exe" %1 | %WinDir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /out:"%~0.exe" %0 | ||
del "%~0.exe" | "%~0.exe" %1 | ||
exit | del "%~0.exe" | ||
exit | |||
*/ | |||
using System; | using System; | ||
using System.Collections.Generic; | using System.Collections.Generic; | ||
using System.IO; | using System.IO; | ||
using System.Text; | using System.Text; | ||
namespace spicemustflow_sortcleaner | namespace spicemustflow_sortcleaner | ||
{ | { | ||
class Program | class Program | ||
{ | { | ||
static string GetFilename(string nameWithoutExtension, bool uniq) | static string GetFilename(string nameWithoutExtension, bool uniq) | ||
{ | { | ||
int n = 1; | int n = 1; | ||
string outputFile = string.Empty; | string outputFile = string.Empty; | ||
while (true) | while (true) | ||
{ | { | ||
outputFile = string.Format("{0}_{1}{2}.txt", | outputFile = string.Format("{0}_{1}{2}.txt", | ||
nameWithoutExtension, uniq ? "uniques" : "duplicates", | nameWithoutExtension, uniq ? "uniques" : "duplicates", | ||
n > 1 ? n.ToString() : string.Empty); | n > 1 ? n.ToString() : string.Empty); | ||
if (File.Exists(outputFile)) n++; | if (File.Exists(outputFile)) n++; | ||
else break; | else break; | ||
} | } | ||
return outputFile; | return outputFile; | ||
} | } | ||
static void Main(string[] args) | static void Main(string[] args) | ||
{ | { | ||
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\"; | string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\"; | ||
string[] filelist = null; | string[] filelist = null; | ||
if (args.Length == 0) filelist = Directory.GetFiles(path, "*.txt", SearchOption.TopDirectoryOnly); | if (args.Length == 0) filelist = Directory.GetFiles(path, "*.txt", SearchOption.TopDirectoryOnly); | ||
else filelist = args; | else filelist = args; | ||
foreach (string filename in filelist) | foreach (string filename in filelist) | ||
{ | { | ||
Encoding enc = Encoding.Default; | Encoding enc = Encoding.Default; | ||
using (FileStream fs = File.OpenRead(filename)) | using (FileStream fs = File.OpenRead(filename)) | ||
{ | { | ||
byte[] data = new byte[3]; | byte[] data = new byte[3]; | ||
while (fs.Read(data, 0, data.Length) > 0) | while (fs.Read(data, 0, data.Length) > 0) | ||
if (data[0] == 0xef && data[1] == 0xbb && data[2] == 0xbf) | if (data[0] == 0xef && data[1] == 0xbb && data[2] == 0xbf) | ||
{ | { | ||
enc = Encoding.UTF8; | enc = Encoding.UTF8; | ||
break; | break; | ||
} | } | ||
else | else | ||
{ | { | ||
enc = Encoding.GetEncoding(1251); | enc = Encoding.GetEncoding(1251); | ||
break; | break; | ||
} | } | ||
} | } | ||
Console.Write("loading {0}..\n", filename); | Console.Write("loading {0}..\n", filename); | ||
string[] input = File.ReadAllLines(filename, enc); | string[] input = File.ReadAllLines(filename, enc); | ||
if (input.Length > 0) | if (input.Length > 0) | ||
{ | { | ||
Console.Write("sorting..\n"); | Console.Write("sorting..\n"); | ||
Array.Sort(input); | Array.Sort(input); | ||
List<string> uniques = new List<string>(); | List<string> uniques = new List<string>(); | ||
List<string> duplicates = new List<string>(); | List<string> duplicates = new List<string>(); | ||
Console.Write("deleting duplicates..\n"); | Console.Write("deleting duplicates..\n"); | ||
uniques.Add(input[0]); | uniques.Add(input[0]); | ||
for (int i = 1; i < input.Length; i++) | for (int i = 1; i < input.Length; i++) | ||
if (input[i] != input[i - 1]) | if (input[i] != input[i - 1]) | ||
uniques.Add(input[i]); | uniques.Add(input[i]); | ||
else | else | ||
duplicates.Add(input[i]); | duplicates.Add(input[i]); | ||
Console.Write("\nsaving..\n"); | Console.Write("\nsaving..\n"); | ||
File.WriteAllLines(path + GetFilename(Path.GetFileNameWithoutExtension(filename), false), duplicates.ToArray(), enc); | File.WriteAllLines(path + GetFilename(Path.GetFileNameWithoutExtension(filename), false), duplicates.ToArray(), enc); | ||
Console.Write("\n\n"); | Console.Write("\n\n"); | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
} | } | ||
</pre> | |||
Latest revision as of 21:11, 30 December 2015
В пределах перевода конкретного плагина исходные (англоязычные) строки дублироваться не должны. В этом случае Миранда будет использовать первый встреченный вариант перевода.
Для нахождения дублирующихся строк можно воспользоваться пакетным файлом (.bat), взятым с http://metaspamer.blogspot.ru/2011/12/programma-dlia-udaleniia-odinakovykh.html и немного измененным под наши нужды. Необходимо передать батнику файл аргументом (берем свой текстовый файл и перетаскивам его мышкой на smf_sortcleaner.bat в проводнике Windows), все остальное он сам сделает и создаст в папке с собой файл, содержаший дублирующиеся строки. А если запустить без аргументов, то он обработает все .txt в папке с собой.
Требует для работы .NET Framework не ниже 2 версии.
После этого удобно пройтись поиском по полученным файлам и отыскать все строки, содержащие символ "[". Это и будут искомые "лишние" строки, присутствие которых в ленгпаке бессмысленно. Содержимое smf_sortcleaner.bat:
/*
@echo off && cls
%WinDir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /out:"%~0.exe" %0
"%~0.exe" %1
del "%~0.exe"
exit
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace spicemustflow_sortcleaner
{
class Program
{
static string GetFilename(string nameWithoutExtension, bool uniq)
{
int n = 1;
string outputFile = string.Empty;
while (true)
{
outputFile = string.Format("{0}_{1}{2}.txt",
nameWithoutExtension, uniq ? "uniques" : "duplicates",
n > 1 ? n.ToString() : string.Empty);
if (File.Exists(outputFile)) n++;
else break;
}
return outputFile;
}
static void Main(string[] args)
{
string path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\";
string[] filelist = null;
if (args.Length == 0) filelist = Directory.GetFiles(path, "*.txt", SearchOption.TopDirectoryOnly);
else filelist = args;
foreach (string filename in filelist)
{
Encoding enc = Encoding.Default;
using (FileStream fs = File.OpenRead(filename))
{
byte[] data = new byte[3];
while (fs.Read(data, 0, data.Length) > 0)
if (data[0] == 0xef && data[1] == 0xbb && data[2] == 0xbf)
{
enc = Encoding.UTF8;
break;
}
else
{
enc = Encoding.GetEncoding(1251);
break;
}
}
Console.Write("loading {0}..\n", filename);
string[] input = File.ReadAllLines(filename, enc);
if (input.Length > 0)
{
Console.Write("sorting..\n");
Array.Sort(input);
List<string> uniques = new List<string>();
List<string> duplicates = new List<string>();
Console.Write("deleting duplicates..\n");
uniques.Add(input[0]);
for (int i = 1; i < input.Length; i++)
if (input[i] != input[i - 1])
uniques.Add(input[i]);
else
duplicates.Add(input[i]);
Console.Write("\nsaving..\n");
File.WriteAllLines(path + GetFilename(Path.GetFileNameWithoutExtension(filename), false), duplicates.ToArray(), enc);
Console.Write("\n\n");
}
}
}
}
}