Decompiled source of CustomBoomboxFixFix v2.0.0

CustomBoomboxFixFix.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("LimeMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LimeMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3543362c-37b7-4d26-ae93-d93ec6946a41")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomBoomboxFixFix;

[BepInPlugin("LimeSkillZ.CustomBoomboxFixFix", "CustomBoomboxFixFix", "1.1.0")]
public class BoomboxFix : BaseUnityPlugin
{
	private const string modGUID = "LimeSkillZ.CustomBoomboxFixFix";

	private const string modName = "CustomBoomboxFixFix";

	private const string modVersion = "1.1.0";

	private string CustomSongsPluginPath => Path.Combine(Paths.PluginPath, "Custom Songs");

	private string TargetPath => Path.Combine(Paths.BepInExRootPath, "Custom Songs", "Boombox Music");

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CustomBoomboxFixFix is loaded!");
		CreatePluginCustomSongsFolder();
		CreateBoomboxMusicFolder();
		DeleteAllFilesInTargetPath();
		SearchAndCopyCustomSongs();
		CopyMusicFiles();
	}

	private void CreatePluginCustomSongsFolder()
	{
		if (!Directory.Exists(CustomSongsPluginPath))
		{
			Directory.CreateDirectory(CustomSongsPluginPath);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Created 'Custom Songs' folder in plugin directory.");
		}
	}

	private void CreateBoomboxMusicFolder()
	{
		if (!Directory.Exists(TargetPath))
		{
			Directory.CreateDirectory(TargetPath);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Created 'Boombox Music' folder in 'BepInEx/Custom Songs' directory.");
		}
	}

	private void DeleteAllFilesInTargetPath()
	{
		try
		{
			if (Directory.Exists(TargetPath))
			{
				string[] files = Directory.GetFiles(TargetPath);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Deleting files in '" + TargetPath + "'..."));
				string[] array = files;
				string[] array2 = array;
				foreach (string path in array2)
				{
					File.Delete(path);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Deleted files in '" + TargetPath + "'"));
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Target path '" + TargetPath + "' does not exist."));
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("An error occurred while trying to delete files: " + ex.Message));
		}
	}

	private void SearchAndCopyCustomSongs()
	{
		string[] directories = Directory.GetDirectories(Paths.PluginPath);
		string[] array = directories;
		string[] array2 = array;
		foreach (string path in array2)
		{
			string text = Path.Combine(path, "Custom Songs");
			if (!Directory.Exists(text))
			{
				continue;
			}
			IEnumerable<string> enumerable = Directory.GetFiles(text, "*.mp3").Concat(Directory.GetFiles(text, "*.wav")).Concat(Directory.GetFiles(text, "*.ogg"));
			foreach (string item in enumerable)
			{
				string fileName = Path.GetFileName(item);
				string text2 = Path.Combine(TargetPath, fileName);
				if (!File.Exists(text2))
				{
					File.Copy(item, text2);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Copied " + fileName + " from " + text + " to Boombox Music folder."));
				}
			}
		}
	}

	private void CopyMusicFiles()
	{
		IEnumerable<string> enumerable = Directory.GetFiles(CustomSongsPluginPath, "*.mp3").Concat(Directory.GetFiles(CustomSongsPluginPath, "*.ogg")).Concat(Directory.GetFiles(CustomSongsPluginPath, "*.wav"));
		foreach (string item in enumerable)
		{
			string fileName = Path.GetFileName(item);
			string text = Path.Combine(TargetPath, fileName);
			if (!File.Exists(text))
			{
				File.Copy(item, text);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Copied " + fileName + " to Boombox Music folder."));
			}
		}
	}
}