Skip to content

Commit

Permalink
Check for missing "ids" and "text" txt files
Browse files Browse the repository at this point in the history
  • Loading branch information
Toksisitee committed Feb 18, 2024
1 parent 5419cd5 commit b7d0495
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public partial class MainWindow : Window
static public int VersionMinor = 0;
static public int VersionPatch = 0;
private string EditorName = "PopLanguageEditor v" + VersionMajor + "." + VersionMinor + "." + VersionPatch;
private const string IDS_FILE = "ids.txt";
private const string TEXT_FILE = "text.txt";

public class LangEntry
{
Expand Down Expand Up @@ -71,19 +73,16 @@ void CreateCache(ref List<string> lines)
data.Add(new LangCache { ID = n, Text = line });
}

string filename = "ids.txt";
string filename2 = "text.txt";
if (File.Exists(IDS_FILE))
File.Delete(IDS_FILE);
if (File.Exists(TEXT_FILE))
File.Delete(TEXT_FILE);

if (File.Exists(filename))
File.Delete(filename);
if (File.Exists(filename2))
File.Delete(filename2);

using StreamWriter file = new StreamWriter(filename);
using StreamWriter file = new StreamWriter(IDS_FILE);
foreach (var entry in data)
file.WriteLine(entry.ID);

using StreamWriter file2 = new StreamWriter(filename2);
using StreamWriter file2 = new StreamWriter(TEXT_FILE);
foreach (var entry in data)
file2.WriteLine(entry.Text);

Expand All @@ -94,10 +93,8 @@ void CreateCache(ref List<string> lines)
List<LangCache> LoadCache()
{
List<LangCache> data = new List<LangCache>();
string filename = "ids.txt";
string filename2 = "text.txt";
string[] lines = File.ReadAllLines(filename);
string[] lines2 = File.ReadAllLines(filename2);
string[] lines = File.ReadAllLines(IDS_FILE);
string[] lines2 = File.ReadAllLines(TEXT_FILE);
for (int i = 0; i < lines.Length; i++)
{
data.Add(new LangCache { ID=Int16.Parse(lines[i]), Text=lines2[i] });
Expand Down Expand Up @@ -229,6 +226,14 @@ public MainWindow()
{
InitializeComponent();
this.Title = EditorName;
if (!File.Exists(IDS_FILE)) {
MessageBox.Show("Missing file: " + IDS_FILE, EditorName, MessageBoxButton.OK, MessageBoxImage.Error);
System.Environment.Exit(1);
}
if (!File.Exists(TEXT_FILE)) {
MessageBox.Show("Missing file: " + TEXT_FILE, EditorName, MessageBoxButton.OK, MessageBoxImage.Error);
System.Environment.Exit(1);
}
LoadCfg();
LoadLanguageFile(FileLoaded);
}
Expand Down Expand Up @@ -404,7 +409,7 @@ private void SaveCommand_Executed(object sender, ExecutedRoutedEventArgs e)

private void About_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Copyright © 2022 Toksisitee (https://github.com/Toksisitee)" +
MessageBox.Show("Copyright © 2022-2024 Toksisitee (https://github.com/Toksisitee)" +
Environment.NewLine + Environment.NewLine +
"PopLanguageEditor is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. PopLanguageEditor is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.",
EditorName, MessageBoxButton.OK, MessageBoxImage.Information);
Expand Down

0 comments on commit b7d0495

Please sign in to comment.