Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

What if we used 4 spaces, though? #66

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ root = true

[*]
indent_style = space
indent_size = 2
indent_size = 4
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8
16 changes: 1 addition & 15 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,7 @@ If you want your PR to be approved and merged quickly, please read the following

### Code Style

If your PR does not follow the project's code style it **will not be approved**. I expect contributors to be capable of fixing code style issues on their own.

Code style should match Microsoft convention. If you aren't sure, run Analyze > Code Cleanup on the file using Visual Studio.

#### Whitespace

- *.cs files
- Lines MUST be indented using four spaces. Tabs are not acceptable.
- MUST use unix-style (LF) line endings. CR or CRLF are not acceptable.
- *.sln files: use the Visual Studio defaults
- indent using tabs
- CRLF line endings
- *.csproj files: use the Visual Studio defaults
- indent using two spaces
- CRLF line endings
If your PR does not follow the project's code style it **will not be approved**. Code style should match our [editor config](../.editorconfig). If you aren't sure, use your IDE's formatter (Analyze > Code Cleanup in Visual Studio).

### New Features

Expand Down
50 changes: 25 additions & 25 deletions NeosModLoader.sln
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeosModLoader", "NeosModLoader\NeosModLoader.csproj", "{D4627C7F-8091-477A-ABDC-F1465D94D8D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {757072E6-E985-4EC2-AB38-C4D1588F6A15}
EndGlobalSection
EndGlobal

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31410.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NeosModLoader", "NeosModLoader\NeosModLoader.csproj", "{D4627C7F-8091-477A-ABDC-F1465D94D8D9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4627C7F-8091-477A-ABDC-F1465D94D8D9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {757072E6-E985-4EC2-AB38-C4D1588F6A15}
EndGlobalSection
EndGlobal
16 changes: 8 additions & 8 deletions NeosModLoader/AssemblyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace NeosModLoader
{
internal class AssemblyFile
{
internal string File { get; }
internal Assembly Assembly { get; set; }
internal AssemblyFile(string file, Assembly assembly)
internal class AssemblyFile
{
File = file;
Assembly = assembly;
internal string File { get; }
internal Assembly Assembly { get; set; }
internal AssemblyFile(string file, Assembly assembly)
{
File = file;
Assembly = assembly;
}
}
}
}
142 changes: 71 additions & 71 deletions NeosModLoader/AssemblyLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,87 @@

namespace NeosModLoader
{
internal static class AssemblyLoader
{
private static string[]? GetAssemblyPathsFromDir(string dirName)
internal static class AssemblyLoader
{
string assembliesDirectory = Path.Combine(Directory.GetCurrentDirectory(), dirName);
private static string[]? GetAssemblyPathsFromDir(string dirName)
{
string assembliesDirectory = Path.Combine(Directory.GetCurrentDirectory(), dirName);

Logger.MsgInternal($"loading assemblies from {dirName}");
Logger.MsgInternal($"loading assemblies from {dirName}");

string[]? assembliesToLoad = null;
try
{
assembliesToLoad = Directory.GetFiles(assembliesDirectory, "*.dll", SearchOption.AllDirectories);
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
}
catch (Exception e)
{
if (e is DirectoryNotFoundException)
{
Logger.MsgInternal($"{dirName} directory not found, creating it now.");
try
{
Directory.CreateDirectory(assembliesDirectory);
}
catch (Exception e2)
{
Logger.ErrorInternal($"Error creating ${dirName} directory:\n{e2}");
}
string[]? assembliesToLoad = null;
try
{
assembliesToLoad = Directory.GetFiles(assembliesDirectory, "*.dll", SearchOption.AllDirectories);
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
}
catch (Exception e)
{
if (e is DirectoryNotFoundException)
{
Logger.MsgInternal($"{dirName} directory not found, creating it now.");
try
{
Directory.CreateDirectory(assembliesDirectory);
}
catch (Exception e2)
{
Logger.ErrorInternal($"Error creating ${dirName} directory:\n{e2}");
}
}
else
{
Logger.ErrorInternal($"Error enumerating ${dirName} directory:\n{e}");
}
}
return assembliesToLoad;
}
else

private static Assembly? LoadAssembly(string filepath)
{
Logger.ErrorInternal($"Error enumerating ${dirName} directory:\n{e}");
string filename = Path.GetFileName(filepath);
SplashChanger.SetCustom($"Loading file: {filename}");
Assembly assembly;
try
{
Logger.MsgInternal($"load assembly {filename} with sha256hash: {Util.GenerateSHA256(filepath)}");
assembly = Assembly.LoadFile(filepath);
}
catch (Exception e)
{
Logger.ErrorInternal($"error loading assembly from {filepath}: {e}");
return null;
}
if (assembly == null)
{
Logger.ErrorInternal($"unexpected null loading assembly from {filepath}");
return null;
}
return assembly;
}
}
return assembliesToLoad;
}

private static Assembly? LoadAssembly(string filepath)
{
string filename = Path.GetFileName(filepath);
SplashChanger.SetCustom($"Loading file: {filename}");
Assembly assembly;
try
{
Logger.MsgInternal($"load assembly {filename} with sha256hash: {Util.GenerateSHA256(filepath)}");
assembly = Assembly.LoadFile(filepath);
}
catch (Exception e)
{
Logger.ErrorInternal($"error loading assembly from {filepath}: {e}");
return null;
}
if (assembly == null)
{
Logger.ErrorInternal($"unexpected null loading assembly from {filepath}");
return null;
}
return assembly;
}

internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
{
List<AssemblyFile> assemblyFiles = new();
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths)
{
foreach (string assemblyFilepath in assemblyPaths)
internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
{
try
{
if (LoadAssembly(assemblyFilepath) is Assembly assembly)
List<AssemblyFile> assemblyFiles = new();
if (GetAssemblyPathsFromDir(dirName) is string[] assemblyPaths)
{
assemblyFiles.Add(new AssemblyFile(assemblyFilepath, assembly));
foreach (string assemblyFilepath in assemblyPaths)
{
try
{
if (LoadAssembly(assemblyFilepath) is Assembly assembly)
{
assemblyFiles.Add(new AssemblyFile(assemblyFilepath, assembly));
}
}
catch (Exception e)
{
Logger.ErrorInternal($"Unexpected exception loading assembly from {assemblyFilepath}:\n{e}");
}
}
}
}
catch (Exception e)
{
Logger.ErrorInternal($"Unexpected exception loading assembly from {assemblyFilepath}:\n{e}");
}
}
}

return assemblyFiles.ToArray();
return assemblyFiles.ToArray();
}
}
}
}
8 changes: 4 additions & 4 deletions NeosModLoader/AutoRegisterConfigKeyAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace NeosModLoader
{
[AttributeUsage(AttributeTargets.Field)]
public class AutoRegisterConfigKeyAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Field)]
public class AutoRegisterConfigKeyAttribute : Attribute
{
}
}
40 changes: 20 additions & 20 deletions NeosModLoader/ConfigurationChangedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
namespace NeosModLoader
{
public class ConfigurationChangedEvent
{
/// <summary>
/// The configuration the change occurred in
/// </summary>
public ModConfiguration Config { get; private set; }
public class ConfigurationChangedEvent
{
/// <summary>
/// The configuration the change occurred in
/// </summary>
public ModConfiguration Config { get; private set; }

/// <summary>
/// The specific key who's value changed
/// </summary>
public ModConfigurationKey Key { get; private set; }
/// <summary>
/// The specific key who's value changed
/// </summary>
public ModConfigurationKey Key { get; private set; }

/// <summary>
/// A custom label that may be set by whoever changed the configuration
/// </summary>
public string? Label { get; private set; }
/// <summary>
/// A custom label that may be set by whoever changed the configuration
/// </summary>
public string? Label { get; private set; }

internal ConfigurationChangedEvent(ModConfiguration config, ModConfigurationKey key, string? label)
{
Config = config;
Key = key;
Label = label;
internal ConfigurationChangedEvent(ModConfiguration config, ModConfigurationKey key, string? label)
{
Config = config;
Key = key;
Label = label;
}
}
}
}
32 changes: 16 additions & 16 deletions NeosModLoader/DebugInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace NeosModLoader
{
internal class DebugInfo
{
internal static void Log()
internal class DebugInfo
{
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(ModLoaderConfiguration.Get().Debug ? " Debug logs will be shown." : "")}");
Logger.MsgInternal($"CLR v{Environment.Version}");
Logger.DebugFuncInternal(() => $"Using .NET Framework: \"{AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}\"");
Logger.DebugFuncInternal(() => $"Using .NET Core: \"{Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}\"");
Logger.MsgInternal($"Using Harmony v{GetAssemblyVersion(typeof(HarmonyLib.Harmony))}");
Logger.MsgInternal($"Using BaseX v{GetAssemblyVersion(typeof(BaseX.floatQ))}");
Logger.MsgInternal($"Using FrooxEngine v{GetAssemblyVersion(typeof(FrooxEngine.IComponent))}");
Logger.MsgInternal($"Using Json.NET v{GetAssemblyVersion(typeof(Newtonsoft.Json.JsonSerializer))}");
}
internal static void Log()
{
Logger.MsgInternal($"NeosModLoader v{ModLoader.VERSION} starting up!{(ModLoaderConfiguration.Get().Debug ? " Debug logs will be shown." : "")}");
Logger.MsgInternal($"CLR v{Environment.Version}");
Logger.DebugFuncInternal(() => $"Using .NET Framework: \"{AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName}\"");
Logger.DebugFuncInternal(() => $"Using .NET Core: \"{Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName}\"");
Logger.MsgInternal($"Using Harmony v{GetAssemblyVersion(typeof(HarmonyLib.Harmony))}");
Logger.MsgInternal($"Using BaseX v{GetAssemblyVersion(typeof(BaseX.floatQ))}");
Logger.MsgInternal($"Using FrooxEngine v{GetAssemblyVersion(typeof(FrooxEngine.IComponent))}");
Logger.MsgInternal($"Using Json.NET v{GetAssemblyVersion(typeof(Newtonsoft.Json.JsonSerializer))}");
}

private static string? GetAssemblyVersion(Type typeFromAssembly)
{
return typeFromAssembly.Assembly.GetName()?.Version?.ToString();
private static string? GetAssemblyVersion(Type typeFromAssembly)
{
return typeFromAssembly.Assembly.GetName()?.Version?.ToString();
}
}
}
}
Loading