Skip to content

Commit

Permalink
Don't change license if user clicks cancel (#1276)
Browse files Browse the repository at this point in the history
  • Loading branch information
papeh authored Jul 14, 2023
1 parent ffd8999 commit 4b260d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
26 changes: 18 additions & 8 deletions SIL.Windows.Forms/ImageToolbox/ImageToolboxControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ public void Closing()
/// <summary>
/// If set, this action will be used instead of the default (launching <see cref="MetadataEditorDialog"/>).
/// For example, the client may want to use a different UI to edit the `Metadata`.
/// The `Action<Metadata>` callback saves the modified `Metadata` to the image.
/// The `Action&lt;Metadata&gt;` callback saves the modified `Metadata` to the image.
/// <see cref="SetNewImageMetadata(Metadata)"/>
/// </summary>
public Action<Metadata, Action<Metadata>> EditMetadataActionOverride { get; set; }
Expand All @@ -366,21 +366,31 @@ private void OnEditMetadataLink_LinkClicked(object sender, LinkLabelLinkClickedE
//it's not clear at the moment where the following belongs... but we want
//to encourage Creative Commons Licensing, so if there is no license, we'll start
//the following dialog out with a reasonable default.
_imageInfo.Metadata.SetupReasonableLicenseDefaultBeforeEditing();
var isSuggesting = false;
var hadChanges = false;
if (_imageInfo.Metadata.IsLicenseNotSet)
{
isSuggesting = true;
hadChanges = _imageInfo.Metadata.HasChanges;
_imageInfo.Metadata.SetupReasonableLicenseDefaultBeforeEditing();
}

if (EditMetadataActionOverride != null)
{
EditMetadataActionOverride(_imageInfo.Metadata, SetNewImageMetadata);
return;
}

using(var dlg = new MetadataEditorDialog(_imageInfo.Metadata))
using var dlg = new MetadataEditorDialog(_imageInfo.Metadata);
if (DialogResult.OK == dlg.ShowDialog())
{
if(DialogResult.OK == dlg.ShowDialog())
{
Guard.AgainstNull(dlg.Metadata, " dlg.Metadata");
SetNewImageMetadata(dlg.Metadata);
}
Guard.AgainstNull(dlg.Metadata, " dlg.Metadata");
SetNewImageMetadata(dlg.Metadata);
}
else if (isSuggesting)
{
_imageInfo.Metadata.License = new NullLicense();
_imageInfo.Metadata.HasChanges = hadChanges;
}
}

Expand Down
4 changes: 2 additions & 2 deletions SIL.Windows.Forms/ImageToolbox/PalasoImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ private static Image LoadImageWithoutLocking(string path, out string tempPath)
{
var leakMe = TempFile.WithExtension(GetCorrectImageExtension(path));
RobustFile.Copy(path, leakMe.Path, true);

//we output the tempPath so that the caller can clean it up later
tempPath = leakMe.Path;

Expand All @@ -327,8 +326,9 @@ private static Image LoadImageWithoutLocking(string path, out string tempPath)
// assume it's a better indication of the problem.
var metadata = Metadata.FromFile(path);
if (metadata.IsOutOfMemoryPlausible(e))
// ReSharper disable once PossibleIntendedRethrow
throw e; // Deliberately NOT just "throw", that loses the extra information IsOutOfMemoryPlausible added to the exception.
throw new TagLib.CorruptFileException("File could not be read and is possible corrupted");
throw new TagLib.CorruptFileException("File could not be read and is possible corrupted", e);
}
}
}
Expand Down

0 comments on commit 4b260d0

Please sign in to comment.