private void init(StarterProfile p) { InitializeComponent(); Translator.TranslateForm(this); InitLocales(); AnyGameStarter.Program.TryRestorePermissions(); GameUtils.RedetectGames(); initGames(); nameBox.Enabled = false; niceLanguageBox.Enabled = false; languageBox.Enabled = false; locationBox.Enabled = false; _dontChangeExecutable = true; foreach (string game in p.InstalledGames) { if (expansionBox.Items.ContainsKey(game)) { expansionBox.Items[game].Checked = expansionBox.CheckBoxes; } } nameBox.Text = p.Name; executableBox.Text = p.Executable; languageBox.Text = p.Locale; Text = Translator.GetText("EditProfileDialog"); AdvancedCheck.Checked = false; }
private void button1_Click(object sender, EventArgs e) { if (expansionBox.Enabled == true) { if (!File.Exists(executableBox.Text)) { MessageBox.Show(Translator.GetText("ExecutableNotFound")); DialogResult = System.Windows.Forms.DialogResult.None; AdvancedCheck.Checked = true; return; } var games = new List <string>(); foreach (ListViewItem item in expansionBox.CheckedItems) { games.Add(item.Name); } if (locationBox.Enabled == true) { target: try { var directory = new DirectoryInfo(locationBox.Text); if (directory.Exists) { var result = MessageBox.Show(Translator.GetText("DirectoryAlreadyExists"), "Any Game Starter 3", MessageBoxButtons.AbortRetryIgnore); if (result == System.Windows.Forms.DialogResult.Retry) { goto target; } if (result == System.Windows.Forms.DialogResult.Abort) { DialogResult = System.Windows.Forms.DialogResult.None; return; } } else { directory.Create(); } } catch (Exception ex) { MessageBox.Show(ex.Message); DialogResult = System.Windows.Forms.DialogResult.None; return; } } Profile = new StarterProfile(executableBox.Text, locationBox.Text, games, nameBox.Text, languageBox.Text); Profile.Save(); Hide(); } else { GameUtils.Locale = languageBox.Text; Hide(); } }
public AddProfileDialog(StarterProfile p) { if (p == null) { init(); } else { init(p); } }
private void Profiles_SelectedIndexChanged(object sender, EventArgs e) { bool b = (Profiles.SelectedIndices.Count == 1); foreach (Control c in panel1.Controls) { if (c is Label) { c.Visible = b; } } if (b) { lblSelectionName.Text = Profiles.SelectedItems[0].Text; if (Profiles.SelectedItems[0].Group == Profiles.Groups[1]) { var item = new StarterProfile(Profiles.SelectedItems[0].Text); var directory = new DirectoryInfo(item.VirtualAppDataFolder); var d2 = FindSimsRoot(directory, 0); if (d2 != null) { directory = d2; } size.Text = FormatSize(DirSize(directory)); mods.Text = NumMods(new DirectoryInfo(Path.Combine(directory.FullName, "Mods"))).ToString(); savegames.Text = NumSafeGames(new DirectoryInfo(Path.Combine(directory.FullName, "Saves"))).ToString(); creation.Text = item.CreationTime.ToString(); language.Text = item.Locale; } else { var directory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Electronic Arts")); var d2 = FindSimsRoot(directory, 0); if (d2 != null) { directory = d2; } size.Text = FormatSize(DirSize(directory)); mods.Text = NumMods(new DirectoryInfo(Path.Combine(directory.FullName, "Mods"))).ToString(); savegames.Text = NumSafeGames(new DirectoryInfo(Path.Combine(directory.FullName, "Saves"))).ToString(); creation.Text = directory.CreationTime.ToString(); language.Text = GameUtils.Locale; } } }
private void Profiles_AfterLabelEdit(object sender, LabelEditEventArgs e) { var label = e.Label; if (String.IsNullOrEmpty(label) || (label.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)) { e.CancelEdit = true; return; } label = label.Trim(); try { StarterProfile.rename(Profiles.Items[e.Item].Text, label); lblSelectionName.Text = label; } catch (Exception ex) { e.CancelEdit = true; MessageBox.Show(ex.Message); } }
private void duplicateMenuItem_Click(object sender, EventArgs e) { if (Profiles.SelectedItems.Count == 1) { StarterProfile oldProfile; String oldFolder; String newProfileAddOn = ""; if (Profiles.SelectedItems[0] == DefaultProfileItem) { oldProfile = null; var directory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Electronic Arts")); var root = FindSimsRoot(directory, 6); oldFolder = root.FullName; newProfileAddOn = Path.Combine(root.Parent.Parent.Name, Path.Combine(root.Parent.Name, root.Name)); } else { oldProfile = new StarterProfile(Profiles.SelectedItems[0].Text); oldFolder = oldProfile.VirtualAppDataFolder; } var diag = new AddProfileDialog(oldProfile, true); diag.ShowDialog(); var newProfile = diag.Profile; if (newProfile == null) { return; } var newFolder = newProfile.VirtualAppDataFolder; if (newProfileAddOn != null) { newFolder = Path.Combine(newFolder, newProfileAddOn); new DirectoryInfo(newFolder).Create(); } try { new Computer().FileSystem.CopyDirectory(oldFolder, newFolder, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException); } catch (Exception ex) { MessageBox.Show(ex.Message); newProfile.Delete(); } ReloadProfiles(); } }
public AddProfileDialog(StarterProfile source, bool copy) : this(source) { if (source == null) { nameBox.Text = Translator.GetText("DefaultProfile") + " - " + Translator.GetText("Copy"); foreach (ListViewItem i in expansionBox.Items) { i.Checked = true; } } else { nameBox.Text = source.Name + " - " + Translator.GetText("Copy"); } nameBox.Enabled = true; niceLanguageBox.Enabled = false; languageBox.Enabled = false; locationBox.Enabled = true; Text = Translator.GetText("CopyProfileDialog"); }
/// <summary> /// Main initialization procedure /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void MainForm_Load(object sender, EventArgs e) { if (GameUtils.BaseGame == null) { if (MessageBox.Show(Translator.GetText("NoSimsFound"), "Any Game Starter 3", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { Close(); Application.Exit(); return; } } //Program.TryRestorePermissions(); Translator.TranslateForm(this); if (StarterProfile.IsFirstRun()) { new AboutBox().ShowDialog(); } DefaultProfileItem = new ListViewItem(Translator.GetText("DefaultProfile")); DefaultProfileItem.SubItems.Add("All"); DefaultProfileItem.ImageIndex = 0; Profiles.Groups.Add("default", Translator.GetText("DefaultProfileSection")); Profiles.Groups.Add("anygame", Translator.GetText("AdditionalProfileSection")); ReloadProfiles(); }
public static StartGameResult StartGame(string profile, bool startLauncher, bool firstStart) { if (!TryRestorePermissions()) return StartGameResult.PermissionsNeeded; GameUtils.RedetectGames(); StarterProfile e = null; try { e = new StarterProfile(profile); } catch (Exception) { } if (e == null) return StartGameResult.ProfileNotFound; CreateSystemRestore(); try { foreach (var game in GameUtils.InstalledGames) { if (game != GameUtils.BaseGame && !e.InstalledGames.Contains(game.Name) && game.RegistryKey != null) { RemovePermissions(game.RegistryKey); } } } catch (SecurityException) { return StartGameResult.PermissionsNeeded; } var oldlocale = GameUtils.Locale; try { GameUtils.Locale = e.Locale; } catch (SecurityException) { return StartGameResult.PermissionsNeeded; } string fname = e.Executable; if (startLauncher) { var games = new List<Game>(); foreach (Game game in GameUtils.InstalledGames) { if (e.InstalledGames.Contains(game.Name)) { games.Add(game); } } fname = GameUtils.UnifiedLauncherExecutable; } string oldMyDocuments; string folder; try { folder = AdjustMyDocuments(e.VirtualAppDataFolder, out oldMyDocuments); } catch (ArgumentException) { GameUtils.Locale = oldlocale; foreach (var game in GameUtils.InstalledGames) { if (game.RegistryKey != null) { RestorePermissions(game.RegistryKey); } } RemoveSystemRestore(); return StartGameResult.Success; } folder = folder.Replace("%USERPROFILE%", e.VirtualAppDataFolder); try { Directory.CreateDirectory(folder); Process p = new Process() { StartInfo = new ProcessStartInfo(fname) { UseShellExecute = false } }; p.StartInfo.EnvironmentVariables["userprofile"] = e.VirtualAppDataFolder; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(fname); p.Start(); try { p.WaitForInputIdle(); if (p.MainWindowTitle == "" || startLauncher) { if (firstStart && !startLauncher) p.Kill(); else p.WaitForExit(); p.Close(); return StartGameResult.Success; } else { p.WaitForExit(); p.Close(); return StartGameResult.EarlyGameExit; } } catch (Exception) { p.Close(); return StartGameResult.Success; } } catch (Exception ex) { MessageBox.Show(ex.Message, Translator.GetText("StartGameErrorDialog"), MessageBoxButtons.OK, MessageBoxIcon.Error); return StartGameResult.Failure; } finally { try { AdjustMyDocuments(oldMyDocuments); } finally { GameUtils.Locale = oldlocale; foreach (var game in GameUtils.InstalledGames) { if (game.RegistryKey != null) { RestorePermissions(game.RegistryKey); } } RemoveSystemRestore(); } } }
public static StartGameResult StartGame(string profile, bool startLauncher, bool firstStart) { if (!TryRestorePermissions()) { return(StartGameResult.PermissionsNeeded); } GameUtils.RedetectGames(); StarterProfile e = null; try { e = new StarterProfile(profile); } catch (Exception) { } if (e == null) { return(StartGameResult.ProfileNotFound); } CreateSystemRestore(); try { foreach (var game in GameUtils.InstalledGames) { if (game != GameUtils.BaseGame && !e.InstalledGames.Contains(game.Name) && game.RegistryKey != null) { RemovePermissions(game.RegistryKey); } } } catch (SecurityException) { return(StartGameResult.PermissionsNeeded); } var oldlocale = GameUtils.Locale; try { GameUtils.Locale = e.Locale; } catch (SecurityException) { return(StartGameResult.PermissionsNeeded); } string fname = e.Executable; if (startLauncher) { var games = new List <Game>(); foreach (Game game in GameUtils.InstalledGames) { if (e.InstalledGames.Contains(game.Name)) { games.Add(game); } } fname = GameUtils.UnifiedLauncherExecutable; } string oldMyDocuments; string folder; try { folder = AdjustMyDocuments(e.VirtualAppDataFolder, out oldMyDocuments); } catch (ArgumentException) { GameUtils.Locale = oldlocale; foreach (var game in GameUtils.InstalledGames) { if (game.RegistryKey != null) { RestorePermissions(game.RegistryKey); } } RemoveSystemRestore(); return(StartGameResult.Success); } folder = folder.Replace("%USERPROFILE%", e.VirtualAppDataFolder); try { Directory.CreateDirectory(folder); Process p = new Process() { StartInfo = new ProcessStartInfo(fname) { UseShellExecute = false } }; p.StartInfo.EnvironmentVariables["userprofile"] = e.VirtualAppDataFolder; p.StartInfo.WorkingDirectory = Path.GetDirectoryName(fname); p.Start(); try { p.WaitForInputIdle(); if (p.MainWindowTitle == "" || startLauncher) { if (firstStart && !startLauncher) { p.Kill(); } else { p.WaitForExit(); } p.Close(); return(StartGameResult.Success); } else { p.WaitForExit(); p.Close(); return(StartGameResult.EarlyGameExit); } } catch (Exception) { p.Close(); return(StartGameResult.Success); } } catch (Exception ex) { MessageBox.Show(ex.Message, Translator.GetText("StartGameErrorDialog"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(StartGameResult.Failure); } finally { try { AdjustMyDocuments(oldMyDocuments); } finally { GameUtils.Locale = oldlocale; foreach (var game in GameUtils.InstalledGames) { if (game.RegistryKey != null) { RestorePermissions(game.RegistryKey); } } RemoveSystemRestore(); } } }
private void Profiles_SelectedIndexChanged(object sender, EventArgs e) { bool b = (Profiles.SelectedIndices.Count == 1); foreach (Control c in panel1.Controls) { if (c is Label) { c.Visible = b; } } if (b) { lblSelectionName.Text = Profiles.SelectedItems[0].Text; if (Profiles.SelectedItems[0].Group == Profiles.Groups[1]) { var item = new StarterProfile(Profiles.SelectedItems[0].Text); var directory = new DirectoryInfo(item.VirtualAppDataFolder); var d2 = FindSimsRoot(directory, 0); if (d2 != null) directory = d2; size.Text = FormatSize(DirSize(directory)); mods.Text = NumMods(new DirectoryInfo(Path.Combine(directory.FullName, "Mods"))).ToString(); savegames.Text = NumSafeGames(new DirectoryInfo(Path.Combine(directory.FullName, "Saves"))).ToString(); creation.Text = item.CreationTime.ToString(); language.Text = item.Locale; } else { var directory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Electronic Arts")); var d2 = FindSimsRoot(directory, 0); if (d2 != null) directory = d2; size.Text = FormatSize(DirSize(directory)); mods.Text = NumMods(new DirectoryInfo(Path.Combine(directory.FullName, "Mods"))).ToString(); savegames.Text = NumSafeGames(new DirectoryInfo(Path.Combine(directory.FullName, "Saves"))).ToString(); creation.Text = directory.CreationTime.ToString(); language.Text = GameUtils.Locale; } } }
private void duplicateMenuItem_Click(object sender, EventArgs e) { if (Profiles.SelectedItems.Count == 1) { StarterProfile oldProfile; String oldFolder; String newProfileAddOn = ""; if (Profiles.SelectedItems[0] == DefaultProfileItem) { oldProfile = null; var directory = new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Electronic Arts")); var root = FindSimsRoot(directory, 6); oldFolder = root.FullName; newProfileAddOn = Path.Combine(root.Parent.Parent.Name, Path.Combine(root.Parent.Name, root.Name)); } else { oldProfile = new StarterProfile(Profiles.SelectedItems[0].Text); oldFolder = oldProfile.VirtualAppDataFolder; } var diag = new AddProfileDialog(oldProfile, true); diag.ShowDialog(); var newProfile = diag.Profile; if (newProfile == null) return; var newFolder = newProfile.VirtualAppDataFolder; if (newProfileAddOn != null) { newFolder = Path.Combine(newFolder, newProfileAddOn); new DirectoryInfo(newFolder).Create(); } try { new Computer().FileSystem.CopyDirectory(oldFolder, newFolder, Microsoft.VisualBasic.FileIO.UIOption.AllDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.ThrowException); } catch (Exception ex) { MessageBox.Show(ex.Message); newProfile.Delete(); } ReloadProfiles(); } }