adjust LangResCollector for v1.14

This commit is contained in:
2023-01-06 15:46:53 +01:00
parent 6d46fab91b
commit fadf1f05c4
3 changed files with 52 additions and 30 deletions

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SM64_ROM_Manager.LangRes_Collector
{
internal class LangResFilterConfig
{
public string[] FileNameBlackList { get; set; }
public string[] FileNameWhiteList { get; set; }
public string[] PropNameBlackList { get; set; }
}
}

View File

@@ -7,8 +7,10 @@ using System.Resources;
using System.Collections;
using System.Linq;
using Microsoft.WindowsAPICodePack.Dialogs;
using Newtonsoft.Json.Linq;
using System.Reflection;
namespace SM64_ROM_Manager_LangRes_Collector
namespace SM64_ROM_Manager.LangRes_Collector
{
class Program
{
@@ -17,24 +19,9 @@ namespace SM64_ROM_Manager_LangRes_Collector
var resFiles = new List<string>();
var ofd = new CommonOpenFileDialog { IsFolderPicker = true };
string rootPath, outputPath;
var fileNameBlackList = new string[]
{
"Resources.resx",
"My*Icons.resx",
"*.de.resx",
"ReflectionSymbols.resx",
"UpdatingAdministrationLangRes"
};
var fileNameWhiteList = new string[]
{
"*.resx"
};
var blackListPropNames = new string[]
{
">>*",
"*.AccessibleName",
"*.AccessibleDescription"
};
var myAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var myConfigFilePath = Path.Combine(myAppDir, "FilterConfig.json");
var filterConfig = JObject.Parse(File.ReadAllText(myConfigFilePath)).ToObject<LangResFilterConfig>();
// Get root path
ofd.Title = "Root (repository) directory";
@@ -53,18 +40,18 @@ namespace SM64_ROM_Manager_LangRes_Collector
// Collect files
if (Directory.Exists(rootPath))
{
foreach (var filePath in Directory.GetFiles(rootPath, "*.resx", SearchOption.AllDirectories))
foreach (var filePath in Directory.GetFiles(rootPath, string.Empty, SearchOption.AllDirectories))
{
var fileName = Path.GetFileName(filePath);
var copyFile = true;
foreach (var blackFileName in fileNameBlackList)
foreach (var blackFileName in filterConfig.FileNameBlackList)
{
if (copyFile && LikeString(fileName, blackFileName, CompareMethod.Binary))
copyFile = false;
}
foreach (var whiteFileName in fileNameWhiteList)
foreach (var whiteFileName in filterConfig.FileNameWhiteList)
{
if (copyFile && !LikeString(fileName, whiteFileName, CompareMethod.Binary))
copyFile = false;
@@ -90,16 +77,16 @@ namespace SM64_ROM_Manager_LangRes_Collector
var propName = (string)kvp.Key;
var useProp = true;
foreach (var blackPropName in blackListPropNames)
// Check for blacklisted property names
foreach (var blackPropName in filterConfig.PropNameBlackList)
{
if (useProp && LikeString(propName, blackPropName, CompareMethod.Binary))
useProp = false;
}
if (useProp && kvp.Value is string)
// Hold property to write later, if it's a string
if (useProp && kvp.Value is string val)
{
var val = (string)kvp.Value;
if (!string.IsNullOrEmpty(val))
propsToCopy.Add(propName, (string)kvp.Value);
}
@@ -110,9 +97,16 @@ namespace SM64_ROM_Manager_LangRes_Collector
// Write output ResX file
if (propsToCopy.Any())
{
var resFileOutput = Path.Combine(outputPath, Path.GetFileName(resFileInput));
var resFileOutput = Path.Combine(outputPath, resFileInput.Replace(rootPath, outputPath));
var resFileOutputDir = Path.GetDirectoryName(resFileOutput);
// Ensure the directory exists
Directory.CreateDirectory(resFileOutputDir);
// Open a ResXResourceWriter
var resWriter = new ResXResourceWriter(resFileOutput);
// Write all hold properties
foreach (var kvp in propsToCopy)
resWriter.AddResource(kvp.Key, kvp.Value);

View File

@@ -4,13 +4,14 @@
<OutputType>Exe</OutputType>
<TargetFramework>net6.0-windows7</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>SM64_ROM_Manager_LangRes_Collector</RootNamespace>
<StartupObject>SM64_ROM_Manager_LangRes_Collector.Program</StartupObject>
<RootNamespace>SM64_ROM_Manager.LangRes_Collector</RootNamespace>
<StartupObject>SM64_ROM_Manager.LangRes_Collector.Program</StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FastColoredTextBox-net5" Version="2.17.30.100" />
<PackageReference Include="FastColoredTextBox.Net5" Version="2.16.26" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
@@ -20,12 +21,18 @@
<Reference Include="DevComponents.DotNetBar.Charts">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Charts.dll</HintPath>
</Reference>
<Reference Include="DevComponents.DotNetBar.Design">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Design.dll</HintPath>
</Reference>
<Reference Include="DevComponents.DotNetBar.Keyboard">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Keyboard.dll</HintPath>
</Reference>
<Reference Include="DevComponents.DotNetBar.Layout">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Layout.dll</HintPath>
</Reference>
<Reference Include="DevComponents.DotNetBar.Layout.Design">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Layout.Design.dll</HintPath>
</Reference>
<Reference Include="DevComponents.DotNetBar.Schedule">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.DotNetBar.Schedule.dll</HintPath>
</Reference>
@@ -38,6 +45,12 @@
<Reference Include="DevComponents.Instrumentation">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.Instrumentation.dll</HintPath>
</Reference>
<Reference Include="DevComponents.Instrumentation.Design">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.Instrumentation.Design.dll</HintPath>
</Reference>
<Reference Include="DevComponents.SuperGrid.Design">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.SuperGrid.Design.dll</HintPath>
</Reference>
<Reference Include="DevComponents.TreeGX">
<HintPath>..\Shared Libs\DotNetBarNew\DevComponents.TreeGX.dll</HintPath>
</Reference>