1
0
mirror of https://github.com/vbondarevsky/OneCleaner.git synced 2026-06-09 00:16:14 +02:00

Асинхронное получение списков

This commit is contained in:
Vladimir Bondarevskiy
2017-05-29 18:01:38 +03:00
parent 7f2728b376
commit b366d9fcfe
2 changed files with 104 additions and 95 deletions
+98 -89
View File
@@ -13,74 +13,80 @@ namespace OneCleaner
{
public class Platform
{
public static List<Cache> GetCache()
public static Task<List<Cache>> GetCache()
{
List<Cache> cache = new List<Cache>();
var localAppData = Environment.GetEnvironmentVariable("LOCALAPPDATA");
var directory = Path.Combine(localAppData, "1C");
Regex reg = new Regex(@"[0-9a-zA-F]{8}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{12}$");
foreach (var path in Directory.GetDirectories(directory, "1cv8*"))
return Task.Run(() =>
{
var dirs = Directory.GetDirectories(path).Where(p => reg.IsMatch(p)).ToList();
List<Cache> cache = new List<Cache>();
foreach (var dir in dirs)
var localAppData = Environment.GetEnvironmentVariable("LOCALAPPDATA");
var directory = Path.Combine(localAppData, "1C");
Regex reg = new Regex(@"[0-9a-zA-F]{8}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{4}-[0-9a-zA-F]{12}$");
foreach (var path in Directory.GetDirectories(directory, "1cv8*"))
{
cache.Add(new Cache() { Path = dir, UUID = Path.GetFileName(dir), Size = Utility.GetDirectorySize(dir) });
}
}
var dirs = Directory.GetDirectories(path).Where(p => reg.IsMatch(p)).ToList();
return cache;
foreach (var dir in dirs)
{
cache.Add(new Cache() { Path = dir, UUID = Path.GetFileName(dir), Size = Utility.GetDirectorySize(dir) });
}
}
return cache;
});
}
public static List<InstalledVersion> GetInstalledVersions()
public static Task<List<InstalledVersion>> GetInstalledVersions()
{
List<InstalledVersion> installedVersions = new List<InstalledVersion>();
var key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
var localMachine32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
var keyUninstall32 = localMachine32.OpenSubKey(key);
var keysUninstall = new List<RegistryKey>() { keyUninstall32 };
if (Environment.Is64BitOperatingSystem)
return Task.Run(() =>
{
var localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var keyUninstall64 = localMachine64.OpenSubKey(key);
keysUninstall.Add(keyUninstall64);
}
List<InstalledVersion> installedVersions = new List<InstalledVersion>();
foreach (var keyUninstall in keysUninstall)
{
foreach (var itemUUID in keyUninstall.GetSubKeyNames())
var key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
var localMachine32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
var keyUninstall32 = localMachine32.OpenSubKey(key);
var keysUninstall = new List<RegistryKey>() { keyUninstall32 };
if (Environment.Is64BitOperatingSystem)
{
var itemKey = keyUninstall.OpenSubKey(itemUUID);
if (itemKey == null)
continue;
var name = (string)itemKey.GetValue("DisplayName", null);
var vendor = (string)itemKey.GetValue("Publisher", null);
var version = (string)itemKey.GetValue("DisplayVersion", "0.0.0.0");
var location = (string)itemKey.GetValue("InstallLocation", "");
var dateStr = (string)itemKey.GetValue("InstallDate", "00010101");
if (name == null || !IsPlatform1C(vendor) || String.IsNullOrEmpty(location))
continue;
InstalledVersion instVerItem = new InstalledVersion
{
Name = name,
Version = version,
UUID = itemUUID,
Location = location,
InstallDate = DateTime.ParseExact(dateStr, "yyyyMMdd", CultureInfo.InvariantCulture),
Size = Utility.GetDirectorySize(location)
};
installedVersions.Add(instVerItem);
var localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var keyUninstall64 = localMachine64.OpenSubKey(key);
keysUninstall.Add(keyUninstall64);
}
}
return installedVersions;
foreach (var keyUninstall in keysUninstall)
{
foreach (var itemUUID in keyUninstall.GetSubKeyNames())
{
var itemKey = keyUninstall.OpenSubKey(itemUUID);
if (itemKey == null)
continue;
var name = (string)itemKey.GetValue("DisplayName", null);
var vendor = (string)itemKey.GetValue("Publisher", null);
var version = (string)itemKey.GetValue("DisplayVersion", "0.0.0.0");
var location = (string)itemKey.GetValue("InstallLocation", "");
var dateStr = (string)itemKey.GetValue("InstallDate", "00010101");
if (name == null || !IsPlatform1C(vendor) || String.IsNullOrEmpty(location))
continue;
InstalledVersion instVerItem = new InstalledVersion
{
Name = name,
Version = version,
UUID = itemUUID,
Location = location,
InstallDate = DateTime.ParseExact(dateStr, "yyyyMMdd", CultureInfo.InvariantCulture),
Size = Utility.GetDirectorySize(location)
};
installedVersions.Add(instVerItem);
}
}
return installedVersions;
});
}
public static Task<bool> Uninstall(string uuid)
@@ -124,43 +130,46 @@ namespace OneCleaner
});
}
public static List<InfoBase> GetInfoBases()
public static Task<List<InfoBase>> GetInfoBases()
{
List<InfoBase> infoBases = new List<InfoBase>();
var localAppData = Environment.GetEnvironmentVariable("APPDATA");
var ibases = Path.Combine(localAppData, "1C", "1CEStart", "ibases.v8i");
var parser = new FileIniDataParser();
parser.Parser.Configuration.AllowDuplicateSections = true;
parser.Parser.Configuration.AllowDuplicateKeys = true;
IniData data = parser.ReadFile(ibases);
InfoBase infoBase;
foreach (var section in data.Sections)
return Task.Run(() =>
{
if (section.Keys["Connect"] != null)
{
infoBase = new InfoBase()
{
Name = section.SectionName,
Connection = section.Keys["Connect"],
UUID = section.Keys["ID"]
};
string path;
if (infoBase.Connection.StartsWith("File"))
{
path = infoBase.Connection.Substring(6, infoBase.Connection.Length - 8);
if (Directory.Exists(path))
infoBase.Size = Utility.GetDirectorySize(path);
}
infoBases.Add(infoBase);
}
}
List<InfoBase> infoBases = new List<InfoBase>();
return infoBases;
var localAppData = Environment.GetEnvironmentVariable("APPDATA");
var ibases = Path.Combine(localAppData, "1C", "1CEStart", "ibases.v8i");
var parser = new FileIniDataParser();
parser.Parser.Configuration.AllowDuplicateSections = true;
parser.Parser.Configuration.AllowDuplicateKeys = true;
IniData data = parser.ReadFile(ibases);
InfoBase infoBase;
foreach (var section in data.Sections)
{
if (section.Keys["Connect"] != null)
{
infoBase = new InfoBase()
{
Name = section.SectionName,
Connection = section.Keys["Connect"],
UUID = section.Keys["ID"]
};
string path;
if (infoBase.Connection.StartsWith("File"))
{
path = infoBase.Connection.Substring(6, infoBase.Connection.Length - 8);
if (Directory.Exists(path))
infoBase.Size = Utility.GetDirectorySize(path);
}
infoBases.Add(infoBase);
}
}
return infoBases;
});
}
private static bool IsPlatform1C(string vendor)
+6 -6
View File
@@ -85,28 +85,28 @@ namespace OneCleaner
Status = Status.Idle;
}
private void PopulateInfoBases()
private async void PopulateInfoBases()
{
InfoBases.Clear();
foreach (var item in Platform.GetInfoBases())
foreach (var item in await Platform.GetInfoBases())
{
InfoBases.Add(new InfoBaseItemViewModel() { Name = item.Name, UUID = item.UUID, Size = item.Size, Connection = item.Connection });
}
}
private void PopulateCache()
private async void PopulateCache()
{
Cache.Clear();
foreach (var item in Platform.GetCache())
foreach (var item in await Platform.GetCache())
{
Cache.Add(new CacheItemViewModel() { Path = item.Path, UUID = item.UUID, Size = item.Size });
}
}
private void PopulateInstalledVersions()
private async void PopulateInstalledVersions()
{
InstalledVersions.Clear();
foreach (var item in Platform.GetInstalledVersions())
foreach (var item in await Platform.GetInstalledVersions())
{
InstalledVersions.Add(
new InstalledVersionItemViewModel()