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 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)); } } } }