private void RunButton_Click(object sender, RoutedEventArgs e) { System.Diagnostics.Debug.Assert((this.ModTreeView.SelectedItem as ModItem).Node.IsRunnable); var arguments = new ModProcessManagerArguments { Node = (this.ModTreeView.SelectedItem as ModItem).Node, //random directory disabled because of the firewall setting //RunningDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Game-" + Guid.NewGuid().ToString().Substring(0, 8)), RunningDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Game"), //ProfileDirectory = (this.ProfilesListView.SelectedItem as ProfileItem).Directory ProfileDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Profiles", (this.ProfilesListView.SelectedItem as ProfileItem).Name, (this.ModTreeView.SelectedItem as ModItem).Node.ID) }; this.IsEnabled = false; this.IsCloseButtonEnabled = false; ModProcessManager modProcessManager = new ModProcessManager(arguments); modProcessManager.RunWorkerCompleted += (object worker_sender, System.ComponentModel.RunWorkerCompletedEventArgs worker_e) => { this.IsEnabled = true; this.IsCloseButtonEnabled = true; if (worker_e.Error == null) { System.Diagnostics.Trace.WriteLine("[Note] Game exited normally. Everything goes fine."); } else { System.Diagnostics.Trace.WriteLine("[Error] " + worker_e.Error.Message); MessageBox.Show(worker_e.Error.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } this.BuildProfiles(); }; //workaround when OS<=win7 if (System.Environment.OSVersion.Version.Major <= 5 || System.Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor <= 1) { modProcessManager.RunLegacyAsync(this); } else { //OS >=Win8 modProcessManager.RunAsync(); } }
public ModProcessManager(ModProcessManagerArguments Arguments) { this.ProfileDirectory = Arguments.ProfileDirectory; this.RunningDirectory = Arguments.RunningDirectory; this.Node = Arguments.Node; }