2014-07-24 05:43:20 +04:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows;
|
2014-07-25 07:05:55 +04:00
|
|
|
|
using System.Windows.Controls;
|
2014-07-24 05:43:20 +04:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
using GARbro.GUI.Strings;
|
|
|
|
|
using GameRes;
|
|
|
|
|
|
|
|
|
|
namespace GARbro.GUI
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for CreateArchive.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class CreateArchiveDialog : Window
|
|
|
|
|
{
|
2014-07-25 07:05:55 +04:00
|
|
|
|
public CreateArchiveDialog (string initial_name = "")
|
2014-07-24 05:43:20 +04:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent ();
|
|
|
|
|
|
2014-07-25 07:05:55 +04:00
|
|
|
|
if (!string.IsNullOrEmpty (initial_name))
|
|
|
|
|
{
|
|
|
|
|
var format = this.ArchiveFormat.SelectedItem as ArchiveFormat;
|
|
|
|
|
if (null != format)
|
|
|
|
|
ArchiveName.Text = Path.ChangeExtension (initial_name, format.Extensions.First());
|
|
|
|
|
}
|
2014-07-24 05:43:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResourceOptions ArchiveOptions { get; private set; }
|
|
|
|
|
|
|
|
|
|
void Button_Click (object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2014-07-25 07:05:55 +04:00
|
|
|
|
string arc_name = Path.GetFullPath (ArchiveName.Text);
|
|
|
|
|
if (File.Exists (arc_name))
|
|
|
|
|
{
|
|
|
|
|
string text = string.Format (guiStrings.MsgOverwrite, arc_name);
|
|
|
|
|
var rc = MessageBox.Show (this, text, guiStrings.TextConfirmOverwrite, MessageBoxButton.YesNo,
|
|
|
|
|
MessageBoxImage.Question);
|
|
|
|
|
if (MessageBoxResult.Yes != rc)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-07-24 05:43:20 +04:00
|
|
|
|
DialogResult = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BrowseExec (object sender, ExecutedRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string file = ChooseFile (guiStrings.TextChooseArchive, ArchiveName.Text);
|
|
|
|
|
if (!string.IsNullOrEmpty (file))
|
|
|
|
|
ArchiveName.Text = file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string GetFilters ()
|
|
|
|
|
{
|
|
|
|
|
var filters = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
var format = this.ArchiveFormat.SelectedItem as ArchiveFormat;
|
|
|
|
|
if (null != format)
|
|
|
|
|
{
|
|
|
|
|
var patterns = format.Extensions.Select (ext => "*."+ext);
|
|
|
|
|
filters.Append (format.Description);
|
|
|
|
|
filters.Append (" (");
|
|
|
|
|
filters.Append (string.Join (", ", patterns));
|
|
|
|
|
filters.Append (")|");
|
|
|
|
|
filters.Append (string.Join (";", patterns));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (filters.Length > 0)
|
|
|
|
|
filters.Append ('|');
|
|
|
|
|
filters.Append (string.Format ("{0} (*.*)|*.*", guiStrings.TextAllFiles));
|
|
|
|
|
return filters.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ChooseFile (string title, string initial)
|
|
|
|
|
{
|
|
|
|
|
string dir = ".";
|
|
|
|
|
if (!string.IsNullOrEmpty (initial))
|
|
|
|
|
{
|
|
|
|
|
var parent = Directory.GetParent (initial);
|
|
|
|
|
if (null != parent)
|
|
|
|
|
dir = parent.FullName;
|
|
|
|
|
}
|
|
|
|
|
dir = Path.GetFullPath (dir);
|
|
|
|
|
var dlg = new OpenFileDialog {
|
|
|
|
|
InitialDirectory = dir,
|
|
|
|
|
Multiselect = false,
|
|
|
|
|
Filter = GetFilters(),
|
|
|
|
|
};
|
|
|
|
|
return dlg.ShowDialog (this).Value ? dlg.FileName : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnFormatSelect (object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var format = this.ArchiveFormat.SelectedItem as ArchiveFormat;
|
|
|
|
|
UIElement widget = null;
|
|
|
|
|
if (null != format)
|
|
|
|
|
{
|
|
|
|
|
var options = format.GetOptions();
|
|
|
|
|
ArchiveOptions = options;
|
|
|
|
|
if (null != options)
|
|
|
|
|
widget = options.Widget as UIElement;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ArchiveOptions = null;
|
|
|
|
|
}
|
|
|
|
|
OptionsWidget.Content = widget;
|
|
|
|
|
OptionsWidget.Visibility = null != widget ? Visibility.Visible : Visibility.Hidden;
|
2014-07-25 07:05:55 +04:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty (ArchiveName.Text))
|
|
|
|
|
{
|
|
|
|
|
ArchiveName.Text = Path.ChangeExtension (ArchiveName.Text, format.Extensions.First());
|
|
|
|
|
}
|
2014-07-24 05:43:20 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CanExecuteAlways (object sender, CanExecuteRoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
e.CanExecute = true;
|
|
|
|
|
}
|
2014-07-25 07:05:55 +04:00
|
|
|
|
|
|
|
|
|
private void ArchiveName_TextChanged (object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.ButtonOk.IsEnabled = ArchiveName.Text.Length > 0;
|
|
|
|
|
}
|
2014-07-24 05:43:20 +04:00
|
|
|
|
}
|
|
|
|
|
}
|