/*********************************************************************************** ** TODO: this should set other result members as well, not just result.files ** ** KDEOpFileChooser::ReadOutput ***********************************************************************************/ void KDEOpFileChooser::ReadOutput(DesktopFileChooserResult& result) { // Read data const size_t bufsize = 1024; OpString8 buffer; OpAutoPtr<OpString> current_file(0); if (!buffer.Reserve(bufsize)) return; // Start reading size_t readsize = read(m_pipe_descriptor[PipeRead], buffer.CStr(), bufsize); while (readsize > 0) { // Terminate result buffer.CStr()[readsize] = '\0'; // Read filenames, separated by '\n' char* buf_ptr = buffer.CStr(); while (buf_ptr && *buf_ptr) { char* next_buf = op_strchr(buf_ptr, '\n'); if (next_buf) *next_buf = '\0'; // Convert filename OpString partial_filename; RETURN_VOID_IF_ERROR(g_oplocale->ConvertFromLocaleEncoding(&partial_filename, buf_ptr)); if (!current_file.get()) { current_file = OP_NEW(OpString, ()); if (!current_file.get()) return; } RETURN_VOID_IF_ERROR(current_file->Append(partial_filename)); if (next_buf) { RETURN_VOID_IF_ERROR(result.files.Add(current_file.get())); current_file.release(); } buf_ptr = next_buf ? next_buf + 1 : 0; } readsize = read(m_pipe_descriptor[PipeRead], buffer.CStr(), bufsize); }
text load_texts_from_file(text current_storage, std::wstring path_name) { int type_of_document=1; std::wifstream current_file(path_name.c_str(),std::ios::binary); //Ниже устанавливаем нужную для распознования кодировку для current_file current_file.imbue(std::locale(current_file.getloc(), new std::codecvt_utf16<wchar_t, 0x10ffff, std::consume_header>)); std::wstring buf, extra_buf; while (type_of_document && std::getline<wchar_t>(current_file, buf)) { if (buf[0] == L'@') type_of_document = 0; else current_storage.short_.push_back(buf); } if (type_of_document == 0) { while (std::getline<wchar_t>(current_file, buf)) { std::cout << "\n buf_size" << buf.size() << std::endl; if (buf[0] != L'@') { extra_buf = extra_buf + buf; //extra_buf[extra_buf.size() - 1] = L'\0'; } else { current_storage.long_.push_back(extra_buf); extra_buf.resize(0); } } } std::cout <<"\n"<< current_storage.long_.size() << std::endl; current_file.close(); //удаляем лишний символ из всех строк for (int counter = 0; counter < current_storage.short_.size();++counter) { current_storage.short_[counter][current_storage.short_[counter].size() - 1] = L'\0'; }; return current_storage; }
void FileChecker::save() const { { WriteBufferFromFile out(tmp_files_info_path); /// Столь сложная структура JSON-а - для совместимости со старым форматом. writeCString("{\"yandex\":{", out); for (auto it = map.begin(); it != map.end(); ++it) { if (it != map.begin()) writeString(",", out); /// escapeForFileName на самом деле не нужен. Но он оставлен для совместимости со старым кодом. writeJSONString(escapeForFileName(it->first), out); writeString(":{\"size\":\"", out); writeIntText(it->second, out); writeString("\"}", out); } writeCString("}}", out); out.next(); } Poco::File current_file(files_info_path); if (current_file.exists()) { std::string old_file_name = files_info_path + ".old"; current_file.renameTo(old_file_name); Poco::File(tmp_files_info_path).renameTo(files_info_path); Poco::File(old_file_name).remove(); } else Poco::File(tmp_files_info_path).renameTo(files_info_path); }