Skip to content

Commit 1d9a0a1

Browse files
committed
Версия 3.6.3
Обновление кода и исправление ошибок - Для создания gender-файлов обавлена логика для распределения слов по родам. - Изменён способ генерации уникальных строк с использованием `Guid.NewGuid()`. - Изменён способ создания диалога поиска папки. - В переводе имён упрощена логика замены текста. - Изменён способ создания текстовых файлов с добавлением кодировки `UTF-8`. - Изменены имена свойств JSON-объектов для api-запроосов. - Улучшена обработка ошибок при загрузке XML-файла. - Обновлена версия пакета `System.Text.Json` с `8.0.5` на `9.0.0`.
1 parent 9fb8c3c commit 1d9a0a1

15 files changed

+456
-142
lines changed

DarkTheme/DarkModeCS.cs

Lines changed: 284 additions & 72 deletions
Large diffs are not rendered by default.

MainForm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public MainForm()
8484
// Выбор папки и обработка изменения адреса папки
8585
private void FolderButton_Click(object sender, EventArgs e)
8686
{
87-
FolderBrowserDialog ofd = new();
87+
using FolderBrowserDialog ofd = new();
8888
DialogResult dr = ofd.ShowDialog();
8989
if (dr == DialogResult.OK)
9090
{
@@ -140,7 +140,7 @@ private void UpdateButton_Click(object sender, EventArgs e)
140140
LinkLabelGithub.Visible = true;
141141
return;
142142
}
143-
string newVersion = json.tag_name.ToString()[1..];
143+
string newVersion = json.TagName.ToString()[1..];
144144
string? oldVersion = System.Reflection.Assembly.GetEntryAssembly()?.GetName().Version?.ToString();
145145
if (oldVersion is null || oldVersion.Length < 5)
146146
{
@@ -169,7 +169,7 @@ private void UpdateButton_Click(object sender, EventArgs e)
169169
else
170170
{
171171
SendToInfoTextBox("Доступна новая версия программы. Её можно скачать на GitHub по ссылке справа");
172-
SendToInfoTextBox($"{json.name}. Что нового?{Environment.NewLine}{json.body}");
172+
SendToInfoTextBox($"{json.Name}. Что нового?{Environment.NewLine}{json.Body}");
173173
UpdateButton.BackgroundImage = Properties.Resources.warn_c;
174174
LinkLabelGithub.Visible = true;
175175
}
@@ -278,7 +278,7 @@ private void ActionHandler(string name, string mask, string code)
278278
result = EncodingFixer.EncodingFixerActivity(currentFile);
279279
break;
280280
case "CommentInserter":
281-
result = CommentInserter.CommentInserterActivity(currentFile);
281+
result = CommentInserter.InsertComments(currentFile);
282282
break;
283283
default:
284284
break;

RimLangKit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Platforms>x64</Platforms>
1212
<ApplicationIcon>images\icon.ico</ApplicationIcon>
1313
<PlatformTarget>x64</PlatformTarget>
14-
<Version>$(VersionPrefix)3.6.2</Version>
14+
<Version>$(VersionPrefix)3.6.3</Version>
1515
<RepositoryUrl>https://github.com/OneCodeUnit/RimLangKit</RepositoryUrl>
1616
<RepositoryType>git</RepositoryType>
1717
<NeutralLanguage>ru</NeutralLanguage>

RimLanguageCore/Activities/CaseCreator.cs

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class CaseCreator
1010
{
1111
private const string CasePath = "\\Languages\\Russian\\WordInfo";
1212

13-
private static List<string> WordsExtract(string file)
13+
private static List<string> ExtractWords(string file)
1414
{
1515
XDocument xDoc = XDocument.Load(file, LoadOptions.PreserveWhitespace);
1616
XElement root = xDoc.Element("LanguageData");
@@ -34,7 +34,7 @@ public static List<string> FindWordsProcessing(string currentFile, string defTyp
3434
// Если файл соответствует заданному defType, то запускатся в работу
3535
if (currentFile.Contains(defType, StringComparison.OrdinalIgnoreCase))
3636
{
37-
words.AddRange(WordsExtract(currentFile));
37+
words.AddRange(ExtractWords(currentFile));
3838
}
3939
return words;
4040
}
@@ -56,17 +56,17 @@ public static void CreateCase(string directoryPath, Dictionary<string, string> w
5656
}
5757

5858
string tempWord = word.Key;
59-
Words result = MorpherHttpClient.GetMorpherWords(tempWord);
59+
WordForms result = MorpherHttpClient.GetMorpherWords(tempWord);
6060
// Case.txt
6161
string tempStringCase = result is null
6262
? $"{tempWord}; {tempWord}; {tempWord}; {tempWord}; {tempWord}; {tempWord}"
63-
: $"{tempWord}; {result.Р}; {result.Д}; {result.В}; {result.Т}; {result.П}";
63+
: $"{tempWord}; {result.Genitive}; {result.Dative}; {result.Accusative}; {result.Instrumental}; {result.Prepositional}";
6464
writerCase.WriteLine(tempStringCase);
6565

6666
// Plural.txt
6767
tempStringCase = result is null
6868
? $"{tempWord}; {tempWord}"
69-
: result.множественное is null ? string.Empty : $"{tempWord}; {result.множественное.И}";
69+
: result.Plural is null ? string.Empty : $"{tempWord}; {result.Plural.Nominative}";
7070
writerPlural.WriteLine(tempStringCase);
7171
}
7272
writerCase.WriteLine();
@@ -83,27 +83,79 @@ public static void CreateGender(string directoryPath, Dictionary<string, string>
8383
string pathGenderFemale = pathGender + "\\Female.txt";
8484
StreamWriter writerFemale = new(pathGenderFemale, true, System.Text.Encoding.UTF8);
8585
writerFemale.WriteLine("// " + defType);
86+
foreach (var word in words)
87+
{
88+
if (word.Value != defType)
89+
{
90+
continue;
91+
}
92+
else if (word.Key.EndsWith("а", StringComparison.OrdinalIgnoreCase) || word.Key.EndsWith("я", StringComparison.OrdinalIgnoreCase))
93+
{
94+
writerFemale.WriteLine(word.Key);
95+
words.Remove(word.Key);
96+
}
97+
}
8698
writerFemale.WriteLine();
8799
writerFemale.Close();
88100

89101
string pathGenderMale = pathGender + "\\Male.txt";
90102
StreamWriter writerMale = new(pathGenderMale, true, System.Text.Encoding.UTF8);
91103
writerMale.WriteLine("// " + defType);
104+
foreach (var word in words)
105+
{
106+
if (word.Value != defType)
107+
{
108+
continue;
109+
}
110+
else if ((!word.Key.EndsWith("а", StringComparison.OrdinalIgnoreCase)) && (!word.Key.EndsWith("я", StringComparison.OrdinalIgnoreCase))
111+
&& (!word.Key.EndsWith("о", StringComparison.OrdinalIgnoreCase)) && (!word.Key.EndsWith("е", StringComparison.OrdinalIgnoreCase))
112+
&& (!word.Key.EndsWith("ы", StringComparison.OrdinalIgnoreCase)) && (!word.Key.EndsWith("и", StringComparison.OrdinalIgnoreCase)))
113+
{
114+
writerMale.WriteLine(word.Key);
115+
words.Remove(word.Key);
116+
}
117+
}
92118
writerMale.WriteLine();
93119
writerMale.Close();
94120

95121
string pathGenderNeuter = pathGender + "\\Neuter.txt";
96122
StreamWriter writerNeuter = new(pathGenderNeuter, true, System.Text.Encoding.UTF8);
97123
writerNeuter.WriteLine("// " + defType);
124+
foreach (var word in words)
125+
{
126+
if (word.Value != defType)
127+
{
128+
continue;
129+
}
130+
else if (word.Key.EndsWith("о", StringComparison.OrdinalIgnoreCase) || word.Key.EndsWith("е", StringComparison.OrdinalIgnoreCase))
131+
{
132+
writerNeuter.WriteLine(word.Key);
133+
words.Remove(word.Key);
134+
}
135+
}
98136
writerNeuter.WriteLine();
99137
writerNeuter.Close();
100138

101139
string pathGenderPlural = pathGender + "\\Plural.txt";
102140
StreamWriter writerPlural = new(pathGenderPlural, true, System.Text.Encoding.UTF8);
103141
writerPlural.WriteLine("// " + defType);
142+
foreach (var word in words)
143+
{
144+
if (word.Value != defType)
145+
{
146+
continue;
147+
}
148+
else if (word.Key.EndsWith("ы", StringComparison.OrdinalIgnoreCase) || word.Key.EndsWith("и", StringComparison.OrdinalIgnoreCase))
149+
{
150+
writerPlural.WriteLine(word.Key);
151+
words.Remove(word.Key);
152+
}
153+
}
104154
writerPlural.WriteLine();
105155
writerPlural.Close();
106156

157+
if (words.Count < 1)
158+
return;
107159
string pathGenderUndefined = pathGender + "\\Undefined.txt";
108160
StreamWriter writerUndefined = new(pathGenderUndefined, true, System.Text.Encoding.UTF8);
109161
writerUndefined.WriteLine("// " + defType);

RimLanguageCore/Activities/ChangesFinder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ public static (bool, string) GetModData(string currentFile)
7070
bool unique = ModData.TryAdd(node.Name.ToString(), node.Value);
7171
if (!unique)
7272
{
73-
DateTime time = DateTime.Now;
74-
string uniqueString = time.ToString("ffff", CultureInfo.InvariantCulture);
75-
TranslationData.TryAdd(node.Name.ToString() + uniqueString, node.Value);
73+
TranslationData.TryAdd(node.Name.ToString() + Guid.NewGuid(), node.Value);
7674
}
7775
}
7876

RimLanguageCore/Activities/CommentInserter.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
namespace RimLanguageCore.Activities
66
{
7+
/// <summary>
8+
/// Вставляет комментарий с содержимым тега перед каждым элементом в указанном XML-файле.
9+
/// </summary>
10+
/// <param name="currentFile">Путь к текущему XML-файлу.</param>
11+
/// <returns>Кортеж, содержащий статус операции (true - успех, false - ошибка) и сообщение об ошибке.</returns>
712
public static class CommentInserter
813
{
9-
public static (bool, string) CommentInserterActivity(string currentFile)
14+
public static (bool, string) InsertComments(string currentFile)
1015
{
1116
(bool, string) result = XmlErrorChecker.XmlErrorCheck(currentFile);
1217
if (!result.Item1)

RimLanguageCore/Activities/FileFixer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static string BrokenFilesWriterActivity()
5252
}
5353

5454
string currentDirectory = Directory.GetCurrentDirectory();
55-
StreamWriter sw = new(Path.Combine(currentDirectory + "\\BrokenFiles.txt"), false);
55+
StreamWriter sw = new(Path.Combine(currentDirectory, "BrokenFiles.txt"), false);
5656
foreach (var file in BrokenFiles)
5757
{
5858
sw.WriteLine($"{file.Value}: {file.Key}");

RimLanguageCore/Activities/LanguageUpdater.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ public static (bool, string) TranslationVersionCheckActivity(string sha, string
2222
{
2323
return (false, "Проверка версии: Ошибка получения данных с GitHub. Что-то с интернетом?");
2424
}
25-
if (json.sha == sha)
25+
if (json.Sha == sha)
2626
{
2727
TempSha = string.Empty;
28-
return (false, $"Ваша версия - {sha[..6]}, доступная версия - {json.sha[..6]}. Обновление не требуется");
28+
return (false, $"Ваша версия - {sha[..6]}, доступная версия - {json.Sha[..6]}. Обновление не требуется");
2929
}
3030
else
3131
{
32-
TempSha = json.sha;
33-
return (true, $"Ваша версия - {sha[..6]}, доступная версия - {json.sha[..6]}. Требуется обновление");
32+
TempSha = json.Sha;
33+
return (true, $"Ваша версия - {sha[..6]}, доступная версия - {json.Sha[..6]}. Требуется обновление");
3434
}
3535
}
3636

RimLanguageCore/Activities/NamesTranslator.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,8 @@ public static (bool, string) NamesTranslatorActivity(string currentFile)
7373
}
7474
}
7575

76-
for (int i = 0; i < sourceLine.Length; i++)
77-
{
78-
if (sourceLine[i] == '=')
79-
{
80-
sourceLine = sourceLine.Replace(sourceLine[i].ToString(), string.Empty);
81-
}
82-
}
76+
sourceLine = sourceLine.Replace("=", string.Empty);
77+
8378
if (sourceLine.Length > 1)
8479
{
8580
sourceLine = char.ToUpper(sourceLine[0], CultureInfo.InvariantCulture) + sourceLine[1..];

RimLanguageCore/Activities/TagCollector.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using System.IO;
55
using System.Linq;
6+
using System.Text;
67
using System.Xml.Linq;
78

89
namespace RimLanguageCore.Activities
@@ -21,7 +22,7 @@ public static class TagCollector
2122
private static Dictionary<string, int> DefsSpread = new();
2223

2324
// Предобработка файла. Сбор данных о тегах в переводе
24-
private static string CheckDef(string currentFile)
25+
private static string ParseDefName(string currentFile)
2526
{
2627
string[] path = currentFile.Split('\\');
2728
string def = path[^2];
@@ -56,7 +57,7 @@ public static (bool, string) TagCollectorActivity(string currentFile)
5657
XElement root = xDoc.Element("LanguageData");
5758

5859
// DefName текущего файла
59-
string def = CheckDef(currentFile);
60+
string def = ParseDefName(currentFile);
6061
if (def == "Keyed")
6162
{
6263
return (false, "Keyed-файл");
@@ -107,7 +108,7 @@ public static string TagWriterActivity()
107108
string directory = Directory.GetCurrentDirectory();
108109

109110
// Запись в файл
110-
StreamWriter sw = new(Path.Combine(directory + "\\TagsByDefs.txt"), false);
111+
StreamWriter sw = new(Path.Combine(directory, "TagsByDefs.txt"), false, Encoding.UTF8);
111112
foreach (string def in Defs)
112113
{
113114
sw.WriteLine($"**{def}**");
@@ -116,18 +117,18 @@ public static string TagWriterActivity()
116117
sw.WriteLine();
117118
}
118119
sw.Close();
119-
StreamWriter swTags = new(Path.Combine(directory + "\\UniqueTags.txt"), false);
120+
StreamWriter swTags = new(Path.Combine(directory, "UniqueTags.txt"), false, Encoding.UTF8);
120121
Tags.ForEach(swTags.WriteLine);
121122
swTags.Close();
122-
StreamWriter swDefs = new(Path.Combine(directory + "\\UniqueDefs.txt"), false);
123+
StreamWriter swDefs = new(Path.Combine(directory, "UniqueDefs.txt"), false, Encoding.UTF8);
123124
Defs.ForEach(swDefs.WriteLine);
124125
swDefs.Close();
125126

126127
// Статистика по тегам
127128
var spreadList = TagSpread.ToList();
128129
spreadList.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value));
129130
spreadList.Reverse();
130-
StreamWriter swSpread = new(Path.Combine(directory + "\\SpreadTags.txt"), false);
131+
StreamWriter swSpread = new(Path.Combine(directory, "SpreadTags.txt"), false, Encoding.UTF8);
131132
foreach (var spread in spreadList)
132133
{
133134
if (spread.Value > 1)
@@ -141,7 +142,7 @@ public static string TagWriterActivity()
141142
var defSpreadList = DefsSpread.ToList();
142143
defSpreadList.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value));
143144
defSpreadList.Reverse();
144-
StreamWriter swDefSpread = new(Path.Combine(directory + "\\SpreadDefs.txt"), false);
145+
StreamWriter swDefSpread = new(Path.Combine(directory, "SpreadDefs.txt"), false, Encoding.UTF8);
145146
foreach (var spread in defSpreadList)
146147
{
147148
if (spread.Value > 1)
@@ -174,7 +175,7 @@ public static string DefsClassGeneratorActivity()
174175
string directory = Directory.GetCurrentDirectory();
175176
string text = string.Empty;
176177
// Создание файла
177-
StreamWriter sw = new(Path.Combine(directory + "\\defsClass.cs"), false);
178+
StreamWriter sw = new(Path.Combine(directory, "defsClass.cs"), false, Encoding.UTF8);
178179

179180
// Заголовок
180181
text += "using System.Xml.Serialization;\n\n";

0 commit comments

Comments
 (0)