public PrinterHint GetHeader(int pagewidth, string text) { int captionHeight = 45; Font font = new Font("宋体", 20); Graphics g = this.button1.CreateGraphics(); int height = (int)g.MeasureString(text, font).Height; int width = (int)g.MeasureString(text, font).Width; g.Dispose(); PrinterHint header = new PrinterHint(); header.Rectangle = new Rectangle(0, 0, pagewidth, height + captionHeight + 12); header.PrintInEveryPage = true; header.Border = BordersEdgeStyle.None; TitleDraw title = new TitleDraw(text); title.Font = font; title.Rectangle = new Rectangle((pagewidth - width) / 2, 0, width, height); title.Border = BordersEdgeStyle.Bottom; TitleDraw line = new TitleDraw(""); line.Rectangle = new Rectangle((pagewidth - width) / 2, 2, width, height); line.Border = BordersEdgeStyle.Bottom; header.Add(title); header.Add(line); StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; Font cap = new Font("宋体", 14); TextDraw header2 = new TextDraw("培训单位: 报考车型: 考试日期: 年 月 日"); header2.Formater = sf; header2.Font = cap; header2.Rectangle = new Rectangle(0, height + 7, pagewidth, captionHeight); header2.Border = BordersEdgeStyle.None; CompanyInfo compInfo = StaticCacheManager.GetConfig <CompanyInfo>(); TextDraw comp = new TextDraw(compInfo.NickName); comp.Formater = sf; comp.Font = cap; comp.Rectangle = new Rectangle(100, height + 7, 200, captionHeight); comp.Border = BordersEdgeStyle.None; header.Add(comp); header.Add(header2); return(header); }
public static void FinishWithError(string message, bool immediate = false) { Console.Clear(); TitleDraw.DumpFailed(Logger); Logger.ErrorL(message, Color.OrangeRed); Console.ResetColor(); Console.WriteLine("Press any key to exit."); if (!immediate) { Console.ReadKey(); } Environment.Exit(1); }
public static void FinishWithSuccess(long process, long metadata, long export, int entries) { Console.Clear(); TitleDraw.Complete(Logger); Logger.Info(" - ", Color.OrangeRed); Logger.Info("Processing took ", Color.White); Logger.Info(process.ToString(), Color.Aquamarine); Logger.Info("ms", Color.LightGoldenrodYellow); Logger.Info(" - ", Color.OrangeRed); Logger.Info("Metadata export took ", Color.White); Logger.Info(metadata.ToString(), Color.Aquamarine); Logger.Info("ms", Color.LightGoldenrodYellow); Logger.Info(" - ", Color.OrangeRed); Logger.Info("File export took ", Color.White); Logger.Info($"{export / 1000}", Color.Aquamarine); Logger.Info("s", Color.Goldenrod); Logger.InfoL(" - ", Color.OrangeRed); Logger.Info(" - ", Color.OrangeRed); Logger.Info("Exported ", Color.White); Logger.Info(entries.ToString(), Color.Aquamarine); Logger.Info(" files.", Color.White); Logger.InfoL(" - ", Color.OrangeRed); Console.ResetColor(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); Environment.Exit(0); }
protected virtual PrinterHint BuildHeader() { StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Far; sf.Alignment = StringAlignment.Far; StringFormat sf2 = new StringFormat(); sf2.LineAlignment = StringAlignment.Center; sf2.Alignment = StringAlignment.Center; CompanyInfo comp = StaticCacheManager.GetConfig<CompanyInfo>(); int pagewidth = customMargin.Width; int captionHeight = 70; Font font = new Font("宋体", 20); Font cap = new Font("宋体", 14); int height = 25; PrinterHint header = new PrinterHint(); header.Rectangle = new Rectangle(0, 0, pagewidth, height + captionHeight + 12); header.PrintInEveryPage = false; header.Border = BordersEdgeStyle.None; //打印单位名称 TitleDraw title = new TitleDraw(comp.NickName+" "+System.DateTime.Now.ToShortDateString()); title.Font = cap; title.Rectangle = new Rectangle(0, 0, pagewidth, height); title.Border = BordersEdgeStyle.None; title.Formater = sf; //打印主标题 TitleDraw titleMain = new TitleDraw(this.headerTitle); titleMain.Font = font; titleMain.Rectangle = new Rectangle(0, height, pagewidth, captionHeight); titleMain.Border = BordersEdgeStyle.None; titleMain.Formater = sf2; header.Add(title); header.Add(titleMain); return header; }
public static void Main(string[] args) { Logger = new LogConsole(null, new LogOptions() { LogTimestamp = false }); Logger.ClearPrependers(); var origVisible = Console.CursorVisible; var origWidth = Console.WindowWidth; var origHeight = Console.WindowHeight; Console.CursorVisible = false; Console.CancelKeyPress += (s, e) => { ms_isTerminating = true; e.Cancel = true; FinishWithError("User terminated execution.", true); }; if (origWidth < 160) { Console.WindowWidth = 160; } if (origHeight < 8 + 16) { Console.WindowHeight = 8 + 16; } Console.Clear(); void DrawCentered(string text, Color col) { Logger.Info(new string(' ', (Console.WindowWidth - text.Length) / 2), col); Console.WriteLine(text); } string filePath = ""; if (args.Length == 0) { TitleDraw.Welcome(Logger); DrawCentered("DR2 Format Tools - by avail (alpha)", Color.OrangeRed); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); DrawCentered("Drop a .big or .tex onto me to dump contents.", Color.Cyan); DrawCentered("(or drop to exe itself next time instead of launching it first)", Color.Green); Logger.Info("\t\t Input -> ", Color.Cyan); bool CheckExtension(char[] data, int len) { int readOffset = 0; if (data[0] == '"') { readOffset += 1; } if (data[len - (readOffset + 2)] == 't' && data[len - (readOffset + 1)] == 'e' && data[len - (readOffset + 0)] == 'x') { return(true); } if (data[len - (readOffset + 2)] == 'b' && data[len - (readOffset + 1)] == 'i' && data[len - (readOffset + 0)] == 'g') { return(true); } return(false); } var input = new char[256]; for (var i = 0; i < input.Length; i++) { input[i] = Console.ReadKey().KeyChar; if (i > 6 && CheckExtension(input, i)) { Console.WriteLine(); break; } } filePath = new string(input).Split('\0')[0].Replace("\"", ""); if (!File.Exists(filePath)) { FinishWithError("The file you specified isn't valid."); } } else { filePath = args[0]; var ext = Path.GetExtension(filePath); if (!File.Exists(filePath) || (ext != ".tex" && ext != ".big")) { FinishWithError("The file you specified isn't valid."); } } var bf = new BigFile(); var dumpDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "dump", Path.GetFileNameWithoutExtension(filePath)); bool success = bf.Read(filePath, true, dumpDir); Console.CursorVisible = origVisible; //Console.WindowWidth = origWidth; //Console.WindowHeight = origHeight; Console.Clear(); Console.SetCursorPosition(0, 0); if (success) { FinishWithSuccess(ProcessElapsed, MetadataElapsed, ExportElapsed, EntryCount); } }
bool Dump(string outputDirectory, BinaryReader str) { m_stopwatch.Restart(); if (Directory.Exists(outputDirectory)) { Directory.Delete(outputDirectory, true); } Directory.CreateDirectory(outputDirectory); File.WriteAllText(Path.Combine(outputDirectory, "__meta.txt"), Serialize()); m_metadataElapsed = m_stopwatch.ElapsedMilliseconds; object locky = new object(); object logLocky = new object(); m_stopwatch.Restart(); // TODO: decouple properly... #if !IS_UI TitleDraw.Exporting(Program.Logger); #endif // imagine if debugging with async shit worked #if true Parallel.ForEach(Entries, new ParallelOptions() { MaxDegreeOfParallelism = 16 }, #else Entries.ForEach( #endif (entry) => { int threadId = Thread.CurrentThread.ManagedThreadId; // TODO: decouple properly... #if !IS_UI lock (logLocky) { Program.UpdateConsole(threadId, entry); } #endif string outPath = Path.Combine(outputDirectory, entry.Name); if (entry.Compression == Compression.None) { byte[] data = new byte[entry.RawSize]; lock (locky) { str.BaseStream.Seek(entry.Offset, SeekOrigin.Begin); data = str.ReadBytes((int)entry.RawSize); } string suffix = ""; if (File.Exists(outPath) || File.Exists(outPath + ".dds")) { suffix += "_" + DateTime.Now.ToFileTime(); } // ITS A DDS BOYS if (TexFixup.IsValidTexture(data)) { data = TexFixup.Perform(data); suffix += ".dds"; } File.WriteAllBytes(outPath + suffix, data); } else if (entry.Compression == Compression.Zlib) { byte[] data = new byte[entry.CompressedSize]; lock (locky) { str.BaseStream.Seek(entry.Offset + 4, SeekOrigin.Begin); data = str.ReadBytes((int)entry.CompressedSize); } var decompressed = DecompressZlib(data, (int)entry.RawSize); string suffix = ""; if (File.Exists(outPath)) { suffix += "_" + DateTime.Now.ToFileTime(); } var ext = Path.GetExtension(outPath); suffix += ext; File.WriteAllBytes(outPath.Replace(ext, "") + suffix, decompressed); } else { // TODO: decouple properly... #if !IS_UI Program.Logger.Info("[", Color.White); Program.Logger.Info("Thread ", Color.Azure); Program.Logger.Info("#" + threadId.ToString().PadLeft(2, '0'), Color.Aquamarine); Program.Logger.Info("] ", Color.White); Program.Logger.Info("Unsupported compression ", Color.OrangeRed); Program.Logger.Info(entry.Compression.ToString(), Color.LightGreen); Program.Logger.Info(" on file: ", Color.OrangeRed); Program.Logger.InfoL(entry.Name, Color.BlueViolet); #endif //Console.WriteLine($"T{threadId}: Unsupported compression ({entry.Compression}) on file: {entry.Name}"); } }); m_stopwatch.Stop(); m_exportElapsed = m_stopwatch.ElapsedMilliseconds; // TODO: decouple properly... #if !IS_UI Program.ProcessElapsed = m_processElapsed; Program.MetadataElapsed = m_metadataElapsed; Program.ExportElapsed = m_exportElapsed; Program.EntryCount = Entries.Count; #endif //Console.WriteLine("Exported successfully."); //Console.WriteLine($"Processing took {m_processElapsed}ms - Metadata export took {m_jsonElapsed}ms - File export took {m_exportElapsed / 1000}s"); return(true); }