Skip to content

Commit

Permalink
Added: API to Temporarily Disable Redirector
Browse files Browse the repository at this point in the history
  • Loading branch information
Sewer56 committed Sep 6, 2021
1 parent 9052b21 commit c6a09db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

namespace Reloaded.Universal.Redirector.Interfaces
{
public interface IRedirectorControllerV4
{
/// <summary>
/// Temporarily disables the redirector.
/// </summary>
void Disable();

/// <summary>
/// Re-enables the redirector after a temporary disable.
/// </summary>
void Enable();
}

public interface IRedirectorControllerV3
{
/// <summary>
Expand Down Expand Up @@ -38,7 +51,7 @@ public interface IRedirectorControllerV2
void RemoveRedirectFolder(string folderPath);
}

public interface IRedirectorController : IRedirectorControllerV2, IRedirectorControllerV3
public interface IRedirectorController : IRedirectorControllerV2, IRedirectorControllerV3, IRedirectorControllerV4
{
Redirecting Redirecting { get; set; }
Loading Loading { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryType>git</RepositoryType>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression />
<Version>1.0.9</Version>
<Version>1.1.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Reloaded.Universal.Redirector/ModConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"ModId": "reloaded.universal.redirector",
"ModName": "Reloaded File Redirector",
"ModAuthor": "Sewer56",
"ModVersion": "1.1.2",
"ModVersion": "1.2.0",
"ModDescription": "File Redirector for Reloaded II",
"ModDll": "Reloaded.Universal.Redirector.dll",
"ModR2RManagedDll32": "x86/Reloaded.Universal.Redirector.dll",
Expand Down
12 changes: 10 additions & 2 deletions Reloaded.Universal.Redirector/Redirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class Redirector
{
private List<ModRedirectorDictionary> _redirections = new List<ModRedirectorDictionary>();
private ModRedirectorDictionary _customRedirections = new ModRedirectorDictionary();
private bool _isDisabled = false;

/* Constructor */
public Redirector(IEnumerable<IModConfigV1> modConfigurations)
Expand Down Expand Up @@ -63,7 +64,12 @@ public void Remove(IModConfigV1 configuration)
}

public bool TryRedirect(string path, out string newPath)
{
{
// Check if disabled.
newPath = path;
if (_isDisabled)
return false;

// Custom redirections.
if (_customRedirections.GetRedirection(path, out newPath))
return true;
Expand All @@ -76,10 +82,12 @@ public bool TryRedirect(string path, out string newPath)
return true;
}

newPath = path;
return false;
}

private string GetRedirectFolder(string modId) => Program.ModLoader.GetDirectoryForModId(modId) + "\\Redirector";

public void Disable() => _isDisabled = true;
public void Enable() => _isDisabled = false;
}
}
2 changes: 2 additions & 0 deletions Reloaded.Universal.Redirector/RedirectorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ public RedirectorController(Redirector redirector)
public void RemoveRedirectFolder(string folderPath) => _redirector.Remove(folderPath);
public void AddRedirectFolder(string folderPath, string sourceFolder) => _redirector.Add(folderPath, sourceFolder);
public void RemoveRedirectFolder(string folderPath, string sourceFolder) => _redirector.Remove(folderPath, sourceFolder);
public void Disable() => _redirector.Disable();
public void Enable() => _redirector.Enable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Version>1.0.3</Version>
<Version>1.0.4</Version>
<ApplicationIcon />
<OutputType>WinExe</OutputType>
<StartupObject />
Expand Down

0 comments on commit c6a09db

Please sign in to comment.