Skip to content

Commit

Permalink
Version 4.6.4
Browse files Browse the repository at this point in the history
 * BUG FIX - Fixed bug where the OutputFile was not always loaded with lowest priority during initialization
 * BUG FIX - Fixed a bug where redirected resources could not be located under certain circumstances (again)

Other changes
 * Included standalone XUnity.ResourceRedirector distribution. XUnity.AutoTranslator is not needed to use this.
  • Loading branch information
randoman committed Nov 4, 2019
1 parent 435ade4 commit 43703a6
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 78 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
### 4.6.3
### 4.6.4
* BUG FIX - Fixed bug where the OutputFile was not always loaded with lowest priority during initialization
* BUG FIX - Fixed a bug where redirected resources could not be located under certain circumstances (again)

### 4.6.3
* MISC - Disable all translator endpoints if output language is the same as the source language

### 4.6.2
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ Often other mods UI are implemented through IMGUI. As you can see above, this is
This may seem like a nice feature to have enabled by default but **never redistribute the mod with this enabled**. The reason here being that IMGUI has a very spammy nature. This does not mean that IMGUI in general will spam the endpoint, just that it is more likely to cause spam (and therefore cause the plugin to shutdown).

## Manual Translations
When you use this plugin, you can always go to the file `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) to edit any auto generated translations and they will show up the next time you run the game. Or you can press (ALT+R) to reload the translation immediately.
When you use this plugin, you can always go to the file `Translation\{Lang}\Text\_AutoGeneratedTranslations.txt` (OutputFile) to edit any auto generated translations and they will show up the next time you run the game. Or you can press (ALT+R) to reload the translation immediately.

It is also worth noting that this plugin will read all text files (*.txt) in the `Translation` (Directory), so if you want to provide a manual translation, you can simply cut out texts from the `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) and place them in new text files in order to replace them with a manual translation. These text files can also be placed in standard .zip archives.

In this context, the `Translation\_AutoGeneratedTranslations.{lang}.txt` (OutputFile) will always have the lowest priority when reading translations. So if the same translation is present in two places, it will not be the one from the (OutputFile) that is used.
In this context, the `Translation\{Lang}\Text\_AutoGeneratedTranslations.txt` (OutputFile) will always have the lowest priority when reading translations. So if the same translation is present in two places, it will not be the one from the (OutputFile) that is used.

In some ADV engines text 'scrolls' into place slowly. Different techniques are used for this and in some instances if you want the translated text to be scrolling in instead of the untranslated text, you may need to set `GeneratePartialTranslations=True`. This should not be turned on unless required by the game.

Expand Down Expand Up @@ -587,9 +587,9 @@ Example configuration that seperates translations for each executable:

```
[Files]
Directory=Translation\{GameExeName}
OutputFile=Translation\{GameExeName}\_AutoGeneratedTranslations.{lang}.txt
SubstitutionFile=Translation\{GameExeName}\_Substitutions.{lang}.txt
Directory=Translation\{GameExeName}\{Lang}\Text
Directory=Translation\{GameExeName}\{Lang}\Text\_AutoGeneratedTranslations.txt
Directory=Translation\{GameExeName}\{Lang}\Text\_Substitutions.txt
```

So when should use scope your translations? Well that depends on the type of scope:
Expand Down Expand Up @@ -673,7 +673,7 @@ ZIP files that are placed in the `PreferredStoragePath` will be indexed during s

## Regarding Redistribution
Redistributing this plugin for various games is absolutely encouraged. However, if you do so, please keep the following in mind:
* **Distribute the _AutoGeneratedTranslations.{lang}.txt file along with the redistribution with as many translations as possible to ensure the online translator is hit as little as possible.**
* **Distribute the _AutoGeneratedTranslations.txt file along with the redistribution with as many translations as possible to ensure the online translator is hit as little as possible.**
* **Test your redistribution with logging/console enabled to ensure the game does not exhibit undesirable behaviour such as spamming the endpoints.**
* Ensure you keep the plugin up-to-date, as much as reasonably possible.
* If you use image loading feature, make sure you read [this section](#texture-translation).
Expand Down
2 changes: 1 addition & 1 deletion src/XUnity.AutoTranslator.Patcher/Patcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public override string Version
{
get
{
return "4.6.2";
return "4.6.4";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class AutoTranslatorPlugin : BaseUnityPlugin, IPluginEnvironment

public AutoTranslatorPlugin()
{
_dataPath = "BepInEx";
// BepInEx 4.x paths cannot be trusted!
_dataPath = Path.Combine( Common.Constants.Paths.GameRoot, "BepInEx" );
_configPath = Path.Combine( _dataPath, "AutoTranslatorConfig.ini" );
//XuaLogger.Current = new BepInLogger();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal class UnzippedDirectory : IDisposable

public UnzippedDirectory( string root, bool cacheNormalFiles )
{
_cacheNormalFiles = cacheNormalFiles;
_zipFiles = new List<ZipFile>();

Directory.CreateDirectory( root );
Expand All @@ -33,9 +34,7 @@ public UnzippedDirectory( string root, bool cacheNormalFiles )
{
_root = Path.Combine( _loweredCurrentDirectory, root.ToLowerInvariant() );
}

Initialize();
_cacheNormalFiles = cacheNormalFiles;
}

public IEnumerable<RedirectedResource> GetFiles( string path, params string[] extensions )
Expand All @@ -44,25 +43,15 @@ public IEnumerable<RedirectedResource> GetFiles( string path, params string[] ex
{
if( Directory.Exists( path ) )
{
if( extensions == null || extensions.Length == 0 )
var noExtensions = extensions == null || extensions.Length == 0;
var files = Directory.GetFiles( path, "*", SearchOption.TopDirectoryOnly );
foreach( var file in files )
{
var files = Directory.GetFiles( path, "*", SearchOption.TopDirectoryOnly );
foreach( var file in files )
if( noExtensions || extensions.Any( x => file.EndsWith( x, StringComparison.OrdinalIgnoreCase ) ) )
{
yield return new RedirectedResource( () => File.OpenRead( file ), null, file );
}
}
else
{
foreach( var extension in extensions )
{
var files = Directory.GetFiles( path, "*" + extension, SearchOption.TopDirectoryOnly );
foreach( var file in files )
{
yield return new RedirectedResource( () => File.OpenRead( file ), null, file );
}
}
}
}
}

Expand Down Expand Up @@ -118,7 +107,7 @@ public IEnumerable<RedirectedResource> GetFile( string path )
.OrderBy( x => x.IsZipped )
.ThenBy( x => x.ContainerFile )
.ThenBy( x => x.FullPath );

foreach( var entry in entries )
{
if( entry.IsZipped )
Expand All @@ -135,6 +124,8 @@ public IEnumerable<RedirectedResource> GetFile( string path )

public bool DirectoryExists( string path )
{
var originalPath = path;

var exists = false;
if( _rootZipDir != null )
{
Expand All @@ -148,11 +139,13 @@ public bool DirectoryExists( string path )
exists = _rootZipDir.DirectoryExists( path );
}

return exists || ( !_cacheNormalFiles && Directory.Exists( path ) );
return exists || ( !_cacheNormalFiles && Directory.Exists( originalPath ) );
}

public bool FileExists( string path )
{
var originalPath = path;

var exists = false;
if( _rootZipDir != null )
{
Expand All @@ -166,7 +159,7 @@ public bool FileExists( string path )
exists = _rootZipDir.FileExists( path );
}

return exists || ( !_cacheNormalFiles && File.Exists( path ) );
return exists || ( !_cacheNormalFiles && File.Exists( originalPath ) );
}

private void Initialize()
Expand All @@ -182,66 +175,65 @@ private void Initialize()

foreach( var file in files )
{
if( !_cacheNormalFiles && !file.EndsWith( ".zip", StringComparison.OrdinalIgnoreCase ) )
{
// skip any files that are not .zip files if we do not cache them all
continue;
}

var current = _rootZipDir;
var relativePath = file.ToLowerInvariant().MakeRelativePath( _root );
var parts = relativePath.Split( PathSeparators, StringSplitOptions.RemoveEmptyEntries );
var isZip = file.EndsWith( ".zip", StringComparison.OrdinalIgnoreCase );

for( int i = 0; i < parts.Length; i++ )
if( isZip || ( _cacheNormalFiles && !isZip ) )
{
var part = parts[ i ];
var current = _rootZipDir;
var relativePath = file.ToLowerInvariant().MakeRelativePath( _root );
var parts = relativePath.Split( PathSeparators, StringSplitOptions.RemoveEmptyEntries );

if( i == parts.Length - 1 )
for( int i = 0; i < parts.Length; i++ )
{
if( part.EndsWith( ".zip", StringComparison.OrdinalIgnoreCase ) )
var part = parts[ i ];

if( i == parts.Length - 1 )
{
// this is the zip file, read the metadata!
var start = current;
if( part.EndsWith( ".zip", StringComparison.OrdinalIgnoreCase ) )
{
// this is the zip file, read the metadata!
var start = current;

var zf = new ZipFile( file );
_zipFiles.Add( zf );
var zf = new ZipFile( file );
_zipFiles.Add( zf );

foreach( ZipEntry entry in zf )
{
current = start;
var internalPath = entry.Name.Replace( '/', '\\' ).ToLowerInvariant();
var internalParts = internalPath.Split( PathSeparators, StringSplitOptions.RemoveEmptyEntries );
for( int j = 0; j < internalParts.Length; j++ )
foreach( ZipEntry entry in zf )
{
var internalPart = internalParts[ j ];
if( j == internalParts.Length - 1 )
current = start;
var internalPath = entry.Name.Replace( '/', '\\' ).ToLowerInvariant();
var internalParts = internalPath.Split( PathSeparators, StringSplitOptions.RemoveEmptyEntries );
for( int j = 0; j < internalParts.Length; j++ )
{
if( entry.IsFile )
var internalPart = internalParts[ j ];
if( j == internalParts.Length - 1 )
{
current.AddFile( internalPart, new FileEntry( internalPath, file, zf, entry ) );
if( entry.IsFile )
{
current.AddFile( internalPart, new FileEntry( internalPath, file, zf, entry ) );
}
else
{
current = current.GetOrCreateChildPath( internalPart );
}
}
else
{
current = current.GetOrCreateChildPath( internalPart );
}
}
else
{
current = current.GetOrCreateChildPath( internalPart );
}
}

}
}
else
{
current.AddFile( part, new FileEntry( file ) );
}
}
else
{
current.AddFile( part, new FileEntry( file ) );
current = current.GetOrCreateChildPath( part );
}
}
else
{
current = current.GetOrCreateChildPath( part );
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static void Configure()
LogAllLoadedResources = PluginEnvironment.Current.Preferences.GetOrDefault( "ResourceRedirector", "LogAllLoadedResources", false );
EnableDumping = PluginEnvironment.Current.Preferences.GetOrDefault( "ResourceRedirector", "EnableDumping", false );
CacheMetadataForAllFiles = PluginEnvironment.Current.Preferences.GetOrDefault( "ResourceRedirector", "CacheMetadataForAllFiles", true );

if( CacheMetadataForAllFiles && EnableDumping )
{
XuaLogger.AutoTranslator.Warn( "'EnableDumping' and 'CacheMetadataForAllOnStartup' cannot be enabled at the same time. Disabling 'CacheMetadataForAllOnStartup'..." );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public static class PluginData
/// <summary>
/// Gets the version of the plugin.
/// </summary>
public const string Version = "4.6.2";
public const string Version = "4.6.4";
}
}
9 changes: 5 additions & 4 deletions src/XUnity.AutoTranslator.Plugin.Core/TextTranslationCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private static IEnumerable<string> GetTranslationFiles()
return Directory.GetFiles( Settings.TranslationsPath, $"*", SearchOption.AllDirectories )
.Where( x => x.EndsWith( ".txt", StringComparison.OrdinalIgnoreCase ) || x.EndsWith( ".zip", StringComparison.OrdinalIgnoreCase ) )
.Select( x => x.Replace( "/", "\\" ) )
.Where( x => !x.EndsWith( "resizer.txt", StringComparison.OrdinalIgnoreCase ) );
.Where( x => !x.EndsWith( "resizer.txt", StringComparison.OrdinalIgnoreCase ) )
.Select( x => new FileInfo( x ).FullName );
}

internal void LoadTranslationFiles()
Expand All @@ -84,11 +85,11 @@ internal void LoadTranslationFiles()
_scopedTranslations.Clear();
Settings.Replacements.Clear();

var mainTranslationFile = Settings.AutoTranslationsFilePath;
var substitutionFile = Settings.SubstitutionFilePath;
var mainTranslationFile = new FileInfo( Settings.AutoTranslationsFilePath ).FullName;
var substitutionFile = new FileInfo( Settings.SubstitutionFilePath ).FullName;
LoadTranslationsInFile( substitutionFile, true, false );
LoadTranslationsInFile( mainTranslationFile, false, true );
foreach( var fullFileName in GetTranslationFiles().Reverse().Except( new[] { mainTranslationFile, substitutionFile } ) )
foreach( var fullFileName in GetTranslationFiles().Reverse().Except( new[] { mainTranslationFile, substitutionFile }, StringComparer.OrdinalIgnoreCase ) )
{
LoadTranslationsInFile( fullFileName, false, false );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class AutoTranslatorPlugin : IPlugin, IPluginEnvironment

public AutoTranslatorPlugin()
{
_dataPath = "Plugins";
_dataPath = Path.Combine( Common.Constants.Paths.GameRoot, "Plugins" );
_configPath = Path.Combine( _dataPath, "AutoTranslatorConfig.ini" );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net35</TargetFramework>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<OutputType>Exe</OutputType>
<TargetFramework>net40</TargetFramework>
<AssemblyName>SetupReiPatcherAndAutoTranslator</AssemblyName>
<Version>4.6.3</Version>
<Version>4.6.4</Version>
<ApplicationIcon>icon.ico</ApplicationIcon>
<Win32Resource />
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,14 @@
</Reference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="Targets" />
</GetAssemblyIdentity>
<ItemGroup>
<VersionNumber Include="$([System.Text.RegularExpressions.Regex]::Replace(&quot;%(Targets.Version)&quot;, &quot;^(.+?)(\.0+)$&quot;, &quot;$1&quot;))" />
</ItemGroup>
<Exec Command="if $(ConfigurationName) == Release (&#xD;&#xA; XCOPY /Y /I &quot;$(TargetDir)XUnity.Common.dll&quot; &quot;$(SolutionDir)dist\RR-BepIn-5x\BepInEx\core\&quot;&#xD;&#xA; XCOPY /Y /I &quot;$(TargetDir)XUnity.ResourceRedirector.dll&quot; &quot;$(SolutionDir)dist\RR-BepIn-5x\BepInEx\plugins\XUnity.ResourceRedirector\&quot;&#xD;&#xA; XCOPY /Y /I &quot;$(TargetDir)$(TargetName)$(TargetExt)&quot; &quot;$(SolutionDir)dist\RR-BepIn-5x\BepInEx\plugins\XUnity.ResourceRedirector\&quot;&#xD;&#xA; COPY /Y &quot;$(SolutionDir)README.md&quot; &quot;$(SolutionDir)dist\RR-BepIn-5x\BepInEx\plugins\README (AutoTranslator).md&quot;&#xD;&#xA; powershell Compress-Archive -Path '$(SolutionDir)dist\RR-BepIn-5x\BepInEx' -DestinationPath '$(SolutionDir)dist\RR-BepIn-5x\XUnity.ResourceRedirector-BepIn-5x-@(VersionNumber).zip' -Force)&#xD;&#xA;)" />
</Target>

</Project>

0 comments on commit 43703a6

Please sign in to comment.