private void Browse_OnExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var parameter = e.Parameter as string;

            if (parameter == null)
            {
                return;
            }

            var isSource      = (parameter.Equals("Source", StringComparison.OrdinalIgnoreCase));
            var isDestination = (parameter.Equals("Destination", StringComparison.OrdinalIgnoreCase));

            if (isSource)
            {
                var dlg = new CommonOpenFileDialog("Open File");
                dlg.Filters.Add(new CommonFileDialogFilter("Coalesced Files", "*.bin;*.xml"));
                dlg.Filters.Add(new CommonFileDialogFilter("Binary Coalesced Files", "*.bin"));
                dlg.Filters.Add(new CommonFileDialogFilter("XML Coalesced Files", "*.xml"));

                if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                {
                    return;
                }

                SourcePath = dlg.FileName;
                var sourceExtension = Path.GetExtension(SourcePath) ?? "";

                switch (sourceExtension.ToLower())
                {
                case ".bin":
                {
                    SourceType = CoalescedType.Binary;

                    break;
                }

                case ".xml":
                {
                    SourceType = CoalescedType.Xml;

                    break;
                }
                }

                if (!string.IsNullOrEmpty(DestinationPath) && ChangeDestinationCheckBox.IsChecked == false)
                {
                    return;
                }

                switch (SourceType)
                {
                case CoalescedType.Binary:
                {
                    DestinationPath = Path.ChangeExtension(SourcePath, null);
                    DestinationType = CoalescedType.Xml;

                    break;
                }

                case CoalescedType.Xml:
                {
                    DestinationPath = Path.ChangeExtension(SourcePath, "bin");
                    DestinationType = CoalescedType.Binary;

                    break;
                }
                }
            }
            else if (isDestination)
            {
                switch (SourceType)
                {
                case CoalescedType.Binary:
                {
                    var dlg = new CommonOpenFileDialog("Select Folder")
                    {
                        IsFolderPicker = true
                    };

                    if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                    {
                        return;
                    }

                    DestinationPath = dlg.FileName;
                    //DestinationType = CoalescedType.Binary;

                    break;
                }

                case CoalescedType.Xml:
                {
                    var dlg = new CommonOpenFileDialog("Open File");
                    dlg.Filters.Add(new CommonFileDialogFilter("Coalesced Files", "*.bin;*.xml"));
                    dlg.Filters.Add(new CommonFileDialogFilter("Binary Coalesced Files", "*.bin"));
                    dlg.Filters.Add(new CommonFileDialogFilter("XML Coalesced Files", "*.xml"));

                    if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
                    {
                        return;
                    }

                    DestinationPath = dlg.FileName;

                    /*if (!Path.HasExtension(DestinationPath))
                     * {
                     *      return;
                     * }
                     *
                     * var destinationExtension = Path.GetExtension(DestinationPath) ?? "";
                     *
                     * switch (destinationExtension.ToLower())
                     * {
                     *      case ".bin":
                     *      {
                     *              break;
                     *      }
                     *      case ".xml":
                     *      {
                     *              break;
                     *      }
                     * }*/

                    break;
                }
                }
            }
        }
Exemplo n.º 2
0
        public void BrowseSource()
        {
            var dlg = new CommonOpenFileDialog("Open File");

            dlg.Filters.Add(new CommonFileDialogFilter("Coalesced Files", "*.bin;*.xml"));
            dlg.Filters.Add(new CommonFileDialogFilter("Binary Coalesced Files", "*.bin"));
            dlg.Filters.Add(new CommonFileDialogFilter("XML Coalesced Files", "*.xml"));

            if (dlg.ShowDialog() != CommonFileDialogResult.Ok)
            {
                return;
            }

            SourcePath = dlg.FileName;
            var sourceExtension = Path.GetExtension(SourcePath) ?? "";

            switch (sourceExtension.ToLower())
            {
            case ".tlk":
            {
                SourceType = CoalescedType.Binary;

                break;
            }

            case ".xml":
            {
                SourceType = CoalescedType.Xml;

                break;
            }

            default:
            {
                SourceType = CoalescedType.None;

                break;
            }
            }

            if (/*!string.IsNullOrEmpty(DestinationPath) && */ !AutoChangeDestination)
            {
                return;
            }

            switch (SourceType)
            {
            case CoalescedType.Binary:
            {
                DestinationPath = Path.ChangeExtension(SourcePath, "xml");
                DestinationType = CoalescedType.Xml;

                break;
            }

            case CoalescedType.Xml:
            {
                DestinationPath = Path.ChangeExtension(SourcePath, "bin");
                DestinationType = CoalescedType.Binary;

                break;
            }

            default:
            {
                DestinationType = CoalescedType.None;
                return;
            }
            }
        }