mirror of
https://github.com/crskycode/GARbro.git
synced 2024-12-25 04:14:13 +08:00
choose destination directory for files conversion.
This commit is contained in:
parent
e098a498ee
commit
5641c8b6ba
@ -4,6 +4,7 @@
|
|||||||
xmlns:s="clr-namespace:GARbro.GUI.Strings"
|
xmlns:s="clr-namespace:GARbro.GUI.Strings"
|
||||||
xmlns:p="clr-namespace:GARbro.GUI.Properties"
|
xmlns:p="clr-namespace:GARbro.GUI.Properties"
|
||||||
xmlns:g="clr-namespace:GameRes;assembly=GameRes"
|
xmlns:g="clr-namespace:GameRes;assembly=GameRes"
|
||||||
|
xmlns:local="clr-namespace:GARbro.GUI"
|
||||||
Title="{x:Static s:guiStrings.TextConvertMedia}" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
Title="{x:Static s:guiStrings.TextConvertMedia}" ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
|
||||||
ResizeMode="NoResize" SizeToContent="WidthAndHeight"
|
ResizeMode="NoResize" SizeToContent="WidthAndHeight"
|
||||||
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}">
|
||||||
@ -15,6 +16,18 @@
|
|||||||
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=appLastImageFormat, Mode=TwoWay}"/>
|
SelectedValue="{Binding Source={x:Static p:Settings.Default}, Path=appLastImageFormat, Mode=TwoWay}"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<TextBlock Text="{x:Static s:guiStrings.TextAudioConversion}" Margin="20,10,20,0"/>
|
<TextBlock Text="{x:Static s:guiStrings.TextAudioConversion}" Margin="20,10,20,0"/>
|
||||||
|
<TextBlock x:Name="DestinationLabel" Text="{x:Static s:guiStrings.LabelDestinationDir}" Margin="20,10,20,10" VerticalAlignment="Top"/>
|
||||||
|
<Grid>
|
||||||
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="350"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
</Grid.ColumnDefinitions>
|
||||||
|
<local:ExtAutoCompleteBox x:Name="DestinationDir" Margin="20,0,0,0" VerticalAlignment="Bottom" Grid.Row="0" Grid.Column="0" Height="23"/>
|
||||||
|
<Button Margin="10,0,20,0" VerticalAlignment="Bottom" HorizontalAlignment="Right" Grid.Row="0" Grid.Column="1"
|
||||||
|
Command="{x:Static local:Commands.Browse}" Height="22" Width="22">
|
||||||
|
<Image Source="{StaticResource IconSearch}" Stretch="Uniform" UseLayoutRounding="True" SnapsToDevicePixels="True" Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Button>
|
||||||
|
</Grid>
|
||||||
<CheckBox Name="IgnoreErrors" Content="{x:Static s:guiStrings.LabelSkipFailures}" Margin="20,10"
|
<CheckBox Name="IgnoreErrors" Content="{x:Static s:guiStrings.LabelSkipFailures}" Margin="20,10"
|
||||||
IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=appIgnoreConversionErrors, Mode=TwoWay}"/>
|
IsChecked="{Binding Source={x:Static p:Settings.Default}, Path=appIgnoreConversionErrors, Mode=TwoWay}"/>
|
||||||
<Separator/>
|
<Separator/>
|
||||||
@ -23,4 +36,7 @@
|
|||||||
<Button Content="{x:Static s:guiStrings.ButtonCancel}" Margin="10" IsCancel="True" Width="75" Height="25"/>
|
<Button Content="{x:Static s:guiStrings.ButtonCancel}" Margin="10" IsCancel="True" Width="75" Height="25"/>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
<Window.CommandBindings>
|
||||||
|
<CommandBinding Command="{x:Static local:Commands.Browse}" Executed="BrowseExec" CanExecute="CanExecuteAlways"/>
|
||||||
|
</Window.CommandBindings>
|
||||||
</Window>
|
</Window>
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using GARbro.GUI.Strings;
|
||||||
|
using Microsoft.WindowsAPICodePack.Dialogs;
|
||||||
|
|
||||||
namespace GARbro.GUI
|
namespace GARbro.GUI
|
||||||
{
|
{
|
||||||
@ -12,6 +15,32 @@ namespace GARbro.GUI
|
|||||||
InitializeComponent ();
|
InitializeComponent ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void BrowseExec (object sender, ExecutedRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
var dlg = new CommonOpenFileDialog
|
||||||
|
{
|
||||||
|
Title = guiStrings.TextChooseDestDir,
|
||||||
|
IsFolderPicker = true,
|
||||||
|
InitialDirectory = DestinationDir.Text,
|
||||||
|
|
||||||
|
AddToMostRecentlyUsedList = false,
|
||||||
|
AllowNonFileSystemItems = false,
|
||||||
|
EnsureFileExists = true,
|
||||||
|
EnsurePathExists = true,
|
||||||
|
EnsureReadOnly = false,
|
||||||
|
EnsureValidNames = true,
|
||||||
|
Multiselect = false,
|
||||||
|
ShowPlacesList = true,
|
||||||
|
};
|
||||||
|
if (dlg.ShowDialog (this) == CommonFileDialogResult.Ok)
|
||||||
|
DestinationDir.Text = dlg.FileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CanExecuteAlways (object sender, CanExecuteRoutedEventArgs e)
|
||||||
|
{
|
||||||
|
e.CanExecute = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void ConvertButton_Click (object sender, RoutedEventArgs e)
|
private void ConvertButton_Click (object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.DialogResult = true;
|
this.DialogResult = true;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
//! \date Fri Aug 22 08:22:47 2014
|
//! \date Fri Aug 22 08:22:47 2014
|
||||||
//! \brief Game resources conversion methods.
|
//! \brief Game resources conversion methods.
|
||||||
//
|
//
|
||||||
// Copyright (C) 2014-2015 by morkt
|
// Copyright (C) 2014-2016 by morkt
|
||||||
//
|
//
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
// of this software and associated documentation files (the "Software"), to
|
// of this software and associated documentation files (the "Software"), to
|
||||||
@ -56,6 +56,14 @@ namespace GARbro.GUI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var convert_dialog = new ConvertMedia();
|
var convert_dialog = new ConvertMedia();
|
||||||
|
|
||||||
|
string destination = ViewModel.Path.First();
|
||||||
|
if (ViewModel.IsArchive)
|
||||||
|
destination = Path.GetDirectoryName (destination);
|
||||||
|
if (!IsWritableDirectory (destination) && Directory.Exists (Settings.Default.appLastDestination))
|
||||||
|
destination = Settings.Default.appLastDestination;
|
||||||
|
convert_dialog.DestinationDir.Text = destination;
|
||||||
|
|
||||||
convert_dialog.Owner = this;
|
convert_dialog.Owner = this;
|
||||||
var result = convert_dialog.ShowDialog() ?? false;
|
var result = convert_dialog.ShowDialog() ?? false;
|
||||||
if (!result)
|
if (!result)
|
||||||
@ -68,16 +76,24 @@ namespace GARbro.GUI
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Directory.SetCurrentDirectory (ViewModel.Path.First());
|
destination = convert_dialog.DestinationDir.Text;
|
||||||
|
Directory.SetCurrentDirectory (destination);
|
||||||
var converter = new GarConvertMedia (this);
|
var converter = new GarConvertMedia (this);
|
||||||
converter.IgnoreErrors = convert_dialog.IgnoreErrors.IsChecked ?? false;
|
converter.IgnoreErrors = convert_dialog.IgnoreErrors.IsChecked ?? false;
|
||||||
converter.Convert (source, format);
|
converter.Convert (source, format);
|
||||||
|
Settings.Default.appLastDestination = destination;
|
||||||
}
|
}
|
||||||
catch (Exception X)
|
catch (Exception X)
|
||||||
{
|
{
|
||||||
PopupError (X.Message, guiStrings.TextMediaConvertError);
|
PopupError (X.Message, guiStrings.TextMediaConvertError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsWritableDirectory (string path)
|
||||||
|
{
|
||||||
|
var info = new DirectoryInfo (path);
|
||||||
|
return !info.Attributes.HasFlag (FileAttributes.ReadOnly);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class GarConvertMedia
|
internal class GarConvertMedia
|
||||||
@ -165,13 +181,14 @@ namespace GARbro.GUI
|
|||||||
{
|
{
|
||||||
if (null == input)
|
if (null == input)
|
||||||
return;
|
return;
|
||||||
|
string output_name = Path.GetFileName (filename);
|
||||||
var source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
|
var source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
|
||||||
string source_format = input.SourceFormat;
|
string source_format = input.SourceFormat;
|
||||||
if (CommonAudioFormats.Contains (source_format))
|
if (CommonAudioFormats.Contains (source_format))
|
||||||
{
|
{
|
||||||
if (source_ext == source_format)
|
if (source_ext == source_format)
|
||||||
return;
|
return;
|
||||||
string output_name = Path.ChangeExtension (filename, source_format);
|
output_name = Path.ChangeExtension (output_name, source_format);
|
||||||
using (var output = CreateNewFile (output_name))
|
using (var output = CreateNewFile (output_name))
|
||||||
{
|
{
|
||||||
input.Source.Position = 0;
|
input.Source.Position = 0;
|
||||||
@ -182,7 +199,7 @@ namespace GARbro.GUI
|
|||||||
{
|
{
|
||||||
if (source_ext == "wav")
|
if (source_ext == "wav")
|
||||||
return;
|
return;
|
||||||
string output_name = Path.ChangeExtension (filename, "wav");
|
output_name = Path.ChangeExtension (output_name, "wav");
|
||||||
using (var output = CreateNewFile (output_name))
|
using (var output = CreateNewFile (output_name))
|
||||||
AudioFormat.Wav.Write (input, output);
|
AudioFormat.Wav.Write (input, output);
|
||||||
}
|
}
|
||||||
@ -194,8 +211,9 @@ namespace GARbro.GUI
|
|||||||
string source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
|
string source_ext = Path.GetExtension (filename).TrimStart ('.').ToLowerInvariant();
|
||||||
if (m_image_format.Extensions.Any (ext => ext == source_ext))
|
if (m_image_format.Extensions.Any (ext => ext == source_ext))
|
||||||
return;
|
return;
|
||||||
|
string target_name = Path.GetFileName (filename);
|
||||||
string target_ext = m_image_format.Extensions.FirstOrDefault();
|
string target_ext = m_image_format.Extensions.FirstOrDefault();
|
||||||
string target_name = Path.ChangeExtension (filename, target_ext);
|
target_name = Path.ChangeExtension (target_name, target_ext);
|
||||||
using (var file = File.OpenRead (filename))
|
using (var file = File.OpenRead (filename))
|
||||||
{
|
{
|
||||||
var image = ImageFormat.Read (filename, file);
|
var image = ImageFormat.Read (filename, file);
|
||||||
|
11
GUI/Strings/guiStrings.Designer.cs
generated
11
GUI/Strings/guiStrings.Designer.cs
generated
@ -1,7 +1,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
// Runtime Version:4.0.30319.34209
|
// Runtime Version:4.0.30319.42000
|
||||||
//
|
//
|
||||||
// Changes to this file may cause incorrect behavior and will be lost if
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
// the code is regenerated.
|
// the code is regenerated.
|
||||||
@ -312,6 +312,15 @@ namespace GARbro.GUI.Strings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Destination directory.
|
||||||
|
/// </summary>
|
||||||
|
public static string LabelDestinationDir {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("LabelDestinationDir", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Choose destination format for images.
|
/// Looks up a localized string similar to Choose destination format for images.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -448,4 +448,8 @@
|
|||||||
<data name="Type_NONE" xml:space="preserve">
|
<data name="Type_NONE" xml:space="preserve">
|
||||||
<value>없음</value>
|
<value>없음</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LabelDestinationDir" xml:space="preserve">
|
||||||
|
<value>Destination directory</value>
|
||||||
|
<comment>translation pending</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -449,4 +449,7 @@ Overwrite?</value>
|
|||||||
<data name="Type_NONE" xml:space="preserve">
|
<data name="Type_NONE" xml:space="preserve">
|
||||||
<value>none</value>
|
<value>none</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LabelDestinationDir" xml:space="preserve">
|
||||||
|
<value>Destination directory</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -470,4 +470,7 @@
|
|||||||
<data name="Type_NONE" xml:space="preserve">
|
<data name="Type_NONE" xml:space="preserve">
|
||||||
<value>без типа</value>
|
<value>без типа</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LabelDestinationDir" xml:space="preserve">
|
||||||
|
<value>Сохранить результаты в</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -449,4 +449,8 @@
|
|||||||
<data name="Type_NONE" xml:space="preserve">
|
<data name="Type_NONE" xml:space="preserve">
|
||||||
<value>无</value>
|
<value>无</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="LabelDestinationDir" xml:space="preserve">
|
||||||
|
<value>Destination directory</value>
|
||||||
|
<comment>translation pending</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
Loading…
x
Reference in New Issue
Block a user