コード例 #1
0
        private static IEnumerable <ScheduledTaskXmlModel> GetInstallerScheduledTasks(DirectoryInfo installDirectory)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(installDirectory + "\\Config");

            foreach (FileInfo file in directoryInfo.EnumerateFiles("*.xml", SearchOption.TopDirectoryOnly).Where(f => !f.Name.StartsWith("Monet", StringComparison.CurrentCulture)))
            {
                if (TryGetScheduledTaskXDocument(file, out XDocument xDoc))
                {
                    ScheduledTaskXmlModel scheduledTask = new ScheduledTaskXmlModel(file);
                    XNamespace            xNs           = xDoc.Root.GetDefaultNamespace();

                    //Not every file has a URI specified :(
                    XElement uri = xDoc.Root.Element(xNs + "RegistrationInfo").Element(xNs + "URI");
                    if (uri != null)
                    {
                        scheduledTask.Uri = uri.Value;
                    }

                    scheduledTask.Description = xDoc.Root.Element(xNs + "RegistrationInfo").Element(xNs + "Description").Value;
                    scheduledTask.Enabled     = bool.Parse(xDoc.Root.Element(xNs + "Settings").Element(xNs + "Enabled").Value);

                    string command   = xDoc.Root.Element(xNs + "Actions").Element(xNs + "Exec").Element(xNs + "Command").Value;
                    string arguments = xDoc.Root.Element(xNs + "Actions").Element(xNs + "Exec").Element(xNs + "Arguments").Value;
                    scheduledTask.Command = $"{command} {arguments}";

                    StaticViewModel.AddDebugMessage($"Found scheduled task {uri} in {file.FullName}");
                    yield return(scheduledTask);
                }
            }
        }
コード例 #2
0
        public void WaitForProcessToEnd(int maxWaitSeconds)
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (IsProcessRunning())
            {
                if (sw.ElapsedMilliseconds >= maxWaitSeconds * 1000)
                {
                    foreach (Process process in Process.GetProcessesByName(_fileNameWithoutExtension))
                    {
                        try
                        {
                            process.Kill();
                        }
                        catch (Exception ex)
                        {
                            StaticViewModel.AddDebugMessage(ex, $"Unable to stop process [{process.Id}] {process.ProcessName}");
                        }
                    }
                }

                Thread.Sleep(1000);
            }
        }
コード例 #3
0
        private static bool TryGetScheduledTaskXDocument(FileInfo file, out XDocument xDocument)
        {
            xDocument = null;

            if (file == null || !file.Exists)
            {
                return(false);
            }

            try
            {
                xDocument = XDocument.Load(file.FullName);
            }
            catch (XmlException)
            {
                //Some files have incorrect encoding :(
                //https://stackoverflow.com/questions/29915467/there-is-no-unicode-byte-order-mark-cannot-switch-to-unicode
                StaticViewModel.AddDebugMessage($"Wrong encoding for {file.FullName}");
                xDocument = XDocument.Parse(File.ReadAllText(file.FullName));
            }

            if (!xDocument.Root.Name.LocalName.Equals("Task", StringComparison.CurrentCulture))
            {
                return(false);
            }

            return(true);
        }
コード例 #4
0
        public AboutView()
        {
            InitializeComponent();

            lblVersion.Text = "Version: " + System.Windows.Forms.Application.ProductVersion;
            StaticViewModel.AddDebugMessage($"{nameof(RadeonSoftwareSlimmer)} version {System.Windows.Forms.Application.ProductVersion}");
        }
コード例 #5
0
        private static IEnumerable <PackageModel> GetAllInstallerPackages(DirectoryInfo installDirectory)
        {
            FileInfo[] packageFiles =
            {
                new FileInfo($@"{installDirectory.FullName}\Bin64\cccmanifest_64.json"),
                new FileInfo($@"{installDirectory.FullName}\Config\InstallManifest.json"),
            };

            foreach (FileInfo file in packageFiles)
            {
                if (file.Exists)
                {
                    using (StreamReader streamReader = new StreamReader(file.OpenRead()))
                        using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
                        {
                            JObject jObject = (JObject)JToken.ReadFrom(jsonTextReader);
                            JToken  jToken  = jObject.SelectToken("Packages.Package");
                            foreach (JToken token in jToken.Children())
                            {
                                PackageModel package = new PackageModel(file);
                                package.Description = token.SelectToken("Info.Description").ToString();
                                package.ProductName = token.SelectToken("Info.productName").ToString();
                                package.Url         = token.SelectToken("Info.url").ToString();
                                package.Type        = token.SelectToken("Info.ptype").ToString();

                                StaticViewModel.AddDebugMessage($"Found package {package.ProductName} in {package.GetFile().FullName}");
                                yield return(package);
                            }
                        }
                }
            }
        }
コード例 #6
0
        private static bool IsRadeonTask(Task scheduledTask)
        {
            string author = scheduledTask.Definition.RegistrationInfo.Author;

            if (!string.IsNullOrWhiteSpace(author) &&
                author.Equals("Advanced Micro Devices", StringComparison.OrdinalIgnoreCase))
            {
                return(true);
            }

            string name = scheduledTask.Name;

            if (!string.IsNullOrWhiteSpace(name) &&
                (
                    name.Equals("StartCN", StringComparison.OrdinalIgnoreCase) ||
                    name.Equals("StartDVR", StringComparison.OrdinalIgnoreCase) ||
                    name.Equals("StartCNBM", StringComparison.OrdinalIgnoreCase)))
            {
                StaticViewModel.AddDebugMessage($"Found scheduled task {name}");
                return(true);
            }


            return(false);
        }
コード例 #7
0
        private static void ClearFolder(string folder)
        {
            DirectoryInfo directoryInfo = new DirectoryInfo(folder);

            if (directoryInfo.Exists)
            {
                foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles())
                {
                    try
                    {
                        fileInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        StaticViewModel.AddDebugMessage(ex, $"Unable to delete {fileInfo.FullName}");
                    }
                }

                foreach (DirectoryInfo subDirectoryInfo in directoryInfo.EnumerateDirectories())
                {
                    ClearFolder(subDirectoryInfo.FullName);

                    try
                    {
                        subDirectoryInfo.Delete();
                    }
                    catch (Exception ex)
                    {
                        StaticViewModel.AddDebugMessage(ex, $"Unable to delete {subDirectoryInfo.FullName}");
                    }
                }
            }
        }
コード例 #8
0
 private void DetermineUninstallCommand()
 {
     //if (_windowsInstaller || UninstallCommand.StartsWith("msiexec", StringComparison.OrdinalIgnoreCase))
     if (_windowsInstaller)
     {
         _uninstallExe = "msiexec.exe";
         if (Guid.TryParse(ProductCode, out Guid productGuid))
         {
             _uninstallArguments = $"/uninstall {productGuid:B}";
             UninstallCommand    = $"{_uninstallExe} {_uninstallArguments}";
             StaticViewModel.AddDebugMessage($"Detected GUID {productGuid} from {ProductCode} for {DisplayName}");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Unable to determine windows installer GUID from {ProductCode} for {DisplayName}");
         }
     }
     else if (!string.IsNullOrWhiteSpace(UninstallCommand))
     {
         //_uninstallExe = "cmd.exe";
         //_uninstallArguments = $"/C \"{UninstallCommand}\"";
         //UninstallCommand = $"{_uninstallExe} {_uninstallArguments}";
         StaticViewModel.AddDebugMessage($"Keeping default uninstall command {UninstallCommand} for {DisplayName}");
     }
     else
     {
         StaticViewModel.AddDebugMessage($"Unable to determine uninstall command for {DisplayName}");
     }
 }
コード例 #9
0
        private void LoadInfFileInformation(IFileInfo infFile)
        {
            StaticViewModel.AddDebugMessage($"Processing inf file {infFile.FullName}");

            using (StreamReader reader = infFile.OpenText())
            {
                string line = string.Empty;
                do
                {
                    line = reader.ReadLine();
                    if (!string.IsNullOrWhiteSpace(line) && line.Equals("[Strings]", StringComparison.Ordinal))
                    {
                        while (!reader.EndOfStream && !string.IsNullOrWhiteSpace(line))
                        {
                            line = reader.ReadLine();

                            //Would love some consistency here
                            if (line.IndexOf("desc", StringComparison.OrdinalIgnoreCase) >= 0 && line.IndexOf("\"", StringComparison.OrdinalIgnoreCase) > 1)
                            {
                                StaticViewModel.AddDebugMessage($"Attempting to obtain inf file description from {line}");
                                Description = line.Substring(line.IndexOf("\"", StringComparison.OrdinalIgnoreCase)).Trim('\"');
                                return;
                            }
                            if (line.IndexOf("ExtendedGraphics", StringComparison.OrdinalIgnoreCase) >= 0 && line.IndexOf("\"", StringComparison.OrdinalIgnoreCase) > 1)
                            {
                                StaticViewModel.AddDebugMessage($"Attempting to obtain inf file description from {line}");
                                Description = line.Substring(line.IndexOf("\"", StringComparison.OrdinalIgnoreCase)).Trim('\"');
                                return;
                            }
                        }
                    }
                } while (!reader.EndOfStream);
            }
        }
コード例 #10
0
 private void DetermineUninstallCommand()
 {
     if (_windowsInstaller)
     {
         _uninstallExe = Environment.GetFolderPath(Environment.SpecialFolder.System) + "\\msiexec.exe";
         if (Guid.TryParse(ProductCode, out Guid productGuid))
         {
             _uninstallArguments = $"/uninstall {productGuid:B}";
             UninstallCommand    = $"{_uninstallExe} {_uninstallArguments}";
             StaticViewModel.AddDebugMessage($"Detected GUID {productGuid} from {ProductCode} for {DisplayName}");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Unable to determine windows installer GUID from {ProductCode} for {DisplayName}");
         }
     }
     else if (!string.IsNullOrWhiteSpace(UninstallCommand))
     {
         StaticViewModel.AddDebugMessage($"Keeping default uninstall command {UninstallCommand} for {DisplayName}");
     }
     else
     {
         StaticViewModel.AddDebugMessage($"Unable to determine uninstall command for {DisplayName}");
     }
 }
コード例 #11
0
        public void Remove()
        {
            if (Keep || !_componentDirectory.Exists)
            {
                return;
            }

            try
            {
                StaticViewModel.AddDebugMessage($"Removing {_componentDirectory.FullName}");

                foreach (IFileInfo file in _componentDirectory.EnumerateFiles("*", SearchOption.AllDirectories))
                {
                    if (file.IsReadOnly)
                    {
                        file.IsReadOnly = false;
                    }
                }

                _componentDirectory.Delete(true);
            }
            catch (Exception ex)
            {
                StaticViewModel.AddDebugMessage(ex, $"Unable to delete {_componentDirectory.FullName}");
            }
        }
コード例 #12
0
        private void LoadCnDirectory()
        {
            using (RegistryKey cnKey = Registry.LocalMachine.OpenSubKey(INSTALL_FOLDER_REGISTRY_KEY))
            {
                if (cnKey != null)
                {
                    string installDir = cnKey.GetValue(INSTALL_FOLDER_REGISTRY_VALUE_NAME).ToString();

                    if (string.IsNullOrWhiteSpace(installDir))
                    {
                        _cnDir = new DirectoryInfo(INSTALL_FOLDER_DEFAULT_PATH);
                        StaticViewModel.AddDebugMessage($"Unable to read {INSTALL_FOLDER_REGISTRY_VALUE_NAME} from {INSTALL_FOLDER_REGISTRY_KEY}. Defaulting to {INSTALL_FOLDER_DEFAULT_PATH}.");
                    }
                    else
                    {
                        _cnDir = new DirectoryInfo(installDir);
                        StaticViewModel.AddDebugMessage($"Found {installDir} from {INSTALL_FOLDER_REGISTRY_KEY}.");
                    }
                }
                else
                {
                    _cnDir = new DirectoryInfo(INSTALL_FOLDER_DEFAULT_PATH);
                    StaticViewModel.AddDebugMessage($"Unable to read from {INSTALL_FOLDER_REGISTRY_KEY}. Defaulting to {INSTALL_FOLDER_DEFAULT_PATH}.");
                }
            }
        }
コード例 #13
0
        public int RunProcess(string arguments)
        {
            if (!_file.Exists)
            {
                StaticViewModel.AddDebugMessage($"{_file.FullName} does not exist or user does not have access");
                return(-1);
            }

            using (Process process = new Process())
            {
                process.StartInfo.FileName               = _file.FullName;
                process.StartInfo.Arguments              = arguments;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.RedirectStandardError  = true;

                StaticViewModel.AddDebugMessage($"Running {process.StartInfo.FileName} {process.StartInfo.Arguments}");
                process.Start();
                process.WaitForExit();
                StaticViewModel.AddDebugMessage($"Process finished with ExitCode: {process.ExitCode}");
                StaticViewModel.AddDebugMessage($"StandardOutput: {process.StandardOutput.ReadToEnd()}");
                StaticViewModel.AddDebugMessage($"StandardError: {process.StandardError.ReadToEnd()}");

                return(process.ExitCode);
            }
        }
コード例 #14
0
        public AboutView()
        {
            InitializeComponent();

            lblVersion.Text = $"Version: {System.Windows.Forms.Application.ProductVersion} (.NET Version: {Environment.Version})";
            StaticViewModel.AddDebugMessage($"{nameof(RadeonSoftwareSlimmer)} version {System.Windows.Forms.Application.ProductVersion} (.NET version {Environment.Version})");
        }
コード例 #15
0
        private void CheckIfHostServiceIsEnabled()
        {
            _rsServFile         = new FileInfo(_cnDir.FullName + HOST_SERVICE_FILE_NAME);
            _rsServDisabledFile = new FileInfo(_cnDir + HOST_SERVICE_DISABLED_FILE_NAME);
            Enabled             = _rsServFile.Exists;

            StaticViewModel.AddDebugMessage($"{_rsServFile.FullName} Exists: {_rsServFile.Exists}");
            StaticViewModel.AddDebugMessage($"{_rsServDisabledFile.FullName} Exists: {_rsServDisabledFile.Exists}");
        }
コード例 #16
0
        private static IEnumerable <ServiceModel> GetAllRadeonServices()
        {
            string[] serviceNames =
            {
                //Values are the first string after AddService in inf files

                //Main display driver
                //Probably no point in showing this. Is there even a reason to remove it?
                //"amdkmdag",
                //"amdwddmg",

                //AMD PCI Root Bus Lower Filter
                //Probably shouldn't mess with this one either
                //"amdkmpfd",

                //System Devices/Kernel Drivers
                "amdfendr",
                "amdlog",
                "AMDXE",

                //Audio
                "amdacpbus",
                "AMDAfdAudioService",
                "AMDHDAudBusService",
                "amdi2stdmafd",
                "AMDSoundWireAudioService",
                "AtiHDAudioService",
                "AMDSAFD",

                //NT/Windows Services
                "AMD Crash Defender Service",
                "AMD External Events Utility",
                "AMD Log Utility",
                "AUEPLauncher",

                //Other
                "AMDRadeonsettings",

                //Radeon Pro Enterprise
                "amducsi",
                "SSGService",
            };

            foreach (string service in serviceNames)
            {
                ServiceModel serviceModel = new ServiceModel(service);

                if (serviceModel.Exists())
                {
                    StaticViewModel.AddDebugMessage($"Found service {service}");
                    yield return(serviceModel);
                }
            }
        }
コード例 #17
0
        public void StopRadeonSoftware()
        {
            StaticViewModel.AddDebugMessage("Stopping Radeon Software Host Service");
            RadeonSoftwareCli(CNCMD_EXIT);

            //The command to stop the services does not wait for them to fully end
            ProcessHandler hostProcess = new ProcessHandler(_cnDir.FullName + "AMDRSServ.exe");

            hostProcess.WaitForProcessToEnd(30);
            ProcessHandler radeonSoftwareProcess = new ProcessHandler(_cnDir.FullName + "RadeonSoftware.exe");

            radeonSoftwareProcess.WaitForProcessToEnd(30);
        }
コード例 #18
0
        public DisplayComponentModel(IDirectoryInfo installerRootDirectory, IDirectoryInfo componentDirectory)
        {
            StaticViewModel.AddDebugMessage($"Found display component in {componentDirectory.FullName}");

            Keep = true;

            _componentDirectory = componentDirectory;
            Directory           = componentDirectory.FullName.Substring(componentDirectory.FullName.IndexOf(installerRootDirectory.FullName) + installerRootDirectory.FullName.Length);
            IFileInfo[] infFiles = componentDirectory.GetFiles("*.inf", SearchOption.TopDirectoryOnly);
            if (infFiles.Length > 0)
            {
                InfFile = infFiles[0].Name;
                LoadInfFileInformation(infFiles[0]);
            }
        }
コード例 #19
0
        private bool IsRadeonUninstall(RegistryKey uninstallKey)
        {
            object publisher   = uninstallKey.GetValue("Publisher");
            object displayName = uninstallKey.GetValue("DisplayName");

            if (publisher != null && displayName != null &&
                publisher.ToString().Equals("Advanced Micro Devices, Inc.", StringComparison.OrdinalIgnoreCase) &&
                !AMD_CHIPSET_NAMES.Any(name => displayName.ToString().Contains(name)))
            {
                StaticViewModel.AddDebugMessage($"Found uninstall item {displayName} under {uninstallKey.Name}");
                return(true);
            }

            return(false);
        }
コード例 #20
0
 public void UninstallIfSelected()
 {
     if (_uninstall && !string.IsNullOrWhiteSpace(UninstallCommand))
     {
         if (_windowsInstaller)
         {
             ProcessHandler processHandler = new ProcessHandler(_uninstallExe);
             processHandler.RunProcess($"{_uninstallArguments} /quiet /norestart REBOOT=ReallySuppress");
         }
         else
         {
             StaticViewModel.AddDebugMessage($"Non-Windows Uninstaller for {DisplayName} not supported");
         }
     }
 }
コード例 #21
0
        public void Disable()
        {
            if (_rsServFile.Exists)
            {
                if (_rsServDisabledFile.Exists)
                {
                    StaticViewModel.AddDebugMessage($"Deleting previous disable file ${_rsServDisabledFile.FullName}");
                    _rsServDisabledFile.Delete();
                }

                StaticViewModel.AddDebugMessage($"Renaming {_rsServFile.Name} to {_rsServDisabledFile.Name}");
                _rsServFile.MoveTo(_rsServDisabledFile.FullName);

                StaticViewModel.AddDebugMessage("Host Service Disabled");
                Enabled = false;
            }
        }
コード例 #22
0
        public void Enable()
        {
            using (Task task = TaskService.Instance.GetTask(Name))
            {
                if (!task.Definition.Settings.Enabled)
                {
                    StaticViewModel.AddDebugMessage($"Enabling scheduled task {Name}");
                    task.Definition.Settings.Enabled = true;

                    task.RegisterChanges();

                    Active  = task.IsActive;
                    State   = task.State;
                    Enabled = task.Enabled;
                }
            }
        }
コード例 #23
0
        private static IEnumerable <TempFileModel> GetAllRadeonTempFiles()
        {
            string[] tempFolders =
            {
                //C:\AMD
                $@"{Environment.GetEnvironmentVariable("SystemDrive", EnvironmentVariableTarget.Process)}\AMD",

                //Computer\HKEY_LOCAL_MACHINE\SOFTWARE\ATI Technologies\Install,InstallDir,C:\Program Files\AMD\CIM
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CIM\Log",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CIM\Reports",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD_Common",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CN\Analytics",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\CN\NewsFeed",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\Dx9Cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\DxCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\GLCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\VkCache",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\AMD\Radeonsoftware\cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify)}\RadeonInstaller\cache",

                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\Dx9Cache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\DxCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\GLCache",
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.DoNotVerify)}\AppData\LocalLow\AMD\VkCache",

                //C:\Windows\System32\AMD
                $@"{Environment.GetFolderPath(Environment.SpecialFolder.System, Environment.SpecialFolderOption.DoNotVerify)}\AMD",
            };

            foreach (string tempFolder in tempFolders)
            {
                if (Directory.Exists(tempFolder))
                {
                    StaticViewModel.AddDebugMessage($"Found temp folder {tempFolder}");
                    yield return(new TempFileModel(tempFolder));
                }
                else
                {
                    StaticViewModel.AddDebugMessage($"Folder {tempFolder} does not exist or cannot be accessed");
                }
            }
        }
コード例 #24
0
        public void TryStop()
        {
            if (_serviceType.HasFlag(ServiceType.KernelDriver))
            {
                StaticViewModel.AddLogMessage($"Cannot stop {Name} because it is a kernel driver");
                return;
            }

            try
            {
                StaticViewModel.AddLogMessage("Stopping " + Name);
                StaticViewModel.IsLoading = true;

                using (ServiceController serviceController = LoadFreshService())
                {
                    if (serviceController.Status == ServiceControllerStatus.Running && serviceController.ServiceType.HasFlag(ServiceType.Win32OwnProcess))
                    {
                        try
                        {
                            serviceController.Stop();
                            serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(30));
                        }
                        catch (InvalidOperationException ex)
                        {
                            StaticViewModel.AddDebugMessage(ex);
                        }

                        Status = serviceController.Status;
                    }
                }

                StaticViewModel.AddLogMessage("Stopped " + Name);
            }
            catch (Exception ex)
            {
                StaticViewModel.AddLogMessage(ex, "Failed to stop " + Name);
            }
            finally
            {
                StaticViewModel.IsLoading = false;
            }
        }
コード例 #25
0
        public void Enable()
        {
            if (_rsServDisabledFile.Exists)
            {
                StaticViewModel.AddDebugMessage($"{_rsServDisabledFile.FullName} exists, attmpting to restore default file name");

                if (_rsServFile.Exists)
                {
                    StaticViewModel.AddDebugMessage($"{_rsServFile.FullName} already exists. Leaving files alone.");
                }
                else
                {
                    StaticViewModel.AddDebugMessage($"Renaming {_rsServDisabledFile.Name} to {_rsServFile.Name}");
                    _rsServDisabledFile.MoveTo(_rsServFile.FullName);
                }

                StaticViewModel.AddDebugMessage("Host Service Enabled");
                Enabled = true;
            }
        }
コード例 #26
0
        public static void RemovePackage(PackageModel packageToRemove)
        {
            if (packageToRemove == null)
            {
                throw new NullReferenceException();
            }

            JObject fullJson;

            StaticViewModel.AddDebugMessage($"Removing package {packageToRemove.ProductName} from {packageToRemove.File.FullName}");

            using (StreamReader streamReader = new StreamReader(packageToRemove.File.FullName))
                using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader))
                {
                    fullJson = (JObject)JToken.ReadFrom(jsonTextReader);
                    JToken jToken = fullJson.SelectToken("Packages.Package");
                    foreach (JToken token in jToken.Children())
                    {
                        PackageModel currentPackage = new PackageModel();
                        currentPackage.Description = token.SelectToken("Info.Description").ToString();
                        currentPackage.ProductName = token.SelectToken("Info.productName").ToString();
                        currentPackage.Url         = token.SelectToken("Info.url").ToString();
                        currentPackage.Type        = token.SelectToken("Info.ptype").ToString();
                        currentPackage.File        = packageToRemove.File;

                        if (currentPackage.Equals(packageToRemove))
                        {
                            token.Remove();
                            break;
                        }
                    }
                }

            using (StreamWriter streamWriter = new StreamWriter(packageToRemove.File.FullName))
                using (JsonTextWriter jsonTextWriter = new JsonTextWriter(streamWriter))
                {
                    jsonTextWriter.Formatting = Formatting.Indented;
                    fullJson.WriteTo(jsonTextWriter);
                }
        }
コード例 #27
0
        public void WaitForProcessToStart(int maxWaitSeconds)
        {
            if (!_file.Exists)
            {
                return;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();

            while (!IsProcessRunning())
            {
                if (sw.ElapsedMilliseconds >= maxWaitSeconds * 1000)
                {
                    StaticViewModel.AddDebugMessage($"Process {_file.Name} did not start");
                    return;
                }

                Thread.Sleep(1000);
            }
        }
コード例 #28
0
        private void LoadOriginalStartMode()
        {
            using (RegistryKey serviceKey = Registry.LocalMachine.OpenSubKey(SERVICES_REG_KEY + Name))
            {
                object original = serviceKey.GetValue(SERVICE_ORIGINAL_START_VALUE_NAME, null);

                if (original == null)
                {
                    SaveOriginalStartMode();
                    original = serviceKey.GetValue(SERVICE_ORIGINAL_START_VALUE_NAME, null);
                }

                if (original != null)
                {
                    OriginalStartMode = (ServiceStartMode)original;
                }
                else
                {
                    StaticViewModel.AddDebugMessage("Unable to determin original start mode");
                }
            }
        }
コード例 #29
0
        private void CalculateSize()
        {
            long          bytes         = 0;
            int           files         = 0;
            DirectoryInfo directoryInfo = new DirectoryInfo(Folder);

            foreach (FileInfo fileInfo in directoryInfo.EnumerateFiles("*.*", SearchOption.AllDirectories))
            {
                try
                {
                    bytes += fileInfo.Length;
                }
                catch (Exception ex)
                {
                    StaticViewModel.AddDebugMessage(ex, $"Unable to determine file size of {fileInfo.FullName}");
                }

                files++;
            }

            Files = files;
            Size  = GetFriendlySize(bytes);
        }
コード例 #30
0
 public void RestartRadeonSoftware()
 {
     StaticViewModel.AddDebugMessage("Restarting Radeon Software Host Service");
     RadeonSoftwareCli(CNCMD_RESTART);
 }