public void DeleteCollection(string collectionName, string libPath) { var collectionPath = Path.Combine(libPath, collectionName); if (IsDirectoryExist(collectionPath)) { try { Directory.Delete(collectionPath, true); var popUp = new TimedPopUp(); popUp.Set($"Удалено"); popUp.Show(); } catch (Exception e) { var popUp = new TimedPopUp(); popUp.Set($"Failed to delete file. {e.Message}"); popUp.ShowError(); } } }
private void CustomPaintButton_Click(object sender, EventArgs e) { SoundPlayer.PlaySettingsSound(); bool needReset = false; ConfirmDialogForm confirm = null; if (ruler.IsGameStarted) { confirm = GetConfirmStatus("Сбросить игру?"); needReset = confirm.Yes; } else { needReset = true; } if (needReset) { ResetGame(); var collectionNameDialog = new CustomCollectionNameDialogForm(); collectionNameDialog.StartPosition = FormStartPosition.Manual; collectionNameDialog.Location = this.Location; collectionNameDialog.StartPosition = FormStartPosition.CenterParent; collectionNameDialog.BackgroundImageLayout = ImageLayout.Stretch; this.Enabled = false; collectionNameDialog.ShowDialog(this); this.Enabled = true; var newCollectionName = collectionNameDialog.GetCollectionName(); if (libManager.GetCategories().Contains(newCollectionName)) { baseForm.ShowStatusMessage($"Коллекция {newCollectionName} уже существует", error: true, true); return; } if (!string.IsNullOrEmpty(newCollectionName)) { var collectionPath = Path.Combine(libManager.LibraryPath, newCollectionName); if (fileManager.IsDirectoryExist(collectionPath)) { var popUpMessage = new TimedPopUp(); popUpMessage.Set($"Коллекция {newCollectionName} уже существует"); popUpMessage.ShowError(3000); this.Invoke((Action)(() => this.Enabled = true)); return; } collectionNameDialog.Dispose(); collectionNameDialog = null; paintForm = new PaintForm(this, baseForm, newCollectionName); new Thread(() => { this.Invoke((Action)(() => paintForm.StartPosition = FormStartPosition.Manual)); this.Invoke((Action)(() => paintForm.Location = this.Location)); this.Invoke((Action)(() => paintForm.StartPosition = FormStartPosition.CenterParent)); this.Invoke((Action)(() => paintForm.BackgroundImageLayout = ImageLayout.Stretch)); this.Invoke((Action)(() => this.Enabled = false)); this.Invoke((Action)(() => paintForm.ShowDialog(this))); List <CustomImage> newCollection = paintForm.GetCollection(); SaveCustomImageCollection(newCollectionName, newCollection); this.Invoke((Action)(() => CategoryComboBox.DataSource = libManager.GetCategories().ToList())); this.Invoke((Action)(() => CategoryComboBox.SelectedIndex = CategoryComboBox.FindStringExact(newCollectionName))); paintForm.Dispose(); paintForm = null; this.Invoke((Action)(() => this.Enabled = true)); }).Start(); } } confirm?.Dispose(); this.Enabled = true; }