void GetCommandHandler::process(ClientSocket* socket, vector<string>& params) { if (params.size() != 3) throw("SYNTAX: GET [remote file] [local file]"); char buff[BUFFERSIZE + 1]; socket->readline(buff, BUFFERSIZE); int iFileSize = stoi(buff); if (iFileSize >= 0) { int iBytesToRead = iFileSize; ofstream osFile(params[2], ofstream::binary | ofstream::trunc); if (osFile.bad()) { throw("Cannot open file for writing"); } /*void (*prev_handler) (int); prev_handler = signal(SIGTERM, interrupt);*/ int iBytesRead, iPercentCompleted; while (iBytesToRead > 0) { try { iBytesRead = socket->read(buff, iBytesToRead > BUFFERSIZE ? BUFFERSIZE : iBytesToRead); } catch (SocketException& ex) { osFile.close(); throw ex; } osFile.write(buff, iBytesRead); iBytesToRead -= iBytesRead; wcout << L"\rProgress: " << (((long long)(iFileSize - iBytesToRead) * 100) / iFileSize) << "% " << (iFileSize - iBytesToRead) / 1000 << L"/" << iFileSize / 1000 << L" KB"; } //signal(SIGTERM, prev_handler); osFile.close(); wcout << endl << L"Done." << endl; } else { wchar_t errbuff[BUFFERSIZE + 1]; while (socket->readline(errbuff, BUFFERSIZE) > 0) { wcout << errbuff << L"\n"; } } }
void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent& WXUNUSED(event)) { ctConfigToolDoc* doc = (ctConfigToolDoc*) GetDocument(); wxString configureStr = doc->GenerateConfigureCommand(); wxString filename = _T("configurewx.sh"); wxString path = wxGetApp().GetSettings().m_lastSetupSaveDir; if (path.empty()) path = doc->GetFrameworkDir(false); wxString wildcard = _T("Shell script files (*.sh)|*.sh|All files (*.*)|*.*"); wxFileDialog dialog(wxTheApp->GetTopWindow(), _("Save Configure Command File As"), path, filename , wildcard, wxSAVE|wxOVERWRITE_PROMPT); if (dialog.ShowModal() == wxID_OK) { wxString fullPath = dialog.GetPath(); wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); wxFileOutputStream osFile(fullPath); if (!osFile.Ok()) { wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK); return; } wxTextOutputStream stream(osFile); stream << configureStr; } }
/// Save the settings file bool ctConfigToolDoc::DoSave(const wxString& filename) { wxFileOutputStream osFile(filename); if (!osFile.Ok()) return false; wxTextOutputStream stream(osFile); stream << wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); stream << wxT("<settings xmlns=\"http://www.wxwidgets.org/wxs\" version=\"2.5.0.1\">"); DoSave(m_topItem, osFile, 1); stream << wxT("\n</settings>\n"); return true; }