| 221 | } |
| 222 | |
| 223 | bool Game_Strings::ToFile(Str_Params params, std::string filename, int encoding) { |
| 224 | std::string str = ToString(Get(params.string_id)); |
| 225 | |
| 226 | if (params.extract) { |
| 227 | filename = Extract(filename, params.hex); |
| 228 | } |
| 229 | |
| 230 | // Maniacs forces the File in Text/ folder with .txt extension |
| 231 | filename = "Text/" + filename; |
| 232 | |
| 233 | // EasyRPG Extension: When "*" is at the end of filename, ".txt" is not appended |
| 234 | if (Player::HasEasyRpgExtensions() && filename.back() == '*') { |
| 235 | filename.pop_back(); |
| 236 | } else { |
| 237 | filename += ".txt"; |
| 238 | } |
| 239 | |
| 240 | auto txt_out = FileFinder::Save().OpenOutputStream(filename); |
| 241 | auto txt_dir = FileFinder::GetPathAndFilename(filename).first; |
| 242 | |
| 243 | if (!txt_out) { |
| 244 | if (!FileFinder::Save().MakeDirectory(txt_dir, false)) { |
| 245 | Output::Warning("Maniac String Op ToFile failed. Cannot create directory {}", txt_dir); |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | txt_out = FileFinder::Save().OpenOutputStream(filename); |
| 250 | if (!txt_out) { |
| 251 | Output::Warning("Maniac String Op ToFile failed. Cannot write to {}", filename); |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | if (encoding == 0) { |
| 257 | lcf::Encoder enc(Player::encoding); |
| 258 | enc.Decode(str); |
| 259 | } |
| 260 | |
| 261 | txt_out << str; |
| 262 | txt_out.Close(); |
| 263 | |
| 264 | AsyncHandler::SaveFilesystem(); |
| 265 | |
| 266 | return true; |
| 267 | } |
| 268 | |
| 269 | std::string_view Game_Strings::PopLine(Str_Params params, int offset, int string_out_id) { |
| 270 | // FIXME: consideration needed around encoding -- what mode are files read in? |
no test coverage detected