protected override void OnStartup(StartupEventArgs e) { ErrorLogging.Initialize(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; ErrorLogging.Log($"Starting TEdit {ErrorLogging.Version}"); ErrorLogging.Log($"OS: {Environment.OSVersion}"); try { ErrorLogging.Log($"OS Name: {DependencyChecker.GetOsVersion()}"); } catch (Exception ex) { ErrorLogging.Log("Failed to verify OS Version. TEdit may not run properly."); ErrorLogging.LogException(ex); } Assembly asm = Assembly.GetExecutingAssembly(); Version = FileVersionInfo.GetVersionInfo(asm.Location).ProductVersion; try { ErrorLogging.Log(DependencyChecker.GetDotNetVersion()); } catch (Exception ex) { ErrorLogging.Log("Failed to verify .Net Framework Version. TEdit may not run properly."); ErrorLogging.LogException(ex); } try { int directxMajorVersion = DependencyChecker.GetDirectxMajorVersion(); if (directxMajorVersion < 11) { ErrorLogging.Log($"DirectX {directxMajorVersion} unsupported. DirectX 11 or higher is required."); } } catch (Exception ex) { ErrorLogging.Log("Failed to verify DirectX Version. TEdit may not run properly."); ErrorLogging.LogException(ex); } try { DependencyChecker.CheckPaths(); } catch (Exception ex) { ErrorLogging.Log("Failed to verify Terraria Paths. TEdit may not run properly."); ErrorLogging.LogException(ex); } try { if (!DependencyChecker.VerifyTerraria()) { ErrorLogging.Log("Unable to locate Terraria. No texture data will be available."); } else { ErrorLogging.Log($"Terraria v{DependencyChecker.GetTerrariaVersion() ?? "not found"}"); ErrorLogging.Log($"Terraria Data Path: {DependencyChecker.PathToContent}"); } } catch (Exception ex) { ErrorLogging.Log("Failed to verify Terraria Paths. No texture data will be available."); ErrorLogging.LogException(ex); } if (e.Args != null && e.Args.Count() > 0) { ErrorLogging.Log($"Command Line Open: {e.Args[0]}"); Properties["OpenFile"] = e.Args[0]; } if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Length > 0) { string fname = "No filename given"; try { fname = AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]; // It comes in as a URI; this helps to convert it to a path. var uri = new Uri(fname); fname = uri.LocalPath; Properties["OpenFile"] = fname; } catch (Exception ex) { // For some reason, this couldn't be read as a URI. // Do what you must... ErrorLogging.LogException(ex); } } DispatcherHelper.Initialize(); TaskFactoryHelper.Initialize(); base.OnStartup(e); }
private void HandleKeyDownEvent(object sender, KeyEventArgs e) { try { if (!(e.Source is View.WorldRenderXna)) { return; } if (e.Key == Key.C && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.CopyCommand.CanExecute(null)) { _vm.CopyCommand.Execute(null); } } else if (e.Key == Key.V && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.PasteCommand.CanExecute(null)) { _vm.PasteCommand.Execute(null); } } else if (e.Key == Key.Z && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { _vm.UndoCommand.Execute(null); } else if (e.Key == Key.OemPlus && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.RequestZoomCommand.CanExecute(true)) { _vm.RequestZoomCommand.Execute(true); } } else if (e.Key == Key.OemMinus && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.RequestZoomCommand.CanExecute(false)) { _vm.RequestZoomCommand.Execute(false); } } else if (e.Key == Key.Y && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { _vm.RedoCommand.Execute(null); } else if (e.Key == Key.A && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.CurrentWorld != null) { _vm.Selection.IsActive = true; _vm.Selection.SetRectangle(new Vector2Int32(0, 0), new Vector2Int32(_vm.CurrentWorld.TilesWide - 1, _vm.CurrentWorld.TilesHigh - 1)); } } else if (e.Key == Key.D && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.CurrentWorld != null) { _vm.Selection.IsActive = false; } } else if (e.Key == Key.S && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.SaveCommand.CanExecute(null)) { _vm.SaveCommand.Execute(null); } } else if (e.Key == Key.O && Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { if (_vm.OpenCommand.CanExecute(null)) { _vm.OpenCommand.Execute(null); } } else if (e.Key == Key.Delete) { if (_vm.DeleteCommand.CanExecute(null)) { _vm.DeleteCommand.Execute(null); } } else if (e.Key == Key.Escape) { if (_vm.ActiveTool != null) { if (_vm.ActiveTool.Name == "Paste") { SetActiveTool("Arrow"); } else { _vm.Selection.IsActive = false; } } } else if (e.Key == Key.Up) { if (_vm.RequestScrollCommand.CanExecute(ScrollDirection.Up)) { _vm.RequestScrollCommand.Execute(ScrollDirection.Up); } e.Handled = true; } else if (e.Key == Key.Down) { if (_vm.RequestScrollCommand.CanExecute(ScrollDirection.Down)) { _vm.RequestScrollCommand.Execute(ScrollDirection.Down); } e.Handled = true; } else if (e.Key == Key.Left) { if (_vm.RequestScrollCommand.CanExecute(ScrollDirection.Left)) { _vm.RequestScrollCommand.Execute(ScrollDirection.Left); } e.Handled = true; } else if (e.Key == Key.Right) { if (_vm.RequestScrollCommand.CanExecute(ScrollDirection.Right)) { _vm.RequestScrollCommand.Execute(ScrollDirection.Right); } e.Handled = true; } else if (World.ShortcutKeys.ContainsKey(e.Key)) { string command = World.ShortcutKeys[e.Key]; if (string.Equals("Eraser", command, StringComparison.InvariantCultureIgnoreCase)) { _vm.TilePicker.IsEraser = !_vm.TilePicker.IsEraser; } else if (string.Equals("Swap", command, StringComparison.InvariantCultureIgnoreCase)) { _vm.TilePicker.Swap(Keyboard.Modifiers); } else { SetActiveTool(command); } } } catch (Exception ex) { ErrorLogging.LogException(ex); } }
private void HandleKeyDownEvent(object sender, KeyEventArgs e) { if (!(e.Source is View.WorldRenderXna)) { return; } try { ScrollEventArgs scrollValue = null; var command = World.ShortcutKeys.Get(e.Key, e.KeyboardDevice.Modifiers); if (command == null) { return; } switch (command) { case "copy": if (_vm.CopyCommand.CanExecute(null)) { _vm.CopyCommand.Execute(null); } break; case "paste": if (_vm.PasteCommand.CanExecute(null)) { _vm.PasteCommand.Execute(null); } break; case "undo": _vm.UndoCommand.Execute(null); break; case "redo": _vm.RedoCommand.Execute(null); break; case "selectall": if (_vm.CurrentWorld != null) { _vm.Selection.IsActive = true; _vm.Selection.SetRectangle(new Vector2Int32(0, 0), new Vector2Int32(_vm.CurrentWorld.TilesWide - 1, _vm.CurrentWorld.TilesHigh - 1)); } break; case "selectnone": if (_vm.CurrentWorld != null) { _vm.Selection.IsActive = false; } break; case "open": if (_vm.OpenCommand.CanExecute(null)) { _vm.OpenCommand.Execute(null); } break; case "save": if (_vm.SaveCommand.CanExecute(null)) { _vm.SaveCommand.Execute(null); } break; case "saveas": if (_vm.SaveAsCommand.CanExecute(null)) { _vm.SaveAsCommand.Execute(null); } break; case "deleteselection": if (_vm.DeleteCommand.CanExecute(null)) { _vm.DeleteCommand.Execute(null); } break; case "resettool": if (_vm.ActiveTool != null) { if (_vm.ActiveTool.Name == "Paste") { SetActiveTool("Arrow"); } else { _vm.Selection.IsActive = false; } } break; case "scrollup": scrollValue = new ScrollEventArgs(ScrollDirection.Up, 10); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrollupfast": scrollValue = new ScrollEventArgs(ScrollDirection.Up, 50); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrollright": scrollValue = new ScrollEventArgs(ScrollDirection.Right, 10); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrollrightfast": scrollValue = new ScrollEventArgs(ScrollDirection.Right, 50); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrolldown": scrollValue = new ScrollEventArgs(ScrollDirection.Down, 10); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrolldownfast": scrollValue = new ScrollEventArgs(ScrollDirection.Down, 50); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrollleft": scrollValue = new ScrollEventArgs(ScrollDirection.Left, 10); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "scrollleftfast": scrollValue = new ScrollEventArgs(ScrollDirection.Left, 50); if (_vm.RequestScrollCommand.CanExecute(scrollValue)) { _vm.RequestScrollCommand.Execute(scrollValue); } e.Handled = true; break; case "pan": if (_vm.RequestPanCommand.CanExecute(true)) { _vm.RequestPanCommand.Execute(true); } break; case "zoomin": if (_vm.RequestZoomCommand.CanExecute(true)) { _vm.RequestZoomCommand.Execute(true); } break; case "zoomout": if (_vm.RequestZoomCommand.CanExecute(false)) { _vm.RequestZoomCommand.Execute(false); } break; case "eraser": _vm.TilePicker.IsEraser = !_vm.TilePicker.IsEraser; break; case "swap": _vm.TilePicker.Swap(Keyboard.Modifiers); break; case "toggletile": _vm.TilePicker.TileStyleActive = !_vm.TilePicker.TileStyleActive; break; case "togglewall": _vm.TilePicker.WallStyleActive = !_vm.TilePicker.WallStyleActive; break; default: SetActiveTool(command); break; } } catch (Exception ex) { ErrorLogging.LogException(ex); } }
public static void CheckPaths() { Properties.Settings.Default.Reload(); string path = Properties.Settings.Default.TerrariaPath; int? steamUserId = TEdit.Terraria.World.SteamUserId; // if hard coded in settings.xml try that location first if (!string.IsNullOrWhiteSpace(TEdit.Terraria.World.AltC)) { if (Directory.Exists(TEdit.Terraria.World.AltC)) { path = TEdit.Terraria.World.AltC; } } // if the folder is missing, reset. if (!Directory.Exists(path)) { Properties.Settings.Default.TerrariaPath = null; try { Properties.Settings.Default.Save(); } catch (Exception ex) { ErrorLogging.LogException(ex); } path = string.Empty; } // SBLogic - attempt to find GOG version if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\GOG.com\Games\1207665503\")) { if (key != null) { path = Path.Combine((string)key.GetValue("PATH"), "Content"); } } } // find steam if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { // try with dionadar's fix using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 105600")) { if (key != null) { path = Path.Combine((string)key.GetValue("InstallLocation"), "Content"); } } } // if that fails, try steam path if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { using (RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\\Valve\\Steam")) { if (key != null) { path = key.GetValue("SteamPath") as string; } } //no steam key, let's try steam in program files if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { path = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); path = Path.Combine(path, "Steam"); } path = Path.Combine(path, "steamapps", "common", "terraria", "Content"); } // if that fails, try steam path - the long way if (string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\Valve\\Steam")) { if (key != null) { path = key.GetValue("InstallPath") as string; } else { using (RegistryKey key2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\\WOW6432Node\\Valve\\Steam")) { if (key2 != null) { path = key2.GetValue("InstallPath") as string; } } } //no steam key, let's try steam in program files if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path)) { var vdfFile = Path.Combine(path, "steamapps", "libraryfolders.vdf"); using (var file = File.Open(vdfFile, FileMode.Open, FileAccess.Read, FileShare.Read)) using (TextReader tr = new StreamReader(file)) { var libraryPaths = new List <string>(); string line = null; bool foundPath = false; while ((line = tr.ReadLine()) != null && !foundPath) { if (!string.IsNullOrWhiteSpace(line)) { var split = line.Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in split) { var trimmed = item.Trim('\"').Replace("\\\\", "\\"); if (Directory.Exists(trimmed)) { var testpath = Path.Combine(trimmed, "steamapps", "common", "terraria", "Content"); if (Directory.Exists(testpath)) { path = testpath; foundPath = true; break; } } } } } } } } } // ug...we still don't have a path. Prompt the user. if (!Directory.Exists(path)) { string tempPath = BrowseForTerraria(); bool retry = true; while (!DirectoryHasContentFolder(tempPath) && retry) { if (MessageBox.Show( string.Format(Properties.Language.dialog_error_terriaria_folder_message, path), Properties.Language.dialog_error_terriaria_folder_title, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error) == DialogResult.Retry) { tempPath = BrowseForTerraria(); } else { retry = false; } } Properties.Settings.Default.TerrariaPath = Path.Combine(tempPath, "Content"); try { Properties.Settings.Default.Save(); } catch (Exception ex) { ErrorLogging.LogException(ex); } } if (!string.IsNullOrWhiteSpace(path) && path.IndexOf("Content", StringComparison.OrdinalIgnoreCase) < 0) { path = Path.Combine(path, "Content"); } path = Path.GetFullPath(path); PathToContent = path; PathToWorlds = GetPathToWorlds(steamUserId); }