Пример #1
0
        /// <summary>
        /// Starts running the Application
        /// You must register the System Module before calling this
        /// </summary>
        public static void Start(string title, int width, int height, WindowFlags flags = WindowFlags.ScaleToMonitor, Action?callback = null)
        {
            if (Running)
            {
                throw new Exception("App is already running");
            }

            if (Exiting)
            {
                throw new Exception("App is still exiting");
            }

            if (string.IsNullOrWhiteSpace(Name))
            {
                Name = title;
            }

            Log.Info($"Version: {Version}");
            Log.Info($"Platform: {RuntimeInformation.OSDescription} ({RuntimeInformation.OSArchitecture})");
            Log.Info($"Framework: {RuntimeInformation.FrameworkDescription}");

#if DEBUG
            Launch();
#else
            try
            {
                Launch();
            }
            catch (Exception e)
            {
                var path = System.DefaultUserDirectory(Name);
                if (Modules.Has <System>())
                {
                    path = Modules.Get <System>().UserDirectory(Name);
                }

                Log.Error(e.Message);
                // TODO - this call was broken with the logging updates!
                //Log.AppendToFile(Name, Path.Combine(path, "ErrorLog.txt"));
                throw;
            }
#endif
            void Launch()
            {
                // init modules
                Modules.ApplicationStarted();

                if (!Modules.Has <System>())
                {
                    throw new Exception("App requires a System Module to be registered before it can Start");
                }

                // our primary Window
                _primaryWindow = new Window(System, title, width, height, flags);
                Modules.FirstWindowCreated();

                // startup application
                Running = true;
                Modules.Startup();
                callback?.Invoke();
                Run();
            }
        }