Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #19 from FelkonEx/FCR/update/2021-09-28
Browse files Browse the repository at this point in the history
2021-09-28 Changes
  • Loading branch information
FelkonEx authored Sep 28, 2021
2 parents 2e61bdf + 0fd68a5 commit c1ef39c
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 58 deletions.
27 changes: 25 additions & 2 deletions FavCat/Adapters/DbPlayerAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,36 @@ public DbPlayerAdapter(StoredPlayer player, StoredFavorite? favorite)
public string Id => myPlayer.PlayerId;
public string Name => myPlayer.Name;
public string ImageUrl => myPlayer.ThumbnailUrl;
public bool IsPrivate => false;
public bool IsPrivate => PlayersModule.GetOnlineApiUser(Id)?.location == "private";
public bool IsInaccessible => false;
public bool SupportsDesktop => false;
public bool SupportsQuest => false;
public StoredPlayer Model => myPlayer;
public StoredFavorite? StoredFavorite => myFavorite;

public Color? CornerIconColor => PlayersModule.IsPlayerOnline(Id) ? new Color(0, 0.75f, 0, 1) : Color.gray;
public Color? CornerIconColor
{
get
{
var onlineUser = PlayersModule.GetOnlineApiUser(Id);
if (onlineUser == null)
return Color.gray;

switch (onlineUser.status)
{
case "join me":
return new Color(0, 0.75f, 0.75f, 1);
case "online":
case "active":
return new Color(0, 0.75f, 0, 1);
case "ask me":
return new Color(1f, 0.5f, 0, 1);
case "busy":
return new Color(0.75f, 0, 0, 1);
default:
return new Color(0.5f, 0.5f, 0, 1);
}
}
}
}
}
9 changes: 8 additions & 1 deletion FavCat/Database/DatabaseImageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ public Task TrimCache(long maxSize)

await TaskUtilities.YieldToMainThread();

MelonDebug.Msg($"Removed {cutoffPoint} images from cache");
MelonLogger.Msg($"Removed {cutoffPoint} images from cache");
}).ContinueWith(task =>
{
if (!task.IsFaulted) return;

MelonLogger.Warning("Image cache trim failed; assuming cache corrupted, clearing collections. Exception: " + task.Exception);
myFileDatabase.GetCollection<LiteFileInfo<string>>("_files").DeleteAll();
myFileDatabase.GetCollection("_chunks").DeleteAll();
});
}

Expand Down
2 changes: 1 addition & 1 deletion FavCat/Database/LocalStoreDatabase.Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void UpdateStoredPlayer(APIUser player)
{
PlayerId = player.id,
Name = player.displayName,
ThumbnailUrl = player.currentAvatarThumbnailImageUrl
ThumbnailUrl = player.profilePicThumbnailImageUrl // already includes override/avatar check
};

myUpdateThreadQueue.Enqueue(() =>
Expand Down
13 changes: 12 additions & 1 deletion FavCat/Database/LocalStoreDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading;
using FavCat.Database.Stored;
using LiteDB;
Expand Down Expand Up @@ -34,7 +35,17 @@ public LocalStoreDatabase(string databasePath, string imageCachePath)

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});
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;
Expand Down
2 changes: 1 addition & 1 deletion FavCat/FavCat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<ClearOutputDirectory>False</ClearOutputDirectory>
<AssemblyVersion>1.1.7</AssemblyVersion>
<AssemblyVersion>1.1.8.1</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.9" />
Expand Down
17 changes: 8 additions & 9 deletions FavCat/FavCatMod.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Reflection;
Expand All @@ -20,7 +19,7 @@
using ImageDownloaderClosure = ImageDownloader.__c__DisplayClass11_0;
using Object = UnityEngine.Object;

[assembly:MelonInfo(typeof(FavCatMod), "FavCatRestored", "1.1.7", "Felkon (Original By Knah)", "https://github.com/FelkonEx/FavCat-Restored")]
[assembly:MelonInfo(typeof(FavCatMod), "FavCatRestored", "1.1.8.1", "Felkon (Original By Knah)", "https://github.com/FelkonEx/FavCat-Restored")]
[assembly:MelonGame("VRChat", "VRChat")]

namespace FavCat
Expand All @@ -31,9 +30,9 @@ internal partial class FavCatMod : MelonMod
internal static FavCatMod Instance;

internal AvatarModule? AvatarModule;
private WorldsModule? myWorldsModule;
internal PlayersModule? playerModule;

internal WorldsModule? WorldsModule;
internal PlayersModule? PlayerModule;
internal static PageUserInfo PageUserInfo;

public override void OnApplicationStart()
Expand Down Expand Up @@ -104,7 +103,7 @@ public void OnUiManagerInit()
try
{
if (FavCatSettings.EnableWorldFavs.Value)
myWorldsModule = new WorldsModule();
WorldsModule = new WorldsModule();
}
catch (Exception ex)
{
Expand All @@ -114,7 +113,7 @@ public void OnUiManagerInit()
try
{
if (FavCatSettings.EnablePlayerFavs.Value)
playerModule = new PlayersModule();
PlayerModule = new PlayersModule();
}
catch (Exception ex)
{
Expand All @@ -129,8 +128,8 @@ public void OnUiManagerInit()
public override void OnUpdate()
{
AvatarModule?.Update();
myWorldsModule?.Update();
playerModule?.Update();
WorldsModule?.Update();
PlayerModule?.Update();
GlobalImageCache.OnUpdate();
}
}
Expand Down
11 changes: 7 additions & 4 deletions FavCat/FavCatSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static class FavCatSettings
internal static MelonPreferences_Entry<bool> MakeClickSounds;
internal static MelonPreferences_Entry<string> AvatarSearchMode;
internal static MelonPreferences_Entry<bool> SortPlayersByOnline;

internal static MelonPreferences_Entry<bool> SortPlayersByJoinable;

internal static void RegisterSettings()
{
Expand All @@ -44,10 +46,11 @@ internal static void RegisterSettings()
MakeClickSounds = category.CreateEntry("MakeClickSounds", true, "Click sounds");
AvatarSearchMode = category.CreateEntry(avatarSearchModeName, "select", "Avatar search result action");
SortPlayersByOnline = category.CreateEntry(nameof(SortPlayersByOnline), true, "Show offline players at the end of the list");


ExpansionKitApi.RegisterSettingAsStringEnum(SettingsCategory, "ImageCachingMode", new[] { ("full", "Full local image cache (fastest, safest)"), ("fast", "Fast, use more RAM"), ("builtin", "Preserve RAM, more API requests") });
ExpansionKitApi.RegisterSettingAsStringEnum(SettingsCategory, avatarSearchModeName, new[] { ("select", "Select avatar"), ("author", "Show avatar author (safer)") });

SortPlayersByJoinable = category.CreateEntry(nameof(SortPlayersByJoinable), true, "Show players in private instances at the end of the list");

ExpansionKitApi.RegisterSettingAsStringEnum(SettingsCategory, "ImageCachingMode", new []{("full", "Full local image cache (fastest, safest)"), ("fast", "Fast, use more RAM"), ("builtin", "Preserve RAM, more API requests")});
ExpansionKitApi.RegisterSettingAsStringEnum(SettingsCategory, avatarSearchModeName, new []{("select", "Select avatar"), ("author", "Show avatar author (safer)")});
}

public static bool UseLocalImageCache => ImageCacheMode.Value == "full";
Expand Down
Loading

0 comments on commit c1ef39c

Please sign in to comment.