private void buttonBinaryUpdate_Click(object sender, EventArgs e)
        {
            TableLayoutControlCollection tableLayoutCtrlColl = this.tableLayoutPanel.Controls;

            System.Windows.Forms.Control labelBinaryName = tableLayoutCtrlColl[this.labelBinaryName.Name];
            System.Windows.Forms.Control labelLatestVer  = tableLayoutCtrlColl[this.labelBinaryLatestVer.Name];
            System.Windows.Forms.Control labelCurVer     = tableLayoutCtrlColl[this.labelBinaryYourVer.Name];
            string binaryName     = labelBinaryName.Text;
            string currentVersion = labelCurVer.Text;

            if (DialogResult.Yes == MessageBox.Show((IWin32Window)sender, string.Format("Are you sure you want to add {0} {1} with version {2} to the repository?",
                                                                                        this.binaryType, binaryName, currentVersion), "Update Repository", MessageBoxButtons.YesNo,
                                                    MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
            {
                string[] filePaths = new string[0];
                bool     success   = BinaryPackagerHelper.Package(this.binaryRootDir, binaryName, false /*singleBin*/, "dll",
                                                                  this.binaryType, this.repositoryDir, ref filePaths, this.logger);
                if (!success)
                {
                    logger.Error("Failed to create {0} update packages", this.binaryType);
                }
                List <MainForm.BinaryPackageItem> binaryPackageItemList = new List <MainForm.BinaryPackageItem>();
                binaryPackageItemList.Add(new MainForm.BinaryPackageItem(this.binaryType, filePaths));
                UpdateRepositoryBinaries(binaryPackageItemList);
            }
        }
        private void buttonPlatUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                TableLayoutControlCollection tableLayoutCtrlColl = this.tableLayoutPanelPlatform.Controls;
                System.Windows.Forms.Control labelDepVer         = tableLayoutCtrlColl[this.labelPlatDeployedVer.Name];
                System.Windows.Forms.Control labelCurVer         = tableLayoutCtrlColl[this.labelPlatYourVer.Name];
                // string hubId = checkbox.Text;
                string  deployedVersion = labelDepVer.Text;
                string  currentVersion  = labelCurVer.Text;
                string  platformDirPath = "";
                Version latestVersion   = null;
                string  platformRootDir = this.textBoxSetupWorkingFolder.Text + "\\binaries\\Platform";
                string  repositoryDir   = this.textBoxSetupWorkingFolder.Text + "\\HomeStore\\Repository";
                string  ftpHost         = this.formRepoAccountInfo.RepoAccountHost;
                string  ftpPort         = this.formRepoAccountInfo.RepoAccountPort;
                string  ftpUser         = this.formRepoAccountInfo.RepoAccountLogin;
                string  ftpPassword     = this.formRepoAccountInfo.RepoAccountPassword;

                // make sure you are updating to a higher version
                Version versionDeployed = new Version(deployedVersion);
                Version versionCurrent  = new Version(currentVersion);

                if (versionCurrent <= versionDeployed)
                {
                    MessageBox.Show(string.Format("Only Updates to higher versions of the platform are permissable, please update the version!"),
                                    "Update Platform",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation
                                    );
                    return;
                }

                if (DialogResult.Yes == MessageBox.Show((IWin32Window)sender, string.Format("Are you sure you want to update the platform from the deployed version {0} to your current version {1}?", deployedVersion, currentVersion), "Update Platform", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button2))
                {
                    string[] filePaths = new string[0];
                    bool     success   = BinaryPackagerHelper.Package(platformRootDir, MainForm.PlatformFilename, true /*singleBin*/, "exe", "platform", repositoryDir, ref filePaths, this.logger);
                    if (!success)
                    {
                        throw new Exception("Failed to create platform update packages");
                    }

                    Debug.Assert(filePaths.Length == 2);

                    for (int i = 0; i < filePaths.Length; ++i)
                    {
                        string[] ftpFileLocations = filePaths[i].Split(new[] { repositoryDir }, StringSplitOptions.RemoveEmptyEntries);
                        if (ftpFileLocations.Length > 0 && !string.IsNullOrWhiteSpace(ftpFileLocations[0]))
                        {
                            string ftpFilePath = ftpFileLocations[0].Replace("\\", "/");
                            string ftpDirPath  = ftpFilePath.Substring(0, ftpFilePath.LastIndexOf("/"));
                            Uri    uriFile     = new Uri(ftpHost + ":" + ftpPort + ftpFilePath);
                            string subDirPath  = "";
                            foreach (string subdir in ftpDirPath.Split(new[] { "/" }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                subDirPath += ("/" + subdir);
                                if (platformDirPath.Length == 0 && subDirPath.ToLower().Contains(PlatformName.ToLower()))
                                {
                                    platformDirPath = subDirPath;
                                }
                                if (subdir.Contains('.'))
                                {
                                    // assume this is the version number of the type x.x.x.x
                                    latestVersion = new Version(subdir);
                                }
                                Uri uriDir = new Uri(ftpHost + ":" + ftpPort + subDirPath);
                                if (!MainForm.IsFtpRemoteDirectoryPresent(uriDir, ftpUser, ftpPassword))
                                {
                                    SecureFtpRepoUpdate.MakeDirectory(uriDir, ftpUser, ftpPassword, true);
                                }
                            }

                            SecureFtpRepoUpdate.UploadFile(uriFile, filePaths[i], ftpUser, ftpPassword, true);
                        }
                    }
                    // update the latest folder for the platform, if this is highest version or if there is no latest folder at all
                    Uri    uriPlatformDir       = new Uri(ftpHost + ":" + ftpPort + platformDirPath);
                    string platformLatestDir    = ftpHost + ":" + ftpPort + platformDirPath + "/Latest";
                    Uri    uriPlatformLatestDir = new Uri(platformLatestDir);
                    if (!MainForm.IsFtpRemoteDirectoryPresent(uriPlatformLatestDir, ftpUser, ftpPassword) || MainForm.GetFtpHighestVersionFromDir(uriPlatformDir, ftpUser, ftpPassword, this.logger) == latestVersion)
                    {
                        for (int i = 0; i < filePaths.Length; ++i)
                        {
                            string filename = filePaths[i].Substring(filePaths[i].LastIndexOf('\\') + 1);
                            Uri    uriFile  = new Uri(platformLatestDir + "/" + filename);
                            if (!MainForm.IsFtpRemoteDirectoryPresent(uriPlatformLatestDir, ftpUser, ftpPassword))
                            {
                                SecureFtpRepoUpdate.MakeDirectory(uriPlatformLatestDir, ftpUser, ftpPassword, true);
                            }

                            SecureFtpRepoUpdate.UploadFile(uriFile, filePaths[i], ftpUser, ftpPassword, true);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                this.logger.ErrorException("Exception while trying to update platform on the ftp server", exception);
                outputBox.Text += "Exception while trying to update platform on the ftp server" + exception + "\r\n";
            }
        }