public LocalStoreDatabase(string databasePath, string imageCachePath)
        {
            var connectionType = FavCatSettings.ConnectionType;

            myStoreDatabase = new LiteDatabase(new ConnectionString {
                Filename = $"{databasePath}/favcat-store.db", Connection = connectionType
            });
            myFavDatabase = new LiteDatabase(new ConnectionString {
                Filename = $"{databasePath}/favcat-favs.db", Connection = connectionType
            });
            myImageDatabase = new LiteDatabase(new ConnectionString {
                Filename = $"{imageCachePath}/favcat-images.db", Connection = connectionType
            });

            myStoreDatabase.Mapper.EmptyStringToNull = false;
            myFavDatabase.Mapper.EmptyStringToNull   = false;
            myImageDatabase.Mapper.EmptyStringToNull = false;

            ImageHandler = new DatabaseImageHandler(myImageDatabase);

            myStoredAvatars = myStoreDatabase.GetCollection <StoredAvatar>("avatars");
            myStoredPlayers = myStoreDatabase.GetCollection <StoredPlayer>("players");
            myStoredWorlds  = myStoreDatabase.GetCollection <StoredWorld>("worlds");

            myStoredOrders = myFavDatabase.GetCollection <StoredCategoryOrder>("category_orders");

            AvatarFavorites = new DatabaseFavoriteHandler <StoredAvatar>(myFavDatabase, DatabaseEntity.Avatar, myStoredAvatars, myStoredOrders);
            WorldFavorites  = new DatabaseFavoriteHandler <StoredWorld>(myFavDatabase, DatabaseEntity.World, myStoredWorlds, myStoredOrders);
            PlayerFavorites = new DatabaseFavoriteHandler <StoredPlayer>(myFavDatabase, DatabaseEntity.Player, myStoredPlayers, myStoredOrders);

            myUpdateThread = new Thread(UpdateThreadMain);
            myUpdateThread.Start();
        }
Esempio n. 2
0
        public LocalStoreDatabase(string databasePath, string imageCachePath)
        {
            var connectionType = ConnectionType.Direct;

            myStoreDatabase = new LiteDatabase(new ConnectionString {
                Filename = $"{databasePath}/favcat-store.db", Connection = connectionType
            });
            myFavDatabase = new LiteDatabase(new ConnectionString {
                Filename = $"{databasePath}/favcat-favs.db", Connection = connectionType
            });
            var imageDbPath = $"{imageCachePath}/favcat-images.db";

            try
            {
                myImageDatabase = new LiteDatabase(new ConnectionString {
                    Filename = imageDbPath, Connection = connectionType
                });
            }
            catch (Exception ex)
            {
                MelonLogger.Warning("Exception when creating image cache; assuming it's corrupted and deleting it. Exception: " + ex);
                File.Delete(imageDbPath);
                myImageDatabase = new LiteDatabase(new ConnectionString {
                    Filename = imageDbPath, Connection = connectionType
                });
            }

            myStoreDatabase.Mapper.EmptyStringToNull = false;
            myFavDatabase.Mapper.EmptyStringToNull   = false;
            myImageDatabase.Mapper.EmptyStringToNull = false;

            ImageHandler = new DatabaseImageHandler(myImageDatabase);

            myStoredAvatars = myStoreDatabase.GetCollection <StoredAvatar>("avatars");
            myStoredPlayers = myStoreDatabase.GetCollection <StoredPlayer>("players");
            myStoredWorlds  = myStoreDatabase.GetCollection <StoredWorld>("worlds");

            myStoredOrders = myFavDatabase.GetCollection <StoredCategoryOrder>("category_orders");

            AvatarFavorites = new DatabaseFavoriteHandler <StoredAvatar>(myFavDatabase, DatabaseEntity.Avatar, myStoredAvatars, myStoredOrders);
            WorldFavorites  = new DatabaseFavoriteHandler <StoredWorld>(myFavDatabase, DatabaseEntity.World, myStoredWorlds, myStoredOrders);
            PlayerFavorites = new DatabaseFavoriteHandler <StoredPlayer>(myFavDatabase, DatabaseEntity.Player, myStoredPlayers, myStoredOrders);

            myUpdateThread = new Thread(UpdateThreadMain);
            myUpdateThread.Start();
        }