private void OnButtonClicked(object sender, RoutedEventArgs e)
        {
            if (bWorking)
            {
                return;
            }

            try
            {
                EMButton button = (EMButton)sender;
                if (button.GetState() == EMButton.eState.INSTALL || button.GetState() == EMButton.eState.UPDATE)
                {
                    Extension extension = (Extension)button.Tag;
                    thread = new Thread(new ParameterizedThreadStart(RunInstall));
                    thread.Start(new Object[] { button, extension, true });
                }
                else if (button.GetState() == EMButton.eState.INSTALLED)
                {
                    Extension extension = (Extension)button.Tag;
                    thread = new Thread(new ParameterizedThreadStart(RunDisable));
                    thread.Start(new Object[] { button, extension });
                }
                else if (button.GetState() == EMButton.eState.DISABLED)
                {
                    Extension extension = (Extension)button.Tag;
                    thread = new Thread(new ParameterizedThreadStart(RunEnable));
                    thread.Start(new Object[] { button, extension });
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void OnMenuItemClicked(object sender, RoutedEventArgs e)
        {
            MenuItem  item      = (MenuItem)sender;
            EMButton  button    = (EMButton)item.Tag;
            Extension extension = (Extension)button.Tag;

            switch (item.Name)
            {
            case "Install":
                try
                {
                    if (!bWorking)
                    {
                        thread = new Thread(new ParameterizedThreadStart(RunInstall));
                        thread.Start(new Object[] { button, extension, true });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "Uninstall":
                try
                {
                    if (!bWorking)
                    {
                        thread = new Thread(new ParameterizedThreadStart(RunInstall));
                        thread.Start(new Object[] { button, extension, false });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "Disable":
                try
                {
                    if (bWorking)
                    {
                        return;
                    }
                    if (button.GetState() == EMButton.eState.INSTALLED || button.GetState() == EMButton.eState.UPDATE)
                    {
                        RunDisable(new Object[] { button, extension });
                    }
                    else if (button.GetState() == EMButton.eState.DISABLED)
                    {
                        RunEnable(new Object[] { button, extension });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "SBVersion":
                break;

            case "ExtVersion":
                break;

            case "InstalledVersion":
                break;

            case "Description":
                break;

            case "Author":
                break;

            case "WebSite":
                try
                {
                    if (null != extension.smallBasicExtension)
                    {
                        Process.Start(extension.smallBasicExtension.WebSite);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "API":
                try
                {
                    if (null != extension.smallBasicExtension)
                    {
                        Process.Start(extension.smallBasicExtension.API);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "APIgenerated":
                try
                {
                    ShowAPI(extension);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "ChangeLog":
                try
                {
                    if (null != extension.smallBasicExtension)
                    {
                        Process.Start(extension.smallBasicExtension.ChangeLog);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;

            case "SaveZip":
                try
                {
                    if (bWorking)
                    {
                        return;
                    }
                    if (null != extension.smallBasicExtension)
                    {
                        thread = new Thread(new ParameterizedThreadStart(RunDownload));
                        thread.Start(new Object[] { button, extension });
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
                break;
            }
        }
        private void RunInstall(Object obj)
        {
            bWorking = true;
            EMButton  button    = (EMButton)((Object[])obj)[0];
            Extension extension = (Extension)((Object[])obj)[1];
            bool      bInstall  = (bool)((Object[])obj)[2];

            if (null != extension && extension.Source == eSource.WEB)
            {
                if (button.GetState() == EMButton.eState.DISABLED)
                {
                    MessageBox.Show("Enable before installing or uninstalling", "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    bWorking = false;
                    return;
                }
                extension.Errors.Clear();
                extension.Valid = true;
                if (bInstall)
                {
                    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)
                {
                    string command = "cd \"" + installationPath + "\\lib\"";
                    if (null != extension && extension.Valid)
                    {
                        for (int i = 0; i < extension.smallBasicExtension.dllFiles.numFile; i++)
                        {
                            string file    = extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.dllFiles.Files[i].File;
                            string newFile = installationPath + "\\lib\\" + System.IO.Path.GetFileName(file);
                            command += " & del \"" + newFile + "\"";
                            if (bInstall)
                            {
                                command += " & copy /B/Y \"" + file + "\" \"" + newFile + "\"";
                            }
                        }
                        for (int i = 0; i < extension.smallBasicExtension.xmlFiles.numFile; i++)
                        {
                            string file    = extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.xmlFiles.Files[i].File;
                            string newFile = installationPath + "\\lib\\" + System.IO.Path.GetFileName(file);
                            command += " & del \"" + newFile + "\"";
                            if (bInstall)
                            {
                                command += " & copy /B/Y \"" + file + "\" \"" + newFile + "\"";
                            }
                        }
                    }
                    extension.UACcommand(command);
                    if (null != extension && extension.Valid && bInstall)
                    {
                        for (int i = 0; i < extension.smallBasicExtension.dllFiles.numFile; i++)
                        {
                            string file = extension.LocalUnZipPath + "\\" + extension.smallBasicExtension.dllFiles.Files[i].File;
                            Zone   zone = Zone.CreateFromUrl(file);
                            if (File.Exists(file) && zone.SecurityZone != SecurityZone.MyComputer)
                            {
                                MessageBox.Show(extension.smallBasicExtension.dllFiles.Files[i].File + " is internet blocked", "Small Basic Extension Manager Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                            }
                        }
                    }
                }
                if (bInstall && !extension.Valid)
                {
                    string message = "";
                    foreach (string Error in extension.Errors)
                    {
                        message += Error + "\n";
                    }
                    message += "\nDo you want to continue anyway?";
                    if (MessageBox.Show(message, "Small Basic Extension Manager Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes)
                    {
                        ZipFile zip  = ZipFile.Read(extension.LocalZip);
                        string  path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/" + extension.Name + "-" + extension.ExtVersion.ToString();
                        zip.ExtractAll(path, ExtractExistingFileAction.OverwriteSilently);
                        zip.Dispose();
                        extension.Valid = true; //We did it anyway
                    }
                    else
                    {
                        try
                        {
                            if (CheckAccess())
                            {
                                extension.Unload();
                            }
                            else
                            {
                                Dispatcher.Invoke(() => { extension.Unload(); });
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
                if (extension.Valid)
                {
                    try
                    {
                        if (CheckAccess())
                        {
                            GetButtonExtensionLists();
                            MakeButtons();
                            SetButtonExtensionLists();
                        }
                        else
                        {
                            Dispatcher.Invoke(() =>
                            {
                                GetButtonExtensionLists();
                                MakeButtons();
                                SetButtonExtensionLists();
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else if (null != extension && extension.Source == eSource.LOCAL && !bInstall)
            {
                if (MessageBox.Show("This will remove a local extension that cannot be reinstalled from this Extension Manager\nOK to proceed?", "Uninstall Local Extension", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                {
                    return;
                }
                string command = "cd \"" + installationPath + "\\lib\"";
                if (null != extension)
                {
                    string file = installationPath + "\\lib\\" + extension.Name + ".dll";
                    command += " & del \"" + file + "\"";
                    file     = installationPath + "\\lib\\" + extension.Name + ".xml";
                    command += " & del \"" + file + "\"";
                }
                extension.UACcommand(command);
                try
                {
                    if (!File.Exists(installationPath + "\\lib\\" + extension.Name + ".dll"))
                    {
                        if (CheckAccess())
                        {
                            GetButtonExtensionLists();
                            MakeButtons();
                            SetButtonExtensionLists();
                        }
                        else
                        {
                            Dispatcher.Invoke(() =>
                            {
                                GetButtonExtensionLists();
                                MakeButtons();
                                SetButtonExtensionLists();
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Small Basic Extension Manager Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            bWorking = false;
        }