Вы находитесь на странице: 1из 4

using System;

using System.Collections.Generic;
using System.Xml;
using System.Xml.Schema;
using System.Diagnostics;
using System.IO;
using Microsoft.Deployment.WindowsInstaller;

namespace VirusBlokAda.CC.RemoteOperations.MsiInfo
{
public static class Vba32VersionInfo
{
private static Dictionary<String, String> dict = new Dictionary<String,
String>();

static void ValidationEventHandler(Object sender, ValidationEventArgs e)


{
switch (e.Severity)
{
case XmlSeverityType.Error:
Debug.WriteLine("Error validating Vba32Versions.xml " +
e.Message);
break;
case XmlSeverityType.Warning:
Debug.WriteLine("Warning validating Vba32Versions.xml " +
e.Message);
break;
}

static Vba32VersionInfo()
{
try
{
XmlReaderSettings settings = new XmlReaderSettings();
XmlSchema schema = new XmlSchema();
schema.SourceUri =
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Settings\Vba32Versions.xsd");
settings.Schemas.Add(schema);
settings.ValidationType = ValidationType.Schema;
XmlReader reader =
XmlReader.Create(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
@"Settings\Vba32Versions.xml"), settings);
XmlDocument document = new XmlDocument();
document.Load(reader);
ValidationEventHandler eventHandler = new
ValidationEventHandler(ValidationEventHandler);
document.Validate(eventHandler);
XmlNodeList nodes = document.GetElementsByTagName("version");
foreach (XmlNode next in nodes)
{
String version = next.InnerText;
String guid = next.Attributes["guid"].Value;
dict.Add(version, guid);
}
}
catch (Exception ex)
{
Debug.WriteLine("Error loading or parsing Vba32Versions.xml " +
ex.Message);
}

}
public static String GetGuid(String version)
{
String guid;
return dict.TryGetValue(version, out guid) ? guid : "unknown";
}

#region Versions

public static readonly String Vba32NTW = "Vba32 WinNT Workstation";


public static readonly String Vba32NTS = "Vba32 WinNT Server";
public static readonly String Vba32Vista = "Vba32 for Windows Vista";
public static readonly String Vba32Vis = "Vba32 for Windows Server 2008";
public static readonly String Vba32RemoteConsoleScanner = "Vba32 Remote
Console Scanner";
public static readonly String Vba32RemoteControlAgent = "Vba32 Remote
Control Agent";
public static readonly String Vba32Antivirus = "Vba32 Antivirus";
public static readonly String KcSazAntivirus = "Vba32 Antivirus x86";
public static readonly String KcSazAntivirusX64 = "Vba32 Antivirus x64";
public static readonly String KanoeX64 = "KANOE x64";
public static readonly String KanoeX86 = "KANOE x86";

#endregion

public static Dictionary<string, string> InfoMsi(String pathMsi)


{
string [] property = Vba32CC.Service.VSIS.VSISWrapper.GetKcSaz()
? new[] {"ProductName", "ProductVersion", "IniVersion"}
: new[] {"InstallVersion"};
Dictionary<string, string> msiProperty = new Dictionary<string,
string>();

using (Database database = new Database(pathMsi,


DatabaseOpenMode.ReadOnly))
{
foreach (String name in property)
msiProperty.Add(name, (String) database.ExecuteScalar("SELECT
`Value` FROM `Property` WHERE `Property` = '{0}'", name));
}
return msiProperty;
}

public static String InfoVersionLanguage(String path)


{
String propertyValue= String.Empty;
if (!File.Exists(path)) return propertyValue;
using (Database database = new Database(path,
DatabaseOpenMode.ReadOnly))
{
propertyValue = String.Format("{0} {1}",
(String) database.ExecuteScalar("SELECT `Value` FROM `Property`
WHERE `Property` = '{0}'", "ProductVersion"),
(String) database.ExecuteScalar("SELECT `Value` FROM `Property`
WHERE `Property` = '{0}'",
"ProductLanguage") == "1033" ? "EN" : "RU");
}
return propertyValue;
}

public static void MstCreator(bool isServer, string folder, string


computer, string product)
{
string x64, x86, sqlAddLocal;

switch (product)
{
case "KANOE":
x64 = "KANOEx64.msi";
x86 = "KANOEx86.msi";
sqlAddLocal =
"VSIS,AGENT,VPP,VIC,VND,VDD,VAS,VMT,VFC,VGI,VKW,VQN";
break;
default:
x64 = "Vba32Antivirusx64.msi";
x86 = "Vba32Antivirusx86.msi";
sqlAddLocal = "VSIS,AGENT,VPP,VQN,VKW,VAS,VMT,VDD,VGI,VMF";
break;
}

string path = @"c:\Windows\Temp";


if (!Directory.Exists(path))
Directory.CreateDirectory(path);

string temp = new DirectoryInfo(path + @"\temp.msi").FullName;

List<string> nameList = new List<string>();


nameList.Add(x64);
nameList.Add(x86);

folder = string.IsNullOrEmpty(folder) ? string.Format("\\\\{0}\\{1}",


computer, product) : folder;

foreach (string n in nameList)


{
string orig = new
DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + @"\Installs\" + n).FullName;
string mst;

switch (product)
{
case "KANOE":
if (isServer) mst = n == x64 ? "s64.mst" : "s86.mst";
else mst = n == x64 ? "c64.mst" : "c86.mst";
break;
default:
if (isServer) mst = n == x64 ? "cfs.mst" : "cfe.mst";
else mst = n == x64 ? "cfss.mst" : "cfse.mst";
break;
}

string transform = new DirectoryInfo(path + @"\" + mst).FullName;

File.Copy(orig, temp, true);


using (Database origDatabase = new Database(orig,
DatabaseOpenMode.ReadOnly))
using (Database database = new Database(temp,
DatabaseOpenMode.Direct))
{
database.Execute(string.Format("Update `Property` Set
`Property`.`Value` = '{0}\\vba32.key' WHERE `Property`.`Property` =
'KEY_FILEPATH'", folder));
database.Execute(string.Format("INSERT INTO `Property`
(`Property`.`Property`, `Property`.`Value`) VALUES ('CC_CFG_FILEPATH',
'{0}\\VbaControlAgent.cfg')", folder));
database.Execute(string.Format("INSERT INTO `Property`
(`Property`.`Property`, `Property`.`Value`) VALUES ('ADDLOCAL', '{0}')",
sqlAddLocal));
database.Execute(string.Format("INSERT INTO `Property`
(`Property`.`Property`, `Property`.`Value`) VALUES ('{0}', '1')", isServer ?
"REMOTE_SCAN_SERVER" : "REMOTE_SCAN_CLIENT"));

if (!isServer)
database.Execute("INSERT INTO `Property`
(`Property`.`Property`, `Property`.`Value`) VALUES ('GENERATE_CLEAR_LIST', '1')");

if (product == "KC_SAZ")
database.Execute("INSERT INTO `Property`
(`Property`.`Property`, `Property`.`Value`) VALUES ('VDD_HIDE_COMPONENTS', '1')");

database.GenerateTransform(origDatabase, transform);
database.CreateTransformSummaryInfo(origDatabase, transform,
TransformErrors.None, TransformValidations.None);
}

File.Delete(temp);
}
}
}
}

Вам также может понравиться