-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tool_Form1.cs
191 lines (176 loc) · 7.01 KB
/
Tool_Form1.cs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop;
using System.Reflection;
using Microsoft.Office.Interop.Excel;
using System.Threading;
namespace exportresstrings
{
public partial class Form1 : Form
{
int column = 1, row = 1;
Dictionary<string, string> resDictionary = new Dictionary<string, string>();
public Form1()
{
InitializeComponent();
}
public void readAllResourceFiles(string pathfromclient)
{
List<Details> resList = new List<Details>();
List<LogInfo> logList = new List<LogInfo>();
Details details = new Details();
LogInfo logInfo = new LogInfo();
int logCount = 0;
string requiredPath = "";
string path = "";
string resDLLName = "Resource DLL Name";
string logPath = @"\resourceToExcelLog.txt";
string[] subFolderArray = Directory.GetDirectories(pathfromclient);
if (subFolderArray.Length == 0)
{
subFolderArray = new string[1];
subFolderArray[0] = pathfromclient;
}
for (int folderCount = 0; folderCount < subFolderArray.Length; folderCount++)
{
requiredPath = null;
string folderName = subFolderArray[folderCount];//.Substring(0, subFolderArray[folderCount].IndexOf("\\"));
try
{
string[] files = Directory.GetFiles(subFolderArray[folderCount], "Resources.resx", SearchOption.AllDirectories);
string[] slnFile = Directory.GetFiles(subFolderArray[folderCount], "*.sln", SearchOption.AllDirectories);
if (slnFile.Length > 0)
{
resDLLName = slnFile[0].Substring(slnFile[0].LastIndexOf(@"\")+1);
}
if (files.Length > 0)
{
for (int count = 0; count < files.Length; count++)
{
if (files[count].EndsWith(@"Localization\Resources.resx", StringComparison.InvariantCultureIgnoreCase))
{
requiredPath = files[count];
}
}
path = requiredPath;
if (path != null)
{
//resDLLName = folderName;
if (File.Exists(path))
{
ResXResourceReader rsxr = new ResXResourceReader(path);
IDictionaryEnumerator id = rsxr.GetEnumerator();
foreach (DictionaryEntry d in rsxr)
{
details.ResourceID = d.Key.ToString();
details.ResourceDLL = resDLLName;
details.EngText = d.Value.ToString();
resList.Add(details);
details = new Details();
}
}
}
}
}
catch (Exception e)
{
logCount++;
logInfo.sNo = logCount;
logInfo.exceptionInfo = e.Message;
logList.Add(logInfo);
DateTime currentDateTime = DateTime.Now;
using (StreamWriter sw = File.AppendText(pathfromclient + logPath))
{
sw.WriteLine(logInfo.sNo + " - " + currentDateTime + " - " + logInfo.exceptionInfo);
}
logInfo = new LogInfo();
}
}
if (resList.Count > 0)
exportToExcel(resList);
else
MessageBox.Show("There are no files by the name Resources.resx in Localization folder in " + pathfromclient);
}
public void exportToExcel(IList<Details> dict)
{
Microsoft.Office.Interop.Excel.Application oXL = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel._Workbook oWB = (Microsoft.Office.Interop.Excel._Workbook)(oXL.Workbooks.Add(Missing.Value));
Microsoft.Office.Interop.Excel._Worksheet oSheet = (Microsoft.Office.Interop.Excel._Worksheet)oWB.ActiveSheet;
Range cellRange = (Range)oSheet.Cells[row, column];
cellRange.Font.Bold = true;
oSheet.Cells[row, column] = "ResourceID";
column++;
cellRange = (Range)oSheet.Cells[row, column];
cellRange.Font.Bold = true;
oSheet.Cells[row, column] = "ResourceDLL";
column++;
cellRange = (Range)oSheet.Cells[row, column];
cellRange.Font.Bold = true;
oSheet.Cells[row, column] = "EnglishText";
row++;
foreach (var p in dict)
{
column = 1;
oSheet.Cells[row, column] = p.ResourceID.ToString();
column++;
oSheet.Cells[row, column] = p.ResourceDLL.ToString();
column++;
oSheet.Cells[row, column] = p.EngText.ToString();
row++;
}
oXL.Visible = true;
oXL.UserControl = true;
}
public void button1_Click(object sender, EventArgs e)
{
Loading l = new Loading();
try
{
button1.Enabled = false;
button2.Enabled = false;
this.Hide();
l.Show();
l.Refresh();
readAllResourceFiles(txtBoxPath.Text.ToString());
l.Close();
this.Close();
}
catch (Exception exce)
{
MessageBox.Show(exce.Message);
this.Show();
l.Close();
button1.Enabled = true;
button2.Enabled = true;
}
}
private void button2_Click(object sender, EventArgs e)
{
FolderBrowserDialog fbd = new FolderBrowserDialog();
DialogResult result = fbd.ShowDialog();
txtBoxPath.Text = fbd.SelectedPath;
}
}
public class Details
{
public string ResourceID { get; set; }
public string ResourceDLL { get; set; }
public string EngText { get; set; }
}
public class LogInfo
{
public int sNo { get; set; }
public string exceptionInfo { get; set; }
//public int sNo { get; set; }
}
}