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); }
private void SelectStage(bool remove) { FileDialog dialog = new OpenFileDialog(); if (remove) { dialog.InitialDirectory = damnedMaps.stagesAndScenesDirectory; } dialog.Filter = "Stage Files (*.stage)|*.stage"; DialogResult result = dialog.ShowDialog(); if (result != DialogResult.OK) { return; } string stagePath = dialog.FileName; string stage = Path.GetFileName(stagePath); if (Path.GetExtension(stage) != ".stage") { MessageBox.Show("You did not pick a stage file. Please select one that is a .stage file", "Please select a different file", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (stage.Contains("menu_background")) { MessageBox.Show("Either you picked the stage that is for the main menu or you decided to name your stage along the lines of \"menu_background\". Either pick a different one or rename your stage.", "Pick a different stage", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (remove) { if (Path.GetFileName(Path.GetDirectoryName(stagePath)) != "Stages") { MessageBox.Show("It seems that the stage that you have selected does not reside inside the Damned directory. Please select a different stage", "Please select a different file", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } damnedRemoveStage.stagePath = stagePath; string newLabelText = Path.GetFileNameWithoutExtension(stage).Replace("_", " "); labelMapToRemove.Text = newLabelText; labelMapToRemove.ForeColor = Color.FromArgb(255, 168, 38); buttonSelectSceneToRemove.Enabled = true; changesMade = true; } else { if (damnedMaps.StageExists(stage)) { MessageBox.Show("This stage is already installed in the game. Please pick another.", "Stage Already Exists", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string reason = String.Empty; if (!DamnedMaps.CheckInnerStageFile(stagePath, ref reason)) { MessageBox.Show(String.Format("{0} Please select a different stage file.", reason), "Failed to check the stage", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (damnedNewStage.newStagePath == String.Empty) { damnedNewStage.count++; } damnedNewStage.newStagePath = stagePath; string newLabelText = stage.Replace("_", " ").Remove(stage.IndexOf("."), 6); labelMapToAdd.Text = newLabelText; labelMapToAdd.ForeColor = Color.FromArgb(255, 168, 38); buttonSelectSceneFile.Enabled = true; changesMade = true; } }