forked from WizaXxX/Com1CMultiRegister
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
243 lines (190 loc) · 8.57 KB
/
Copy pathProgram.cs
File metadata and controls
243 lines (190 loc) · 8.57 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
using System;
using System.Collections.Generic;
using System.Linq;
using COMAdmin;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;
namespace COM1CMR
{
public class INIManager
{
public INIManager(string aPath)
{
path = aPath;
}
public INIManager() : this("") { }
public string GetPrivateString(string aSection, string aKey)
{
StringBuilder buffer = new StringBuilder(SIZE);
GetPrivateString(aSection, aKey, null, buffer, SIZE, path);
return buffer.ToString();
}
public void WritePrivateString(string aSection, string aKey, string aValue)
{
WritePrivateString(aSection, aKey, aValue, path);
}
public string Path { get => path;
set { path = value; } }
private const int SIZE = 1024;
private string path = null;
[DllImport("kernel32.dll", EntryPoint = "GetPrivateProfileString")]
private static extern int GetPrivateString(string section, string key, string def, StringBuilder buffer, int size, string path);
[DllImport("kernel32.dll", EntryPoint = "WritePrivateProfileString")]
private static extern int WritePrivateString(string section, string key, string str, string path);
}
internal class Program
{
private static readonly INIManager Settings = new INIManager("settings.ini");
class Info1C
{
public string ComPath { get; set; }
public string Ver { get; set; }
public string Clsid { get; set; }
public Info1C (string comPathc, string verc)
{
ComPath = comPathc;
Ver = verc;
}
}
static void Main(string[] args)
{
Console.WriteLine("Запущено формирование com оберток.\n");
try
{
CreateNewCom();
Console.WriteLine("\nФормирование оберток прошло успешно.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("Для продолжения нажмите любую клавишу....");
Console.ReadKey();
}
static void CreateNewCom()
{
ICatalogObject catalogObject1Cv8 = null;
ICatalogObject mainConnector = null;
var dir1C = Settings.GetPrivateString("settings", "dir1C");
Console.WriteLine("Каталог для поиска библиотек com: " + dir1C + "\n");
COMAdminCatalog catalog = new COMAdminCatalogClass();
ICatalogCollection appCollection = (ICatalogCollection)catalog.GetCollection("Applications");
appCollection.Populate();
foreach (ICatalogObject catalogObject in appCollection)
{
if (catalogObject.Name.ToString().ToLower() == "1cv8")
{
catalogObject1Cv8 = catalogObject;
Console.WriteLine("Каталог компонент 1cv8 найден.\n");
break;
}
}
if (catalogObject1Cv8 == null)
{
Console.WriteLine("Каталог компонент 1cv8 НЕ найден.\n");
ICatalogObject new1Cv8App = (ICatalogObject)appCollection.Add();
new1Cv8App.Value["Name"] = "1cv8";
new1Cv8App.Value["Activation"] = COMAdminActivationOptions.COMAdminActivationInproc;
appCollection.SaveChanges();
Console.WriteLine("Каталог компонент 1cv8 создан\n");
catalogObject1Cv8 = new1Cv8App;
}
if (!Directory.Exists(dir1C))
{
Console.WriteLine("Каталог: " + dir1C + " НЕ найден.\n");
return;
}
Console.WriteLine("Каталог: " + dir1C + " найден.\n");
List <Info1C> verList = new List<Info1C>();
String[] catalog1C = Directory.GetDirectories(@"C:\Program Files (x86)\1cv8", "8.*");
foreach (string path in catalog1C)
{
String[] arrayName = path.Split('\\');
var ver = arrayName[arrayName.Length - 1];
var comPath = path + @"\bin\comcntr.dll";
if (!File.Exists(comPath))
{
continue;
}
Console.WriteLine("Найдена компонента версии: " + ver);
verList.Add(new Info1C(comPath, ver));
}
Console.WriteLine("\n");
ICatalogCollection comCollections = (ICatalogCollection)appCollection.GetCollection("Components", catalogObject1Cv8.Key);
comCollections.Populate();
foreach (ICatalogObject catalogObject in comCollections)
{
if (catalogObject.Name.ToString() == "V83.COMConnector.1")
{
Console.WriteLine("Основная обертка: V83.COMConnector найдена.\n");
mainConnector = catalogObject;
}
var arrayName = catalogObject.Name.ToString().Split('_');
var ver = arrayName[arrayName.Length - 1];
var findVer = verList.Where(s => s.Ver == ver);
if (findVer.Count() != 0)
{
Console.WriteLine("Найдена обертка для версии: " + findVer.First().Ver);
verList.Remove(findVer.First());
}
}
if (mainConnector == null)
{
Console.WriteLine("Основная обертка: V83.COMConnector НЕ найдена.");
catalog.InstallComponent("1cv8", verList.Last().ComPath, "", "");
Console.WriteLine("Основная обертка: V83.COMConnector создана");
mainConnector = findMainCom(comCollections);
}
foreach (Info1C itemVer in verList)
{
Console.WriteLine("\n");
Console.WriteLine("Создание обертки для версии: " + itemVer.Ver);
catalog.AliasComponent("1cv8", mainConnector.get_Value("CLSID").ToString(), "", "V83.COMConnector_" + itemVer.Ver, "");
Console.WriteLine("Обертка для версии: " + itemVer.Ver + " создана.");
}
comCollections.Populate();
Console.WriteLine("\n");
Console.WriteLine("Начато изменение данных в реестре.");
foreach (ICatalogObject catalogObject in comCollections)
{
if (catalogObject.Name.ToString() == "V83.COMConnector.1")
{
continue;
}
var arrayName = catalogObject.Name.ToString().Split('_');
Info1C findingItem = null;
try
{
findingItem = verList.First(s => s.Ver == arrayName[arrayName.Length - 1]);
}
catch { continue; }
if (findingItem == null)
{
continue;
}
string clsid = catalogObject.get_Value("CLSID").ToString();
Console.WriteLine("\n");
Console.WriteLine("Начато изменение данных в реестре, для версии: " + findingItem.Ver);
RegistryKey readKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\Wow6432Node\\CLSID\\" + clsid + "\\InprocServer32", true);
readKey.SetValue("", findingItem.ComPath);
readKey.Close();
Console.WriteLine("Произведено изменение данных в реестре, для версии: " + findingItem.Ver);
}
comCollections.SaveChanges();
}
static ICatalogObject findMainCom(ICatalogCollection comCollections)
{
comCollections.Populate();
foreach (ICatalogObject catalogObject in comCollections)
{
if (catalogObject.Name.ToString() == "V83.COMConnector.1")
{
return catalogObject;
}
}
return null;
}
}
}