private async void ButtonLaunch_Click(object sender, RoutedEventArgs eventArg)
        {
            SoftwareModel soft = (SoftwareModel)DataGrid_SoftwareList.SelectedItem;

            if (soft == null)
            {
                return;
            }

            showLoading();

            try {
                int    timeout = int.Parse(TextBox_Timeout.Text);
                string path    = soft.path;
                string args    = TextBox_LaunchArgs.Text;

                var tasks = computers.Select(async(computer) => {
                    var r = new ValueOrError <WMIExecutionResult, Exception>();
                    try {
                        r.value = await Task.Run(async() => {
                            // Install on the current computer
                            return(await computer.installSoftware(path, new string[] { args }, timeout));
                        });
                    } catch (Exception e) {
                        r.error = e;
                    }

                    return(r);
                });

                var results = await Task.WhenAll(tasks);

                var reports = new List <WMIExecutionResult>();

                foreach (var result in results)
                {
                    if (result.hasValue())
                    {
                        reports.Add(result.value);
                    }
                    else
                    {
                        errorHandler.addError(result.error);
                        WarningImage.Visibility = Visibility.Visible;
                    }
                }

                // Show reports
                var reporter = new ExecutionReportsWindow(reports);
                reporter.Left = this.Left + 50;
                reporter.Top  = this.Top + 50;
                reporter.Show();
            } catch (Exception e) {
                WarningImage.Visibility = Visibility.Visible;
                errorHandler.addError(e);
            } finally {
                hideLoading();
            }
        }
        private void dataGrid_SoftwareList_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            SoftwareModel soft = (SoftwareModel)DataGrid_SoftwareList.SelectedItem;

            if (soft == null)
            {
                return;
            }

            string arg = subDirectoryParameters.GetValueOrDefault(Directory.GetParent(soft.path).Name);

            TextBox_LaunchArgs.Text      = arg == null ? "" : arg;
            TextBox_LaunchArgs.IsEnabled = !(soft.path.ToLower().EndsWith(".msi"));
        }
        private void AppsToDeploy_Loaded(object sender, RoutedEventArgs e)
        {
            string path = App.config.get("softwarepath");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            List <string> dirs = new List <string>();

            dirs.AddRange(Directory.GetFiles(path));

            foreach (var sub in subDirectoryParameters)
            {
                string subPath = $@"{path}\{sub.Key}";

                if (!Directory.Exists(subPath))
                {
                    Directory.CreateDirectory(subPath);
                }

                dirs.AddRange(Directory.GetFiles(subPath));
            }

            dirs.Sort();

            var data = new List <SoftwareModel>();

            foreach (var filePath in dirs)
            {
                var sysicon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
                var bmpSrc  = Imaging.CreateBitmapSourceFromHIcon(sysicon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                sysicon.Dispose();

                FileInfo fileInfo = new FileInfo(filePath);
                var      itm      = new SoftwareModel();
                itm.icon     = bmpSrc;
                itm.fileInfo = fileInfo;
                itm.size     = Utils.getBytesReadable(fileInfo.Length);
                itm.file     = fileInfo.Name;
                itm.path     = filePath;
                if (fileInfo.Extension == ".msi")
                {
                    itm.name    = Utils.getMsiProperty(filePath, "ProductName");
                    itm.version = Utils.getMsiProperty(filePath, "ProductVersion");
                    itm.company = Utils.getMsiProperty(filePath, "Manufacturer");
                }
                else
                {
                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(filePath);

                    itm.name    = fileVersionInfo.ProductName?.Trim();
                    itm.version = fileVersionInfo.FileVersion;
                    itm.company = fileVersionInfo.CompanyName?.Trim();
                }
                data.Add(itm);
            }

            DataGrid_SoftwareList.ItemsSource = data;
        }