From b366d9fcfe5a1012ddec142dc136568dfd0236ec Mon Sep 17 00:00:00 2001 From: Vladimir Bondarevskiy Date: Mon, 29 May 2017 18:01:38 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D1=81=D0=B8=D0=BD=D1=85=D1=80=D0=BE?= =?UTF-8?q?=D0=BD=D0=BD=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OneCleaner/Model/Platform.cs | 187 ++++++++++---------- OneCleaner/ViewModel/MainWindowViewModel.cs | 12 +- 2 files changed, 104 insertions(+), 95 deletions(-) diff --git a/OneCleaner/Model/Platform.cs b/OneCleaner/Model/Platform.cs index 97fdb2b..dd3d548 100644 --- a/OneCleaner/Model/Platform.cs +++ b/OneCleaner/Model/Platform.cs @@ -13,74 +13,80 @@ namespace OneCleaner { public class Platform { - public static List GetCache() + public static Task> GetCache() { - List cache = new List(); - - 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 = new List(); - 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 GetInstalledVersions() + public static Task> GetInstalledVersions() { - List installedVersions = new List(); - - var key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; - var localMachine32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); - var keyUninstall32 = localMachine32.OpenSubKey(key); - - var keysUninstall = new List() { keyUninstall32 }; - if (Environment.Is64BitOperatingSystem) + return Task.Run(() => { - var localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); - var keyUninstall64 = localMachine64.OpenSubKey(key); - keysUninstall.Add(keyUninstall64); - } + List installedVersions = new List(); - 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() { 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 Uninstall(string uuid) @@ -124,43 +130,46 @@ namespace OneCleaner }); } - public static List GetInfoBases() + public static Task> GetInfoBases() { - List infoBases = new List(); - - 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 infoBases = new List(); - 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) diff --git a/OneCleaner/ViewModel/MainWindowViewModel.cs b/OneCleaner/ViewModel/MainWindowViewModel.cs index ac3dd48..a26b0a9 100644 --- a/OneCleaner/ViewModel/MainWindowViewModel.cs +++ b/OneCleaner/ViewModel/MainWindowViewModel.cs @@ -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()