Example #1
0
        private void ButtonPackageStage_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog browser = new FolderBrowserDialog()
            {
                Description = "Select a folder where you want to save your new Damned package(s)."
            };

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

            string        folderPath = browser.SelectedPath;
            DamnedPackage package    = new DamnedPackage();

            package.Package(damnedNewStagesList.ToArray(), folderPath);
        }
        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));
                    }
                }
            }
        }
Example #3
0
    public async static Task HandleUpdateCommand(SocketMessage message, CommunityRepository repository)
    {
        var attachments = message.Attachments;

        if (attachments.Count == 0)
        {
            await message.Channel.SendMessageAsync("You did not upload a file for me to update in the community repository");

            return;
        }

        if (attachments.Count > 1)
        {
            await message.Channel.SendMessageAsync("Please only send one file at a time.");

            return;
        }

        var    attachment = message.Attachments.ElementAt(0);
        string stageName  = Path.GetFileNameWithoutExtension(attachment.Filename).Replace("_", " ").Replace("-", " ");

        Stage stage = new Stage()
        {
            Name   = stageName,
            Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()),
            Date   = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()
        };

        if (!repository.StageExists(stage))
        {
            await message.Channel.SendMessageAsync("Failed to update the stage because the stage does not exist in the community repository.");

            return;
        }

        Stage repositoryStage = repository.GetStage(stage.Name);

        if (stage.Author != repositoryStage.Author)
        {
            await message.Channel.SendMessageAsync("Failed to update the stage because you are not the author of the stage.");

            return;
        }

        string URL          = attachment.Url;
        string fileName     = attachment.Filename.Replace("_", " ").Replace("-", " ");
        int    randomNumber = new Random().Next();
        string damnedStageCheckerDirectoryName = String.Format("DamnedStageChecker_{0}", randomNumber);
        string tempArchive       = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName, fileName);
        string parentTempArchive = Path.Combine(Path.GetTempPath(), damnedStageCheckerDirectoryName);

        if (Directory.Exists(parentTempArchive))
        {
            Directory.Delete(parentTempArchive, true);
        }

        Directory.CreateDirectory(parentTempArchive);

        using (WebClient client = new WebClient())
        {
            client.DownloadFile(new Uri(URL), tempArchive);
        }


        DamnedPackage package = new DamnedPackage();

        await message.Channel.SendMessageAsync("Checking your updated stage archive now...");

        if (!package.Check(tempArchive))
        {
            Directory.Delete(parentTempArchive, true);
            Directory.Delete(package.tempDirectory, true);
            await message.Channel.SendMessageAsync(package.reasonForFailedCheck);

            return;
        }

        await message.Channel.SendMessageAsync("Stage check successful! I am updating your stage in the community repository now...");

        string oldFilePath = repository.GetPathToStageInCommunityRepository(repositoryStage);

        File.Delete(oldFilePath);
        File.Copy(tempArchive, fileName);
        Directory.Delete(parentTempArchive, true);
        Directory.Delete(package.tempDirectory, true);
        repository.UpdateStage(repositoryStage, stage);

        string commitMessage = String.Format("Updated the stage {0} in the community repository", stage.Name);

        MainClass.UpdateGitHub(commitMessage);
        await message.Channel.SendMessageAsync("Succcessfully updated your stage that is in the community repository!");
    }
Example #4
0
    public async static Task HandleUploadCommand(SocketMessage message, CommunityRepository repository)
    {
        var attachments = message.Attachments;

        if (attachments.Count == 0)
        {
            await message.Channel.SendMessageAsync("You did not attach a zip file to your message. Please try again.");

            return;
        }

        if (attachments.Count > 1)
        {
            await message.Channel.SendMessageAsync("Please upload only one stage package at a time.");

            return;
        }

        Attachment attachment  = attachments.ElementAt(0);
        string     oldFileName = attachment.Filename;
        bool       changesMade = false;

        if (oldFileName.Contains("-") || oldFileName.Contains("_"))
        {
            changesMade = true;
        }

        string fileName = oldFileName.Replace("-", " ").Replace("_", " ");

        Stage stage = new Stage()
        {
            Name   = Path.GetFileNameWithoutExtension(fileName),
            Author = String.Format("{0}#{1}", message.Author.Username.ToLower(), message.Author.Discriminator.ToLower()),
            Date   = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()
        };

        if (repository.StageExists(stage))
        {
            string response = String.Format("This stage already exists in the community repository. If you are the author of the existing stage, please use !update instead to update your stage.");
            await message.Channel.SendMessageAsync(response);

            return;
        }

        string URL = attachment.Url;

        using (WebClient client = new WebClient())
        {
            client.DownloadFile(new Uri(URL), fileName);
        }

        DamnedPackage package = new DamnedPackage();

        await message.Channel.SendMessageAsync("Checking your stage archive now...");

        if (!package.Check(fileName))
        {
            string reason = package.reasonForFailedCheck;
            await message.Channel.SendMessageAsync(reason);

            Directory.Delete(package.tempDirectory, true);
            Directory.Delete(fileName);
            return;
        }

        await message.Channel.SendMessageAsync("Stage check successful! I am adding your stage into the community repository now...");

        repository.AddStage(stage);
        string commitMessage = String.Format("Added in new stage {0} to the community repository", stage.Name);

        MainClass.UpdateGitHub(commitMessage);
        Directory.Delete(package.tempDirectory, true);

        if (changesMade)
        {
            string response = String.Format("Success! Your stage has been added into the community repository!\n\nBy the way, I have renamed your zip file from \"{0}\" to \"{1}.zip\" because it looks nicer and is slightly easier to search for", fileName, stage.Name);
            await message.Channel.SendMessageAsync(response);

            return;
        }

        await message.Channel.SendMessageAsync("Success! Your stage has been added into the community repository!");
    }
Example #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;
        }