private static async Task <bool> PerformPatch(string inputFile, string mapDirectory) { var config = ConfigParser.ParseConfig(true, mapDirectory); var context = new Context(config); var inputValidator = new InputValidator(context); var inputTransformer = new InputTransformer(context); var seemsCorrect = await inputValidator.ValidateInput(inputFile, mapDirectory); if (!seemsCorrect) { return(false); } var filename = "song.egg"; var infoFile = Path.Combine(mapDirectory, "info.dat"); if (!File.Exists(infoFile)) { infoFile = Path.Combine(mapDirectory, "Info.dat"); } if (File.Exists(infoFile)) { try { // Try to use the output filename from the info.dat file using (StreamReader file = File.OpenText(infoFile)) using (JsonTextReader reader = new JsonTextReader(file)) { JObject info = JObject.Load(reader); var filenameToken = info.Value <string>("_songFilename"); if (!string.IsNullOrEmpty(filenameToken)) { filename = filenameToken; } } } catch (Exception) { } } var outputFile = Path.Combine(mapDirectory, filename); var success = await inputTransformer.TransformInput(inputFile, outputFile); if (!success) { throw new Exception("Failed to transform audio."); } return(true); }
private async Task <InputItems> ExecuteAsync(IStaticSite site, IInput input, ITextMiddleware[] middlewares, bool write) { try { var textContext = new TextInputContext(site, input); var executor = new InputTransformer(_readMiddleware, middlewares, write ? _writer : null, textContext); await executor.ExecuteAsync().ConfigureAwait(false); return(textContext.Items); } catch (Exception e) { throw new ParseException($"Error while parsing file {input.RelativeName}", e); } }