Exemplo n.º 1
0
        private void ButtonBackUp_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            string text = String.Format("Backing up \"{0}\" to \"{1}\"\n\n", directory, backupDirectory);

            loggingTextBox.AppendText(text);

            if (!DamnedCopyFiles(directory, backupDirectory))
            {
                MessageBox.Show("Failed to backup Damned Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Cursor.Current = Cursors.Default;
                return;
            }

            DamnedFiles damnedFiles = new DamnedFiles(backupDirectory);;

            if (damnedFiles.Check())
            {
                loggingTextBox.AppendText("Looks like you have a good backup folder!\n\n");
                damnedBackupFolderStringLabel.ForeColor = Color.FromArgb(255, 138, 38);
                validBackUpFolder     = true;
                buttonRestore.Enabled = true;
            }

            else
            {
                damnedBackupFolderStringLabel.ForeColor = Color.Red;
                MessageBox.Show("The folder you have selecetd is not a valid back up folder. Please select another.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Cursor.Current = Cursors.Default;
        }
Exemplo n.º 2
0
        private void LoadSettings()
        {
            string setting = Properties.Settings.Default.damnedGamePath;

            labelDamnedDirectoryPath.Text = directory;

            if (setting != String.Empty)
            {
                labelDamnedDirectoryPath.Text = setting;
                directory = setting;

                try
                {
                    damnedFiles = new DamnedFiles(directory);
                }

                catch (IOException)
                {
                    ResetSettings();
                    string message = String.Format("The directory \"{0}\" seems to no longer exist. Your settings have been reset.", setting);
                    MessageBox.Show(message, "Directory No Longer Exists", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    labelDamnedDirectoryPath.Text = "Your Damned directory path will appear here.";
                    directory = String.Empty;
                    return;
                }

                if (damnedFiles.Check())
                {
                    labelDamnedDirectoryPath.ForeColor = Color.FromArgb(255, 168, 38);
                    damnedWelcomeTextbox.AppendText($"\n\nChecked the saved directory {directory} successfully!");
                    EnableControls();
                }
            }
        }
        private void ButtonModifyStages_Click(object sender, EventArgs e)
        {
            PrepareToModifyStages();

            if (selectedRows.Count < 1)
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            string tempDirectory = DamnedFiles.CreateTempWorkshopDirectory();
            string terrorZipFile = damnedFiles.damnedImages.terrorZipFile;

            ZipFile.ExtractToDirectory(terrorZipFile, tempDirectory);
            string tempTerrorZipFileLocation = damnedFiles.damnedImages.GetLayoutFileFromZip(tempDirectory);

            damnedFiles.damnedImages.UpdateXmlFiles(tempTerrorZipFileLocation, removeStagesList.ToArray(), newStagesList.ToArray());
            string destination = Path.Combine(damnedFiles.damnedImages.guiDirectory, "Terror.zip");

            File.Delete(destination);
            ZipFile.CreateFromDirectory(tempDirectory, destination);
            Directory.Delete(tempDirectory, true);
            RefreshDataView();
            Cursor.Current = Cursors.Default;
            MessageBox.Show("Successfully modified the stages in the game.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 4
0
    private static void CleanUpAddedFiles(DamnedFiles oldFiles, DamnedFiles newFiles)
    {
        FileInfo[]    oldInfo = new DirectoryInfo(oldFiles.directory).GetFiles("*", SearchOption.AllDirectories);
        FileInfo[]    newInfo = new DirectoryInfo(newFiles.directory).GetFiles("*", SearchOption.AllDirectories);
        bool          foundMatchingFile;
        List <string> filesToDelete = new List <string>();

        for (int i = 0; i < newInfo.Length; i++)
        {
            foundMatchingFile = false;
            string newCurrentFileName = newInfo[i].Name;

            for (int k = 0; k < oldInfo.Length; k++)
            {
                string oldCurrentFileName = oldInfo[k].Name;

                if (newCurrentFileName == oldCurrentFileName)
                {
                    foundMatchingFile = true;
                    break;
                }
            }

            if (!foundMatchingFile)
            {
                filesToDelete.Add(newInfo[i].FullName);
            }
        }

        for (int i = 0; i < filesToDelete.Count; i++)
        {
            File.Delete(filesToDelete[i]);
        }
    }
 public DamnedCommunityStagesForm(DamnedMainForm form, DamnedFiles files)
 {
     this.form    = form;
     damnedFiles  = files;
     damnedStages = damnedFiles.damnedMaps;
     InitializeComponent();
 }
 private void ButtonBack_Click(object sender, EventArgs e)
 {
     this.Close();
     form.Enabled = true;
     form.Show();
     DamnedFiles.DeleteWorkshopTempDirectories();
 }
Exemplo n.º 7
0
    public static string CreateTempFileInTempDirectory(string sourceFilePath)
    {
        string filePath     = DamnedFiles.CreateTempWorkshopDirectory();
        string fileName     = Path.GetFileName(sourceFilePath);
        string destFilePath = Path.Combine(filePath, fileName);

        File.Copy(sourceFilePath, destFilePath);
        return(destFilePath);
    }
Exemplo n.º 8
0
        private void ButtonModifyStages_Click(object sender, EventArgs e)
        {
            if (damnedNewStage.count > 0)
            {
                if (damnedNewStage.count != 5)
                {
                    MessageBox.Show("You did not select a loading screen image or a lobby button image for your new stages(s). Finish selecting those first before adding them into the game.", "Finish Selecting", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }

            ModifyStages();
            DamnedFiles.DeleteWorkshopTempDirectories();
        }
        private void RefreshDataView()
        {
            damnedDataView.Rows.Clear();
            string link = "https://raw.githubusercontent.com/Sweats/Damned-Community-Stages/master/CommunityStages.json";

            if (!(DamnedFiles.DownloadFile(link, JSON_FILE_NAME)))
            {
                MessageBox.Show("Failed to download the latest stages listing from the community repository. Do you have a valid internet connection?", "Failed To Update the Stage Listing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            CommunityRepository repository = JsonConvert.DeserializeObject <CommunityRepository>(File.ReadAllText(JSON_FILE_NAME));

            for (int i = 0; i < repository.Stages.Count; i++)
            {
                Stage  stage       = repository.Stages[i];
                string stageToFind = String.Format("{0}.stage", stage.Name).Replace(" ", "_");

                if (String.IsNullOrEmpty(stage.Description))
                {
                    stage.Description = "No description provided.";
                }

                if (String.IsNullOrEmpty(stage.Date))
                {
                    stage.Date = "Unknown upload date.";
                }

                if (damnedStages.StageExists(stageToFind))
                {
                    string[] newRow   = new string[] { stage.Name, stage.Author, stage.Date, stage.Description, "Yes" };
                    int      newIndex = damnedDataView.Rows.Add(newRow);
                    damnedDataView.Rows[newIndex].ReadOnly = true;
                    damnedDataView.Rows[newIndex].DefaultCellStyle.ForeColor = Color.FromArgb(255, 168, 38);
                }

                else
                {
                    string[] newRow   = new string[] { stage.Name, stage.Author, stage.Date, stage.Description, "No" };
                    int      newIndex = damnedDataView.Rows.Add(newRow);
                    damnedDataView.Rows[newIndex].ReadOnly = true;
                    damnedDataView.Rows[newIndex].DefaultCellStyle.ForeColor = Color.White;
                }
            }


            File.Delete(JSON_FILE_NAME);
        }
Exemplo n.º 10
0
        private void DamnedMappingForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (changesMade)
            {
                DialogResult result = MessageBox.Show("You have unsaved changes. Do you wish to close this window?", "Unsaved changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

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

            mainForm.Enabled = true;
            mainForm.Show();
            DamnedFiles.DeleteWorkshopTempDirectories();
        }
Exemplo n.º 11
0
        private void ButtonOnlyCheck_Click(object sender, EventArgs e)
        {
            DamnedFiles damnedFiles = new DamnedFiles(backupDirectory);

            if (damnedFiles.Check())
            {
                loggingTextBox.AppendText("Looks like you have a good backup folder!\n\n");
                damnedBackupFolderStringLabel.ForeColor = Color.FromArgb(255, 168, 38);
                validBackUpFolder     = true;
                buttonRestore.Enabled = true;
            }

            else
            {
                damnedBackupFolderStringLabel.ForeColor = Color.Red;
                buttonRestore.Enabled = false;
            }
        }
Exemplo n.º 12
0
        private void ModifyStages()
        {
            Cursor.Current = Cursors.WaitCursor;
            string terrorImagesZipFile = damnedImages.terrorZipFile;

            tempDirectory = DamnedFiles.CreateTempWorkshopDirectory();
            ZipFile.ExtractToDirectory(terrorImagesZipFile, tempDirectory);
            string layoutFilePath = damnedImages.GetLayoutFileFromZip(tempDirectory);

            damnedImages.UpdateXmlFiles(layoutFilePath, damnedRemoveStagesList.ToArray(), damnedNewStagesList.ToArray());
            string destination = Path.Combine(damnedImages.guiDirectory, "Terror.zip");

            File.Delete(destination);
            ZipFile.CreateFromDirectory(tempDirectory, destination);
            Directory.Delete(tempDirectory, true);
            Reset();
            Cursor.Current = Cursors.Default;
            MessageBox.Show("Successfully modified the stages in the game.", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 13
0
        private void ButtonCheckPath_Click(object sender, EventArgs e)
        {
            if (directory == String.Empty)
            {
                MessageBox.Show("You did not select a directory", "No directory selected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            try
            {
                damnedFiles = new DamnedFiles(directory);
            }

            catch (IOException)
            {
                MessageBox.Show("This directory does not exist. Either the default location for Damned does not exist on your system, or the directory that you selected was moved or deleted by something else. Please select a new directory where Damned is installed.", "Directory Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                labelDamnedDirectoryPath.Text = "Your Damned directory path will appear here.";
                directory = String.Empty;
                return;
            }

            if (damnedFiles.Check())
            {
                labelDamnedDirectoryPath.ForeColor = Color.FromArgb(255, 168, 38);
                EnableControls();
                Properties.Settings.Default.damnedGamePath = directory;
                Properties.Settings.Default.Save();
                damnedFiles.Load();
                damnedWelcomeTextbox.AppendText($"\n\nCheck successful! The directory {directory} is a valid Damned directory!");
            }

            else
            {
                labelDamnedDirectoryPath.ForeColor = Color.Red;
                damnedWelcomeTextbox.AppendText($"\n\nCheck failed! The directory {directory} is not a valid Damned directory!");
                DisableControls();
            }
        }
Exemplo n.º 14
0
        private void ButtonRestore_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (!validBackUpFolder)
            {
                MessageBox.Show("You have one or more invalid directories. Please select another", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Cursor.Current = Cursors.Default;
                return;
            }

            if (!DamnedCopyFiles(backupDirectory, directory))
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Failed to restore Damned to its original backup. Did the directories get changed by something else?\n\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DamnedFiles backupFiles = new DamnedFiles(backupDirectory);

            DamnedFiles.CleanUpNewFiles(backupFiles, damnedFiles);
            Cursor.Current = Cursors.Default;
            MessageBox.Show("Restored the game back to its unpatched state!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
 private void DamnedCommunityStagesForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     form.Enabled = true;
     form.Show();
     DamnedFiles.DeleteWorkshopTempDirectories();
 }
Exemplo n.º 16
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;
        }
Exemplo n.º 17
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);
    }
Exemplo n.º 18
0
 public static void CleanUpNewFiles(DamnedFiles oldFiles, DamnedFiles newFiles)
 {
     CleanUpAddedDirectories(oldFiles, newFiles);
     CleanUpAddedFiles(oldFiles, newFiles);
 }
        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.º 20
0
    public string CopyTerrorZipFileIntoTempDirectory()
    {
        string filePath = Path.Combine(DamnedFiles.CreateTempWorkshopDirectory(), terrorZipFile);

        return(filePath);
    }
Exemplo n.º 21
0
 public DamnedPatcherForm(DamnedFiles damnedFiles, DamnedMainForm mainForm)
 {
     InitializeComponent();
     this.mainForm    = mainForm;
     this.damnedFiles = damnedFiles;
 }