Ejemplo n.º 1
0
CString CComplexArray::AsString (void) const

//	AsString
//
//	Represent as a string

	{
	CStringBuffer Output;

	Output.Write("(", 1);

	for (int i = 0; i < m_Array.GetCount(); i++)
		{
		if (i != 0)
			Output.Write(" ", 1);

		CString sResult = m_Array[i].AsString();
		Output.Write(sResult);
		}

	Output.Write(")", 1);

	CString sOutput;
	sOutput.TakeHandoff(Output);
	return sOutput;
	}
Ejemplo n.º 2
0
CString CAeonInterface::EncodeFilePathComponent (const CString &sValue)

//	EncodeFilePathComponent
//
//	Encodes a file path component by replacing any invalid characters with ~hh
//	(where hh is the hexcode).

	{
	char *pPos = sValue.GetParsePointer();
	char *pEndPos = pPos + sValue.GetLength();
	CStringBuffer Output;

	while (pPos < pEndPos)
		{
		if (!strIsASCIIAlpha(pPos)					//	alpha
				&& !strIsDigit(pPos)				//	numbers
				&& *pPos != '-'
				&& *pPos != '_'
				&& *pPos != '.'
				&& *pPos != '~'
				&& !strIsASCIIHigh(pPos))			//	unicode characters
			{
			CString sChar = strPattern("~%x", (DWORD)(BYTE)*pPos);
			Output.Write(sChar);
			}
		else
			Output.Write(pPos, 1);

		pPos++;
		}

	//	Done

	return CString::CreateFromHandoff(Output);
	}
Ejemplo n.º 3
0
dword CConsoleMenuItem::GetTitleSize() const
{
	CStringBuffer tmp;

	tmp = CreateMenuTitle();
	return tmp.GetLength();
}
Ejemplo n.º 4
0
CStringBuffer CConsoleClipboard::GetClipboardText()
{
	CStringBuffer tmp;

#ifdef OK_SYS_WINDOWS
	if (!IsClipboardFormatAvailable(_CLIPBOARDTEXTFORMAT))
		return tmp;

	HWND hwnd = GetConsoleWindow();

	if ( !hwnd )
		return tmp;
    if (!OpenClipboard(hwnd)) 
		return tmp;
 
    HGLOBAL hglb = GetClipboardData(_CLIPBOARDTEXTFORMAT); 
    if (hglb != NULL) 
    { 
        LPTSTR  lptstr = (LPTSTR)GlobalLock(hglb); 
        if (lptstr != NULL) 
        {
			dword tlen = s_strlen(lptstr, INT_MAX);
			tmp.SetSize(__FILE__LINE__ tlen + 1);
			s_strcpy(CastMutable(CPointer, tmp.GetString()), tlen + 1, lptstr);
            GlobalUnlock(hglb); 
        } 
    } 
    CloseClipboard();
#endif
#ifdef OK_SYS_UNIX
	tmp = _clipboardtext;
#endif
	return tmp;
 }
Ejemplo n.º 5
0
bool CDatum::DeserializeTextUTF8 (IByteStream &Stream, CDatum *retDatum)

//	DeserializeTextUTF8
//
//	Loads straight UTF-8 into a single string value.

	{
	CStringBuffer Buffer;

	//	See if we have an encoding mark

	BYTE BOM[3];
	Stream.Read(BOM, sizeof(BOM));
	if (BOM[0] == 0xef && BOM[1] == 0xbb && BOM[2] == 0xbf)
		;	//	UTF-8

	//	Otherwise, not an encoding mark, so write it to the buffer

	else
		Buffer.Write(BOM, sizeof(BOM));

	//	Write the rest

	Buffer.Write(Stream, Stream.GetStreamLength());
	return CreateStringFromHandoff(Buffer, retDatum);
	}
Ejemplo n.º 6
0
int ExecuteScript (const SOptions &Options)
	{
	int i, j;

	//	Load the script file

	CDatum dScript;
	CString sError;
	if (!CDatum::CreateFromFile(Options.sScriptFile, CDatum::formatAEONScript, &dScript, &sError))
		{
		printf("ERROR: %s\n", (LPSTR)sError);
		return 1;
		}

	//	Get the server to connect to

	CString sServer = dScript.GetElement(FIELD_SERVER);
	if (sServer.IsEmpty())
		sServer = Options.sServer;

	//	Connect

	CSocket theSocket;
	if (!ConnectToArcology(STR_ARC_CONSOLE, sServer, Options, &theSocket))
		return 1;

	//	Run the script

	CDatum dCommands = dScript.GetElement(FIELD_COMMANDS);
	for (i = 0; i < dCommands.GetCount(); i++)
		{
		CDatum dCommand = dCommands.GetElement(i);

		//	Generate a command-line from the command

		CStringBuffer Buffer;
		for (j = 0; j < dCommand.GetCount(); j++)
			{
			if (j != 0)
				Buffer.Write(" ", 1);

			dCommand.Serialize(CDatum::formatAEONScript, Buffer);
			}

		//	Run

		printf("%s\n", (LPSTR)(const CString &)Buffer);
		CString sResult = ExecuteArcologyCommand(theSocket, Buffer);
		PrintUTF8(sResult);
		printf("\n");
		}

	//	Done

	return 0;
	}
Ejemplo n.º 7
0
static void TestTCPClientKeepAlive_SendData(CTcpClient& tcpClient, const CStringBuffer& buffer)
{
	CStringBuffer sBuffer;
	CByteBuffer bBuffer;
	dword numBytesSend;

	sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
	sBuffer.convertToByteBuffer(bBuffer);
	tcpClient.SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
	assert(numBytesSend == bBuffer.get_BufferSize());
}
Ejemplo n.º 8
0
	void SendData(CTcpClient* tcpClient, const CStringBuffer& buffer)
	{
		CScopedLock _lock;
		CStringBuffer sBuffer;
		CByteBuffer bBuffer;
		dword numBytesSend;

		sBuffer.FormatString(__FILE__LINE__ _T("##%05d## %s"), buffer.GetLength(), buffer.GetString());
		sBuffer.convertToByteBuffer(bBuffer);
		_lock.unlock();
		tcpClient->SendData(bBuffer.get_Buffer(), bBuffer.get_BufferSize(), &numBytesSend);
		assert(numBytesSend == bBuffer.get_BufferSize());
	}
Ejemplo n.º 9
0
void TestTCPClientKeepAlive(CStringLiteral command)
{
	CTcpClient tcpClient;
	CStringBuffer sBuffer;
	CStringBuffer sBuffer0(__FILE__LINE__ _T("10: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer1(__FILE__LINE__ _T("20: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer2(__FILE__LINE__ _T("30: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer3(__FILE__LINE__ _T("40: Testdaten (Client): 0123456789"));
	CStringBuffer sBuffer4(__FILE__LINE__ _T("50: Testdaten (Client): 0123456789"));

	try
	{
		tcpClient.OpenConnection(_T("localhost"), DEFAULT_PORT);

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer0);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer1);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer2);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer3);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		sBuffer.Clear();
		if ( !!command )
		{
			COUT << command << endl;
			sBuffer.AppendString(command);
			sBuffer.AppendString(_T("\r\n"));
		}
		sBuffer.AppendString(sBuffer4);
		TestTCPClientKeepAlive_SendData(tcpClient, sBuffer);
		TestTCPClientKeepAlive_ReceiveData(tcpClient, sBuffer);
		COUT << sBuffer << endl;

		tcpClient.CloseConnection();
	}
	catch ( CTcpClientException* ex )
	{
		COUT << ex->GetExceptionMessage() << endl;
		tcpClient.CloseConnection();
	}
}
Ejemplo n.º 10
0
bool CDatum::CreateStringFromHandoff (CStringBuffer &String, CDatum *retDatum)

//	CreateStringFromHandoff
//
//	Creates a string by taking a handoff from a string buffer

	{
	//	Take ownership of the data

	LPSTR pString = String.Handoff();

	//	Track it with our allocator (but only if not NULL).
	//	(If pString is NULL then this is represented as Nil).

	if (pString)
		g_StringAlloc.New(pString);

	//	Store the pointer

	retDatum->m_dwData = (DWORD_PTR)pString;

	//	Done

	return true;
	}
Ejemplo n.º 11
0
CString CComplexStruct::AsString (void) const

//	AsString
//
//	Represent as a string

	{
	CStringBuffer Output;

	Output.Write("{", 1);

	for (int i = 0; i < m_Map.GetCount(); i++)
		{
		if (i != 0)
			Output.Write(" ", 1);

		Output.Write(m_Map.GetKey(i));
		Output.Write(":", 1);

		Output.Write(m_Map[i].AsString());
		}

	Output.Write("}", 1);

	CString sOutput;
	sOutput.TakeHandoff(Output);
	return sOutput;
	}
Ejemplo n.º 12
0
CStringBuffer CConsoleMenuItem::CreateMenuTitle() const
{
	CStringBuffer tmp;

	tmp = m_Title;
	if ( m_KeyModifiers & KeyStateCtrlMask )
	{
		TCHAR buf [2];

		tmp += _T(" CTRL+");
		buf[0] = m_VirtualKeyCode;
		buf[1] = 0;
		tmp += buf;
	}
	if ( tmp.IsEmpty() )
		tmp.SetString(__FILE__LINE__ _T(" "));
	return tmp;
}
Ejemplo n.º 13
0
void CComplexBinary::TakeHandoff (CStringBuffer &Buffer)

//	TakeHandoff
//
//	Takes ownership

	{
	if (m_pData)
		delete [] GetBuffer();

	m_pData = Buffer.Handoff();
	}
Ejemplo n.º 14
0
bool UString::getCString(CStringBuffer& buffer) const
{
    int length = size();
    int neededSize = length + 1;
    buffer.resize(neededSize);
    char* buf = buffer.data();

    UChar ored = 0;
    const UChar* p = data();
    char* q = buf;
    const UChar* limit = p + length;
    while (p != limit) {
        UChar c = p[0];
        ored |= c;
        *q = static_cast<char>(c);
        ++p;
        ++q;
    }
    *q = '\0';

    return !(ored & 0xFF00);
}
Ejemplo n.º 15
0
	dword ClientTask()
	{
		CScopedLock _lock;
		CTcpClient* pClient = NULL;
		CDataDoubleLinkedListT<CTcpClient>::Iterator it = _tcpclients.Begin();
				
		if ( it && (*it) )
		{
			pClient = *it;
			_tcpclients.Remove(it, EmptyDeleteFunc, NULL);
		}
		if ( !pClient )
			return 0;

		CStringBuffer sBuffer;

		wcout(_T("ClientTask"));
		try
		{
			CStringConstIterator itB;
			bool bExit = false;

			_lock.unlock();
			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			ReceiveData(pClient, sBuffer);
			itB = sBuffer;
			itB.Find(_T("STOP\r\n"));
			if ( itB.IsBegin() )
				bExit = true;
			wcout(sBuffer.GetString());
			SendData(pClient, sBuffer);

			pClient->CloseConnection();
			_lock.lock();
			pClient->release();
			_bExit = bExit;
		}
		catch ( CTcpClientException* ex )
		{
			COUT << ex->GetExceptionMessage() << endl;
			pClient->CloseConnection();
		}
		return 0;
	}
Ejemplo n.º 16
0
CString CAeonInterface::FilespecToFilePath (const CString &sFilespec)

//	FilespecToFilePath
//
//	Converts a filespec to an Aeon filePath. We convert \ to / and escape all
//	characters that are not valid Aeon path characters.

	{
	char *pPos = sFilespec.GetParsePointer();
	char *pEndPos = pPos + sFilespec.GetLength();
	CStringBuffer Output;

	while (pPos < pEndPos)
		{
		if (*pPos == '\\')
			Output.Write("/", 1);
		else if (!strIsASCIIAlpha(pPos)				//	alpha
				&& !strIsDigit(pPos)				//	numbers
				&& *pPos != '-'
				&& *pPos != '_'
				&& *pPos != '.'
				&& *pPos != '~'
				&& !strIsASCIIHigh(pPos))			//	unicode characters
			{
			CString sChar = strPattern("_%x_", (DWORD)(BYTE)*pPos);
			Output.Write(sChar);
			}
		else
			Output.Write(pPos, 1);

		pPos++;
		}

	//	Done

	return CString::CreateFromHandoff(Output);
	}
Ejemplo n.º 17
0
	void ReceiveData(CTcpClient* tcpClient, CStringBuffer& buffer)
	{
		CScopedLock _lock;
		CStringBuffer responseString;
		CByteBuffer responseBuffer;
		dword numDataReceived = 0;
		dword totalDataReceived = 0;
		CStringConstIterator itB;
		CStringBuffer sBuffer;
		dword numData;

		for ( ; totalDataReceived < 10; )
		{
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived + MAX_BUFFER);
			_lock.unlock();
			tcpClient->ReceiveData(responseBuffer.get_Buffer() + totalDataReceived, MAX_BUFFER, &numDataReceived);
			totalDataReceived += numDataReceived;
			_lock.lock();
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived);
		}
		responseString.convertFromByteBuffer(responseBuffer);
		itB = responseString.GetString();
		buffer = responseString;
		if ( (itB[0] == _T('#')) && (itB[1] == _T('#')) && (itB[7] == _T('#')) && (itB[8] == _T('#')) )
		{
			responseString.SubString(2, 5, sBuffer);
			if ( sBuffer.ScanString(_T("%u"), &numData) <= 0 )
				return;
		}
		else
			return;
		for ( ; totalDataReceived < (10 + numData); )
		{
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived + MAX_BUFFER);
			_lock.unlock();
			tcpClient->ReceiveData(responseBuffer.get_Buffer() + totalDataReceived, MAX_BUFFER, &numDataReceived);
			totalDataReceived += numDataReceived;
			_lock.lock();
			responseBuffer.set_BufferSize(__FILE__LINE__ totalDataReceived);
		}
		responseString.convertFromByteBuffer(responseBuffer);
		responseString.SubString(10, numData, buffer);
	}
Ejemplo n.º 18
0
	virtual int main()
	{
		int result = 0;

		if (m_bHelp)
		{
			CStringBuffer tmp;

			usage(tmp);
			MessageBox(NULL, tmp.GetString(), _T("Usage"), MB_OK | MB_ICONINFORMATION);
			return result;
		}

		if (!m_bAnyOption)
		{
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowAccelarator, IDC_XGUILOG);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowTitle, IDS_APP_TITLE);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowIcon, IDI_XGUILOG);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowSmallIcon, IDI_SMALL);
			get_ResourceManager()->add_resource(_T("CFRAMEWND"), CResourceManager::WindowMenu, IDC_XGUILOG);

			XGuiLog* win = OK_NEW_OPERATOR XGuiLog();

			win->set_ClientBorder(TRUE);
			win->set_ClientHScrollEnabled(TRUE);
			win->set_ClientVScrollEnabled(TRUE);
			win->set_StatusBarEnabled(TRUE);
			win->set_ToolBarEnabled(TRUE);
			win->set_DockingEnabled(TRUE);
			result = do_messageloop(win);
		}
		if (m_bMDITest)
		{
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowAccelarator, IDC_XMDITEST);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowTitle, IDS_APP_TITLE);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowIcon, IDI_XGUILOG);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowSmallIcon, IDI_SMALL);
			get_ResourceManager()->add_resource(_T("CMDIFRAME"), CResourceManager::WindowMenu, IDC_XMDITEST);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowTitle, IDS_DOCKING);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowIcon, IDI_DOCKING);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest1"), CResourceManager::WindowSmallIcon, IDI_DOCKING);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowTitle, IDS_CLASSVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowIcon, IDI_CLASSVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest2"), CResourceManager::WindowSmallIcon, IDI_CLASSVIEW);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowTitle, IDS_FILEVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowIcon, IDI_FILEVIEW);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest3"), CResourceManager::WindowSmallIcon, IDI_FILEVIEW);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowTitle, IDS_RECT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowIcon, IDI_RECT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest4"), CResourceManager::WindowSmallIcon, IDI_RECT);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowTitle, IDS_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowIcon, IDI_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest5"), CResourceManager::WindowSmallIcon, IDI_TEXT);

			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowTitle, IDS_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowIcon, IDI_TEXT);
			get_ResourceManager()->add_resource(_T("XGuiMDIChildTest6"), CResourceManager::WindowSmallIcon, IDI_TEXT);

			XGuiMDITest* win = OK_NEW_OPERATOR XGuiMDITest();

			win->set_StatusBarEnabled(TRUE);
			win->set_ToolBarEnabled(TRUE);
			win->set_DockingEnabled(TRUE);
			result = do_messageloop(win);
		}
		return result;
	}
Ejemplo n.º 19
0
double UString::toDouble(bool tolerateTrailingJunk, bool tolerateEmptyString) const
{
    double d;

    // FIXME: If tolerateTrailingJunk is true, then we want to tolerate non-8-bit junk
    // after the number, so this is too strict a check.
    CStringBuffer s;
    if (!getCString(s))
        return NaN;
    const char* c = s.data();

    // skip leading white space
    while (isASCIISpace(*c))
        c++;

    // empty string ?
    if (*c == '\0')
        return tolerateEmptyString ? 0.0 : NaN;

    // hex number ?
    if (*c == '0' && (*(c + 1) == 'x' || *(c + 1) == 'X')) {
        const char* firstDigitPosition = c + 2;
        c++;
        d = 0.0;
        while (*(++c)) {
            if (*c >= '0' && *c <= '9')
                d = d * 16.0 + *c - '0';
            else if ((*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f'))
                d = d * 16.0 + (*c & 0xdf) - 'A' + 10.0;
            else
                break;
        }

        if (d >= mantissaOverflowLowerBound)
            d = parseIntOverflow(firstDigitPosition, c - firstDigitPosition, 16);
    } else {
        // regular number ?
        char* end;
        d = strtod(c, &end);
        if ((d != 0.0 || end != c) && d != Inf && d != -Inf) {
            c = end;
        } else {
            double sign = 1.0;

            if (*c == '+')
                c++;
            else if (*c == '-') {
                sign = -1.0;
                c++;
            }

            // We used strtod() to do the conversion. However, strtod() handles
            // infinite values slightly differently than JavaScript in that it
            // converts the string "inf" with any capitalization to infinity,
            // whereas the ECMA spec requires that it be converted to NaN.

            if (c[0] == 'I' && c[1] == 'n' && c[2] == 'f' && c[3] == 'i' && c[4] == 'n' && c[5] == 'i' && c[6] == 't' && c[7] == 'y') {
                d = sign * Inf;
                c += 8;
            } else if ((d == Inf || d == -Inf) && *c != 'I' && *c != 'i')
                c = end;
            else
                return NaN;
        }
    }

    // allow trailing white space
    while (isASCIISpace(*c))
        c++;
    // don't allow anything after - unless tolerant=true
    if (!tolerateTrailingJunk && *c != '\0')
        d = NaN;

    return d;
}
Ejemplo n.º 20
0
	virtual int main()
	{
		CStreamFile* pOutFile = NULL;
		CFilePath fcurdir;
		CFilePath fziparchive(__FILE__LINE__ m_sZipArchive);
		CFilePath foutf(__FILE__LINE__ m_sOutputFile);
		int result = 0;

		if ( m_help )
		{
			CStringBuffer tmp;

			usage(tmp);
			CERR << tmp;
			return 0;
		}
		if ( !m_AnyZipOption )
		{
			m_AnyZipOption = true;
			m_bAddFiles = true;
		}
		if (m_bInputDir)
		{
			CFilePath finputdir(__FILE__LINE__ m_sInputDir);

			if (CWinDirectoryIterator::FileExists(finputdir))
				finputdir.set_Filename(NULL);
			finputdir.MakeDirectory();
			if (CWinDirectoryIterator::DirectoryExists(finputdir) < 0)
			{
				CERR << finputdir.get_Path() << _T(" does not exist.") << endl;
				return -4;
			}
			CDirectoryIterator::GetCurrentDirectory(fcurdir);
			fziparchive.MakeAbsolute();
			if (m_bOutputFile)
				foutf.MakeAbsolute();
			CDirectoryIterator::SetCurrentDirectory(finputdir);
		}
		if (m_bOutputFile) 
		{
			if (CDirectoryIterator::FileExists(foutf))
				CDirectoryIterator::RemoveFile(foutf);
			else if (foutf.is_File())
			{
				CFilePath tmp(foutf);

				tmp.set_Filename(NULL);
				CDirectoryIterator::MakeDirectory(tmp);
			}
			else
			{
				CDateTime now;
				CStringBuffer tmp;

				now.Now();
				tmp.FormatString(__FILE__LINE__ _T("XZip%04hd%02hd%02hd%02hd%02hd%02hd.log"),
					now.GetYears(), now.GetMonths(), now.GetDays(),
					now.GetHours(), now.GetMinutes(), now.GetSeconds());
				foutf.set_Filename(tmp);
			}
			pOutFile = OK_NEW_OPERATOR CStreamFile;
			pOutFile->ReOpen(foutf, stdout);
		}
		if ( m_bAddFiles )
		{
			if (!m_bZipFileSpec)
			{
				CERR << _T("No FileSpec given. Do not know, what to do.") << endl;
				result = -4;
			}
			else
				XZipAddFiles(fziparchive, m_bRecurseFolders, m_sZipFileSpec, m_sExclude);
		}
		if ( m_bViewFiles )
		{
			if ( !m_bZipFileSpec )
				m_sZipFileSpec.Append(_T("*.*"));
			XZipViewFiles(fziparchive, m_sZipFileSpec, m_sExclude, m_sViewFiles);
		}
		if ( m_bFreshenFiles )
		{
			if ( !m_bZipFileSpec )
				m_sZipFileSpec.Append(_T("*.*"));
			XZipFreshenFiles(fziparchive, m_sZipFileSpec, m_sExclude);
		}
		if ( m_bUpdateFiles )
		{
			if ( !m_bZipFileSpec )
			{
				CERR << _T("No FileSpec given. Do not know, what to do.") << endl;
				result = -4;
			}
			else
				XZipUpdateFiles(fziparchive, m_bRecurseFolders, m_sZipFileSpec, m_sExclude);
		}
		if (pOutFile)
		{
			pOutFile->Close();
			pOutFile->release();
		}
		if (m_bInputDir)
			CDirectoryIterator::SetCurrentDirectory(fcurdir);
		return result;
	}
Ejemplo n.º 21
0
CString ExecuteUpgrade (CSocket &theSocket, const CString &sCmd)
	{
	int i;

	CString sRoot = fileGetPath(fileGetExecutableFilespec());

	//	Make a list of all executable files to upgrade

	TArray<CString> FileList;
	if (!fileGetFileList(sRoot, NULL_STR, CString("*.exe"), FFL_FLAG_RELATIVE_FILESPEC, &FileList))
		return CString("ERROR: Unable to obtain a list of executable files to upgrade.");

	//	Prepare a request upgrade command

	CStringBuffer Output;
	Output.Write("requestUpgrade (", 16);

	for (i = 0; i < FileList.GetCount(); i++)
		{
		CString sFilespec = fileAppend(sRoot, FileList[i]);

		//	Version

		SFileVersionInfo Info;
		if (!fileGetVersionInfo(sFilespec, &Info))
			{
			printf("ERROR: Unable to get file version: %s\n", (LPSTR)sFilespec);
			continue;
			}

		CIPInteger Version(Info.dwProductVersion);
		CString sVersion = Version.AsString();

		//	Checksum

		DWORD dwChecksum = fileChecksumAdler32(sFilespec);
		if (dwChecksum == 0)
			{
			printf("ERROR: Unable to get file checksum: %s\n", (LPSTR)sFilespec);
			continue;
			}

		CString sOutput = strPattern("{filename:\"%s\" version:%s checksum:%d} ", FileList[i], sVersion, dwChecksum);
		Output.Write(sOutput);
		}

	Output.Write(")", 1);

	//	Send the command

	CString sSend = CString::CreateFromHandoff(Output);
	CString sResult;
	CDatum dResult;
	ExecuteArcologyCommand(theSocket, sSend, &sResult, &dResult);
	if (strEquals(sResult, CString("ERROR")))
		return dResult.AsString();

	//	Show all the files to upgrade

	CDatum dUpgradeDesc = dResult.GetElement(0).GetElement(FIELD_UPGRADE_DESC);
	for (i = 0; i < dUpgradeDesc.GetCount(); i++)
		{
		CDatum dFileDesc = dUpgradeDesc.GetElement(i);

		printf("Upgrading %s\n", (LPSTR)dFileDesc.GetElement(FIELD_FILENAME).AsString());
		}

	//	Confirm

	CString sConfirm = GetInputLine(CString("\nAre you sure you want to upgrade the arcology? [y/n] : "));
	if (*sConfirm.GetParsePointer() != 'y' && *sConfirm.GetParsePointer() != 'Y')
		return NULL_STR;

	//	Upload the new files.

	for (i = 0; i < dUpgradeDesc.GetCount(); i++)
		{
		CDatum dFileDesc = dUpgradeDesc.GetElement(i);
		const CString &sFilename = dFileDesc.GetElement(FIELD_FILENAME);
		CString sFilespec = fileAppend(sRoot, sFilename);

		CString sResult = UploadFile(theSocket, CMD_UPLOAD_UPGRADE, sFilename, sFilespec);
		printf("%s\n", (LPSTR)sResult);
		}

	//	Complete the upgrade

	return ExecuteArcologyCommand(theSocket, CMD_COMPLETE_UPGRADE);
	}
Ejemplo n.º 22
0
void SgmlElement::AppendTChar(const _TCHAR newChar, bool bIsParameter, bool bIsMasked) {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    static bool s_bIsBlank = false;
    static bool s_bIsEqual = false;
    static bool s_bHasName = false;
    static bool s_bIsGroup = false;
    static CStringBuffer s_szBuf;
    static Attribute *s_pLastAttribute = NULL;

    if (m_bIsNotInitialized) {
        s_bIsBlank = false;
        s_bIsEqual = false;
        s_bHasName = false;
        s_bIsGroup = false;
        s_szBuf.Empty();
        s_pLastAttribute = NULL;
        m_bIsNotInitialized = false;
    }

    if (bIsParameter) {
        if (m_csParameter.IsEmpty() && newChar == _T(' ') && (_tcscmp(GetName(), _T("TEXTITEM")) != 0))
            return;
        m_csParameter.Add(newChar);
    } else {
        if (!bIsMasked && s_bIsBlank && newChar == _T(' '))
            return;

        if (!bIsMasked && newChar == _T('\"')) {
            if (s_bIsGroup)
                s_bIsGroup = false;
            else
                s_bIsGroup = true;
            return;
        }

        if (!bIsMasked && !s_bIsGroup && newChar == _T(' '))
            s_bIsBlank = true;
        else
            s_bIsBlank = false;

        if (!bIsMasked && !s_bIsGroup && newChar == _T('='))
            s_bIsEqual = true;
        else
            s_bIsEqual = false;

        if (s_bIsBlank) {
            if (!s_bHasName) {
                m_csName = s_szBuf.GetStringBuffer();
                s_bHasName = true;
            } else {
                if (s_pLastAttribute != NULL)
                    s_pLastAttribute->SetValue(s_szBuf.GetStringBuffer());
            }
            s_szBuf.Empty();
            s_pLastAttribute = new Attribute();
            m_aAttributes.Add(s_pLastAttribute);
        } else if (s_bIsEqual) {
            if (s_pLastAttribute) {
                s_pLastAttribute->SetName(s_szBuf.GetStringBuffer());
            }
            s_szBuf.Empty();
        } else if (!bIsMasked && newChar == _T('>')) {
            if (!s_bHasName) {
                m_csName = s_szBuf.GetStringBuffer();
                s_bHasName = true;
            }
            else if (s_pLastAttribute) {
                s_pLastAttribute->SetValue(s_szBuf.GetStringBuffer());
            }
            s_szBuf.Empty();
        } else {
            s_szBuf.Add(newChar);
        }
    }
}