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; }
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); }
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); }
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; }
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; }
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); }
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); }