Skip to content

Commit

Permalink
Merge pull request #96 from PKBeam/93-edda-crashes-if-cover-file-has-…
Browse files Browse the repository at this point in the history
…wrong-dpi

Edda crashes if cover file has wrong DPI
  • Loading branch information
Brollyy authored Jan 27, 2024
2 parents 547940a + 1c4b5d3 commit a07340a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,13 @@ private void SelectNewCoverImage() {
string newFile = Helper.SanitiseCoverFileName(sourceFile);
string newPath = Path.Combine(mapEditor.mapFolder, newFile);

// skip only when the chosen file is already the map cover file
if (prevPath != sourceFile) {
// if there is no need to copy the file, only update map value
if (newPath == sourceFile) {
mapEditor.SetMapValue("_coverImageFilename", newFile);
SaveBeatmap();
}
// skip when the chosen file is already the map cover file
else if (prevPath != sourceFile) {
// remove the previous cover image
Helper.FileDeleteIfExists(prevPath);
// delete any existing files in the map folder with conflicting names
Expand All @@ -883,11 +888,22 @@ private void SelectNewCoverImage() {
}
private void LoadCoverImage() {
var fileName = (string)mapEditor.GetMapValue("_coverImageFilename");
if (fileName == "") {
var filePath = Path.Combine(mapEditor.mapFolder, fileName);
if (!string.IsNullOrEmpty(fileName) && !File.Exists(filePath)) {
fileName = "";
mapEditor.SetMapValue("_coverImageFilename", fileName);
MessageBox.Show(this,
"Cover image file no longer exists",
"Warning",
MessageBoxButton.OK,
MessageBoxImage.Warning
);
}
if (string.IsNullOrEmpty(fileName)) {
ClearCoverImage();
} else {
// Need to ignore cache, since we replace the contents of the cover.* file.
BitmapImage b = Helper.BitmapGenerator(new Uri(Path.Combine(mapEditor.mapFolder, fileName)), true);
BitmapImage b = Helper.BitmapGenerator(new Uri(filePath), true);
imgCover.Source = b;
txtCoverFileName.Text = fileName;
borderImgCover.BorderThickness = new(2);
Expand Down

0 comments on commit a07340a

Please sign in to comment.