public MainWindow() { Configuration.Load(false); // choose language if (!LanguageWindow.ShowSelection(Configuration.Language)) { Close(); return; } if (Configuration.Language != Localization.LanguageIndex) { Configuration.Language = Localization.LanguageIndex; } StartTroopChange.Load(); ResourceChange.Load(); Version.AddExternalChanges(); // init main window InitializeComponent(); // set title this.Title = string.Format("{0} {1}", Localization.Get("Name"), Version.PatcherVersion); // set search path in ui SetBrowsePath(); SetLocalizedUIElements(); DisplayLicense(); }
static void Main(string[] args) { Configuration.Load(); StartTroopChange.Load(); ResourceChange.Load(); Version.AddExternalChanges(); ResolvePath(); ResolveArgs(args); SilentInstall(); }
static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc) { fails.Clear(); SectionEditor.Reset(); // only take binary changes var changes = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange)); List <Change> todoList = new List <Change>(changes); int todoIndex = 0; double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data // read original data & section preparation byte[] oriData = File.ReadAllBytes(filePath); byte[] data = (byte[])oriData.Clone(); SectionEditor.Init(data); todoIndex += 3; perc.Set(todoIndex / todoCount); ChangeArgs args = new ChangeArgs(data, oriData); // change version display in main menu try { (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args); } catch (Exception e) { Debug.Error(e); } perc.Set(++todoIndex / todoCount); // change stuff foreach (Change change in todoList) { change.Activate(args); perc.Set(++todoIndex / todoCount); } AICChange.DoChange(args); StartTroopChange.DoChange(args); ResourceChange.DoChange(args); todoIndex += 2; perc.Set(todoIndex / todoCount); // Write everything to file data = SectionEditor.AttachSection(data); if (filePath.EndsWith(BackupFileEnding)) { filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length); } else { File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup } File.WriteAllBytes(filePath, data); perc.Set(1); ShowFailures(filePath); }
public static void Load(bool changesOnly = false) { List <string> aicConfigurationList = null; List <string> aivConfigurationList = null; List <string> resourceConfigurationList = null; List <string> startTroopConfigurationList = null; if (File.Exists(ConfigFile)) { using (StreamReader sr = new StreamReader(ConfigFile)) { string line; while ((line = sr.ReadLine()) != null) { if (Regex.Replace(@"\s+", "", line).Contains("aic_")) { if (aicConfigurationList == null) { aicConfigurationList = new List <string>(); } aicConfigurationList.Add(line); continue; } else if (Regex.Replace(@"\s+", "", line).StartsWith("aiv_")) { if (aivConfigurationList == null) { aivConfigurationList = new List <string>(); } aivConfigurationList.Add(line); continue; } else if (Regex.Replace(@"\s+", "", line).StartsWith("res_")) { if (resourceConfigurationList == null) { resourceConfigurationList = new List <string>(); } resourceConfigurationList.Add(line); continue; } else if (Regex.Replace(@"\s+", "", line).StartsWith("s_")) { if (startTroopConfigurationList == null) { startTroopConfigurationList = new List <string>(); } startTroopConfigurationList.Add(line); continue; } string[] changeLine = line.Split(new char[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries).Select(str => str.Trim()).ToArray(); if (changeLine.Length < 2) { continue; } string changeKey = changeLine[0]; string changeSetting = changeLine[1]; if (!changesOnly) { if (changeKey == "Path") { Configuration.Path = changeSetting; } else if (changeKey == "Language") { if (int.TryParse(changeSetting, out int result)) { Configuration.Language = result; } } } if (changeKey == "Path" || changeKey == "Language") { continue; } Change change = Version.Changes.Find(c => c.TitleIdent == changeKey); if (change == null) { continue; } int numChanges = changeSetting.Count(ch => ch == '='); string[] changes = changeSetting.Split(new char[] { '}' }, numChanges, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < numChanges; i++) { string headerKey = changes[i].Split('=')[0].Replace(" ", "").Replace("{", String.Empty); string headerValue = changes[i].Split('=')[1].Replace(" ", "").Replace("{", String.Empty).Replace("}", String.Empty); DefaultHeader header = change.FirstOrDefault(c => c.DescrIdent == headerKey); header.LoadValueString(headerValue); } } } } AICChange.LoadConfiguration(aicConfigurationList); AIVChange.LoadConfiguration(aivConfigurationList); ResourceChange.LoadConfiguration(resourceConfigurationList); StartTroopChange.LoadConfiguration(startTroopConfigurationList); }
static void DoBinaryChanges(string filePath, bool xtreme, Percentage perc) { fails.Clear(); SectionEditor.Reset(); string gameSeedsFolder = Path.Combine(Configuration.Path, GAME_SEEDS_FOLDER); if (!Directory.Exists(gameSeedsFolder)) { Directory.CreateDirectory(gameSeedsFolder); } // Retrieve set of selected binary changes var changes = Version.Changes.Where(c => c.IsChecked && c is Change && !(c is ResourceChange) && !(c is StartTroopChange)); List <Change> todoList = new List <Change>(changes); int todoIndex = 0; double todoCount = 9 + todoList.Count; // +2 for AIprops +3 for read, +1 for version edit, +3 for writing data // Read original data & perform section preparation adding .ucp section to binary byte[] oriData = File.ReadAllBytes(filePath); byte[] data = (byte[])oriData.Clone(); SectionEditor.Init(data); todoIndex += 3; perc.Set(todoIndex / todoCount); ChangeArgs args = new ChangeArgs(data, oriData); // Change version display in main menu try { (xtreme ? Version.MenuChange_XT : Version.MenuChange).Activate(args); } catch (Exception e) { Debug.Error(e); } perc.Set(++todoIndex / todoCount); // Apply each selected binary change foreach (Change change in todoList) { change.Activate(args); perc.Set(++todoIndex / todoCount); } // Apply changes handled in their respective submodules AICChange.DoChange(args); StartTroopChange.DoChange(args); ResourceChange.DoChange(args); todoIndex += 2; perc.Set(todoIndex / todoCount); // Write everything to file data = SectionEditor.AttachSection(data); if (filePath.EndsWith(BackupFileEnding)) { filePath = filePath.Remove(filePath.Length - BackupFileEnding.Length); } else { File.WriteAllBytes(filePath + BackupFileEnding, oriData); // create backup } File.WriteAllBytes(filePath, data); perc.Set(1); ShowFailures(filePath); }