LEditor* MainBook::NewEditor() { static int fileCounter = 0; wxString fileNameStr(_("Untitled")); fileNameStr << ++fileCounter; wxFileName fileName(fileNameStr); // A Nice trick: hide the notebook, open the editor // and then show it bool hidden(false); if(m_book->GetPageCount() == 0) hidden = GetSizer()->Hide(m_book); LEditor* editor = new LEditor(m_book); editor->SetFileName(fileName); AddPage(editor, fileName.GetFullName(), fileName.GetFullPath(), wxNullBitmap, true); #ifdef __WXMAC__ m_book->GetSizer()->Layout(); #endif // SHow the notebook if(hidden) GetSizer()->Show(m_book); editor->SetActive(); return editor; }
void FirmwareData::readFromFile(const char * fileName) { assert(!*this); std::string fileNameStr(fileName); auto filePtr = openFileOrPipeInput(fileNameStr); std::istream & file = *filePtr; // Get the first character so we can figure out what kind of file this is. char first_char; file.get(first_char); if (file.fail()) { throw std::runtime_error(fileNameStr + ": Failed to read first character."); } // Put that character back in the buffer. file.unget(); if (file.fail()) { throw std::runtime_error(fileNameStr + ": Failed to unget character from file."); } if (first_char == ':') { hexData.readFromFile(file, fileName); } else { firmwareArchiveData.readFromFile(file, fileName); } if (!*this) { throw std::runtime_error(fileNameStr + ": file contains no firmware data."); } }
void LogStatus(QTSS_ServerState theServerState) { static QTSS_ServerState lastServerState = 0; static char *sPLISTHeader[] = { "<?xml version=\"1.0\" encoding=\"UTF-8\"?>", #if __MacOSX__ "<!DOCTYPE plist SYSTEM \"file://localhost/System/Library/DTDs/PropertyList.dtd\">", #else "<!ENTITY % plistObject \"(array | data | date | dict | real | integer | string | true | false )\">", "<!ELEMENT plist %plistObject;>", "<!ATTLIST plist version CDATA \"0.9\">", "", "<!-- Collections -->", "<!ELEMENT array (%plistObject;)*>", "<!ELEMENT dict (key, %plistObject;)*>", "<!ELEMENT key (#PCDATA)>", "", "<!--- Primitive types -->", "<!ELEMENT string (#PCDATA)>", "<!ELEMENT data (#PCDATA)> <!-- Contents interpreted as Base-64 encoded -->", "<!ELEMENT date (#PCDATA)> <!-- Contents should conform to a subset of ISO 8601 (in particular, YYYY '-' MM '-' DD 'T' HH ':' MM ':' SS 'Z'. Smaller units may be omitted with a loss of precision) -->", "", "<!-- Numerical primitives -->", "<!ELEMENT true EMPTY> <!-- Boolean constant true -->", "<!ELEMENT false EMPTY> <!-- Boolean constant false -->", "<!ELEMENT real (#PCDATA)> <!-- Contents should represent a floating point number matching (\"+\" | \"-\")? d+ (\".\"d*)? (\"E\" (\"+\" | \"-\") d+)? where d is a digit 0-9. -->", "<!ELEMENT integer (#PCDATA)> <!-- Contents should represent a (possibly signed) integer number in base 10 -->", "]>", #endif }; static int numHeaderLines = sizeof(sPLISTHeader) / sizeof(char*); static char* sPlistStart = "<plist version=\"0.9\">"; static char* sPlistEnd = "</plist>"; static char* sDictStart = "<dict>"; static char* sDictEnd = "</dict>"; static char* sKey = " <key>%s</key>\n"; static char* sValue = " <string>%s</string>\n"; static char *sAttributes[] = { "qtssSvrServerName", "qtssSvrServerVersion", "qtssSvrServerBuild", "qtssSvrServerPlatform", "qtssSvrRTSPServerComment", "qtssSvrServerBuildDate", "qtssSvrStartupTime", "qtssSvrCurrentTimeMilliseconds", "qtssSvrCPULoadPercent", "qtssSvrState", "qtssRTPSvrCurConn", "qtssRTSPCurrentSessionCount", "qtssRTSPHTTPCurrentSessionCount", "qtssRTPSvrCurBandwidth", "qtssRTPSvrCurPackets", "qtssRTPSvrTotalConn", "qtssRTPSvrTotalBytes", "qtssMP3SvrCurConn", "qtssMP3SvrTotalConn", "qtssMP3SvrCurBandwidth", "qtssMP3SvrTotalBytes" }; static int numAttributes = sizeof(sAttributes) / sizeof(char*); static StrPtrLen statsFileNameStr("server_status"); if (false == sServer->GetPrefs()->ServerStatFileEnabled()) return; UInt32 interval = sServer->GetPrefs()->GetStatFileIntervalSec(); if (interval == 0 || (OS::UnixTime_Secs() % interval) > 0 ) return; // If the total number of RTSP sessions is 0 then we // might not need to update the "server_status" file. char* thePrefStr = NULL; // We start lastRTSPSessionCount off with an impossible value so that // we force the "server_status" file to be written at least once. static int lastRTSPSessionCount = -1; // Get the RTSP session count from the server. (void)QTSS_GetValueAsString(sServer, qtssRTSPCurrentSessionCount, 0, &thePrefStr); int currentRTSPSessionCount = ::atoi(thePrefStr); delete [] thePrefStr; thePrefStr = NULL; if (currentRTSPSessionCount == 0 && currentRTSPSessionCount == lastRTSPSessionCount) { // we don't need to update the "server_status" file except the // first time we are in the idle state. if (theServerState == qtssIdleState && lastServerState == qtssIdleState) { lastRTSPSessionCount = currentRTSPSessionCount; lastServerState = theServerState; return; } } else { // save the RTSP session count for the next time we execute. lastRTSPSessionCount = currentRTSPSessionCount; } StrPtrLenDel pathStr(sServer->GetPrefs()->GetErrorLogDir()); StrPtrLenDel fileNameStr(sServer->GetPrefs()->GetStatsMonitorFileName()); ResizeableStringFormatter pathBuffer(NULL,0); pathBuffer.PutFilePath(&pathStr,&fileNameStr); pathBuffer.PutTerminator(); char* filePath = pathBuffer.GetBufPtr(); FILE* statusFile = ::fopen(filePath, "w"); char* theAttributeValue = NULL; int i; if (statusFile != NULL) { ::chmod(filePath, 0640); for ( i = 0; i < numHeaderLines; i++) { qtss_fprintf(statusFile, "%s\n",sPLISTHeader[i]); } qtss_fprintf(statusFile, "%s\n", sPlistStart); qtss_fprintf(statusFile, "%s\n", sDictStart); // show each element value for ( i = 0; i < numAttributes; i++) { (void)QTSS_GetValueAsString(sServer, QTSSModuleUtils::GetAttrID(sServer,sAttributes[i]), 0, &theAttributeValue); if (theAttributeValue != NULL) { qtss_fprintf(statusFile, sKey, sAttributes[i]); qtss_fprintf(statusFile, sValue, theAttributeValue); delete [] theAttributeValue; theAttributeValue = NULL; } } qtss_fprintf(statusFile, "%s\n", sDictEnd); qtss_fprintf(statusFile, "%s\n\n", sPlistEnd); ::fclose(statusFile); } lastServerState = theServerState; }