-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (94 loc) · 3.41 KB
/
Copy pathProgram.cs
File metadata and controls
107 lines (94 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Resources;
using System.Collections;
using System.IO;
namespace ResourceReader
{
class ResXProc
{
private readonly string _dirPath;
private readonly string _outputFullFileName;
/// <summary>
/// Constructor with parameters
/// </summary>
/// <param name="dirPath">Directory path to process .resx files</param>
/// <param name="outputFullFileName">Full file name of the output file</param>
public ResXProc(string dirPath, string outputFullFileName)
{
_dirPath = dirPath;
_outputFullFileName = outputFullFileName;
}
/// <summary>
/// Starts the Process of the parsing
/// </summary>
public void Process()
{
if (!Directory.Exists(_dirPath))
{
Console.WriteLine($"Error: Directory '{_dirPath}' does not exist.");
return;
}
DirectoryInfo dirInfo = new DirectoryInfo(_dirPath);
FileInfo[] resxFiles = dirInfo.GetFiles("*.resx");
using (var sw = new StreamWriter(_outputFullFileName))
{
foreach (FileInfo file in resxFiles)
{
ProcessSingleFile(file, sw);
}
}
Console.WriteLine("Processing complete. Press any key to exit.");
Console.ReadKey(true);
}
/// <summary>
/// Processes single file from the directory
/// </summary>
/// <param name="file">File to process</param>
/// <param name="sw">Stream writer for the output file</param>
private void ProcessSingleFile(FileInfo file, StreamWriter sw)
{
string filename = file.Name;
string filePath = file.FullName;
Console.WriteLine($"### {filename} ###\n");
sw.WriteLine($"### {filename} ###\n");
try
{
ReadResxContents(filePath, sw);
}
catch (Exception ex)
{
Console.WriteLine($"Error reading file {filename}: {ex.Message}");
sw.WriteLine($"Error reading file {filename}: {ex.Message}");
}
Console.WriteLine($"### {filename} ###\n");
sw.WriteLine($"### {filename} ###\n");
}
/// <summary>
/// ResX contents reading
/// </summary>
/// <param name="filePath">Path to resX file</param>
/// <param name="sw">Stream writer for the output file</param>
private void ReadResxContents(string filePath, StreamWriter sw)
{
using (var rsxr = new ResXResourceReader(filePath))
{
foreach (DictionaryEntry entry in rsxr)
{
string value = entry.Value != null ? entry.Value.ToString() : "(null)";
Console.WriteLine($"\"{value}\"");
sw.WriteLine($"\"{value}\"");
}
}
}
}
class Program
{
static void Main()
{
string directoryPath = @"C:\example\path";
string outputFilePath = @"C:\strings.txt";
ResXProc processor = new ResXProc(directoryPath, outputFilePath);
processor.Process();
}
}
}