Ejemplo n.º 1
0
        public void InternalMoveContent(string directory, string aimPath)
        {
            foreach (FtpItem item in ListDirectoriesAndFiles(directory, false)
                     .Where(
                         item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
            {
                FtpClient ftp = null;
                try
                {
                    ftp = new FtpClient(Host, Port, Protocol)
                    {
                        DataTransferMode = UsePassiveMode ? TransferMode.Passive : TransferMode.Active,
                        FileTransferType = TransferType.Binary,
                        Proxy            = Proxy != null ? new HttpProxyClient(Proxy.Address.ToString()) : null
                    };
                    ftp.Open(Username, Password.ConvertToUnsecureString());

                    Guid guid; // Just for the out-reference of TryParse
                    if (item.ItemType == FtpItemType.Directory && UpdateVersion.IsValid(item.Name))
                    {
                        ftp.ChangeDirectoryMultiPath(aimPath);
                        if (!IsExisting(aimPath, item.Name))
                        {
                            ftp.MakeDirectory(item.Name);
                        }
                        ftp.ChangeDirectoryMultiPath(item.Name);

                        InternalMoveContent(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));
                        DeleteDirectory(item.FullPath);
                    }
                    else if (item.ItemType == FtpItemType.File &&
                             (item.Name == "updates.json" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
                    // Second condition determines whether the item is a package-file or not
                    {
                        if (!IsExisting(aimPath, item.Name))
                        {
                            // "MoveFile"-method damages the files, so we do it manually with a work-around
                            //ftp.MoveFile(item.FullPath, String.Format("{0}/{1}", aimPath, item.Name));

                            string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
                            ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
                            ftp.PutFile(localFilePath, String.Format("{0}/{1}", aimPath, item.Name),
                                        FileAction.Create);
                            File.Delete(localFilePath);
                        }
                        DeleteFile(item.ParentPath, item.Name);
                    }
                }
                finally
                {
                    if (ftp != null)
                    {
                        ftp.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void MoveContent(string directory, string aimPath)
        {
            foreach (var item in ListDirectoriesAndFiles(directory, false)
                     .Where(
                         item => item.FullPath != aimPath && item.FullPath != aimPath.Substring(aimPath.Length - 1)))
            {
                using (var ftp = GetNewFtpsClient())
                {
                    ftp.Open(Username, Password.ConvertToInsecureString());

                    Guid guid; // Just for the out-reference of TryParse
                    if (item.ItemType == ServerItemType.Directory && UpdateVersion.IsValid(item.Name))
                    {
                        ftp.ChangeDirectoryMultiPath(aimPath);
                        if (!IsExisting(aimPath, item.Name))
                        {
                            ftp.MakeDirectory(item.Name);
                        }
                        ftp.ChangeDirectoryMultiPath(item.Name);

                        MoveContent(item.FullPath, $"{aimPath}/{item.Name}");
                        DeleteDirectory(item.FullPath);
                    }
                    else if (item.ItemType == ServerItemType.File &&
                             (item.Name == "updates.json" || item.Name == "statistics.php" || Guid.TryParse(item.Name.Split('.')[0], out guid)))
                    // Second condition determines whether the item is a package-file or not
                    {
                        if (!IsExisting(aimPath, item.Name))
                        {
                            // "MoveFile"-method damages the files, so we do it manually with a work-around
                            ftp.MoveFile(item.FullPath, $"{aimPath}/{item.Name}");

                            /*string localFilePath = Path.Combine(Path.GetTempPath(), item.Name);
                             * ftp.GetFile(item.FullPath, localFilePath, FileAction.Create);
                             * ftp.PutFile(localFilePath, $"{aimPath}/{item.Name}",
                             *  FileAction.Create);
                             * File.Delete(localFilePath);*/
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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();
            }
        }