private void PrepareToModifyStages()
        {
            newStagesList.Clear();
            removeStagesList.Clear();

            selectedRows = damnedDataView.SelectedRows;

            for (int i = 0; i < selectedRows.Count; i++)
            {
                var cellsInRow = selectedRows[i].Cells;

                for (int j = 0; j < cellsInRow.Count; j++)
                {
                    var cell = cellsInRow[j];

                    if (cell.ColumnIndex != COLUMN_INSTALLED)
                    {
                        continue;
                    }

                    string cellValue = cell.Value.ToString();

                    int result = String.Compare(cellValue, "yes", true);

                    if (result != 0)
                    {
                        string githubLink = "https://github.com/Sweats/Damned-Community-Stages/raw/master/";

                        string archiveToDownload = $"{cellsInRow[COLUMN_NAME].Value.ToString()}.zip";
                        string downloadLink      = $"{githubLink}{archiveToDownload}".Replace(" ", "%20");
                        string workshopTempPath  = DamnedFiles.CreateTempWorkshopDirectory();
                        string archiveLocation   = Path.Combine(workshopTempPath, archiveToDownload);

                        if (!DamnedFiles.DownloadFile(downloadLink, archiveLocation))
                        {
                            MessageBox.Show($"Failed to download the stage archive {archiveToDownload} from {downloadLink}. Do you have a valid internet connection? ", "Failed To Download", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Directory.Delete(workshopTempPath, true);
                            return;
                        }

                        DamnedPackage package = new DamnedPackage();

                        if (!package.Check(archiveLocation))
                        {
                            string reason = $"Failed to prepare the stage archive {archiveToDownload} for installation:\n\n{package.reasonForFailedCheck}";
                            MessageBox.Show(reason, "Failed to prepare the stage archive.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Directory.Delete(workshopTempPath, true);
                            return;
                        }

                        package.Load();

                        DamnedNewStage newStage = new DamnedNewStage()
                        {
                            loadingImagePath = package.loadingImagePath,
                            lobbyImageButtonHighlightedPath = package.lobbyButtonImageHighlightedPath,
                            lobbyImageButtonPath            = package.lobbyButtonImagePath,
                            newScenePath   = package.scenePath,
                            newStagePath   = package.stagePath,
                            newObjectsPath = package.objectsPath,
                            hasObjects     = package.hasObjects
                        };

                        newStagesList.Add(newStage);
                    }


                    else
                    {
                        string            stageToFind = $"{cellsInRow[COLUMN_NAME].Value.ToString()}.stage".Replace(" ", "_");
                        string            sceneToFind = $"{cellsInRow[COLUMN_NAME].Value.ToString()}.scene".Replace(" ", "_");
                        DamnedRemoveStage removeStage = new DamnedRemoveStage();
                        string            pathToStage = Path.Combine(damnedStages.stagesAndScenesDirectory, stageToFind);
                        string            pathToScene = Path.Combine(damnedStages.stagesAndScenesDirectory, sceneToFind);
                        removeStage.stagePath = pathToStage;
                        removeStage.scenePath = pathToScene;
                        removeStagesList.Add(new DamnedRemoveStage(removeStage));
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void ButtonSelectPackage_Click(object sender, EventArgs e)
        {
            FileDialog dialog = new OpenFileDialog()
            {
                Filter = "Zip File (*.zip)|*.zip"
            };


            DialogResult result = dialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            string zipArchivePath = dialog.FileName;

            DamnedPackage package = new DamnedPackage();

            string tempDirectoryPath   = DamnedFiles.CreateTempWorkshopDirectory();
            string zipName             = Path.GetFileName(zipArchivePath);
            string tempArchiveLocation = Path.Combine(tempDirectoryPath, zipName);

            File.Copy(zipArchivePath, tempArchiveLocation);

            if (!package.Check(tempArchiveLocation))
            {
                Directory.Delete(package.tempDirectory, true);
                MessageBox.Show(package.reasonForFailedCheck, "Failed Check", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            package.Load();

            damnedNewStage = new DamnedNewStage()
            {
                loadingImagePath = package.loadingImagePath,
                lobbyImageButtonHighlightedPath = package.lobbyButtonImageHighlightedPath,
                hasObjects           = package.hasObjects,
                newObjectsPath       = package.objectsPath,
                newStagePath         = package.stagePath,
                newScenePath         = package.scenePath,
                lobbyImageButtonPath = package.lobbyButtonImagePath
            };


            if (damnedMaps.StageExists(Path.GetFileName(damnedNewStage.newStagePath)))
            {
                string stageName = Path.GetFileNameWithoutExtension(damnedNewStage.newStagePath).Replace("_", " ");
                Directory.Delete(package.tempDirectory, true);
                Reset();
                MessageBox.Show(String.Format("This stage \"{0}\" is already installed in the game. Please select another stage", stageName), "Stage already installed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            for (int i = 0; i < damnedNewStagesList.Count; i++)
            {
                string stageNameInList  = Path.GetFileName(damnedNewStagesList[i].newStagePath);
                string currentStageName = Path.GetFileName(damnedNewStage.newStagePath);

                if (String.Compare(stageNameInList, currentStageName, true) == 0)
                {
                    string stageNameFormatted = Path.GetFileNameWithoutExtension(damnedNewStage.newStagePath).Replace("_", " ");
                    MessageBox.Show($"The selected package for the stage \"{stageNameFormatted}\" is already selected to be added into the game. Please select another", "Stage already selected to be added", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    damnedNewStage.Clear();
                    return;
                }
            }

            if (package.objectsCount > 0)
            {
                labelObjectsCount.Text              = String.Format("{0} new objects will be added.", package.objectsCount);
                labelObjectsCount.ForeColor         = Color.FromArgb(255, 168, 38);
                checkBoxCustomObjects.Checked       = true;
                checkBoxCustomObjects.Enabled       = true;
                buttonSelectObjectsForStage.Enabled = true;
            }

            labelLoadingScreenImage.Text             = Path.GetFileName(damnedNewStage.loadingImagePath);
            labelLoadingScreenImage.ForeColor        = Color.FromArgb(255, 168, 38);
            labelLobbyButtonPicture.Text             = Path.GetFileName(damnedNewStage.lobbyImageButtonPath);
            labelLobbyButtonPicture.ForeColor        = Color.FromArgb(255, 168, 38);
            labelSelectedHighlightedButton.Text      = Path.GetFileName(damnedNewStage.lobbyImageButtonHighlightedPath);
            labelSelectedHighlightedButton.ForeColor = Color.FromArgb(255, 168, 38);
            labelScene.Text         = Path.GetFileName(damnedNewStage.newScenePath);
            labelScene.ForeColor    = Color.FromArgb(255, 168, 38);
            labelMapToAdd.Text      = Path.GetFileNameWithoutExtension(damnedNewStage.newStagePath).Replace("_", " ");
            labelMapToAdd.ForeColor = Color.FromArgb(255, 168, 38);
            pictureDamnedButtonLobbyPicture.ImageLocation      = damnedNewStage.lobbyImageButtonPath;
            pictureLobbyButtonHighlightedExample.ImageLocation = damnedNewStage.lobbyImageButtonHighlightedPath;

            damnedNewStage.count = 5;
            changesMade          = true;
            buttonSelectHighlightedLobbyButtons.Enabled = true;
            buttonSelectLobbyButtonPicture.Enabled      = true;
            buttonSelectMapLoadingScreen.Enabled        = true;
            buttonSelectSceneFile.Enabled = true;
            buttonAddStageToList.Enabled  = true;
        }