private async void convertFiles(object sender, RoutedEventArgs e) { mainMenu.IsEnabled = false; SpinnerConvert.Visibility = Visibility.Visible; tbConvert.Text = "Converting"; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.InitialDirectory = Settings.Default.lastConvertedPath; openFileDialog.Multiselect = true; string operationType = (sender as MenuItem).Tag.ToString(); //await DdtFileUtils.Ddt2PngAsync(@"D:\Development\Resource Manager\Resource Manager\bin\Release\netcoreapp3.1\Art\ui\alerts\alert_treatyend_bump.ddt"); if (operationType == "totga") { openFileDialog.Filter = "Age of Empires 3 ddt files (*.ddt)|*.ddt"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { await DdtFileUtils.Ddt2TgaAsync(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "topng") { openFileDialog.Filter = "Age of Empires 3 ddt files (*.ddt)|*.ddt"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { await DdtFileUtils.Ddt2PngAsync(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxml") { openFileDialog.Filter = "Age of Empires 3 xmb files (*.xmb)|*.xmb"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { var data = await File.ReadAllBytesAsync(file); if (Alz4Utils.IsAlz4File(data)) { data = await Alz4Utils.ExtractAlz4BytesAsync(data); } else { if (L33TZipUtils.IsL33TZipFile(data)) { data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data); } } using MemoryStream stream = new MemoryStream(data); XMBFile xmb = await XMBFile.LoadXMBFile(stream); var newName = Path.ChangeExtension(file, ""); xmb.file.Save(newName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "jsontoxml") { openFileDialog.Filter = "JSON files (*.json)|*.json"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { var data = await File.ReadAllBytesAsync(file); if (Alz4Utils.IsAlz4File(data)) { data = await Alz4Utils.ExtractAlz4BytesAsync(data); } else { if (L33TZipUtils.IsL33TZipFile(data)) { data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data); } } string json = await File.ReadAllTextAsync(file); var xml = JsonConvert.DeserializeXmlNode(json); var newName = Path.ChangeExtension(file, ""); xml.Save(newName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "xmbtojson") { openFileDialog.Filter = "Age of Empires 3 xmb files (*.xmb)|*.xmb"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { var data = await File.ReadAllBytesAsync(file); if (Alz4Utils.IsAlz4File(data)) { data = await Alz4Utils.ExtractAlz4BytesAsync(data); } else { if (L33TZipUtils.IsL33TZipFile(data)) { data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data); } } using MemoryStream stream = new MemoryStream(data); XMBFile xmb = await XMBFile.LoadXMBFile(stream); string json = JsonConvert.SerializeXmlNode(xmb.file); await File.WriteAllTextAsync(Path.ChangeExtension(file, "json"), json); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "xmltojson") { openFileDialog.Filter = "Age of Empires 3 xml files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { XmlDocument xml = new XmlDocument(); xml.Load(file); string json = JsonConvert.SerializeXmlNode(xml); await File.WriteAllTextAsync(Path.ChangeExtension(file, "json"), json); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "jsontoxmblegacy") { openFileDialog.Filter = "JSON files (*.json)|*.json"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { string json = await File.ReadAllTextAsync(file); var xml = JsonConvert.DeserializeXmlNode(json); await XMBFile.CreateXMBFileL33T(xml, file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "jsontoxmbde") { openFileDialog.Filter = "JSON files (*.json)|*.json"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { string json = await File.ReadAllTextAsync(file); var xml = JsonConvert.DeserializeXmlNode(json); await XMBFile.CreateXMBFileALZ4(xml, file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxmbde") { openFileDialog.Filter = "Age of Empires 3 xml files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); foreach (var file in openFileDialog.FileNames) { try { await XMBFile.CreateXMBFileALZ4(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxmbcc") { openFileDialog.Filter = "Age of Empires 3 xml files (*.*)|*.*"; if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { Settings.Default.lastConvertedPath = Path.GetDirectoryName(openFileDialog.FileName); Settings.Default.Save(); try { await XMBFile.CreateXMBFileL33T(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } tbConvert.Text = "Convert"; SpinnerConvert.Visibility = Visibility.Collapsed; mainMenu.IsEnabled = true; }
private async void convertFiles(object sender, RoutedEventArgs e) { mainMenu.IsEnabled = false; SpinnerConvert.Visibility = Visibility.Visible; tbConvert.Text = "Converting"; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = true; string operationType = (sender as MenuItem).Tag.ToString(); //await DdtFileUtils.Ddt2PngAsync(@"D:\Development\Resource Manager\Resource Manager\bin\Release\netcoreapp3.1\Art\ui\alerts\alert_treatyend_bump.ddt"); if (operationType == "topng") { openFileDialog.Filter = "Age of Empires 3 ddt files (*.ddt)|*.ddt"; if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { try { await DdtFileUtils.Ddt2PngAsync(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxml") { openFileDialog.Filter = "Age of Empires 3 xmb files (*.xmb)|*.xmb"; if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { try { var data = await File.ReadAllBytesAsync(file); if (Alz4Utils.IsAlz4File(data)) { data = await Alz4Utils.ExtractAlz4BytesAsync(data); } else { if (L33TZipUtils.IsL33TZipFile(data)) { data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data); } } using MemoryStream stream = new MemoryStream(data); XMBFile xmb = await XMBFile.LoadXMBFile(stream); var newName = Path.ChangeExtension(file, ""); xmb.file.Save(newName); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxmbde") { openFileDialog.Filter = "Age of Empires 3 xml files (*.xml)|*.xml"; if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { try { await XMBFile.CreateXMBFileALZ4(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } if (operationType == "toxmbcc") { openFileDialog.Filter = "Age of Empires 3 xml files (*.xml)|*.xml"; if (openFileDialog.ShowDialog() == true) { foreach (var file in openFileDialog.FileNames) { try { await XMBFile.CreateXMBFileL33T(file); } catch (Exception ex) { MessageBox.Show(ex.Message, "Conversion error - " + Path.GetFileName(file), MessageBoxButton.OK, MessageBoxImage.Error); } } } } tbConvert.Text = "Convert"; SpinnerConvert.Visibility = Visibility.Collapsed; mainMenu.IsEnabled = true; }