Decompiled source of BoomboxStations v1.0.0

BoomboxStations.dll

Decompiled 2 years ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BoomboxStations")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A selection of loops, songs and audio clips to use with Steven's Custom Boombox Music mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoomboxStations")]
[assembly: AssemblyTitle("BoomboxStations")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BoomboxStations
{
	[BepInPlugin("BoomboxStations", "BoomboxStations", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private string CustomSongsPluginPath => Path.Combine(Paths.PluginPath, "LeedleBumpany-BoomboxStations", "Custom Songs", "Boombox Music");

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

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

		private void CopyMusicFiles()
		{
			if (!Directory.Exists(TargetPath))
			{
				Directory.CreateDirectory(TargetPath);
			}
			foreach (string item in Directory.GetFiles(CustomSongsPluginPath, "*.mp3").Concat(Directory.GetFiles(CustomSongsPluginPath, "*.wav")))
			{
				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."));
				}
			}
		}

		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;
					for (int i = 0; i < array.Length; i++)
					{
						File.Delete(array[i]);
					}
					((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);
			for (int i = 0; i < directories.Length; i++)
			{
				string text = Path.Combine(directories[i], "Custom Songs");
				if (!Directory.Exists(text))
				{
					continue;
				}
				foreach (string item in Directory.GetFiles(text, "*.mp3").Concat(Directory.GetFiles(text, "*.wav")))
				{
					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."));
					}
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BoomboxStations";

		public const string PLUGIN_NAME = "BoomboxStations";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}