| 258 | } |
| 259 | |
| 260 | void HttpCookie::writeFile() |
| 261 | { |
| 262 | constexpr auto cookieText = |
| 263 | "# Netscape HTTP Cookie File\n" |
| 264 | "# http://curl.haxx.se/docs/http-cookies.html\n" |
| 265 | "# This file was generated by axmol! Edit at your own risk.\n" |
| 266 | "# Test axmol cookie write.\n\n"sv; |
| 267 | constexpr auto endLine = "\n"sv; |
| 268 | |
| 269 | auto out = FileUtils::getInstance()->openFileStream(_cookieFileName, IFileStream::Mode::WRITE); |
| 270 | out->write(cookieText.data(), cookieText.size()); |
| 271 | |
| 272 | std::string line; |
| 273 | |
| 274 | char expires[32] = {0}; // LONGLONG_STRING_SIZE=20 |
| 275 | for (auto&& cookie : _cookies) |
| 276 | { |
| 277 | line.clear(); |
| 278 | line.append(cookie.domain); |
| 279 | line.append(1, '\t'); |
| 280 | cookie.tailmatch ? line.append("TRUE") : line.append("FALSE"); |
| 281 | line.append(1, '\t'); |
| 282 | line.append(cookie.path); |
| 283 | line.append(1, '\t'); |
| 284 | cookie.secure ? line.append("TRUE") : line.append("FALSE"); |
| 285 | line.append(1, '\t'); |
| 286 | fmt::format_to(std::back_inserter(line), FMT_COMPILE("{}"), cookie.expires); |
| 287 | line.append(1, '\t'); |
| 288 | line.append(cookie.name); |
| 289 | line.append(1, '\t'); |
| 290 | line.append(cookie.value); |
| 291 | // line.append(1, '\n'); |
| 292 | |
| 293 | out->write(line.c_str(), static_cast<unsigned int>(line.length())); |
| 294 | out->write(endLine.data(), static_cast<unsigned int>(endLine.size())); |
| 295 | } |
| 296 | |
| 297 | out->close(); |
| 298 | } |
| 299 | |
| 300 | void HttpCookie::setCookieFileName(std::string_view filename) |
| 301 | { |