private void UI_ImportTextureButton_Click(object sender, RoutedEventArgs e) { var ofd = new OpenFileDialog(); ofd.Filter = "All Supported Files|*.tex;*.png|Texture|*.tex|Supported Image Files|*.png"; if (ofd.ShowDialog() == true) { if (ofd.FileName.ToLower(CultureInfo.GetCultureInfo("en-US")).EndsWith(".tex")) { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load new Texture newTexture.Load(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Import Texture into PCK PCKFontArchive.ReplaceFile(textureFilePath, File.ReadAllBytes(ofd.FileName)); // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } else { var textureFilePath = PCKFontArchive.SearchForFile(".tex"); var newTexture = new TEXFile(); // Set Sigless newTexture.Sigless = true; // Load Image to Texture newTexture.LoadSheetImage(ofd.FileName); // Check Dimensions if (FontImageTexFile.SheetData != null && (newTexture.SheetWidth != FontImageTexFile.SheetWidth || newTexture.SheetHeight != FontImageTexFile.SheetHeight)) { if (MessageBox.Show("Texture dimensions do not match!\n" + "FontEditor currently does not support rescaling, Do you want to continue?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } } // Save Texture to PCK using (var stream = new MemoryStream()) { newTexture.Save(stream); PCKFontArchive.ReplaceFile(textureFilePath, stream.ToArray()); } // Set Texture UI_FontImage.Source = ImageTools.ConvertToSource((FontImageTexFile = newTexture).CreateBitmap()); } } }
public static void Main(string[] args) { var tex = new TEXFile(); if (args.Length == 0) { ShowHelp("Not Enough Arguments!"); return; } // Preprocess if (args.Length > 1) { string path = ""; for (int i = 0; i < args.Length; ++i) { if (args[i].StartsWith("-") && args[i].Length > 1) { switch (args[i][1]) { case 'z': tex.UseSmallSig = true; break; case 'e': tex.UseBigEndian = true; break; case 'c': CheckOverwrite = false; break; case 'o': path = args[i + 1]; break; default: break; } continue; } } // Actions for (int i = args.Length - 1; i >= 0; --i) { if (args[i].StartsWith("-") && args[i].Length > 1) { switch (args[i][1]) { case 'p': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = RemoveExtension(args[args.Length - 1]); } Directory.CreateDirectory(path); for (int ii = 0; ii < tex.Frames.Count; ++ii) { SaveFrame(tex, ii, Path.Combine(path, $"frame{ii:d2}.png")); } break; case 's': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".png"); } if (CheckForOverwrite(path)) { tex.SaveSheetImage(path); } break; case 'i': tex.Load(args[args.Length - 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".xml"); } SaveAllFrameInformation(tex, path); break; case 'f': tex.Load(args[args.Length - 1]); if (CheckForOverwrite(path)) { SaveFrame(tex, int.Parse(args[i + 1]), path); } break; case 'b': BuildTEX(ref tex, args[i + 1], args[i + 2]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".tex"); } if (CheckForOverwrite(path)) { tex.Save(path); } break; case 'm': BuildTEX(ref tex, args[i + 1]); if (string.IsNullOrEmpty(path)) { path = Path.ChangeExtension(args[args.Length - 1], ".tex"); } if (CheckForOverwrite(path)) { tex.Save(path); } break; } } } } else { if (Path.GetExtension(args[0]) == ".png" || Path.GetExtension(args[0]) == ".xml" || Directory.Exists(args[0])) { Console.WriteLine("Building Files detected, Building..."); BuildTEX(ref tex, args[0]); string path = Path.ChangeExtension(args[0], ".tex"); if (CheckForOverwrite(path)) { tex.Save(path); } } else { tex.Load(args[0]); tex.SaveSheetImage(Path.ChangeExtension(args[0], ".png")); SaveAllFrameInformation(tex, Path.ChangeExtension(args[0], ".xml")); } } }