static int ConvertTextFiles(ConsoleService c, string cmdName, string str) { ConsoleParam[] args = { new ConsoleParam("[srcdir]", ConsoleService.Prompt, "Input source directory: ", ConsoleService.EvalNotEmpty, null), new ConsoleParam("dst", ConsoleService.Prompt, "Input destination directory: ", ConsoleService.EvalNotEmpty, null), new ConsoleParam("encode"), new ConsoleParam("bom"), new ConsoleParam("newline"), }; ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args); string srcdir = vl.DefaultParam.StrValue; string dstdir = vl["dst"].StrValue; string encode = vl["encode"].StrValue._FilledOrDefault("utf8"); bool bom = vl["bom"].BoolValue; string newline = vl["newline"].StrValue._FilledOrDefault("crlf"); Encoding?encoding = null; switch (encode.ToLower()) { case "sjis": encoding = Str.ShiftJisEncoding; break; case "euc": encoding = Str.EucJpEncoding; break; case "utf8": encoding = Str.Utf8Encoding; break; default: throw new CoresException("encode param is invalid."); } CrlfStyle crlfStyle = CrlfStyle.CrLf; switch (newline.ToLower()) { case "crlf": crlfStyle = CrlfStyle.CrLf; break; case "lf": crlfStyle = CrlfStyle.Lf; break; case "platform": crlfStyle = CrlfStyle.LocalPlatform; break; default: throw new CoresException("newline param is invalid."); } var srcFileList = Lfs.EnumDirectory(srcdir, true); foreach (var srcFile in srcFileList) { if (srcFile.IsFile) { string relativeFileName = Lfs.PathParser.GetRelativeFileName(srcFile.FullPath, srcdir); string destFileName = Lfs.PathParser.Combine(dstdir, relativeFileName); string body = Lfs.ReadStringFromFile(srcFile.FullPath); body = Str.NormalizeCrlf(body, crlfStyle); Con.WriteLine(relativeFileName); Lfs.WriteStringToFile(destFileName, body, FileFlags.AutoCreateDirectory, encoding: encoding, writeBom: bom); } } return(0); }
public static Task _SendStringContentsAsync(this HttpResponse h, string body, string contentsType = Consts.MimeTypes.TextUtf8, Encoding?encoding = null, CancellationToken cancel = default(CancellationToken), int statusCode = Consts.HttpStatusCodes.Ok, CrlfStyle normalizeCrlf = CrlfStyle.NoChange) { body = body._NormalizeCrlf(normalizeCrlf); if (encoding == null) { encoding = Str.Utf8Encoding; } byte[] ret_data = encoding.GetBytes(body); h.ContentType = contentsType; h.ContentLength = ret_data.Length; h.StatusCode = statusCode; return(h.Body.WriteAsync(ret_data, 0, ret_data.Length, cancel)); }