bool CTarArchive::CleanClose(const std::string& output) { bool Ret = false; std::ofstream l_out(output.c_str(), std::ios::out | std::ios::binary | std::ios::app | std::ios::ate); if(!l_out.good()) { std::cout << i8n("[ERR] Cannot open ") << output << i8n(" file!") << '\n'; Ret = false; } else { int l_AmountToRound = RoundTo512(l_out.tellp()) - l_out.tellp(); for(int i = 0; i < l_AmountToRound; ++i) { l_out.put('\0'); } l_out.put('\0'); l_out.put('\0'); l_out.close(); Ret = true; } return Ret; }
std::string Util::ToChar(const std::wstring & p_in, const std::locale & p_loc) { typedef std::wstring::traits_type::state_type TsType; typedef std::codecvt<wchar_t, char, TsType> Tcvt; try{ std::string l_out(p_in.length(), char()); const Tcvt & l_cvt = std::use_facet<Tcvt>(p_loc); const wchar_t* l_from_nxt; char* l_to_nxt; TsType l_state = TsType(); l_cvt.out(l_state, &p_in[0], &p_in[0] + p_in.size(), l_from_nxt, &l_out[0], &l_out[0] + l_out.size(), l_to_nxt); return l_out; } catch (...) { return std::string(); } };
bool CTarArchive::WriteData(const std::string& _input, const std::string& output) { bool Ret = false; /*int iAmountToRound = 0; static bool bFirstEntry = true; std::fstream f_In, f_Out; std::string strData = strTarfile;*/ posix_header lheader; if(FillHeader(_input, lheader)) { std::ofstream l_out(output.c_str(), std::ios::out | std::ios::binary | std::ios::app | std::ios::ate); if(!l_out.good()) { std::cerr << i8n("[ERR] Error output file: ") << output << '\n'; Ret = false; } else { std::ifstream l_in(_input.c_str(), std::ios::in | std::ios::binary); if(!l_in.good()) { std::cerr << i8n("[WNG] Error in file: ") << _input << i8n(" (file is skipped)") << '\n'; Ret = true; // If we cannot read a file it's not vital, we skip, but we need to inform user ! } else { //Round it to % 512 if(m_FirstFile) { int l_AmountToRound = RoundTo512(l_out.tellp()) - l_out.tellp(); for(int i = 0; i < l_AmountToRound; ++i) l_out.put('\0'); } m_FirstFile = true; //Write header l_out.write(reinterpret_cast<char*>(&lheader), sizeof(lheader)); //Append file content char l_char; while(l_in.get(l_char)) l_out.put(l_char); l_in.close(); l_out.close(); Ret = true; } } } else { std::cerr << i8n("[WNG] File '") << _input << i8n("' hasn't been add to tar archive !") << '\n'; Ret = true; // If we cannot compute header, we skip it. } return Ret; }
LRESULT PublicHubsFrame::onSelChangedISPTree(int /*idCtrl*/, LPNMHDR pnmh, BOOL& /*bHandled*/) { NMTREEVIEW* p = (NMTREEVIEW*) pnmh; if (p->itemNew.state & TVIS_SELECTED) { CWaitCursor l_cursor_wait; //-V808 m_ctrlHubs.DeleteAllItems(); if (p->itemNew.lParam == e_HubListItem) { tstring buf; buf.resize(100); if (m_ctrlTree.GetItemText(p->itemNew.hItem, &buf[0], buf.size())) { const string l_url = Text::fromT(buf.c_str()); CFlyLog l_log("Download Hub List"); std::vector<byte> l_data; l_log.step("URL = " + l_url); CFlyHTTPDownloader l_http_downloader; //l_http_downloader.setInetFlag(INTERNET_FLAG_RESYNCHRONIZE); l_http_downloader.m_is_use_cache = true; if (l_http_downloader.getBinaryDataFromInet(l_url, l_data, 1000)) { const string ext = Util::getFileExt(l_url); if (stricmp(ext, ".bz2") == 0) { std::vector<byte> l_out(l_data.size() * 20); size_t outSize = l_out.size(); size_t sizeRead = l_data.size(); UnBZFilter unbzip; try { unbzip(l_data.data(), (size_t &)sizeRead, &l_out[0], outSize); l_out[outSize] = 0; HubEntryList& l_list = m_publicListMatrix[l_url]; l_list.clear(); try { PubHubListXmlListLoader loader(l_list); SimpleXMLReader(&loader).parse((const char*)l_out.data(), outSize, false); m_hubs = l_list; updateList(); } catch (const Exception& e) { l_log.step("XML parse error = " + e.getError()); } } catch (const Exception& e) { l_log.step("Unpack error = " + e.getError()); } } } } } else { TStringSet l_items; LoadTreeItems(l_items, p->itemNew.hItem); int cnt = 0; for (auto i = l_items.cbegin(); i != l_items.end(); ++i) { TStringList l; l.resize(COLUMN_LAST); l[COLUMN_SERVER] = *i; m_ctrlHubs.insert(cnt++, l, I_IMAGECALLBACK); // !SMT!-IP } } m_ctrlHubs.resort(); updateStatus(); } return 0; }