Ejemplo n.º 1
0
        private void ftpImportButton_Click(object sender, EventArgs e)
        {
            using (var fileDialog = new OpenFileDialog())
            {
                fileDialog.Filter      = "nUpdate Project Files (*.nupdproj)|*.nupdproj";
                fileDialog.Multiselect = false;
                if (fileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    var importProject = UpdateProject.LoadProject(fileDialog.FileName);
                    ftpHostTextBox.Text = importProject.FtpHost;
                    ftpPortTextBox.Text = importProject.FtpPort.ToString(CultureInfo.InvariantCulture);
                    ftpUserTextBox.Text = importProject.FtpUsername;
                    ftpProtocolComboBox.SelectedIndex = importProject.FtpProtocol;
                    ftpModeComboBox.SelectedIndex     = importProject.FtpUsePassiveMode ? 0 : 1;
                    ftpDirectoryTextBox.Text          = importProject.FtpDirectory;
                    ftpPasswordTextBox.Focus();
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while importing project data.", ex,
                                    PopupButtons.Ok);
                }
            }
        }
Ejemplo n.º 2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (!Path.IsPathRooted(programPathTextBox.Text))
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Invalid path set.",
                                "The current path for the program data is not valid.", PopupButtons.Ok);
                return;
            }

            if (programPathTextBox.Text != Settings.Default.ProgramPath)
            {
                try
                {
                    var projectConfiguration = ProjectConfiguration.Load();
                    if (projectConfiguration != null)
                    {
                        foreach (
                            var project in
                            projectConfiguration.Select(config => UpdateProject.LoadProject(config.Path))
                            .Where(project => project.Packages != null))
                        {
                            foreach (var package in project.Packages)
                            {
                                package.LocalPackagePath = Path.Combine(programPathTextBox.Text, "Projects",
                                                                        project.Name,
                                                                        Directory.GetParent(package.LocalPackagePath).Name,
                                                                        Path.GetFileName(package.LocalPackagePath));
                            }

                            UpdateProject.SaveProject(project.Path, project);
                        }

                        CopyFilesRecursively(Settings.Default.ProgramPath, programPathTextBox.Text);
                    }
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while moving the program data.", ex,
                                    PopupButtons.Ok);
                    return;
                }
            }

            Settings.Default.Language =
                new CultureInfo(
                    languagesComboBox.GetItemText(languagesComboBox.SelectedItem).Split('-')[1].Trim());
            Settings.Default.ProgramPath = programPathTextBox.Text;
            Settings.Default.Save();
            Settings.Default.Reload();
            Close();
        }
Ejemplo n.º 3
0
        public UpdateProject OpenProject(string projectPath)
        {
            UpdateProject project;

            try
            {
                project = UpdateProject.LoadProject(projectPath);
            }
            catch (Exception ex)
            {
                Popup.ShowPopup(this, SystemIcons.Error, "Error while reading the project.", ex,
                                PopupButtons.Ok);
                return(null);
            }

            if (!project.SaveCredentials)
            {
                var credentialsDialog = new CredentialsDialog();
                if (credentialsDialog.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        _ftpPassword =
                            AesManager.Decrypt(Convert.FromBase64String(project.FtpPassword),
                                               credentialsDialog.Password.Trim(), credentialsDialog.Username.Trim());

                        if (project.Proxy != null)
                        {
                            _proxyPassword =
                                AesManager.Decrypt(Convert.FromBase64String(project.ProxyPassword),
                                                   credentialsDialog.Password.Trim(), credentialsDialog.Username.Trim());
                        }

                        if (project.UseStatistics)
                        {
                            _sqlPassword =
                                AesManager.Decrypt(Convert.FromBase64String(project.SqlPassword),
                                                   credentialsDialog.Password.Trim(), credentialsDialog.Username.Trim());
                        }
                    }
                    catch (CryptographicException)
                    {
                        Popup.ShowPopup(this, SystemIcons.Error, "Invalid credentials.",
                                        "The entered credentials are invalid.", PopupButtons.Ok);
                        return(null);
                    }
                }
Ejemplo n.º 4
0
        private void continueButton_Click(object sender, EventArgs e)
        {
            backButton.Enabled = true;
            if (_sender == optionTabPage)
            {
                if (importProjectRadioButton.Checked)
                {
                    wizardTabControl.SelectedTab = importTabPage;
                    _sender = importTabPage;
                }
                else if (shareProjectRadioButton.Checked)
                {
                    wizardTabControl.SelectedTab = shareTabPage;
                    _sender = shareTabPage;
                }
            }
            else if (_sender == importTabPage)
            {
                if (!ValidationManager.Validate(importTabPage))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                    "All fields need to have a value.", PopupButtons.Ok);
                    return;
                }

                if (!Path.IsPathRooted(projectToImportTextBox.Text) || !File.Exists(projectToImportTextBox.Text))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Invalid path.",
                                    "The given local path for the project is invalid.", PopupButtons.Ok);
                    return;
                }

                wizardTabControl.SelectedTab = importTabPage1;
                _sender = importTabPage1;
            }
            else if (_sender == importTabPage1)
            {
                if (!ValidationManager.Validate(importTabPage1))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                    "All fields need to have a value.", PopupButtons.Ok);
                    return;
                }

                if (_projectConfigurations.Any(item => item.Name == projectNameTextBox.Text))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Project already existing.",
                                    String.Format("A project with the name \"{0}\" does already exist.", projectNameTextBox.Text), PopupButtons.Ok);
                    return;
                }

                try
                {
                    string folderPath         = Path.Combine(Program.Path, "ImpProj");
                    string statisticsFilePath = Path.Combine(folderPath, "statistics.php");
                    string projectFilePath    = Path.Combine(folderPath,
                                                             String.Format("{0}.nupdproj", projectNameTextBox.Text));
                    Directory.CreateDirectory(folderPath);

                    var updateProject = UpdateProject.LoadProject(projectFilePath);
                    if (updateProject.UseStatistics)
                    {
                        Popup.ShowPopup(this, SystemIcons.Warning, "Incompatible project.", "This project cannot be imported because the support for projects using statistics is currently missing. It will be available in the next version(s) of nUpdate Administration.", PopupButtons.Ok);
                        Directory.Delete(folderPath);
                        return;
                    }

                    //if (updateProject.ConfigVersion != "3b2")
                    //{
                    //    Popup.ShowPopup(this, SystemIcons.Warning, "Incompatible project.", "This project is not compatible to this version of nUpdate Administration. Please download the newest version of nUpdate Administration and then export the project again.", PopupButtons.Ok);
                    //    Directory.Delete(folderPath);
                    //    return;
                    //}

                    updateProject.Path = projectFilePathTextBox.Text;
                    //if (updateProject.UseStatistics)
                    //{
                    //    var statisticsServers = Serializer.Deserialize<List<StatisticsServer>>(Path.Combine(Program.Path, "statservers.json"));
                    //    if (!statisticsServers.Any(item => item.WebUrl == updateProject.SqlWebUrl && item.DatabaseName == updateProject.SqlDatabaseName && item.Username == updateProject.SqlUsername))
                    //    {
                    //        if (Popup.ShowPopup(this, SystemIcons.Information, "New statistics server found.", "This project uses a statistics server that isn't currently available on this computer. Should nUpdate Administration add this server to your list?", PopupButtons.YesNo) == DialogResult.Yes)
                    //        {
                    //            statisticsServers.Add(new StatisticsServer(updateProject.SqlWebUrl, updateProject.SqlDatabaseName, updateProject.SqlUsername));
                    //            File.WriteAllText(Path.Combine(Program.Path, "statservers.json"), Serializer.Serialize(statisticsServers));
                    //        }
                    //    }
                    //}

                    UpdateProject.SaveProject(updateProject.Path, updateProject);

                    string projectPath = Path.Combine(Program.Path, "Projects", projectNameTextBox.Text);
                    if (!Directory.Exists(projectPath))
                    {
                        Directory.CreateDirectory(projectPath);
                    }

                    using (var zip = new ZipFile(projectToImportTextBox.Text))
                    {
                        zip.ExtractAll(folderPath);
                    }

                    if (File.Exists(statisticsFilePath))
                    {
                        File.Move(statisticsFilePath, Path.Combine(projectPath, "statistics.php"));
                    }
                    File.Move(projectFilePath, projectFilePathTextBox.Text);

                    foreach (var versionDirectory in new DirectoryInfo(folderPath).GetDirectories())
                    {
                        Directory.Move(versionDirectory.FullName, Path.Combine(projectPath, versionDirectory.Name));
                    }

                    Directory.Delete(folderPath);
                    _projectConfigurations.Add(new ProjectConfiguration(projectNameTextBox.Text,
                                                                        projectFilePathTextBox.Text));
                    File.WriteAllText(Program.ProjectsConfigFilePath, Serializer.Serialize(_projectConfigurations));
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while importing the project.", ex, PopupButtons.Ok);
                    return;
                }

                Close();
            }
            else if (_sender == shareTabPage)
            {
                wizardTabControl.SelectedTab = shareTabPage1;
                _sender = shareTabPage1;
            }
            else if (_sender == shareTabPage1)
            {
                if (!ValidationManager.Validate(shareTabPage1))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Missing information found.",
                                    "All fields need to have a value.", PopupButtons.Ok);
                    return;
                }

                if (!Path.IsPathRooted(projectOutputPathTextBox.Text))
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Invalid path.",
                                    "The given local path for the project is invalid.", PopupButtons.Ok);
                    return;
                }

                try
                {
                    string projectPath = Path.Combine(Program.Path, "Projects", projectsListBox.SelectedItem.ToString());
                    using (var zip = new ZipFile())
                    {
                        string statisticsFilePath = Path.Combine(projectPath, "statistics.php");
                        if (File.Exists(statisticsFilePath))
                        {
                            zip.AddFile(statisticsFilePath, "/");
                        }
                        zip.AddFile(
                            _projectConfigurations.First(item => item.Name == projectsListBox.SelectedItem.ToString())
                            .Path, "/");

                        foreach (
                            var versionDirectory in
                            new DirectoryInfo(projectPath).GetDirectories()
                            .Where(item => UpdateVersion.IsValid(item.Name)))
                        {
                            zip.AddDirectoryByName(versionDirectory.Name);
                            zip.AddDirectory(versionDirectory.FullName, versionDirectory.Name);
                        }

                        zip.Save(projectOutputPathTextBox.Text);
                    }
                }
                catch (Exception ex)
                {
                    Popup.ShowPopup(this, SystemIcons.Error, "Error while sharing the project.", ex, PopupButtons.Ok);
                    return;
                }

                Close();
            }
        }