Example #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log($"Starting TEdit {ErrorLogging.Version}");
            ErrorLogging.Log($"OS: {Environment.OSVersion}");

            Assembly asm = Assembly.GetExecutingAssembly();

            Version = FileVersionInfo.GetVersionInfo(asm.Location);

            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();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }
Example #2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log(string.Format("TEdit版本 {0} (CN: {1})", ErrorLogging.Version, CnVersion.ToString(3)));
            ErrorLogging.Log(string.Format("OS: {0}", Environment.OSVersion));

            Assembly asm = Assembly.GetExecutingAssembly();

            Version = FileVersionInfo.GetVersionInfo(asm.Location);

            try
            {
                int directxMajorVersion = DependencyChecker.GetDirectxMajorVersion();
                if (directxMajorVersion < 11)
                {
                    ErrorLogging.Log(string.Format("DirectX {0} 过旧. 需要 DirectX 11 及更高版本.", directxMajorVersion));
                }
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("无法验证DirectX版本. TEdit 可能无法正确运行.");
                ErrorLogging.LogException(ex);
            }

            try
            {
                DependencyChecker.CheckPaths();
            }
            catch (Exception ex)
            {
                ErrorLogging.Log("寻找 Terraria 材质路径失败. TEdit 可能无法正确运行.");
                ErrorLogging.LogException(ex);
            }


            try
            {
                if (!DependencyChecker.VerifyTerraria())
                {
                    ErrorLogging.Log("寻找 Terraria 目录失败. 没有可用的材质.");
                }
                else
                {
                    ErrorLogging.Log(string.Format("Terraria v{0}", DependencyChecker.GetTerrariaVersion() ?? "not found"));
                    ErrorLogging.Log(string.Format("Terraria Data Path: {0}", 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(string.Format("Command Line Open: {0}", e.Args[0]));
                this.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;

                    this.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();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            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 == "粘贴") // 工具名
                        {
                            SetActiveTool("光标");
                        }
                        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);
            }
        }
Example #4
0
        protected override void OnStartup(StartupEventArgs e)
        {
            ErrorLogging.Initialize();
            ErrorLogging.Log(string.Format("Starting TEdit {0}", ErrorLogging.Version));
            ErrorLogging.Log(string.Format("OS: {0}", Environment.OSVersion));

            if (!DependencyChecker.VerifyDotNet())
            {
                MessageBox.Show("Please install .Net 4.0", "Missing .Net", MessageBoxButton.OK, MessageBoxImage.Stop);
                ErrorLogging.LogException(new ApplicationException("MISSING .NET"));
                Shutdown();
            }
            else
            {
                ErrorLogging.Log(".Net >= 4.0");
            }

            if (!DependencyChecker.VerifyXna())
            {
                MessageBox.Show("Please install XNA Framework 4.0", "Missing XNA", MessageBoxButton.OK, MessageBoxImage.Stop);
                ErrorLogging.LogException(new ApplicationException("MISSING XNA"));
                Shutdown();
            }
            else
            {
                ErrorLogging.Log("XNA 4.0");
            }

            if (!DependencyChecker.VerifyTerraria())
            {
                ErrorLogging.Log("Unable to locate Terraria. No texture data will be available.");
            }
            else
            {
                ErrorLogging.Log(string.Format("Terraria Data Path: {0}", DependencyChecker.PathToContent));
            }

            if (e.Args != null && e.Args.Count() > 0)
            {
                ErrorLogging.Log(string.Format("Command Line Open: {0}", e.Args[0]));
                this.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;

                    this.Properties["OpenFile"] = fname;
                }
                catch (Exception ex)
                {
                    // For some reason, this couldn't be read as a URI.
                    // Do what you must...
                    ErrorLogging.LogException(ex);
                }
            }

            BCCL.MvvmLight.Threading.TaskFactoryHelper.Initialize();
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            base.OnStartup(e);
        }