Обновление
* Добавлен расшифровщик сохранений * Добавлена конфигурация для сборщика проекта в один файл * Начата разработка логики основного окна Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
212
MainForm.cs
212
MainForm.cs
@@ -1,20 +1,220 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SaveWizard_rewritten
|
||||
{
|
||||
public partial class MainForm: Form
|
||||
{
|
||||
private readonly string config_file_name = "update.cfg";
|
||||
|
||||
[DllImport("SII_Decrypt.dll")]
|
||||
public static extern int GetFileFormat(string FileName);
|
||||
|
||||
[DllImport("SII_Decrypt.dll")]
|
||||
public static extern int DecryptAndDecodeFile(string InputFile, string OutputFile);
|
||||
|
||||
private Dictionary<TextBox, WindowText> items = null;
|
||||
|
||||
private string opened_file_path, selected_game;
|
||||
|
||||
private Dictionary<string, string> dlc = null;
|
||||
private Dictionary<string, bool> owns = null;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Test stuff
|
||||
//string path = Path.Combine(Environment.CurrentDirectory, "configs");
|
||||
//if (Directory.Exists(path))
|
||||
// Directory.Delete(path, true);
|
||||
//path = Path.Combine(Environment.CurrentDirectory, "update.cfg");
|
||||
//if (File.Exists(path))
|
||||
// File.Delete(path);
|
||||
}
|
||||
|
||||
private class WindowText
|
||||
{
|
||||
private CheckBox Check { get; set; }
|
||||
private string Str { get; set; }
|
||||
|
||||
public WindowText(CheckBox _check, string _str)
|
||||
{
|
||||
Check = _check;
|
||||
Str = _str;
|
||||
}
|
||||
|
||||
public CheckBox GetCheck()
|
||||
{
|
||||
return Check;
|
||||
}
|
||||
|
||||
public string GetString()
|
||||
{
|
||||
return Str;
|
||||
}
|
||||
}
|
||||
|
||||
private void boxTextChanged(object sender, EventArgs e)
|
||||
{
|
||||
TextBox _sender = sender as TextBox;
|
||||
items[_sender].GetCheck().Checked = false;
|
||||
}
|
||||
|
||||
private void ValidateBasic(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (!(e.KeyChar >= '0' && e.KeyChar <= '9') && !char.IsControl(e.KeyChar))
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void ValidateSkills(object sender, KeyPressEventArgs e)
|
||||
{
|
||||
if (!(e.KeyChar >= '0' && e.KeyChar <= '6') && !char.IsControl(e.KeyChar))
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void GetFileData(string filename)
|
||||
{
|
||||
string file_data = File.ReadAllText(filename);
|
||||
RegexHandler.FillLines(Regex.Split(file_data, "\n").ToList());
|
||||
|
||||
foreach (KeyValuePair<TextBox, WindowText> item in items)
|
||||
item.Key.Text = RegexHandler.GetValue(RegexHandler.SearchLine(item.Value.GetString()));
|
||||
|
||||
if (RegexHandler.SearchLine("company.volatile.stokes.calais") != 0)
|
||||
selected_game = "ets2";
|
||||
else if (RegexHandler.SearchLine("company.volatile.ed_mkt.elko") != 0)
|
||||
selected_game = "ats";
|
||||
else
|
||||
selected_game = null;
|
||||
if (selected_game != null)
|
||||
{
|
||||
string config_path = $"configs/{selected_game}/dlc.json";
|
||||
if (File.Exists(config_path))
|
||||
{
|
||||
dlc = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(config_path));
|
||||
owns = new Dictionary<string, bool>
|
||||
{
|
||||
{ "base", true }
|
||||
};
|
||||
List<string> companies = RegexHandler.GetArrayItems(RegexHandler.SearchLine("companies:"));
|
||||
foreach (var company in companies)
|
||||
foreach (var item in dlc)
|
||||
if (company.Contains(item.Value))
|
||||
owns[item.Key] = true;
|
||||
owns = null;
|
||||
}
|
||||
else
|
||||
MessageBox.Show($"'dlc.json' from '{selected_game}' have errors or not found, functionality has been limited", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
btn_unlock_garages.Enabled = true;
|
||||
btn_recover_backup.Enabled = true;
|
||||
btn_apply_changes.Enabled = true;
|
||||
}
|
||||
|
||||
private void ClearData()
|
||||
{
|
||||
opened_file_path = null;
|
||||
RegexHandler.FillLines(null);
|
||||
selected_game = null;
|
||||
dlc = null;
|
||||
owns = null;
|
||||
foreach (KeyValuePair<TextBox, WindowText> item in items)
|
||||
{
|
||||
item.Key.Text = "";
|
||||
item.Value.GetCheck().Checked = true;
|
||||
}
|
||||
btn_unlock_garages.Enabled = false;
|
||||
btn_recover_backup.Enabled = false;
|
||||
btn_apply_changes.Enabled = false;
|
||||
}
|
||||
|
||||
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
Application.Exit();
|
||||
}
|
||||
|
||||
private void MainForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
items = new Dictionary<TextBox, WindowText>
|
||||
{
|
||||
{ txt_money, new WindowText(chk_money, "money_account:") },
|
||||
{ txt_experience, new WindowText(chk_experience, "experience_points:") },
|
||||
{ txt_loan_limit, new WindowText(chk_loan_limit, "loan_limit:") },
|
||||
{ txt_long_distance, new WindowText(chk_long_distance, "long_dist:") },
|
||||
{ txt_high_value_cargo, new WindowText(chk_high_value_cargo, "heavy:") },
|
||||
{ txt_fragile_cargo, new WindowText(chk_fragile_cargo, "fragile:") },
|
||||
{ txt_urgent_delivery, new WindowText(chk_urgent_delivery, "urgent:") },
|
||||
{ txt_ecodriving, new WindowText(chk_ecodriving, "mechanical:") },
|
||||
};
|
||||
KeyPressEventHandler basic = new KeyPressEventHandler(ValidateBasic);
|
||||
txt_money.KeyPress += basic;
|
||||
txt_experience.KeyPress += basic;
|
||||
txt_loan_limit.KeyPress += basic;
|
||||
//txt_adr.KeyPress += new KeyPressEventHandler(ValidateADR);
|
||||
KeyPressEventHandler skills = new KeyPressEventHandler(ValidateSkills);
|
||||
txt_long_distance.KeyPress += skills;
|
||||
txt_high_value_cargo.KeyPress += skills;
|
||||
txt_fragile_cargo.KeyPress += skills;
|
||||
txt_urgent_delivery.KeyPress += skills;
|
||||
txt_ecodriving.KeyPress += skills;
|
||||
foreach (TextBox txtbox in items.Keys)
|
||||
txtbox.TextChanged += boxTextChanged;
|
||||
Dictionary<string, bool> update_conf = new Dictionary<string, bool>
|
||||
{
|
||||
{ "update_on_start", false }
|
||||
};
|
||||
string path = Path.Combine(Environment.CurrentDirectory, config_file_name);
|
||||
if (File.Exists(path))
|
||||
update_conf = JsonConvert.DeserializeObject<Dictionary<string, bool>>(File.ReadAllText(path));
|
||||
if (update_conf["update_on_start"])
|
||||
{
|
||||
chk_update_on_start.Checked = true;
|
||||
UpdateForm window = new UpdateForm();
|
||||
window.ShowDialog();
|
||||
window.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void chk_update_on_start_CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
File.WriteAllText(
|
||||
Path.Combine(Environment.CurrentDirectory, config_file_name),
|
||||
JsonConvert.SerializeObject(new Dictionary<string, bool>
|
||||
{
|
||||
{ "update_on_start", chk_update_on_start.Checked }
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private void btn_open_save_Click(object sender, EventArgs e)
|
||||
{
|
||||
ClearData();
|
||||
OpenFileDialog ofd = new OpenFileDialog()
|
||||
{
|
||||
Title = "Выберите файл сохранения",
|
||||
Filter = "Сохранение в формате SII|game.sii",
|
||||
Multiselect = false,
|
||||
};
|
||||
if (ofd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (GetFileFormat(ofd.FileName) == 2)
|
||||
{
|
||||
if (DecryptAndDecodeFile(ofd.FileName, ofd.FileName) != 0)
|
||||
{
|
||||
MessageBox.Show("Something went wrong with decrypting file. Try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
GetFileData(ofd.FileName);
|
||||
opened_file_path = ofd.FileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user