diff --git a/ConvertImages.xaml b/ConvertMedia.xaml
similarity index 66%
rename from ConvertImages.xaml
rename to ConvertMedia.xaml
index af669997..a62d0ad6 100644
--- a/ConvertImages.xaml
+++ b/ConvertMedia.xaml
@@ -1,28 +1,24 @@
-
-
-
-
-
-
-
-
+
+
+ ItemsSource="{Binding Source={x:Static g:FormatCatalog.Instance}, Path=ImageFormats, Mode=OneWay}" SelectedValuePath="Tag"
+ SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=appLastImageFormat, Mode=TwoWay}"/>
-
-
+
+
+
-
+
diff --git a/ConvertImages.xaml.cs b/ConvertMedia.xaml.cs
similarity index 69%
rename from ConvertImages.xaml.cs
rename to ConvertMedia.xaml.cs
index 3c02b060..a027794c 100644
--- a/ConvertImages.xaml.cs
+++ b/ConvertMedia.xaml.cs
@@ -3,11 +3,11 @@
namespace GARbro.GUI
{
///
- /// Interaction logic for ConvertImages.xaml
+ /// Interaction logic for ConvertMedia.xaml
///
- public partial class ConvertImages : Window
+ public partial class ConvertMedia : Window
{
- public ConvertImages ()
+ public ConvertMedia ()
{
InitializeComponent ();
}
diff --git a/GARbro.GUI.csproj b/GARbro.GUI.csproj
index 6fc0dfc0..433a0669 100644
--- a/GARbro.GUI.csproj
+++ b/GARbro.GUI.csproj
@@ -126,8 +126,8 @@
ArcParameters.xaml
-
- ConvertImages.xaml
+
+ ConvertMedia.xaml
CreateArchive.xaml
@@ -168,7 +168,7 @@
Designer
MSBuild:Compile
-
+
Designer
MSBuild:Compile
diff --git a/GarConvert.cs b/GarConvert.cs
index c8cc1ac3..779e56ab 100644
--- a/GarConvert.cs
+++ b/GarConvert.cs
@@ -2,6 +2,26 @@
//! \date Fri Aug 22 08:22:47 2014
//! \brief Game resources conversion methods.
//
+// Copyright (C) 2014-2015 by morkt
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//
using System;
using System.IO;
@@ -23,53 +43,61 @@ namespace GARbro.GUI
///
/// Convert selected images to another format.
///
- void ConvertImageExec (object sender, ExecutedRoutedEventArgs e)
+ void ConvertMediaExec (object sender, ExecutedRoutedEventArgs e)
{
if (ViewModel.IsArchive)
return;
var source = CurrentDirectory.SelectedItems.Cast()
- .Where (f => f.Type == "image").Select (f => f.Name);
- var convert_dialog = new ConvertImages();
+ .Where (f => f.Type == "image" || f.Type == "audio")
+ .Select (f => f.Source);
+ if (!source.Any())
+ {
+ PopupError (guiStrings.MsgNoMediaFiles, guiStrings.TextMediaConvertError);
+ return;
+ }
+ var convert_dialog = new ConvertMedia();
convert_dialog.Owner = this;
var result = convert_dialog.ShowDialog() ?? false;
if (!result)
return;
- var selected = convert_dialog.ImageConversionFormat.SelectedValue as string;
- var format = FormatCatalog.Instance.ImageFormats.FirstOrDefault (f => f.Tag == selected);
+ var format = convert_dialog.ImageConversionFormat.SelectedItem as ImageFormat;
+// var format = FormatCatalog.Instance.ImageFormats.FirstOrDefault (f => f.Tag == selected);
if (null == format)
{
- Trace.WriteLine ("Format is not selected", "ConvertImageExec");
+ Trace.WriteLine ("Format is not selected", "ConvertMediaExec");
return;
}
try
{
Directory.SetCurrentDirectory (ViewModel.Path);
- var converter = new GarConvertImages (this);
+ var converter = new GarConvertMedia (this);
converter.Convert (source, format);
}
catch (Exception X)
{
- PopupError (X.Message, guiStrings.TextImageConvertError);
+ PopupError (X.Message, guiStrings.TextMediaConvertError);
}
}
}
- internal class GarConvertImages
+ internal class GarConvertMedia
{
private MainWindow m_main;
private ProgressDialog m_progress_dialog;
- private IEnumerable m_source;
+ private IEnumerable m_source;
private ImageFormat m_image_format;
private Exception m_pending_error;
+ private List> m_failed = new List>();
public bool IgnoreErrors { get; set; }
+ public IEnumerable> FailedFiles { get { return m_failed; } }
- public GarConvertImages (MainWindow parent)
+ public GarConvertMedia (MainWindow parent)
{
m_main = parent;
}
- public void Convert (IEnumerable images, ImageFormat format)
+ public void Convert (IEnumerable images, ImageFormat format)
{
m_main.StopWatchDirectoryChanges();
m_source = images;
@@ -91,46 +119,28 @@ namespace GARbro.GUI
m_pending_error = null;
try
{
- string target_ext = m_image_format.Extensions.First();
int total = m_source.Count();
int i = 0;
- foreach (var filename in m_source)
+ foreach (var entry in m_source)
{
if (m_progress_dialog.CancellationPending)
throw new OperationCanceledException();
+ var filename = entry.Name;
int progress = i++*100/total;
- string target_name = Path.ChangeExtension (filename, target_ext);
- if (filename == target_name)
- continue;
- string source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
- if (m_image_format.Extensions.Any (ext => ext == source_ext))
- continue;
+ m_progress_dialog.ReportProgress (progress, string.Format (guiStrings.MsgConvertingFile,
+ Path.GetFileName (filename)), null);
try
{
- using (var file = File.OpenRead (filename))
- {
- m_progress_dialog.ReportProgress (progress, string.Format (guiStrings.MsgConvertingImage,
- filename), target_name);
- var image = ImageFormat.Read (file);
- if (null == image)
- continue;
- try
- {
- using (var output = File.Create (target_name))
- m_image_format.Write (output, image);
- }
- catch // delete destination file on conversion failure
- {
- File.Delete (target_name);
- throw;
- }
- }
+ if ("image" == entry.Type)
+ ConvertImage (filename);
+ else if ("audio" == entry.Type)
+ ConvertAudio (filename);
}
catch (Exception X)
{
if (!IgnoreErrors)
throw;
- m_pending_error = X;
+ m_failed.Add (Tuple.Create (Path.GetFileName (filename), X.Message));
}
}
}
@@ -140,6 +150,67 @@ namespace GARbro.GUI
}
}
+ public static readonly HashSet CommonAudioFormats = new HashSet { "wav", "mp3", "ogg" };
+ public static readonly AudioFormat WavFormat = FormatCatalog.Instance.AudioFormats.First (f => f.Tag == "WAV");
+
+ void ConvertAudio (string filename)
+ {
+ using (var file = File.OpenRead (filename))
+ using (var input = AudioFormat.Read (file))
+ {
+ if (null == input)
+ return;
+ var source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
+ string source_format = input.SourceFormat;
+ if (CommonAudioFormats.Contains (source_format))
+ {
+ if (source_ext == source_format)
+ return;
+ string output_name = Path.ChangeExtension (filename, source_format);
+ using (var output = File.Create (output_name))
+ {
+ input.Source.Position = 0;
+ input.Source.CopyTo (output);
+ }
+ }
+ else
+ {
+ if (source_ext == "wav")
+ return;
+ string output_name = Path.ChangeExtension (filename, "wav");
+ using (var output = File.Create (output_name))
+ WavFormat.Write (input, output);
+ }
+ }
+ }
+
+ void ConvertImage (string filename)
+ {
+ string target_ext = m_image_format.Extensions.First();
+ string target_name = Path.ChangeExtension (filename, target_ext);
+ if (filename == target_name)
+ return;
+ string source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
+ if (m_image_format.Extensions.Any (ext => ext == source_ext))
+ return;
+ using (var file = File.OpenRead (filename))
+ {
+ var image = ImageFormat.Read (file);
+ if (null == image)
+ return;
+ try
+ {
+ using (var output = File.Create (target_name))
+ m_image_format.Write (output, image);
+ }
+ catch // delete destination file on conversion failure
+ {
+ File.Delete (target_name);
+ throw;
+ }
+ }
+ }
+
void OnConvertComplete (object sender, RunWorkerCompletedEventArgs e)
{
m_main.ResumeWatchDirectoryChanges();
@@ -149,7 +220,7 @@ namespace GARbro.GUI
if (m_pending_error is OperationCanceledException)
m_main.SetStatusText (m_pending_error.Message);
else
- m_main.PopupError (m_pending_error.Message, guiStrings.TextImageConvertError);
+ m_main.PopupError (m_pending_error.Message, guiStrings.TextMediaConvertError);
}
m_main.Activate();
m_main.RefreshView();
diff --git a/GarExtract.cs b/GarExtract.cs
index 88ec8cee..617546bb 100644
--- a/GarExtract.cs
+++ b/GarExtract.cs
@@ -113,8 +113,6 @@ namespace GARbro.GUI
private ProgressDialog m_progress_dialog;
private Exception m_pending_error;
- public static readonly HashSet CommonAudioFormats = new HashSet { "wav", "mp3", "ogg" };
-
public bool IsActive { get { return m_extract_in_progress; } }
public GarExtract (MainWindow parent, string source)
@@ -365,7 +363,7 @@ namespace GARbro.GUI
public static void ConvertAudio (string entry_name, SoundInput input)
{
string source_format = input.SourceFormat;
- if (CommonAudioFormats.Contains (source_format))
+ if (GarConvertMedia.CommonAudioFormats.Contains (source_format))
{
string output_name = Path.ChangeExtension (entry_name, source_format);
using (var output = ArchiveFormat.CreateFile (output_name))
@@ -376,10 +374,9 @@ namespace GARbro.GUI
}
else
{
- var wav_format = FormatCatalog.Instance.AudioFormats.First (f => f.Tag == "WAV");
string output_name = Path.ChangeExtension (entry_name, "wav");
using (var output = ArchiveFormat.CreateFile (output_name))
- wav_format.Write (input, output);
+ GarConvertMedia.WavFormat.Write (input, output);
}
}
diff --git a/MainWindow.xaml b/MainWindow.xaml
index 04f6d7eb..b95b10c8 100644
--- a/MainWindow.xaml
+++ b/MainWindow.xaml
@@ -94,7 +94,7 @@
Command="{x:Static local:Commands.Refresh}"/>
+ Command="{x:Static local:Commands.ConvertMedia}" />
@@ -107,7 +107,7 @@
+ Command="{x:Static local:Commands.ConvertMedia}" />