static void Main(string[] args) { bool ConsoleMode = args.Length > 1; if (ConsoleMode) { AllocConsole(); var inputFile = args[0]; var outputFile = args[1]; var tool = new TEXTool(); tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read)); tool.SaveFile(outputFile); } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm form = new MainForm(); // Open With.. if (args.Length > 0) { form.Tool.OpenFile(args[0], new FileStream(args[0], FileMode.Open, FileAccess.Read)); } Application.Run(form); } }
private void OpenFileDialog() { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Filter = "Klei Texture Files (*.tex)|*.tex|(Klei Xml File)|*.xml|All Files (*.*)|*.*"; dialog.DefaultExt = "tex"; if (dialog.ShowDialog(this) == DialogResult.OK) { string[] file = dialog.FileName.Split('.'); if (file[file.Length - 1] == "xml") { TEXTool tool = new TEXTool(); XmlDocument anxml = new XmlDocument(); anxml.LoadXml(File.ReadAllText(dialog.FileName)); XmlNode atlas = anxml.GetElementsByTagName("Atlas")[0]; XmlNode texture = atlas.SelectSingleNode("Texture"); string texname = texture.Attributes["filename"].Value; string dictor = Path.GetDirectoryName(dialog.FileName) + @"\"; string xmlpath = dictor + texname; Console.WriteLine(xmlpath); tool.OpenFile(dialog.SafeFileName, new FileStream(xmlpath, FileMode.Open)); int alterwidth = tool.CurrentFileRaw.Width; int alterheight = tool.CurrentFileRaw.Height; XmlNode Elements = atlas.SelectSingleNode("Elements"); XmlNodeList elements = Elements.SelectNodes("Element"); foreach (XmlNode node in elements) { string name = node.Attributes["name"].Value.Split('.')[0] + ".png"; float u1 = Convert.ToSingle(node.Attributes["u1"].Value); float u2 = Convert.ToSingle(node.Attributes["u2"].Value); float v1 = Convert.ToSingle(node.Attributes["v1"].Value); float v2 = Convert.ToSingle(node.Attributes["v2"].Value); int imageheight = (int)(alterheight * v2 - alterheight * v1); int imagewidth = (int)(alterwidth * u2 - alterwidth * u1); Console.WriteLine("(" + (int)(alterwidth * u1) + "," + (int)(alterheight - (alterheight * v1) - imageheight) + ") (" + (int)(alterwidth * u2) + "," + (int)(alterheight - alterheight * v2 + imageheight) + ")"); Rectangle cloneRect = new Rectangle((int)(alterwidth * u1), (int)(alterheight - (alterheight * v1) - imageheight), imagewidth, imageheight); //Rectangle cloneRect = new Rectangle(0, (int)(alterheight - (alterheight * v1) - imageheight), (int)(alterwidth * u2), (int)(alterheight - alterheight * v2 + imageheight)); System.Drawing.Imaging.PixelFormat format = tool.CurrentFileRaw.PixelFormat; Bitmap cloneBitmap = tool.CurrentFileRaw.Clone(cloneRect, format); FileStream wimage = new FileStream(dictor + name, FileMode.Create); cloneBitmap.Save(wimage, ImageFormat.Png); wimage.Close(); } System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe"); psi.Arguments = "/e,/select," + dialog.FileName; System.Diagnostics.Process.Start(psi); return; } ProgressForm = new ProgressForm(); ProgressForm.StartPosition = FormStartPosition.CenterParent; backgroundWorker.RunWorkerAsync(dialog); ProgressForm.ShowDialog(this); } } }
static void Main(string[] args) { bool ConsoleMode = args.Length > 1; if (ConsoleMode) { AllocConsole(); var inputFile = args[0]; var outputFile = args[1]; var tool = new TEXTool(); tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read)); tool.FileOpened += (sender, ev) => { tool.SaveFile(outputFile); }; } else { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainForm form = new MainForm(); // Open With.. //if (args.Length > 0) // form.Tool.OpenFile(args[0], new FileStream(args[0], FileMode.Open, FileAccess.Read)); Task t = new Task(() => { Thread.Sleep(1000); if (args.Length > 0) { form.OpenExternalFile(args[0]); } }); t.Start(); Application.Run(form); } }
public MainForm() { Tool = new TEXTool(); Tool.FileOpened += new FileOpenedEventHandler(TEXTool_FileOpened); Tool.FileRawImage += new FileRawImageEventHandler(tool_FileRawImage); Tool.OnProgressUpdate += tool_OnProgressUpdate; InitializeComponent(); FillZoomLevelComboBox(); versionToolStripLabel.Text = string.Format("Version: {0}", Assembly.GetEntryAssembly().GetName().Version); foreach (PropertyInfo prop in typeof(Color).GetProperties()) { if (prop.PropertyType.FullName == "System.Drawing.Color") { atlasElementBorderColors.ComboBox.Items.Add(prop.Name); } } atlasElementBorderColors.ComboBox.SelectedItem = "Black"; atlasElementsListToolStripComboBox.ComboBox.DisplayMember = "Name"; }
static void Main(string[] args) { if (args.Length == 0 || (args.Length == 1 && !args[0].StartsWith("-"))) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm(args)); } else { bool covertall = false; string inputFile = ""; string outputFile = ""; string elementname = ""; string outputDictionary = ""; Dictionary <string, string> arguments = new Dictionary <string, string>(); for (int i = 0; i < args.Length - 1; i++) { if (args[i].StartsWith("-")) { arguments.Add(args[i], i + 1 <= args.Length & args[i + 1].StartsWith("-") ? "" : args[i + 1]); } } if (args[args.Length - 1].StartsWith("-")) { arguments.Add(args[args.Length - 1], ""); } foreach (KeyValuePair <string, string> kvp in arguments) { switch (kvp.Key) { case "-i": inputFile = kvp.Value; break; case "-o": outputFile = kvp.Value; break; case "-a": covertall = true; break; case "-l": elementname = kvp.Value; break; case "-od": outputDictionary = kvp.Value; break; case "--help": Console.WriteLine("Welcome to use TexTool. You can use: TexTools [options...] <FileName/DictionaryName>"); Console.WriteLine("-i <input> Type in the input filename"); Console.WriteLine("-o <output> Type in the output filename"); Console.WriteLine(" Only effect while using -l or without -a"); Console.WriteLine("-a Covert all of the single images into separate single files"); Console.WriteLine("-l <imagename> Covert the image which is named as <imagename>"); Console.WriteLine(" The output filename will be <output> or <imagename>"); Console.WriteLine(" depense on the <output> is given"); Console.WriteLine("-od <dictionary> Type in the output dictionary"); Console.WriteLine(" If the <dictionary> is given while path is alse in <output>,"); Console.WriteLine(" the output file will be move into <dictionary> and named as <output>"); Console.WriteLine("If you have any problem or find any bug, please submit an issus on https://github.com/zxcvbnm3057/dont-starve-tools"); break; default: CommandError(); break; } } if (outputDictionary != "") { Directory.SetCurrentDirectory(outputDictionary); } else if (outputFile != "") { Directory.SetCurrentDirectory(Path.GetDirectoryName(outputFile)); } else if (inputFile != "") { Directory.SetCurrentDirectory(Path.GetDirectoryName(inputFile)); } if (outputFile != "") { outputFile = Path.GetFileName(outputFile); } if (inputFile != "") { if (covertall) { var tool = new TEXTool(); tool.ImageLoaded += (sender, ev) => { foreach (KleiTextureAtlasElement element in TEXTool.atlasElements) { tool.SaveFileSingle(Path.GetFileNameWithoutExtension(element.Name) + ".png", element); } }; tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read)); } else if (elementname != "") { var tool = new TEXTool(); tool.ImageLoaded += (sender, ev) => { foreach (KleiTextureAtlasElement element in TEXTool.atlasElements) { if (element.Name == elementname) { tool.SaveFileSingle(outputFile != "" ? outputFile : Path.GetFileNameWithoutExtension(element.Name) + ".png", element); break; } } }; tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read)); } else { var tool = new TEXTool(); tool.ImageLoaded += (sender, ev) => { tool.SaveFileAll(outputFile != "" ? outputFile : Path.GetFileNameWithoutExtension(ev.FileName) + ".png"); }; tool.OpenFile(inputFile, new FileStream(inputFile, FileMode.Open, FileAccess.Read)); } } else { CommandError(); } } }