From 71fbaa03c5d61c07221270c26445c8deb37b2276 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Sun, 13 Jul 2025 19:25:04 +0200 Subject: [PATCH] fix android path --- Main.cs | 4 ++-- Modules/BanManager.cs | 6 +++--- Modules/CustomSounds.cs | 16 ++++++++++++---- Modules/ModUpdater.cs | 8 ++++++-- Modules/SpamManager.cs | 2 +- Modules/TemplateManager.cs | 2 +- Modules/Translator.cs | 2 +- Modules/Utils.cs | 11 ++++++++++- 8 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Main.cs b/Main.cs index fb212979a..d1e6c2293 100644 --- a/Main.cs +++ b/Main.cs @@ -845,8 +845,8 @@ public class Main : BasePlugin string serialized = JsonSerializer.Serialize(RoleColors, new JsonSerializerOptions { WriteIndented = true }); File.WriteAllText($"{DataPath}/OriginalRoleColors.json", serialized); - if (!Directory.Exists("EHR_DATA")) - Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{DataPath}/EHR_DATA")) + Directory.CreateDirectory($"{DataPath}/EHR_DATA"); var path = $"{DataPath}/EHR_DATA/RoleColors.json"; diff --git a/Modules/BanManager.cs b/Modules/BanManager.cs index 47bd850f7..493deec0b 100644 --- a/Modules/BanManager.cs +++ b/Modules/BanManager.cs @@ -26,7 +26,7 @@ public static class BanManager { try { - Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{Main.DataPath}/EHR_DATA")) Directory.CreateDirectory($"{Main.DataPath}/EHR_DATA"); if (!File.Exists(BanListPath)) { @@ -115,7 +115,7 @@ public static class BanManager try { - Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{Main.DataPath}/EHR_DATA")) Directory.CreateDirectory($"{Main.DataPath}/EHR_DATA"); if (!File.Exists(DenyNameListPath)) File.Create(DenyNameListPath).Close(); using StreamReader sr = new(DenyNameListPath); @@ -216,7 +216,7 @@ public static class BanManager try { - Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{Main.DataPath}/EHR_DATA")) Directory.CreateDirectory($"{Main.DataPath}/EHR_DATA"); if (!File.Exists(BanListPath)) File.Create(BanListPath).Close(); using StreamReader sr = new(BanListPath); diff --git a/Modules/CustomSounds.cs b/Modules/CustomSounds.cs index d7cd334cc..6ce81c6a6 100644 --- a/Modules/CustomSounds.cs +++ b/Modules/CustomSounds.cs @@ -8,10 +8,13 @@ namespace EHR.Modules; public static class CustomSoundsManager { - private static readonly string SOUNDS_PATH = @$"{Environment.CurrentDirectory.Replace(@"\", "/")}/BepInEx/resources/"; +#if !ANDROID + private static readonly string SoundsPath = $"{Environment.CurrentDirectory.Replace(@"\", "/")}/BepInEx/resources/"; +#endif public static void RPCPlayCustomSound(this PlayerControl pc, string sound, bool force = false) { +#if !ANDROID if (!force) { if (!AmongUsClient.Instance.AmHost || !pc.IsModdedClient()) @@ -27,16 +30,19 @@ public static class CustomSoundsManager MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.Reliable, pc.OwnerId); writer.Write(sound); AmongUsClient.Instance.FinishRpcImmediately(writer); +#endif } public static void RPCPlayCustomSoundAll(string sound) { +#if !ANDROID if (!AmongUsClient.Instance.AmHost) return; MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlayCustomSound, SendOption.Reliable); writer.Write(sound); AmongUsClient.Instance.FinishRpcImmediately(writer); Play(sound); +#endif } public static void ReceiveRPC(MessageReader reader) @@ -46,12 +52,13 @@ public static class CustomSoundsManager public static void Play(string sound) { +#if !ANDROID if (!Constants.ShouldPlaySfx() || !Main.EnableCustomSoundEffect.Value) return; - string path = SOUNDS_PATH + sound + ".wav"; - if (!Directory.Exists(SOUNDS_PATH)) Directory.CreateDirectory(SOUNDS_PATH); + string path = SoundsPath + sound + ".wav"; + if (!Directory.Exists(SoundsPath)) Directory.CreateDirectory(SoundsPath); - DirectoryInfo folder = new(SOUNDS_PATH); + DirectoryInfo folder = new(SoundsPath); if ((folder.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) folder.Attributes = FileAttributes.Hidden; if (!File.Exists(path)) @@ -71,6 +78,7 @@ public static class CustomSoundsManager StartPlay(path); Logger.Msg($"Playing sound: {sound}", "CustomSounds"); +#endif } [DllImport("winmm.dll", CharSet = CharSet.Unicode)] diff --git a/Modules/ModUpdater.cs b/Modules/ModUpdater.cs index 7518c4619..9cf302eda 100644 --- a/Modules/ModUpdater.cs +++ b/Modules/ModUpdater.cs @@ -32,12 +32,15 @@ public static class ModUpdater [HarmonyPriority(2)] public static void Start_Prefix() { +#if !ANDROID NewVersionCheck(); DeleteOldFiles(); +#endif InfoPopup = Object.Instantiate(TwitchManager.Instance.TwitchPopup); InfoPopup.name = "InfoPopup"; InfoPopup.TextAreaTMP.GetComponent().sizeDelta = new(2.5f, 2f); +#if !ANDROID if (!IsChecked) { bool done = CheckReleaseFromGithub(Main.BetaBuildUrl.Value != "").GetAwaiter().GetResult(); @@ -47,6 +50,7 @@ public static class ModUpdater Logger.Info("downloadUrl: " + DownloadUrl, "CheckRelease"); Logger.Info("latestVersionl: " + LatestVersion, "CheckRelease"); } +#endif } public static string Get(string url) @@ -152,9 +156,9 @@ public static class ModUpdater { try { - if (Directory.Exists("TOH_DATA") && File.Exists($"{Main.DataPath}/EHR_DATA/BanWords.txt")) + if (Directory.Exists($"{Main.DataPath}/TOH_DATA") && File.Exists($"{Main.DataPath}/EHR_DATA/BanWords.txt")) { - DirectoryInfo di = new("TOH_DATA"); + DirectoryInfo di = new($"{Main.DataPath}/TOH_DATA"); di.Delete(true); Logger.Warn("Directory deleted: TOH_DATA", "NewVersionCheck"); } diff --git a/Modules/SpamManager.cs b/Modules/SpamManager.cs index bcf1f4dfd..81668b42d 100644 --- a/Modules/SpamManager.cs +++ b/Modules/SpamManager.cs @@ -27,7 +27,7 @@ public static class SpamManager { try { - if (!Directory.Exists("EHR_DATA")) Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{Main.DataPath}/EHR_DATA")) Directory.CreateDirectory($"{Main.DataPath}/EHR_DATA"); if (File.Exists($"{Main.DataPath}/BanWords.txt")) File.Move($"{Main.DataPath}/BanWords.txt", BannedWordsFilePath); diff --git a/Modules/TemplateManager.cs b/Modules/TemplateManager.cs index e57128b0d..ce46c6da0 100644 --- a/Modules/TemplateManager.cs +++ b/Modules/TemplateManager.cs @@ -52,7 +52,7 @@ public static class TemplateManager { try { - if (!Directory.Exists("EHR_DATA")) Directory.CreateDirectory("EHR_DATA"); + if (!Directory.Exists($"{Main.DataPath}/EHR_DATA")) Directory.CreateDirectory($"{Main.DataPath}/EHR_DATA"); if (File.Exists($"{Main.DataPath}/template.txt")) File.Move($"{Main.DataPath}/template.txt", TemplateFilePath); diff --git a/Modules/Translator.cs b/Modules/Translator.cs index a4cd16d8e..c3942013a 100644 --- a/Modules/Translator.cs +++ b/Modules/Translator.cs @@ -81,7 +81,7 @@ public static class Translator catch (Exception ex) { Logger.Error($"Error: {ex}", "Translator"); } // Loading custom translation files - if (!Directory.Exists(LanguageFolderName)) Directory.CreateDirectory(LanguageFolderName); + if (!Directory.Exists($"{Main.DataPath}/{LanguageFolderName}")) Directory.CreateDirectory($"{Main.DataPath}/{LanguageFolderName}"); // Creating a translation template CreateTemplateFile(); diff --git a/Modules/Utils.cs b/Modules/Utils.cs index d7f51159c..b5a14863b 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -3550,11 +3550,20 @@ public static class Utils if (finish) CustomLogger.Instance.Finish(); var t = DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss"); +#if ANDROID + var f = $"{Main.DataPath}/EHR_Logs/{t}"; +#else var f = $"{Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}/EHR_Logs/{t}"; +#endif if (!Directory.Exists(f)) Directory.CreateDirectory(f); var filename = $"{f}/EHR-v{Main.PluginVersion}-LOG"; - FileInfo[] files = [new($"{Environment.CurrentDirectory}/BepInEx/LogOutput.log"), new($"{Environment.CurrentDirectory}/BepInEx/log.html")]; +#if ANDROID + var directory = Main.DataPath; +#else + string directory = Environment.CurrentDirectory; +#endif + FileInfo[] files = [new($"{directory}/BepInEx/LogOutput.log"), new($"{directory}/BepInEx/log.html")]; files.Do(x => x.CopyTo($"{filename}{x.Extension}")); if (!open) return;