Files
VRCX/Dotnet/AppApi/Common/LocalPlayerModerations.cs
Natsumi 938fff63d0 Electron support for Linux (#1074)
* init

* SQLite changes

* Move html folder, edit build scripts

* AppApi interface

* Build flags

* AppApi inheritance

* Finishing touches

* Merge upstream changes

* Test CI

* Fix class inits

* Rename AppApi

* Merge upstream changes

* Fix SQLiteLegacy on Linux, Add Linux interop, build tools

* Linux specific localisation strings

* Make it run

* Bring back most of Linux functionality

* Clean up

* Fix TTS voices

* Fix UI var

* Changes

* Electron minimise to tray

* Remove separate toggle for WlxOverlay

* Fixes

* Touchups

* Move csproj

* Window zoom, Desktop Notifications, VR check on Linux

* Fix desktop notifications, VR check spam

* Fix building on Linux

* Clean up

* Fix WebApi headers

* Rewrite VRCX updater

* Clean up

* Linux updater

* Add Linux to build action

* init

* SQLite changes

* Move html folder, edit build scripts

* AppApi interface

* Build flags

* AppApi inheritance

* Finishing touches

* Merge upstream changes

* Test CI

* Fix class inits

* Rename AppApi

* Merge upstream changes

* Fix SQLiteLegacy on Linux, Add Linux interop, build tools

* Linux specific localisation strings

* Make it run

* Bring back most of Linux functionality

* Clean up

* Fix TTS voices

* Changes

* Electron minimise to tray

* Remove separate toggle for WlxOverlay

* Fixes

* Touchups

* Move csproj

* Window zoom, Desktop Notifications, VR check on Linux

* Fix desktop notifications, VR check spam

* Fix building on Linux

* Clean up

* Fix WebApi headers

* Rewrite VRCX updater

* Clean up

* Linux updater

* Add Linux to build action

* Test updater

* Rebase and handle merge conflicts

* Fix Linux updater

* Fix Linux app restart

* Fix friend order

* Handle AppImageInstaller, show an install message on Linux

* Updates to the AppImage installer

* Fix Linux updater, fix set version, check for .NET, copy wine prefix

* Handle random errors

* Rotate tall prints

* try fix Linux restart bug

* Final

---------

Co-authored-by: rs189 <35667100+rs189@users.noreply.github.com>
2025-01-11 13:09:44 +13:00

92 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace VRCX
{
public partial class AppApi
{
public Dictionary<string, short> GetVRChatModerations(string currentUserId)
{
// 004 = hideAvatar
// 005 = showAvatar
var filePath = Path.Combine(GetVRChatAppDataLocation(), @$"LocalPlayerModerations\{currentUserId}-show-hide-user.vrcset");
if (!File.Exists(filePath))
return null;
var output = new Dictionary<string, short>();
using var reader = new StreamReader(filePath);
string line;
while ((line = reader.ReadLine()) != null)
{
var index = line.IndexOf(' ');
if (index <= 0)
continue;
var userId = line.Substring(0, index);
var type = short.Parse(line.Substring(line.Length - 3));
output.Add(userId, type);
}
return output;
}
public short GetVRChatUserModeration(string currentUserId, string userId)
{
var filePath = Path.Combine(GetVRChatAppDataLocation(), @$"LocalPlayerModerations\{currentUserId}-show-hide-user.vrcset");
if (!File.Exists(filePath))
return 0;
using var reader = new StreamReader(filePath);
string line;
while ((line = reader.ReadLine()) != null)
{
var index = line.IndexOf(' ');
if (index <= 0)
continue;
if (userId == line.Substring(0, index))
{
return short.Parse(line.Substring(line.Length - 3));
}
}
return 0;
}
public bool SetVRChatUserModeration(string currentUserId, string userId, int type)
{
var filePath = Path.Combine(GetVRChatAppDataLocation(), @$"LocalPlayerModerations\{currentUserId}-show-hide-user.vrcset");
if (!File.Exists(filePath))
return false;
var lines = File.ReadAllLines(filePath).ToList();
var index = lines.FindIndex(x => x.StartsWith(userId));
if (index >= 0)
lines.RemoveAt(index);
if (type != 0)
{
var sb = new StringBuilder(userId);
while (sb.Length < 64)
sb.Append(' ');
sb.Append(type.ToString("000"));
lines.Add(sb.ToString());
}
try
{
File.WriteAllLines(filePath, lines);
}
catch (Exception)
{
return false;
}
return true;
}
}
}