public static ACResult ShowConfirmation() { var form = new ApplyConfirmation(); form.mbBackup.Click += (o, e) => { form.Result = ACResult.BACKUP; form.Close(); }; form.mbOverwrite.Click += (o, e) => { form.Result = ACResult.OVERWRITE; form.Close(); }; form.ShowDialog(); return(form.Result); }
private void ApplyChanges(object sender, EventArgs e) { if (PreviewPane.BackgroundImage == null) { MessageBox.Show("No changes were made.", "Operation Aborted"); return; } ACResult result = ApplyConfirmation.ShowConfirmation(); if (result == ACResult.IGNORE) { return; } StartProgress(); int width = int.Parse(tbCWidth.Text); int height = int.Parse(tbCHeight.Text); if (width < 640 || width > 7680) { width = 800; } if (height < 480 || height > 4320) { height = 600; } string newBGPath = PreviewPane.BackgroundLocation + "\\background"; ChangeProgress(loaddlg, 25); if (!Directory.Exists(newBGPath)) { Directory.CreateDirectory(newBGPath); } newBGPath += "\\HLBC"; if (!Directory.Exists(newBGPath)) { Directory.CreateDirectory(newBGPath); } Bitmap[,] newBmps = PreviewPane.ChopNewImage(width, height); ChangeProgress(loaddlg, 50); string[] newBmpsLocations = PreviewPane.NewBitmapLocations; ChangeProgress(loaddlg, 75); int bmpWCount = newBmps.GetLength(0); int bmpHCount = newBmps.Length; int x = 0; int y = 0; string backgroundLayoutContents = "resolution\t" + width + "\t" + height + "\n"; string errorMsg = string.Empty; foreach (var bmpLoc in newBmpsLocations) { string bmpRelPath = PreviewPanel.RemoveExtraSpaces(bmpLoc).Split()[0]; string bmpPath = PreviewPane.BackgroundLocation.Remove(PreviewPane.BackgroundLocation.Length - 9, 9) + "\\" + bmpRelPath; backgroundLayoutContents += bmpLoc + "\n"; try { newBmps[x, y].Save(bmpPath + ".bmp"); Surface surf = Surface.LoadFromFile(bmpPath + ".bmp", ImageLoadFlags.TARGA_LoadRGB888); surf.SaveToFile(ImageFormat.TARGA, bmpPath, ImageSaveFlags.Default); } catch { errorMsg += "File has been probably corrupted: " + bmpPath + "\n"; } // cleanup!!! File.Delete(bmpPath + ".bmp"); if (++x >= bmpWCount) { x = 0; if (++y >= bmpHCount) { break; } } } ChangeProgress(loaddlg, 100); if (errorMsg.Length > 0) { Activate(); MessageBox.Show("Background Change Failed! Permission to write to file was denied.\n" + errorMsg, "File IO Error"); return; } switch (result) { case ACResult.BACKUP: if (File.Exists(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt")) { int cr = 1; while (File.Exists(PreviewPane.BackgroundLocation + "\\BackgroundLayout_v" + cr + ".txt")) { cr++; } string bgLines = File.ReadAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt"); File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout_v" + cr + ".txt", bgLines); MessageBox.Show("Backup saved as: BackgroundLayout_v" + cr + ".txt", "Backup Saved"); } else { MessageBox.Show("BackgroundLayout.txt was not found inside the resources folder. Backup is unnecessary.", "Backup Skipped"); } File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt", backgroundLayoutContents); break; case ACResult.OVERWRITE: File.WriteAllText(PreviewPane.BackgroundLocation + "\\BackgroundLayout.txt", backgroundLayoutContents); break; } MessageBox.Show("Successfully Changed Background Layout!\r\nDon't forget to match the in-game resolution with your newly created background.", "Changes Saved"); Activate(); }