Skip to content

Commit 4f67780

Browse files
committed
улучшение обработки ошибок конфигурации
1 parent 7f45e6f commit 4f67780

2 files changed

Lines changed: 21 additions & 45 deletions

File tree

Program.cs

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
using ICSharpCode.SharpZipLib.Zip;
12
using System.Globalization;
23
using System.Xml.Linq;
3-
using ICSharpCode.SharpZipLib.Zip;
44

55
namespace RTK
66
{
@@ -309,14 +309,14 @@ internal static (bool, string) TranscriptionProcessing(string CurrentFile, bool
309309
internal static (bool, string) CheckConfig(string CurrentFile)
310310
{
311311
string error = string.Empty;
312+
XDocument xdoc = new();
312313
if (!File.Exists("config.xml"))
313314
{
314-
XDocument xdoc = new XDocument();
315315
XElement configuration = new XElement("configuration");
316316
XElement xmlsha = new XElement("sha", "0");
317317
XElement xmllanguage = new XElement("language", "Russian(GitHub)");
318318
XElement xmldirectory = new XElement("directory", CurrentFile);
319-
XElement xmlrepo= new XElement("repo", "RimWorld-ru");
319+
XElement xmlrepo = new XElement("repo", "RimWorld-ru");
320320
configuration.Add(xmlsha);
321321
configuration.Add(xmllanguage);
322322
configuration.Add(xmldirectory);
@@ -328,46 +328,22 @@ internal static (bool, string) CheckConfig(string CurrentFile)
328328
}
329329
else
330330
{
331-
XDocument xdoc;
332-
try
333-
{
334-
xdoc = XDocument.Load("config.xml");
335-
}
336-
catch
337-
{
338-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
339-
return (false, error);
340-
}
341-
XElement? configuration = xdoc.Element("configuration");
342-
if (configuration.IsEmpty)
343-
{
344-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
345-
return (false, error);
346-
}
347-
string? sha = configuration.Element("sha")?.Value;
348-
if (sha is null)
349-
{
350-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
351-
return (false, error);
352-
}
353-
string? language = configuration.Element("language")?.Value;
354-
if (language is null)
355-
{
356-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
357-
return (false, error);
358-
}
359-
string? directory = configuration.Element("directory")?.Value;
360-
if (directory is null)
361-
{
362-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
363-
return (false, error);
364-
}
365-
string? repo = configuration.Element("repo")?.Value;
366-
if (repo is null)
367-
{
368-
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
369-
return (false, error);
370-
}
331+
string? temp;
332+
error = "Ôàéë íàñòðîåê ïîâðåæä¸í.";
333+
try { xdoc = XDocument.Load("config.xml"); }
334+
catch { return (false, error); }
335+
try { temp = xdoc.Element("configuration")?.Element("sha")?.Value; }
336+
catch { return (false, error); }
337+
if (temp is null) return (false, error);
338+
try { temp = xdoc.Element("configuration")?.Element("language")?.Value; }
339+
catch { return (false, error); }
340+
if (temp is null) return (false, error);
341+
try { temp = xdoc.Element("configuration")?.Element("directory")?.Value; }
342+
catch { return (false, error); }
343+
if (temp is null) return (false, error);
344+
try { temp = xdoc.Element("configuration")?.Element("repo")?.Value; }
345+
catch { return (false, error); }
346+
if (temp is null) return (false, error);
371347
}
372348
return (true, error);
373349
}

XRaw.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using System.Xml.Linq;
2-
using System.Xml;
1+
using System.Xml;
2+
using System.Xml.Linq;
33

44
namespace RTK
55
{

0 commit comments

Comments
 (0)