Program.cs~RFab5f66.TMP
12.1 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using Microsoft.VisualStudio.VCProjectEngine;
using System.Threading;
namespace Convert_vc6TOvc9_cmd
{
class Program
{
[STAThread]
static void Main(string[] args)
{
string oTxt = "";
//string argsStr = String.Join(" ", args);
string tipocompilazione = "0"; //solo .NET
//string tipocompilazione = "1"; //solo .COM
//string tipocompilazione = "2"; //.COM e .NET
if (args.Length > 1)
tipocompilazione = args[1];
string[] sep = { "," };
string[] prjConv = args[0].Split(sep, StringSplitOptions.None);
for (int i = 0; i < prjConv.Length; i++)
{
Console.WriteLine("Start: [" + prjConv[i] + "]");
string sExecute = "";
DirectoryInfo diIn = new DirectoryInfo(prjConv[i]);
FileInfo[] dspFile = diIn.GetFiles("*.dsp");
sExecute = execute(prjConv[i] + @"\" + dspFile[0].Name, dspFile[0].Name);
Console.WriteLine ("Convert: [" + sExecute.ToString() + "]");
if (sExecute != "CATCH")
{
Console.WriteLine("ReplaceVcproj");
replaceVcproj(diIn.FullName + @"\" + sExecute.Replace(".dsp", ""), sExecute.Replace(".dsp", ""));
//Replace _L( in SOURCEFILE
DirectoryInfo diIn2 = new DirectoryInfo(prjConv[i] + "\\src");
FileInfo[] coFile = diIn2.GetFiles("Co*.cpp");
FileStream fs = File.Open(coFile[0].FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
StreamReader reader = new StreamReader(fs);
string contentFile = reader.ReadToEnd();
if (contentFile.IndexOf("_L(") > -1)
{
Console.WriteLine("Replace _L");
contentFile = contentFile.Replace("_L(", "_T(");
reader.Close();
fs.Close();
FileInfo tw = new FileInfo(coFile[0].FullName);
StreamWriter texW = tw.CreateText();
texW.Write(contentFile);
texW.Close();
}
else
{
reader.Close();
fs.Close();
}
Console.WriteLine("ReplaceVcproj: end");
}
else
{
//traccio ko
Console.WriteLine("execute: ko");
}
}
}
static bool replaceVcproj(string path, string sExecute)
{
FileInfo fi = new FileInfo(path);
StreamReader sw = fi.OpenText();
string sLine;
string tmp;
string sLineAll = "";
bool inizioAnalisi = false;
string countTmp = "000000";
bool ok = false;
bool okFirstTime = true;
string[] replaceStr = {@"Name=""Svil Debug|Win32",
@"ATLMinimizesCRunTimeLibraryUsage=""false",
@"PreprocessorDefinitions=""WIN32;_DEBUG;_WINDOWS;_USRDLL",
@"RuntimeLibrary=""0",
@"AdditionalDependencies=""qtlbased.lib libcpmtd.lib atl.lib LIBCMTD.lib COMSUPP.lib xlibd.lib",
@"IgnoreAllDefaultLibraries=""true",
@"
copy $(TargetPath)",
@"AdditionalDependencies=""qtlbased.lib libcpmtd.lib atl.lib LIBCMTD.lib COMSUPP.lib",
@"AdditionalDependencies=""Xlibd.lib qtlbased.lib libcpmtd.lib atl.lib LIBCMTD.lib COMSUPP.lib",
@"AdditionalDependencies=""qtlbased.lib libcpmtd.lib atl.lib LIBCMTD.lib Xlibd.lib COMSUPP.lib"
};
string[] replaceStrCon = {"",
@"CharacterSet=""2""",
@"PreprocessorDefinitions=""WIN32;_DEBUG;_WINDOWS;""",
@"RuntimeLibrary=""3""",
@"AdditionalDependencies=""qtlbased.lib xlibd.lib""",
@"IgnoreAllDefaultLibraries=""false""",
@"
copy "$(TargetPath)"",
@"AdditionalDependencies=""qtlbased.lib""",
@"AdditionalDependencies=""qtlbased.lib xlibd.lib""",
};
string[] replaceStrCon2 = {"",
"",
"",
@"EnableFunctionLevelLinking=""false""",
"",
@"IgnoreDefaultLibraryNames=""msvcprtd.lib libcmtd.lib"""
};
StringBuilder sb = new StringBuilder();
sb.AppendFormat("\t\t\t\t");
while ((sLine = sw.ReadLine()) != null)
{
if (sLine.IndexOf(replaceStr[0]) > 0 && okFirstTime)
{
inizioAnalisi = true;
countTmp = countTmp.Remove(0, 1);
countTmp = countTmp.Insert(0, "1");
okFirstTime = false;
}
if (inizioAnalisi)
{
if (sLine.ToLower().IndexOf(replaceStr[1].ToLower()) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[1], replaceStrCon[1]);
tmp = sb.ToString() + replaceStrCon[1];
sLineAll = sLineAll + tmp + "\r";
countTmp = countTmp.Remove(1, 1);
countTmp = countTmp.Insert(1, "1");
}
else if (sLine.ToLower().IndexOf(replaceStr[2].ToLower()) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[2], replaceStrCon[2]);
tmp = sb.ToString() + replaceStrCon[2];
sLineAll = sLineAll + tmp + "\r";
countTmp = countTmp.Remove(2, 1);
countTmp = countTmp.Insert(2, "1");
}
else if (sLine.ToLower().IndexOf(replaceStr[3].ToLower()) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[3], replaceStrCon[3]);
tmp = sb.ToString() + replaceStrCon[3];
sLineAll = sLineAll + tmp + "\r";
tmp = sLine;
tmp = tmp.Replace(replaceStr[3], replaceStrCon2[3]);
tmp = sb.ToString() + replaceStrCon2[3];
sLineAll = sLineAll + tmp + "\r";
countTmp = countTmp.Remove(3, 1);
countTmp = countTmp.Insert(3, "1");
}
else if (sLine.ToLower().IndexOf(replaceStr[4].ToLower()) > 0 || sLine.ToLower().IndexOf(replaceStr[7].ToLower()) > 0 || sLine.ToLower().IndexOf(replaceStr[8].ToLower()) > 0 || sLine.ToLower().IndexOf(replaceStr[9].ToLower()) > 0)
{
int eccDovePrendo;
if (sLine.ToLower().IndexOf(replaceStr[4].ToLower()) > 0)
{
eccDovePrendo = 4;
}
else if (sLine.ToLower().IndexOf(replaceStr[7].ToLower()) > 0)
{
eccDovePrendo = 7;
}
else
{
eccDovePrendo = 8;
}
tmp = sLine;
tmp = tmp.Replace(replaceStr[eccDovePrendo], replaceStrCon[eccDovePrendo]);
tmp = sb.ToString() + replaceStrCon[eccDovePrendo];
sLineAll = sLineAll + tmp + "\r";
countTmp = countTmp.Remove(4, 1);
countTmp = countTmp.Insert(4, "1");
}
else if (sLine.ToLower().IndexOf(replaceStr[5].ToLower()) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[5], replaceStrCon[5]);
tmp = sb.ToString() + replaceStrCon[5];
sLineAll = sLineAll + tmp + "\r";
tmp = sLine;
tmp = tmp.Replace(replaceStr[5], replaceStrCon2[5]);
tmp = sb.ToString() + replaceStrCon2[5];
sLineAll = sLineAll + tmp + "\r";
countTmp = countTmp.Remove(5, 1);
countTmp = countTmp.Insert(5, "1");
}
else if (sLine.ToLower().IndexOf(replaceStr[6].ToLower()) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[6], replaceStrCon[6]);
//tmp = sb.ToString() + replaceStrCon[6];
sLineAll = sLineAll + tmp + "\r";
}
else if (sLine.IndexOf("</Configuration>") > 0)
{
sLineAll = sLineAll + sLine + "\r";
if (countTmp.IndexOf("0") >= 0)
{
//Manca qualche riferimento
inizioAnalisi = false;
}
else
{
//Tutto ok
ok = true;
inizioAnalisi = false;
}
}
else
{
if (sLine.IndexOf(replaceStr[6]) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[6], replaceStrCon[6]);
sLineAll = sLineAll + tmp + "\r";
}
else
{
sLineAll = sLineAll + sLine + "\r";
}
}
}
else
{
if (sLine.IndexOf(replaceStr[6]) > 0)
{
tmp = sLine;
tmp = tmp.Replace(replaceStr[6], replaceStrCon[6]);
sLineAll = sLineAll + tmp + "\r";
}
else
{
sLineAll = sLineAll + sLine + "\r";
}
}
}
sw.Close();
if (ok)
{
StreamWriter swToFile = new StreamWriter(path);
swToFile.Write(sLineAll);
swToFile.Flush();
swToFile.Close();
return true;
}
else
{
return false;
}
}
static string execute(string path, string nameDsp)
{
try
{
Console.WriteLine("Convert start: [" + nameDsp + "]");
Microsoft.VisualStudio.VCProjectEngine.VCProjectEngineObject vcPengine = new VCProjectEngineObject();
VCProject obj = vcPengine.LoadProject(path) as VCProject;
obj.ProjectFile = nameDsp.Replace(".dsp", "") + ".vcproj";
obj.Save();
return nameDsp + ".vcproj";
}
catch (Exception ecc)
{
Console.WriteLine("Convert exception: [" + ecc.Message + "]");
return "CATCH";
}
}
}
}