void ViewerCmdLine::parseOptionsFile() { StringStorage pathToIniFile = m_options[OPTIONS_FILE]; if (pathToIniFile.findChar(_T('\\')) == -1) { StringStorage newPathToIniFile; newPathToIniFile.format(_T(".\\%s"), pathToIniFile.getString()); pathToIniFile = newPathToIniFile; } IniFileSettingsManager sm(pathToIniFile.getString()); sm.setApplicationName(_T("connection")); StringStorage host; if (!sm.getString(_T("host"), &host)) { throw CommandLineFormatException(_T("Could not read options file.")); } StringStorage port; if (sm.getString(_T("port"), &port)) { StringStorage hostString; hostString.format(_T("%s:%s"), host.getString(), port.getString()); m_conData->setHost(&hostString); } else { m_conData->setHost(&host); } StringStorage password; sm.getString(_T("password"), &password); if (!password.isEmpty()) { m_conData->setCryptedPassword(&password); } else { parsePassword(); } sm.setApplicationName(_T("options")); m_conConf->loadFromStorage(&sm); }
Logger *ViewerConfig::initLog(const TCHAR logDir[], const TCHAR logName[]) { m_logName = logName; StringStorage logFileFolderPath; StringStorage appDataPath; // After that logFilePath variable will contain path to folder // where tvnviewer.log must be located if (Environment::getSpecialFolderPath(Environment::APPLICATION_DATA_SPECIAL_FOLDER, &appDataPath)) { logFileFolderPath.format(_T("%s\\%s"), appDataPath.getString(), logDir); } else { logFileFolderPath.format(_T("%s"), logDir); } // Create TightVNC folder { File folder(logFileFolderPath.getString()); folder.mkdir(); } // Path to log file AutoLock l(&m_cs); m_pathToLogFile = logFileFolderPath; if (m_logger != 0) { delete m_logger; } m_logger = new FileLogger(m_pathToLogFile.getString(), logName, m_logLevel, false); return m_logger; }
void ReconnectingChannel::waitForReconnect(const TCHAR *funName, Channel *channel) { DateTime startTime = DateTime::now(); bool success = false; while (!success) { unsigned int timeForWait = max((int)m_timeOut - (int)(DateTime::now() - startTime).getTime(), 0); if (timeForWait == 0 || m_isClosed) { StringStorage errMess; errMess.format(_T("The ReconnectingChannel::%s() function") _T(" failed."), funName); throw IOException(errMess.getString()); } m_timer.waitForEvent(timeForWait); AutoLock al(&m_chanMut); if (m_channel != channel) { m_chanWasChanged = false; success = true; } } Log::info(_T("ReconnectingChannel was successfully reconnected.")); if (channel != 0) { StringStorage errMess; errMess.format(_T("Transport was reconnected in the") _T(" %s() function. The %s()") _T(" function() at this time will be aborted"), funName, funName); throw ReconnectException(errMess.getString()); } }
Channel *ReconnectingChannel::getChannel(const TCHAR *funName) { if (m_isClosed) { StringStorage errMess; errMess.format(_T("The %s() function has failed:") _T(" connection has already been closed."), funName); throw IOException(errMess.getString()); } Channel *channel; { AutoLock al(&m_chanMut); if (m_oldChannel != 0) { delete m_oldChannel; m_oldChannel = 0; } if (m_chanWasChanged) { m_chanWasChanged = false; StringStorage errMess; errMess.format(_T("Transport was reconnected outside from") _T(" the %s() function. The %s()") _T(" function at this time will be aborted."), funName, funName); throw ReconnectException(errMess.getString()); } channel = m_channel; } return channel; }
void RemoteViewerCore::setFbProperties(const Dimension *fbDimension, const PixelFormat *fbPixelFormat) { const PixelFormat &pxFormat = *fbPixelFormat; StringStorage pxString; pxString.format(_T("[bits-per-pixel: %d, depth: %d, big-endian-flag: %d, ") _T("true-color-flag: is set, ") // true color always is set _T("red-max: %d, green-max: %d, blue-max: %d, ") _T("red-shift: %d, green-shift: %d, blue-shift: %d]"), pxFormat.bitsPerPixel, pxFormat.colorDepth, pxFormat.bigEndian, pxFormat.redMax, pxFormat.greenMax, pxFormat.blueMax, pxFormat.redShift, pxFormat.greenShift, pxFormat.blueShift); m_logWriter.detail(_T("Setting frame buffer properties...")); m_logWriter.info(_T("Frame buffer dimension: (%d, %d)"), fbDimension->width, fbDimension->height); m_logWriter.info(_T("Frame buffer pixel format: %s"), pxString.getString()); if (!m_frameBuffer.setProperties(fbDimension, fbPixelFormat) || !m_rectangleFb.setProperties(fbDimension, fbPixelFormat)) { StringStorage error; error.format(_T("Failed to set property frame buffer. ") _T("Dimension: (%d, %d), Pixel format: %s"), fbDimension->width, fbDimension->height, pxString.getString()); throw Exception(error.getString()); } m_rectangleFb.setColor(0, 0, 0); m_frameBuffer.setColor(0, 0, 0); refreshFrameBuffer(); m_fbUpdateNotifier.onPropertiesFb(); m_logWriter.debug(_T("Frame buffer properties set")); }
void QueryConnectionDialog::updateTimeoutLabel() { StringStorage labelText; if (m_acceptByDefault) { labelText.format(StringTable::getString(IDS_AUTO_ACCEPT_CONNECTION_FORMAT), m_timeout); } else { labelText.format(StringTable::getString(IDS_AUTO_REJECT_CONNECTION_FORMAT), m_timeout); } m_timeoutLabel.setText(labelText.getString()); }
void DesktopServerProto::checkPixelFormat(const PixelFormat *pf) { StringStorage errMess; if (pf->bitsPerPixel != 16 && pf->bitsPerPixel != 32) { errMess.format(_T("Wrong value of bits per pixel (%d)"), (int)pf->bitsPerPixel); throw Exception(errMess.getString()); } if (pf->colorDepth > pf->bitsPerPixel) { errMess.format(_T("Wrong value (color depth (%d) > bits per pixel (%d))"), (int)pf->colorDepth, (int)pf->bitsPerPixel); throw Exception(errMess.getString()); } }
StringStorage ViewerWindow::formatWindowName() const { StringStorage desktopName = m_viewerCore->getRemoteDesktopName(); if (desktopName.isEmpty() && !m_conData->getHost().isEmpty()) { desktopName = m_conData->getHost(); } StringStorage windowName; if (!desktopName.isEmpty()) { windowName.format(_T("%s - %s"), desktopName.getString(), ProductNames::VIEWER_PRODUCT_NAME); } else { windowName.format(_T("%s"), ProductNames::VIEWER_PRODUCT_NAME); } return windowName; }
void AnonymousPipe::close() { AutoLock al(&m_hPipeMutex); bool wrSuc = true; bool rdSuc = true; StringStorage wrErrText, rdErrText; if (m_hWrite != INVALID_HANDLE_VALUE && m_neededToClose) { if (CloseHandle(m_hWrite) == 0) { Environment::getErrStr(_T("Cannot close anonymous pipe write handle."), &wrErrText); wrSuc = false; } m_log->debug(_T("Closed m_hWrite(%p) AnonymousPipe handle"), m_hWrite); } m_hWrite = INVALID_HANDLE_VALUE; if (m_hRead != INVALID_HANDLE_VALUE && m_neededToClose) { if (CloseHandle(m_hRead) == 0) { Environment::getErrStr(_T("Cannot close anonymous pipe read handle."), &wrErrText); rdSuc = false; } m_log->debug(_T("Closed m_hRead(%p) AnonymousPipe handle"), m_hRead); } m_hRead = INVALID_HANDLE_VALUE; if (!wrSuc || !rdSuc) { StringStorage errMess; errMess.format(_T("AnonymousPipe::close() funciton has failed (%s %s)"), wrErrText.getString(), rdErrText.getString()); throw Exception(errMess.getString()); } }
void ViewerWindow::dialogConnectionInfo() { StringStorage host = m_conData->getHost(); std::vector<TCHAR> kbdName; kbdName.resize(KL_NAMELENGTH); memset(&kbdName[0], 0, sizeof(TCHAR) * KL_NAMELENGTH); if (!GetKeyboardLayoutName(&kbdName[0])) { kbdName[0] = _T('?'); kbdName[1] = _T('?'); kbdName[2] = _T('?'); } Rect geometry; int pixelSize = 0; m_dsktWnd.getServerGeometry(&geometry, &pixelSize); StringStorage str; str.format(StringTable::getString(IDS_CONNECTION_INFO_FORMAT), host.getString(), m_viewerCore->getRemoteDesktopName().getString(), m_viewerCore->getProtocolString().getString(), geometry.getWidth(), geometry.getHeight(), pixelSize, &kbdName[0]); MessageBox(getHWnd(), str.getString(), StringTable::getString(IDS_CONNECTION_INFO_CAPTION), MB_OK | MB_ICONINFORMATION); }
void UserInputServer::onRequest(UINT8 reqCode, BlockingGate *backGate) { switch (reqCode) { case POINTER_POS_CHANGED: applyNewPointerPos(backGate); break; case CLIPBOARD_CHANGED: applyNewClipboard(backGate); break; case KEYBOARD_EVENT: applyKeyEvent(backGate); break; case USER_INFO_REQ: ansUserInfo(backGate); break; case USER_INPUT_INIT: serverInit(backGate); break; default: StringStorage errMess; errMess.format(_T("Unknown %d protocol code received") _T(" from a UserInputClient"), reqCode); throw Exception(errMess.getString()); break; } }
void ControlClient::getServerInfoMsgRcvd() { bool acceptFlag = false; bool serviceFlag = false; StringStorage logPath; StringStorage statusText; TvnServerInfo info; TvnServer::getInstance()->getServerInfo(&info); StringStorage status; { AutoLock al(&m_tcpDispValuesMutex); if (m_tcpDispId != 0) { status.format(_T("[ID = %u] %s"), m_tcpDispId, info.m_statusText.getString()); } else { status.setString(info.m_statusText.getString()); } } m_gate->writeUInt32(ControlProto::REPLY_OK); m_gate->writeUInt8(info.m_acceptFlag ? 1 : 0); m_gate->writeUInt8(info.m_serviceFlag ? 1 : 0); m_gate->writeUTF8(status.getString()); }
void CommentHistory::truncate() { StringStorage valueName; StringStorage value; size_t i = (size_t)m_limit; while (true) { valueName.format(_T("%u"), i); if (i >= getCommCount()) { return ; } removeCom(getCom(i)); if (!m_key->getValueAsString(valueName.getString(), &value)) { break; } m_key->deleteSubKey(value.getString()); m_key->deleteValue(valueName.getString()); i++; } load(); }
void WsConfigRunner::execute() { Process *process = 0; try { // Prepare path to executable. StringStorage pathToBin; Environment::getCurrentModulePath(&pathToBin); pathToBin.quoteSelf(); // Prepare arguments. StringStorage args; args.format(_T("%s %s"), m_serviceMode ? ControlCommandLine::CONTROL_SERVICE : ControlCommandLine::CONTROL_APPLICATION, ControlCommandLine::SLAVE_MODE); // Start process. process = new Process(pathToBin.getString(), args.getString()); process->start(); } catch (Exception &e) { m_log.error(_T("Cannot start the WsControl process (%s)"), e.getMessage()); } if (process != 0) { delete process; } }
bool IniFileSettingsManager::setInt(const TCHAR *name, int value) { StringStorage stringVal; stringVal.format(_T("%d"), value); return setString(name, stringVal.getString()); }
BOOL AboutDialog::onInitDialog() { // Update product version string. StringStorage versionString(_T("unknown")); try { StringStorage binaryPath; Environment::getCurrentModulePath(&binaryPath); VersionInfo productInfo(binaryPath.getString()); versionString.setString(productInfo.getProductVersionString()); } catch (SystemException &ex) { MessageBox(m_ctrlThis.getWindow(), ex.getMessage(), StringTable::getString(IDS_MBC_TVNVIEWER), MB_OK | MB_ICONEXCLAMATION); } // Format product version and build time for displaying on the dialog. StringStorage versionText; versionText.format(StringTable::getString(IDS_PRODUCT_VERSION_FORMAT), versionString.getString(), BuildTime::DATE); // Show version info on the dialog. Control versionLabel; versionLabel.setWindow(GetDlgItem(m_ctrlThis.getWindow(), IDC_STATIC_VERSION)); versionLabel.setText(versionText.getString()); // Show licensing info and/or special build info. Control licensingLabel; licensingLabel.setWindow(GetDlgItem(m_ctrlThis.getWindow(), IDC_STATIC_LICENSING)); licensingLabel.setText(StringTable::getString(IDS_LICENSING_INFO)); return FALSE; }
void AnonymousPipe::close() { bool wrSuc = true; bool rdSuc = true; StringStorage wrErrText, rdErrText; if (m_hWrite != 0 && m_neededToClose) { if (CloseHandle(m_hWrite) == 0) { Environment::getErrStr(_T("Cannot close anonymous pipe write handle."), &wrErrText); wrSuc = false; } } m_hWrite = 0; if (m_hRead != 0 && m_neededToClose) { if (CloseHandle(m_hRead) == 0) { Environment::getErrStr(_T("Cannot close anonymous pipe read handle."), &wrErrText); rdSuc = false; } } m_hRead = 0; if (!wrSuc || !rdSuc) { StringStorage errMess; errMess.format(_T("AnonymousPipe::close() funciton has failed (%s %s)"), wrErrText.getString(), rdErrText.getString()); throw Exception(errMess.getString()); } }
void ClipboardExchange::onRequest(UINT32 reqCode, RfbInputGate *input) { switch (reqCode) { case ClientMsgDefs::CLIENT_CUT_TEXT: input->readUInt8(); // pad input->readUInt16(); // pad { UINT32 length = input->readUInt32(); std::vector<char> charBuff(length + 1); input->readFully(&charBuff.front(), length); charBuff[length] = '\0'; AnsiStringStorage ansiText(&charBuff.front()); if (!m_viewOnly) { StringStorage clipText; ansiText.toStringStorage(&clipText); m_desktop->setNewClipText(&clipText); } } break; default: StringStorage errMess; errMess.format(_T("Unknown %d protocol code received"), (int)reqCode); throw Exception(errMess.getString()); break; } }
void LogConn::execute() { try { assignConnection(); // In success go to normal phase DataInputStream input(m_logListenChannel); StringStorage fileName; input.readUTF8(&fileName); m_handle = m_extAuthListener->onLogConnAuth(this, true, fileName.getString()); m_logLevelSender.startSender(m_levelSendChannel); // Send first log level value { AutoLock al(&m_logLevelMutex); m_logLevelSender.updateLevel(m_logLevel); } dispatch(); } catch (Exception &e) { StringStorage errMess; errMess.format(_T("The log connection has failed: %s"), e.getMessage()); m_extLogListener->onAnErrorFromLogConn(errMess.getString()); } m_extAuthListener->onDisconnect(this); }
void ClientInputHandler::onRequest(UINT32 reqCode, RfbInputGate *input) { switch (reqCode) { case ClientMsgDefs::KEYBOARD_EVENT: { bool down = input->readUInt8() != 0; input->readUInt16(); UINT32 keyCode = input->readUInt32(); if (!m_viewOnly) { m_extEventListener->onKeyboardEvent(keyCode, down); } } break; case ClientMsgDefs::POINTER_EVENT: { UINT8 buttonMask = input->readUInt8(); UINT16 x = input->readUInt16(); UINT16 y = input->readUInt16(); if (!m_viewOnly) { m_extEventListener->onMouseEvent(x, y, buttonMask); } } break; default: StringStorage errMess; errMess.format(_T("Unknown %d protocol code received"), (int)reqCode); throw Exception(errMess.getString()); break; } }
void UploadOperation::startUpload() { if (isTerminating()) { killOp(); return ; } // terminate operation is needed // Current file info FileInfo *fileInfo = m_toCopy->getFileInfo(); // Logging if (m_toCopy->getFirst()->getParent() == NULL) { StringStorage message; message.format(_T("Uploading '%s' %s"), m_pathToSourceFile.getString(), fileInfo->isDirectory() ? _T("folder") : _T("file")); notifyInformation(message.getString()); } // logging if (fileInfo->isDirectory()) { processFolder(); } else { processFile(); } // if not directory if (isTerminating()) { killOp(); return ; } // terminate operation is needed } // void
BOOL AboutDialog::onInitDialog() { Control versionLabel; versionLabel.setWindow(GetDlgItem(m_ctrlThis.getWindow(), IDC_STATIC_VERSION)); StringStorage binaryPath; StringStorage versionText; StringStorage versionString(_T("unknown")); Environment::getCurrentModulePath(&binaryPath); try { VersionInfo productInfo(binaryPath.getString()); versionString.setString(productInfo.getProductVersionString()); } catch (SystemException &ex) { MessageBox(m_ctrlThis.getWindow(), ex.getMessage(), StringTable::getString(IDS_MBC_TVNCONTROL), MB_OK | MB_ICONEXCLAMATION); } versionText.format(StringTable::getString(IDS_PRODUCT_VERSION_FORMAT), versionString.getString(), BuildTime::DATE); versionLabel.setText(versionText.getString()); return FALSE; }
void DownloadOperation::startDownload() { if (isTerminating()) { killOp(); return ; } // if terminating FileInfo *fileInfo = m_toCopy->getFileInfo(); // Logging if (m_toCopy->getFirst()->getParent() == NULL) { StringStorage message; message.format(_T("Downloading '%s' %s"), m_pathToTargetFile.getString(), fileInfo->isDirectory() ? _T("folder") : _T("file")); notifyInformation(message.getString()); } // logging if (fileInfo->isDirectory()) { processFolder(); } else { processFile(); } // if not directory if (isTerminating()) { killOp(); return ; } // if terminating }
void ClipboardExchange::onRequest(UINT32 reqCode, RfbInputGate *input) { switch (reqCode) { case ClientMsgDefs::CLIENT_CUT_TEXT: input->readUInt8(); input->readUInt16(); { UINT32 length = input->readUInt32(); char *receivedText = new char[length + 1]; try { input->readFully(receivedText, length); } catch (...) { delete[] receivedText; throw; } if (!m_viewOnly) { receivedText[length] = '\0'; StringStorage clipText; clipText.fromAnsiString(receivedText); delete[] receivedText; m_desktop->setNewClipText(&clipText); } else { delete[] receivedText; } } break; default: StringStorage errMess; errMess.format(_T("Unknown %d protocol code received"), (int)reqCode); throw Exception(errMess.getString()); break; } }
void WinDxgiDevice::getAdapter(IDXGIAdapter **dxgiAdapter) { HRESULT hr = m_dxgiDevice->GetAdapter(dxgiAdapter); if (FAILED(hr)) { StringStorage errMess; errMess.format(_T("Can't get default Adapter for IDXGIDevice (%ld)"), (long)hr); throw Exception(errMess.getString()); } }
void ControlApplication::notifyServerSideException(const TCHAR *reason) { StringStorage message; message.format(StringTable::getString(IDS_CONTROL_SERVER_RAISE_EXCEPTION), reason); MessageBox(0, message.getString(), StringTable::getString(IDS_MBC_TVNSERVER), MB_OK | MB_ICONERROR); }
void ControlCommandLine::parseDisplayNumber(const StringStorage *strDispNumber) { if (!StringParser::parseByte(strDispNumber->getString(), &m_displayNumber)) { StringStorage errMess; errMess.format(_T("Can't parse the %s argument to a display number"), strDispNumber->getString()); } }
BOOL ConfirmDialog::onInitDialog() { setControlById(m_text, IDC_CONFIRM_TEXT); StringStorage text; text.format(_T("管理员%s需要控制您的电脑,确定?"), m_tvnServerApplication->getUser().getString()); m_text.setText(text.getString()); return TRUE; }
void RemoteFilesDeleteOperation::remove(bool removeIfFolder) { if (isTerminating()) { killOp(); return ; } if (m_toDelete == NULL) { return ; } FileInfo *fileInfo = m_toDelete->getFileInfo(); StringStorage remotePath; getRemotePath(m_toDelete, m_pathToTargetRoot.getString(), &remotePath); // // Logging // if (((fileInfo->isDirectory() && !removeIfFolder) || (!fileInfo->isDirectory())) && (m_toDelete->getFirst()->getParent() == NULL)) { StringStorage message; message.format(_T("Deleting remote '%s' %s"), remotePath.getString(), fileInfo->isDirectory() ? _T("folder") : _T("file")); notifyInformation(message.getString()); } // // Try remove file if it's not folder or have order to forced // file removal. // if (!fileInfo->isDirectory() || removeIfFolder) { // Send request to server m_sender->sendRmFileRequest(remotePath.getString()); // // If file is folder and we have order to forced removal // we must set folder child to NULL. If we dont do than // program will try to remove already removed files next step. // if ((removeIfFolder) && (fileInfo->isDirectory())) { m_toDelete->setChild(NULL, 0); } } else { // Send file list request cause we must remove subfolders and files from // folder before we can delete it m_sender->sendFileListRequest(remotePath.getString(), m_replyBuffer->isCompressionSupported()); } }
void DownloadOperation::notifyFailedToDownload(const TCHAR *errorDescription) { StringStorage message; message.format(_T("Error: failed to download '%s' (%s)"), m_pathToSourceFile.getString(), errorDescription); notifyError(message.getString()); }