Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Changed: Modernize Project
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Mar 24, 2022
1 parent a9d5dcf commit eef7d67
Show file tree
Hide file tree
Showing 20 changed files with 1,422 additions and 856 deletions.
406 changes: 374 additions & 32 deletions Publish.ps1

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions PublishAll.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

# Set Working Directory
Split-Path $MyInvocation.MyCommand.Path | Push-Location
[Environment]::CurrentDirectory = $PWD

./Publish.ps1 -ProjectPath "SonicHeroes.Utils.OneRedirector/SonicHeroes.Utils.OneRedirector.csproj" `
-PackageName "SonicHeroes.Utils.OneRedirector" `

Pop-Location
31 changes: 15 additions & 16 deletions SonicHeroes.Utils.OneRedirector/Configuration/Config.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
using System.ComponentModel;

namespace SonicHeroes.Utils.OneRedirector.Configuration
namespace SonicHeroes.Utils.OneRedirector.Configuration;

public class Config : Configurable<Config>
{
public class Config : Configurable<Config>
{
/*
User Properties:
- Please put all of your configurable properties here.
- Tip: Consider using the various available attributes https://stackoverflow.com/a/15051390/11106111
By default, configuration saves as "Config.json" in mod folder.
Need more config files/classes? See Configuration.cs
*/
/*
User Properties:
- Please put all of your configurable properties here.
- Tip: Consider using the various available attributes https://stackoverflow.com/a/15051390/11106111
By default, configuration saves as "Config.json" in mod folder.
Need more config files/classes? See Configuration.cs
*/


[DisplayName("Always Build Archives")]
[Description("Rebuilds the .ONE archive every time the game opens the files. This allows you to swap out files while the game is running at the expense or more time taken to load the file(s).")]
public bool AlwaysBuildArchive { get; set; } = false;
}
}
[DisplayName("Always Build Archives")]
[Description("Rebuilds the .ONE archive every time the game opens the files. This allows you to swap out files while the game is running at the expense or more time taken to load the file(s).")]
public bool AlwaysBuildArchive { get; set; } = false;
}
4 changes: 2 additions & 2 deletions SonicHeroes.Utils.OneRedirector/Configuration/Configurable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace SonicHeroes.Utils.OneRedirector.Configuration
{
// Default Serialization Options
// If you wish to change the serializer used, refer to Reloaded.Messaging documentation: https://github.com/Reloaded-Project/Reloaded.Messaging
public static JsonSerializerOptions SerializerOptions { get; } = new JsonSerializerOptions()
public static JsonSerializerOptions SerializerOptions { get; } = new()
{
Converters = { new JsonStringEnumConverter() },
WriteIndented = true
Expand Down Expand Up @@ -90,7 +90,7 @@ public void DisposeEvents()
/// Safety lock for when changed event gets raised twice on file save.
/// </summary>
[Browsable(false)]
private static object _readLock = new object();
private static readonly object _readLock = new();

/// <summary>
/// Loads a specified configuration from the hard disk, or creates a default if it does not exist.
Expand Down
50 changes: 38 additions & 12 deletions SonicHeroes.Utils.OneRedirector/Configuration/Configurator.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
using System.IO;
using System;
using System.IO;
using Reloaded.Mod.Interfaces;

namespace SonicHeroes.Utils.OneRedirector.Configuration
{
public class Configurator : IConfigurator
public class Configurator : IConfiguratorV2
{
/* For latest documentation:
- See the interface! (Go To Definition) or if not available
- Google the Source Code!
*/
private const string ConfigFileName = "Config.json";

/// <summary>
/// Full path to the mod folder.
/// The folder where the modification files are stored.
/// </summary>
public string ModFolder { get; private set; }

/// <summary>
/// Full path to the config folder.
/// </summary>
public string ConfigFolder { get; private set; }

/// <summary>
/// Returns a list of configurations.
/// </summary>
Expand All @@ -26,7 +29,7 @@ private IUpdatableConfigurable[] MakeConfigurations()
_configurations = new IUpdatableConfigurable[]
{
// Add more configurations here if needed.
Configurable<Config>.FromFile(Path.Combine(ModFolder, "Config.json"), "Default Config")
Configurable<Config>.FromFile(Path.Combine(ConfigFolder, ConfigFileName), "ONE Redirector Options")
};

// Add self-updating to configurations.
Expand All @@ -43,9 +46,27 @@ private IUpdatableConfigurable[] MakeConfigurations()
}

public Configurator() { }
public Configurator(string modDirectory) : this()
public Configurator(string configDirectory) : this()
{
ModFolder = modDirectory;
ConfigFolder = configDirectory;
}

/* Configurator V2 */

/// <summary>
/// Migrates from the old config location to the newer config location.
/// </summary>
/// <param name="oldDirectory">Old directory containing the mod configs.</param>
/// <param name="newDirectory">New directory pointing to user config folder.</param>
public void Migrate(string oldDirectory, string newDirectory)
{
TryMoveFile(ConfigFileName);

void TryMoveFile(string fileName)
{
try { File.Move(Path.Combine(oldDirectory, fileName), Path.Combine(newDirectory, fileName), true); }
catch (Exception) { /* Ignored */ }
}
}

/* Configurator */
Expand All @@ -58,9 +79,9 @@ public Configurator(string modDirectory) : this()
/* IConfigurator. */

/// <summary>
/// Sets the mod directory for the Configurator.
/// Sets the config directory for the Configurator.
/// </summary>
public void SetModDirectory(string modDirectory) => ModFolder = modDirectory;
public void SetConfigDirectory(string configDirectory) => ConfigFolder = configDirectory;

/// <summary>
/// Returns a list of user configurations.
Expand All @@ -72,5 +93,10 @@ public Configurator(string modDirectory) : this()
/// If you have your own configuration program/code, run that code here and return true, else return false.
/// </summary>
public bool TryRunCustomConfiguration() => false;

/// <summary>
/// Sets the mod directory for the Configurator.
/// </summary>
public void SetModDirectory(string modDirectory) { ModFolder = modDirectory; }
}
}
17 changes: 8 additions & 9 deletions SonicHeroes.Utils.OneRedirector/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace SonicHeroes.Utils.OneRedirector
namespace SonicHeroes.Utils.OneRedirector;

public static class Constants
{
public static class Constants
{
public const string OneExtension = ".one";
public const string PrsExtension = ".prs";
public const string DeleteExtension = ".del";
public const string RedirectorFolderName = "OneRedirector";
}
}
public const string OneExtension = ".one";
public const string PrsExtension = ".prs";
public const string DeleteExtension = ".del";
public const string RedirectorFolderName = "OneRedirector";
}
48 changes: 42 additions & 6 deletions SonicHeroes.Utils.OneRedirector/ModConfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
{
{
"ModId": "sonicheroes.utils.oneredirector",
"ModName": "Generic Heroes ONE Archive Redirector",
"ModAuthor": "Sewer56",
"ModVersion": "1.0.0",
"ModVersion": "1.0.1",
"ModDescription": "Experimental Windows FileSystem level hook allowing redirection of Sonic Heroes ONE archive contents.",
"ModDll": "SonicHeroes.Utils.OneRedirector.dll",
"ModIcon": "Preview.png",
"ModR2RManagedDll32": "x86/SonicHeroes.Utils.OneRedirector.dll",
"ModR2RManagedDll64": "x64/SonicHeroes.Utils.OneRedirector.dll",
"ModNativeDll32": "",
"ModNativeDll64": "",
"ModDependencies": [ "reloaded.sharedlib.hooks", "reloaded.sharedlib.csharp.prs" ],
"OptionalDependencies": [ "reloaded.universal.redirector" ],
"SupportedAppId": [ "tsonic_win.exe" ]
}
"IsLibrary": false,
"ReleaseMetadataFileName": "Sewer56.Update.ReleaseMetadata.json",
"PluginData": {
"GitHubDependencies": {
"IdToConfigMap": {
"reloaded.sharedlib.hooks": {
"Config": {
"UserName": "Reloaded.SharedLib.Hooks.ReloadedII",
"RepositoryName": "Sewer56",
"UseReleaseTag": true,
"AssetFileName": "reloaded.sharedlib.hooks.zip"
}
}
}
},
"GitHubRelease": {
"UserName": "Sewer56",
"RepositoryName": "Heroes.Utils.OneRedirector.ReloadedII",
"UseReleaseTag": true,
"AssetFileName": "Mod.zip"
},
"NuGet": {
"AllowUpdateFromAnyRepository": false,
"DefaultRepositoryUrls": [
"http://packages.sewer56.moe:5000/v3/index.json"
]
}
},
"IsUniversalMod": false,
"ModDependencies": [
"reloaded.sharedlib.hooks",
"reloaded.sharedlib.csharp.prs"
],
"OptionalDependencies": [
"reloaded.universal.redirector"
],
"SupportedAppId": [
"tsonic_win.exe"
]
}
Loading

0 comments on commit eef7d67

Please sign in to comment.