private void OpenDatabase()
        {
            try
            {
                this.database         = new LiteDatabase(this.connectionString);
                this.screenCollection = this.database.GetCollection <Screen>("screens");

                this.screenCollection.EnsureIndex(s => s.Name, true);
            }
            catch (Exception e)
            {
                Logger.Error($"Failed to open database. error: {e.Message}");
                throw;
            }
        }
        /// <summary>
        /// CalculateMaxActiveScaleforms is used to specify how many scaleforms can be active at the same time.
        /// The limit of max. active scaleforms is limited by number of *.gfx files in resource's stream directory.
        /// </summary>
        private void CalculateMaxActiveScaleforms()
        {
            var resourcePath = API.GetResourcePath(API.GetCurrentResourceName());

            var streamDirectory = Path.Combine(resourcePath, "stream");

            if (Directory.Exists(streamDirectory))
            {
                var regExp = new Regex(@"hypnonema_texture_renderer\d+\.+gfx");

                this.maxActiveScaleforms = Directory.GetFiles(streamDirectory, "*.gfx")
                                           .Where(path => regExp.IsMatch(path)).ToList().Count;

                Logger.Debug($"maxActiveScaleforms: {this.maxActiveScaleforms}");
            }
            else
            {
                Logger.Error($"Failed to read stream directory. Path: {streamDirectory}");
            }
        }
        private void PopulateDatabaseIfEmpty()
        {
            if (this.screenCollection.Count() >= 1)
            {
                return;
            }

            var exampleScreen = Screen.CreateExampleScreen();

            try
            {
                this.screenCollection.Insert(exampleScreen);
            }
            catch (Exception e)
            {
                Logger.Error($"Failed to create example screen: {e.Message}");
                throw;
            }

            Logger.Verbose($"Created example screen: \"{exampleScreen.Name}\".");
        }