private static void DeserializeDetectTextResponse() { var jsonFilePath = @"C:\Temp\temp.json"; var detectTextResponse = JsonFileSerializer.Deserialize <DetectTextResponse>(jsonFilePath); }
public void OnExecute() { // Don't execute if we are showing help. if (ShowHelp) { return; } MtxEncoding encoding = null; var version = Version ?? "auto"; if (version == "auto") { if (FntPath != null || FpdPath != null) { version = "1"; } else { version = "2"; } } if (version == "1") { if (FntPath != null) { if (!File.Exists(FntPath)) { Error(string.Format(ErrorMessages.FileDoesNotExist, FntPath)); return; } var fntFile = new FntFile(FntPath); encoding = new CharacterMapMtxEncoding(fntFile.Characters); } else if (FpdPath != null) { if (!File.Exists(FpdPath)) { Error(string.Format(ErrorMessages.FileDoesNotExist, FpdPath)); return; } var fpdFile = new FpdFile(FpdPath); encoding = new CharacterMapMtxEncoding(fpdFile.Characters); } else { Error(ErrorMessages.FntOrFpdOptionMustBeSet); return; } } else if (version == "2") { encoding = new Utf16MtxEncoding(); } foreach (var file in Files) { if (!File.Exists(file)) { Error(string.Format(ErrorMessages.FileDoesNotExist, file)); continue; } var format = Format ?? "auto"; if (format == "auto") { var extension = Path.GetExtension(file); if (extension.Equals(".mtx", StringComparison.OrdinalIgnoreCase)) { format = "json"; } else if (extension.Equals(".json", StringComparison.OrdinalIgnoreCase)) { format = "mtx"; } else { Error(string.Format(ErrorMessages.CouldNotDetermineOutputFormat, file)); continue; } } if (format == "json") { var outputFilename = Output ?? Path.ChangeExtension(file, ".json"); try { var mtxFile = new MtxFile(file, encoding); var mtxJson = new MtxJson { Has64BitOffsets = mtxFile.Has64BitOffsets, Entries = mtxFile.Entries, }; JsonFileSerializer.Serialize(outputFilename, mtxJson); } catch (Exception e) { Error(e.Message); } } else if (format == "mtx") { var outputFilename = Output ?? Path.ChangeExtension(file, ".mtx"); try { var mtxJson = JsonFileSerializer.Deserialize <MtxJson>(file); var mtxFile = new MtxFile(mtxJson.Entries, encoding, mtxJson.Has64BitOffsets ? true : Has64BitOffsets); mtxFile.Save(outputFilename); } catch (Exception e) { Error(e.Message); } } } }
public static int Main(string[] args) { try { #pragma warning disable CA1416 ConsoleHelper.RedefineConsoleColors(bgColor: Color.FromArgb(17, 17, 17)); #pragma warning restore CA1416 var cmdLineParser = ComparisonServices.CmdLineParser; cmdLineParser.ThrowIfNull(nameof(cmdLineParser)); IOptions options = null !; string? configToLoad = null; CmdLineParserSoE cmdParser = new(); if (File.Exists(DefaultConfigFileName)) { configToLoad = DefaultConfigFileName; } else { options = cmdParser.Parse(args); if (options.ConfigPath is { } configFile) { configToLoad = configFile; } } if (configToLoad is not null) { try { var loadedConfig = JsonFileSerializer.Deserialize <Options>(configToLoad); options = cmdParser.Parse(args, loadedConfig); } catch (Exception ex) { ConsolePrinter.PrintError(ex); options = cmdParser.Parse(args); } } ConsolePrinter.ColorizeOutput = options.ColorizeOutput; if (configToLoad is not null) { ConsolePrinter.PrintSectionHeader(); ConsolePrinter.PrintColoredLine(ConsoleColor.Green, Resources.StatusConfigFileLoadedTemplate.InsertArgs(configToLoad)); ConsolePrinter.ResetColor(); } if (options.BatchCommands is null) { CommandMenu.Instance.Show(options); } else { CommandQueue.Instance.Start(options); } } catch (Exception ex) { ConsolePrinter.PrintFatalError(ex.Message + Environment.NewLine + ex.StackTrace); try { Console.ReadKey(); } catch { // Ignore } } return(0); }