adjust LangResCollector for v1.14
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user