2025-03-05 23:36:41 +01:00
|
|
|
|
using Microsoft.Win32;
|
2025-03-03 22:16:47 +01:00
|
|
|
|
using ProgrammList.sql;
|
|
|
|
|
using System.Net;
|
2025-03-05 23:12:50 +01:00
|
|
|
|
|
2025-03-03 22:16:47 +01:00
|
|
|
|
namespace ProgrammList.ListPrograms {
|
|
|
|
|
internal class ListPrograms {
|
|
|
|
|
|
|
|
|
|
string prgm_path = Directory.GetCurrentDirectory() + "\\";
|
2025-03-05 23:12:50 +01:00
|
|
|
|
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
|
2025-03-05 23:36:41 +01:00
|
|
|
|
private SqlBase sql = null;
|
2025-03-05 23:12:50 +01:00
|
|
|
|
|
2025-03-07 23:36:20 +01:00
|
|
|
|
internal ListPrograms(string sqlType, params string[] filename) {
|
2025-03-05 23:12:50 +01:00
|
|
|
|
if (sqlType == null) {
|
|
|
|
|
Console.WriteLine("SQL Database not defined in app.conf, allowed types:");
|
|
|
|
|
Console.WriteLine("MYSQL");
|
|
|
|
|
Console.WriteLine("MARIADB");
|
|
|
|
|
Console.WriteLine("MSSQL");
|
|
|
|
|
Console.WriteLine("SQLITE");
|
|
|
|
|
throw new ArgumentNullException();
|
|
|
|
|
}
|
2025-03-03 22:16:47 +01:00
|
|
|
|
|
2025-03-05 23:12:50 +01:00
|
|
|
|
if (sqlType.Equals("MYSQL", StringComparison.OrdinalIgnoreCase) || sqlType.Equals("MARIADB", StringComparison.OrdinalIgnoreCase)) {
|
|
|
|
|
sql = new Mysql();
|
|
|
|
|
}
|
|
|
|
|
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
|
|
|
|
|
sql = new Mssql();
|
|
|
|
|
}
|
2025-03-07 23:36:20 +01:00
|
|
|
|
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase) && filename != null) {
|
|
|
|
|
sql = new Sqlite(prgm_path, filename[0]);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
// Default sqlite im gleichen ordner
|
|
|
|
|
sql = new Sqlite(prgm_path, "sqllite.db");
|
2025-03-05 23:12:50 +01:00
|
|
|
|
}
|
2025-03-03 22:16:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void DeleteOldData() {
|
2025-03-05 23:12:50 +01:00
|
|
|
|
sql.CheckTableExists();
|
|
|
|
|
sql.DeleteOldData(Dns.GetHostName());
|
2025-03-03 22:16:47 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void createList(string hkey, string bit) {
|
|
|
|
|
RegistryKey key = Registry.LocalMachine.OpenSubKey(hkey);
|
|
|
|
|
try {
|
|
|
|
|
if (key == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
string[] programmIds = key.GetSubKeyNames();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string programId in programmIds) {
|
|
|
|
|
|
|
|
|
|
RegistryKey programIdSubIds = key.OpenSubKey(programId);
|
|
|
|
|
|
|
|
|
|
string result = "";
|
|
|
|
|
int count = 0;
|
|
|
|
|
Dictionary<string, String> value = new Dictionary<string, string>();
|
|
|
|
|
for (var i = 0; i <= keyvaluenames.Length - 1; i++) {
|
|
|
|
|
value.Add(keyvaluenames[i], "'" + (string)programIdSubIds.GetValue(keyvaluenames[i]) + "'");
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = String.Join("", value.ToArray());
|
|
|
|
|
|
2025-03-05 23:12:50 +01:00
|
|
|
|
if (result.EndsWith(",")) {
|
|
|
|
|
result = result.Remove(result.Length - 1);
|
|
|
|
|
}
|
2025-03-03 22:16:47 +01:00
|
|
|
|
|
|
|
|
|
value.Add("PCID", "'" + Dns.GetHostName() + "'");
|
|
|
|
|
value.Add("update_date", "'" + DateTime.Now + "'");
|
|
|
|
|
value.Add("APP_Architecture", "'" + bit + "'");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sql.InsertOrUpdateData(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
Console.Error.WriteLine(e.ToString());
|
|
|
|
|
System.Environment.Exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|