Skip to content

Commit

Permalink
Changed drag annd drop functionality to create a 1:1 copy of image.
Browse files Browse the repository at this point in the history
  • Loading branch information
iGemini committed Jan 2, 2014
1 parent 2c707f2 commit 0167dbe
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions octgnFX/Octgn/DeckBuilder/DeckEditorPreviewControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,36 +383,33 @@ private void OnImageDrop(object sender, DragEventArgs args)

var file = dropFiles[0];

using (var imageStream = File.OpenRead(file))
using (var image = Image.FromStream(imageStream))
{
var set = Card.Card.GetSet();
var set = Card.Card.GetSet();

var garbage = Paths.Get().GraveyardPath;
if (!Directory.Exists(garbage))
Directory.CreateDirectory(garbage);
var garbage = Paths.Get().GraveyardPath;
if (!Directory.Exists(garbage)) Directory.CreateDirectory(garbage);

var files =
Directory.GetFiles(set.ImagePackUri, Card.Card.GetImageUri() + ".*")
.OrderBy(x => x.Length)
.ToArray();
var files =
Directory.GetFiles(set.ImagePackUri, Card.Card.GetImageUri() + ".*")
.OrderBy(x => x.Length)
.ToArray();

// Delete all the old picture files
foreach (var f in files.Select(x => new FileInfo(x)))
{
f.MoveTo(System.IO.Path.Combine(garbage, f.Name));
}
// Delete all the old picture files
foreach (var f in files.Select(x => new FileInfo(x)))
{
f.MoveTo(System.IO.Path.Combine(garbage, f.Name));
}

var newPath = System.IO.Path.Combine(set.ImagePackUri, Card.Card.GetImageUri() + ".png");
var newPath = System.IO.Path.Combine(set.ImagePackUri, Card.Card.GetImageUri() + Path.GetExtension(file));
File.Copy(file, newPath);
OnPropertyChanged("Card");

image.Save(newPath, ImageFormat.Png);
OnPropertyChanged("Card");
}
}
catch (Exception e)
{
Log.Warn("Could not replace image", e);
Program.DoCrazyException(e, "Could not replace the image, something went terribly wrong...You might want to try restarting OCTGN and/or your computer.");
Program.DoCrazyException(
e,
"Could not replace the image, something went terribly wrong...You might want to try restarting OCTGN and/or your computer.");
}
}

Expand Down

0 comments on commit 0167dbe

Please sign in to comment.