86 lines
3.0 KiB
C#
Raw Normal View History

using Microsoft.Win32;
using ProgrammList.ConfigManager;
2025-03-03 22:16:47 +01:00
using ProgrammList.sql;
using System;
using System.Collections.Generic;
using System.IO;
2025-03-03 22:16:47 +01:00
using System.Net;
2025-03-03 22:16:47 +01:00
namespace ProgrammList.ListPrograms {
public class ListPrograms {
2025-03-03 22:16:47 +01:00
string prgm_path = Directory.GetCurrentDirectory() + "\\";
string[] keyvaluenames = { "DisplayName", "DisplayVersion", "InstallDate" };
private SqlBase sql = null;
public void init() {
string sqlType = PrmListConfigManager.GetSetting("DB_Type");
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
if (sqlType.Equals("MYSQL", StringComparison.OrdinalIgnoreCase) || sqlType.Equals("MARIADB", StringComparison.OrdinalIgnoreCase)) {
sql = new Mysql();
}
else if (sqlType.Equals("MSSQL", StringComparison.OrdinalIgnoreCase)) {
sql = new Mssql();
}
else if (sqlType.Equals("SQLITE", StringComparison.OrdinalIgnoreCase)) {
sql = new Sqlite(prgm_path);
}
2025-03-03 22:16:47 +01:00
}
public void DeleteOldData() {
sql.CheckTableExists();
sql.DeleteOldData(Dns.GetHostName());
2025-03-03 22:16:47 +01:00
}
public void createList(string hkey, string bit) {
2025-03-03 22:16:47 +01:00
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());
//
// 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);
}
}
}
}