コード例 #1
0
 public DamnedNewStage(DamnedNewStage copy)
 {
     this.loadingImagePath                = copy.loadingImagePath;
     this.lobbyImageButtonPath            = copy.lobbyImageButtonPath;
     this.newStagePath                    = copy.newStagePath;
     this.lobbyImageButtonHighlightedPath = copy.lobbyImageButtonHighlightedPath;
     this.newScenePath                    = copy.newScenePath;
     this.newObjectsPath                  = new List <string>(copy.newObjectsPath);
     this.hasObjects = copy.hasObjects;
 }
コード例 #2
0
 public DamnedMappingForm(DamnedMaps damnedMaps, DamnedImages damnedImages, DamnedMainForm mainForm)
 {
     InitializeComponent();
     this.mainForm = mainForm;
     this.mainForm.Hide();
     this.damnedMaps        = damnedMaps;
     this.damnedImages      = damnedImages;
     this.tempDirectory     = String.Empty;
     damnedRemoveStage      = new DamnedRemoveStage();
     damnedNewStage         = new DamnedNewStage();
     damnedNewStagesList    = new List <DamnedNewStage>();
     damnedRemoveStagesList = new List <DamnedRemoveStage>();
     RefreshDamnedStagesList();
 }
コード例 #3
0
        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));
                    }
                }
            }
        }
コード例 #4
0
    // Too much work to write this. Probably a better way to do this.
    private void Package(DamnedNewStage newStage, string destination)
    {
        tempDirectory = DamnedFiles.CreateTempWorkshopDirectory();
        CreateDirectories();
        DirectoryInfo[] info = new DirectoryInfo(tempDirectory).GetDirectories("*", SearchOption.AllDirectories);

        string newStageNamePath                   = newStage.newStagePath;
        string newStageName                       = Path.GetFileName(newStageNamePath);
        string newSceneNamePath                   = newStage.newScenePath;
        string newSceneName                       = Path.GetFileName(newStage.newScenePath);
        string newLoadingImageNamePath            = newStage.loadingImagePath;
        string newLoadingImageName                = Path.GetFileName(newLoadingImageNamePath);
        string newLobbyButtonImagePath            = newStage.lobbyImageButtonPath;
        string newLobbyButtnImageName             = Path.GetFileName(newStage.lobbyImageButtonPath);
        string newLobbyButtonImageHighlightedPath = newStage.lobbyImageButtonHighlightedPath;
        string newLobbyButtonImageHighlightedName = Path.GetFileName(newStage.lobbyImageButtonHighlightedPath);

        string stageAndScenePath = GetPath(info, "Stages");
        string guiPath           = GetPath(info, "GUI");
        string terrorImagesPath  = GetPath(info, "TerrorImages");

        string newZipArchiveName = Path.GetFileNameWithoutExtension(newStageName).Replace("_", " ");

        newZipArchiveName = String.Format("{0}.zip", newZipArchiveName);

        string newPath = Path.Combine(stageAndScenePath, newStageName);

        File.Copy(newStageNamePath, newPath);
        newPath = Path.Combine(stageAndScenePath, newSceneName);
        File.Copy(newSceneNamePath, newPath);
        newPath = Path.Combine(terrorImagesPath, newLoadingImageName);
        File.Copy(newLoadingImageNamePath, newPath);
        newPath = Path.Combine(guiPath, newLobbyButtnImageName);
        File.Copy(newLobbyButtonImagePath, newPath);
        newPath = Path.Combine(guiPath, newLobbyButtonImageHighlightedName);
        File.Copy(newLobbyButtonImageHighlightedPath, newPath);
        destination = Path.Combine(destination, newZipArchiveName);

        if (newStage.hasObjects)
        {
            CreateObjectsDirectory();
            DamnedObjects damnedObjects = new DamnedObjects(tempDirectory);
            damnedObjects.CopyObjects(newStage.newObjectsPath.ToArray(), damnedObjects.objectsDirectory);
        }

        if (File.Exists(destination))
        {
            string       message = String.Format("Package \"{0}\" already exists at this location. Do you wish to overwrite it?", newZipArchiveName);
            DialogResult result  = MessageBox.Show(message, "Package already exists", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == DialogResult.Yes)
            {
                File.Delete(destination);
            }

            else
            {
                Directory.Delete(tempDirectory, true);
                return;
            }
        }

        ZipFile.CreateFromDirectory(tempDirectory, destination);
        Directory.Delete(tempDirectory, true);
    }
コード例 #5
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;
        }