private void RunDownload(Object obj) { bWorking = true; ExtensionItem dataItem = (ExtensionItem)((Object[])obj)[0]; if (dataItem.Downloaded == "NO") { Extension extension = dataItem.Extension; if (null != extension && extension.Source == eSource.WEB) { extension.Errors.Clear(); extension.DownloadZip(); extension.UnZip(); if (extension.smallBasicExtension.dllFiles.numFile == 0) { extension.Errors.Add("No dll files in download zip"); } else { extension.Verify(extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.dllFiles.Files[0].File); } extension.Validate(); if (extension.Valid) { //MessageBox.Show("Extension Download Succeeded", "Small Basic Extension Manager", MessageBoxButton.OK, MessageBoxImage.Information); } else { string message = ""; foreach (string Error in extension.Errors) { message += Error + "\n"; } MessageBox.Show(message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error); try { if (CheckAccess()) { extension.Unload(); LoadExtensions(); } else { Dispatcher.Invoke(() => { extension.Unload(); LoadExtensions(); }); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error); } } } } bWorking = false; }
private void ShowControls() { for (int i = 0; i < dataGridExtensions.Items.Count; i++) { DataGridRow row = (DataGridRow)dataGridExtensions.ItemContainerGenerator.ContainerFromIndex(i); if (null != row) { for (int j = 0; j < dataGridExtensions.Columns.Count; j++) { var cellContent = dataGridExtensions.Columns[j].GetCellContent(row); if (null != cellContent) { if (cellContent.GetType() == typeof(TextBlock)) { TextBlock control = (TextBlock)cellContent; //object item = dataGridExtensions.Items[i]; //dataGridExtensions.SelectedItem = item; //dataGridExtensions.ScrollIntoView(item); } else if (cellContent.GetType() == typeof(ContentPresenter)) { ContentPresenter control = (ContentPresenter)cellContent; ExtensionItem item = (ExtensionItem)control.Content; if (dataGridExtensions.Columns[j].Header.ToString() == "Install") { if (item.Name == "" || item.Location == "LOCAL" || item.Downloaded == "NO" || !item.Extension.Valid) { control.Visibility = Visibility.Hidden; } } else if (dataGridExtensions.Columns[j].Header.ToString() == "UnInstall") { if (item.Installed == "NO" || item.Location == "LOCAL" || !item.Extension.Valid) { control.Visibility = Visibility.Hidden; } } else if (dataGridExtensions.Columns[j].Header.ToString() == "Download") { if (item.Location == "LOCAL") { control.Visibility = Visibility.Hidden; } } control.IsEnabled = !bWorking; } } } } } }
private void OnInstall(object sender, RoutedEventArgs e) { if (bWorking) { return; } try { Button button = (Button)sender; ExtensionItem dataItem = (ExtensionItem)button.DataContext; if (dataItem.Downloaded == "YES") { Extension extension = dataItem.Extension; string command = "cd \"" + textBoxInstallationPath.Text + "\\lib\""; if (null != extension && extension.Source == eSource.WEB && extension.Valid) { for (int i = 0; i < extension.smallBasicExtension.dllFiles.numFile; i++) { string file = extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.dllFiles.Files[i].File; string newFile = textBoxInstallationPath.Text + "\\lib\\" + Path.GetFileName(file); command += " & del \"" + newFile + "\""; command += " & copy /B/Y \"" + file + "\" \"" + newFile + "\""; //File.Delete(newFile); //File.Copy(file, newFile); } for (int i = 0; i < extension.smallBasicExtension.xmlFiles.numFile; i++) { string file = extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.xmlFiles.Files[i].File; string newFile = textBoxInstallationPath.Text + "\\lib\\" + Path.GetFileName(file); command += " & del \"" + newFile + "\""; command += " & copy /B/Y \"" + file + "\" \"" + newFile + "\""; //File.Delete(newFile); //File.Copy(file, newFile); } } extension.UACcommand(command); //MessageBox.Show("Extension Install Succeeded", "Small Basic Extension Manager", MessageBoxButton.OK, MessageBoxImage.Information); LoadExtensions(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void OnDownload(object sender, RoutedEventArgs e) { if (bWorking) { return; } try { Button button = (Button)sender; ExtensionItem dataItem = (ExtensionItem)button.DataContext; thread = new Thread(new ParameterizedThreadStart(RunDownload)); thread.Start(new Object[] { dataItem }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void LoadExtensions() { dataGridExtensions.Items.Clear(); foreach (Extension extension in webExtension.extensions) { //if (!extension.Valid) continue; string installed = "NO"; string[] files = Directory.GetFiles(textBoxInstallationPath.Text + "\\lib"); foreach (string file in files) { if (Path.GetFileName(file) == extension.Name + ".dll") { Version ExtVersion = new Extension().GetVersion(file); if (ExtVersion == extension.ExtVersion) { installed = "YES"; } } } Uri uriWebsite; Uri uriAPI; Uri uriChangeLog; Uri.TryCreate(extension.smallBasicExtension.WebSite, UriKind.RelativeOrAbsolute, out uriWebsite); Uri.TryCreate(extension.smallBasicExtension.API, UriKind.RelativeOrAbsolute, out uriAPI); Uri.TryCreate(extension.smallBasicExtension.ChangeLog, UriKind.RelativeOrAbsolute, out uriChangeLog); double zipSize = 0; if (EMWindow.bWebAccess) { try { WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials; WebRequest webRequest = HttpWebRequest.Create(extension.smallBasicExtension.ZipLocation); webRequest.Method = "HEAD"; WebResponse webResponse = webRequest.GetResponse(); zipSize = webResponse.ContentLength; webResponse.Close(); } catch { EMWindow.bWebAccess = false; } } ExtensionItem rowItem = new ExtensionItem { Name = extension.Name, Description = null == extension.smallBasicExtension.Description ? "" : extension.smallBasicExtension.Description, Author = null == extension.smallBasicExtension.Author ? "" : extension.smallBasicExtension.Author, WebSite = uriWebsite, API = uriAPI, ChangeLog = uriChangeLog, SBVersion = null == extension.SBVersion ? extension.smallBasicExtension.SBVersion : extension.SBVersion.ToString(), ExtVersion = null == extension.ExtVersion ? extension.smallBasicExtension.ExtVersion : extension.ExtVersion.ToString(), ZipSize = zipSize <= 0 ? "" : string.Format("{0:0.###}", zipSize / 1024.0 / 1024.0), Installed = installed, Downloaded = extension.Downloaded ? "YES" : "NO", Location = extension.Source.ToString(), Extension = extension }; dataGridExtensions.Items.Add(rowItem); } localExtension.Load(textBoxInstallationPath.Text); foreach (Extension extension in localExtension.extensions) { foreach (Extension extension2 in webExtension.extensions) { if (extension.Name == extension2.Name) { extension.Valid = false; } } if (!extension.Valid) { continue; } ExtensionItem rowItem = new ExtensionItem { Name = extension.Name, //Description = "N/A", //Author = "Unknown", //WebSite = new Uri(""), //API = new Uri(""), //ChangeLog = new Uri(""), SBVersion = extension.SBVersion.ToString(), ExtVersion = extension.ExtVersion.ToString(), //ZipSize = "N/A", Installed = "YES", //Downloaded = "N/A", Location = extension.Source.ToString(), Extension = extension }; dataGridExtensions.Items.Add(rowItem); } dataGridExtensions.UpdateLayout(); ShowControls(); }