bool CAeonEngine::OpenTableDefinitions (void) // OpenTableDefinitions // // Opens and reads all tables in all volumes. Note that we have no idea what // could have happened since our last boot--someone could have copied files // all over the place. We make almost no assumptions. { CSmartLock Lock(m_cs); int i, j; CString sError; // Loop over all volumes and end up with a list of tables and volumes TSortMap<CString, TArray<CString>> Tables; for (i = 0; i < m_LocalVolumes.GetCount(); i++) { CString sVolume = m_LocalVolumes.GetVolume(i); TArray<CString> Dirs; fileGetFileList(fileAppend(m_LocalVolumes.GetPath(i), FILESPEC_TABLE_DIR_FILTER), FFL_FLAG_DIRECTORIES_ONLY | FFL_FLAG_RELATIVE_FILESPEC, &Dirs); for (j = 0; j < Dirs.GetCount(); j++) { TArray<CString> *pList = Tables.SetAt(Dirs[j]); pList->Insert(sVolume); } } // Open all tables for (i = 0; i < Tables.GetCount(); i++) { CString sName = Tables.GetKey(i); CAeonTable *pTable = new CAeonTable; if (!pTable->Open(GetProcessCtx(), &m_LocalVolumes, sName, Tables[i], &sError)) { Log(MSG_LOG_ERROR, strPattern("Unable to load %s: %s", sName, sError)); delete pTable; continue; } m_Tables.Insert(sName, pTable); } // Done return true; }
ALERROR CListSaveFilesTask::OnExecute (ITaskProcessor *pProcessor, CString *retsResult) // OnExecute // // Execute the task { int i; const CVisualPalette &VI = m_HI.GetVisuals(); // Make a list of all files in the directory TArray<CString> SaveFiles; bool bAtLeastOneFolder = false; for (i = 0; i < m_Folders.GetCount(); i++) { if (!fileGetFileList(m_Folders[i], NULL_STR, CONSTLIT("*.sav"), 0, &SaveFiles)) ::kernelDebugLogMessage("Unable to read from save file folder: %s", m_Folders[i]); else bAtLeastOneFolder = true; } // If we couldn't read from any folder, return an error if (!bAtLeastOneFolder) { *retsResult = ERR_DIRECTORY_FAILED; return ERR_FAIL; } // Sort by modified time (most recent first) TSortMap<CTimeDate, CString> SortedList(DescendingSort); for (i = 0; i < SaveFiles.GetCount(); i++) SortedList.Insert(fileGetModifiedTime(SaveFiles[i]), SaveFiles[i]); // Generate a Reanimator list of the profile. The root will be a CAniListBox m_pList = new CAniListBox; m_pList->SetPropertyMetric(PROP_FADE_EDGE_HEIGHT, 0.0); m_pList->SetPropertyMetric(PROP_PADDING_BOTTOM, (Metric)MAJOR_PADDING_BOTTOM); // Set the selection style for the list IAnimatron *pStyle = new CAniRoundedRect; pStyle->SetPropertyColor(PROP_COLOR, VI.GetColor(colorAreaDialogInputFocus)); pStyle->SetPropertyOpacity(PROP_OPACITY, 255); pStyle->SetPropertyString(PROP_LINE_TYPE, LINE_TYPE_SOLID); pStyle->SetPropertyColor(PROP_LINE_COLOR, VI.GetColor(colorAreaDialogHighlight)); pStyle->SetPropertyInteger(PROP_LINE_WIDTH, SELECTION_BORDER_WIDTH); pStyle->SetPropertyInteger(PROP_UL_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_UR_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_LL_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_LR_RADIUS, SELECTION_CORNER_RADIUS); m_pList->SetStyle(STYLE_SELECTION_FOCUS, pStyle); pStyle = new CAniRoundedRect; pStyle->SetPropertyColor(PROP_COLOR, VI.GetColor(colorAreaDialogInputFocus)); pStyle->SetPropertyOpacity(PROP_OPACITY, 255); pStyle->SetPropertyInteger(PROP_UL_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_UR_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_LL_RADIUS, SELECTION_CORNER_RADIUS); pStyle->SetPropertyInteger(PROP_LR_RADIUS, SELECTION_CORNER_RADIUS); m_pList->SetStyle(STYLE_SELECTION, pStyle); // No need to log image load g_pUniverse->SetLogImageLoad(false); // Loop over all files and add them to the scroller int y = MAJOR_PADDING_TOP; for (i = 0; i < SortedList.GetCount(); i++) { CString sFilename = SortedList[i]; CGameFile GameFile; // Ignore files that we can't open if (GameFile.Open(sFilename) != NOERROR) continue; // If the universe is not valid, then this is not a proper save file // (this can happen in the first system). if (!GameFile.IsUniverseValid()) continue; // If we're signed in, then we only show games for the given user // (or unregistered games). if (GameFile.IsRegistered() && !strEquals(GameFile.GetUsername(), m_sUsername)) continue; // Generate a record for the file IAnimatron *pEntry; int cyHeight; CreateFileEntry(GameFile, SortedList.GetKey(i), y, &pEntry, &cyHeight); m_pList->AddEntry(sFilename, pEntry); y += cyHeight + INTER_LINE_SPACING; // Done GameFile.Close(); } g_pUniverse->SetLogImageLoad(true); // Done return NOERROR; }
CString ExecuteUploadPackage (CSocket &theSocket, const CString &sCmd) { int i; char *pPos = sCmd.GetParsePointer() + STR_UPLOAD_PACKAGE_PREFIX.GetLength(); // Get the package name if (*pPos == '\"') pPos++; char *pStart = pPos; while (*pPos != ' ' && *pPos != '\"' && *pPos != '\0') pPos++; CString sPackageName(pStart, pPos - pStart); if (*pPos != '\0') pPos++; if (*pPos == '\"') pPos++; // Skip whitespace while (*pPos == ' ') pPos++; // Get the filespec pStart = pPos; while (*pPos != '\0') pPos++; CString sFilespec(pStart, pPos - pStart); // Get the directory CString sPackageFolder = fileGetPath(sFilespec); CString sPackageDescFilespec = fileGetFilename(sFilespec); // Upload the package descriptor CString sPackageDesc = strPattern("/Arc.services/%s.ars", sPackageName); printf("Uploading %s to /Arc.services/%s.ars...", (LPSTR)sFilespec, (LPSTR)sPackageName); CString sResult = UploadFile(theSocket, CMD_UPLOAD, sPackageDesc, sFilespec); printf("%s\n", (LPSTR)sResult); // Now loop over all files in the directory TArray<CString> Files; if (!fileGetFileList(fileAppend(sPackageFolder, CString("*.*")), FFL_FLAG_RELATIVE_FILESPEC | FFL_FLAG_RECURSIVE, &Files)) { printf("ERROR: Unable to list directory: %s\\*.*\n", (LPSTR)sPackageFolder); return NULL_STR; } for (i = 0; i < Files.GetCount(); i++) { if (!strEquals(Files[i], sPackageDescFilespec)) { CString sFilePath = strPattern("/Arc.services/%s/%s", sPackageName, CAeonInterface::FilespecToFilePath(Files[i])); printf("Uploading %s to %s...", (LPSTR)fileAppend(sPackageFolder, Files[i]), (LPSTR)sFilePath); CString sResult = UploadFile(theSocket, CMD_UPLOAD, sFilePath, fileAppend(sPackageFolder, Files[i])); printf("%s\n", (LPSTR)sResult); } } // Refresh printf("Refreshing Hyperion..."); return ExecuteArcologyCommand(theSocket, CMD_REFRESH_PACKAGES); }
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); }
// ========================***************************============================== void fileSelect(const char *startdir, char *out_dir, char *out_fname, netbuf *buf, bool allow_cancel, bool allow_up) { bool select = false; static int size_list = 18; int num_files = 0; int sel_file = 0; int first_file = 0; // get list of files in current dir if (buf) ftpGetFileList("/", buf, num_files); else fileGetFileList(startdir, num_files); filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); while (!select) { // get_event uint32 keys = keysCurrent(); // handle_event if (keys & KEY_DOWN) { if (sel_file < num_files-1) { sel_file++; if (sel_file >= first_file + size_list - 1) first_file = sel_file - (size_list - 1); filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); } else { // wrap around to top of list sel_file = 0; first_file = 0; filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); } } else if (keys & KEY_UP) { if (sel_file > 0) { sel_file--; if (sel_file < first_file) first_file = sel_file; filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); } else { // wrap around to bottom of list sel_file = num_files - 1; first_file = sel_file - (size_list - 1); filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); } } else if (keys & KEY_A) { // get selected file name char *buf2 = (char*)data; char fname[128]; for (int i = 0; i < sel_file; i++) { buf2 = strchr(buf2, '\n') + 1; } char c; sscanf(buf2, "%c%[^\n]", &c, fname); // gets 'd' or 'f' - dir or file // special cases if (stricmp(fname, ".") == 0) // don't do anything continue; if (stricmp(fname, "..") == 0) { // return to parent function (usually results in "back to higher level") while (keysCurrent() & (KEY_A | KEY_B)); if (!allow_up) continue; if (buf) FtpChdir("..", buf); return; } // get selected file properties char fullname[512]; sprintf(fullname, "%s%s", startdir, fname); struct stat statbuf; stat(fullname, &statbuf); if (c == 'd') { char fullpath[512]; sprintf(fullpath, "%s%s/", startdir, fname); if (buf) FtpChdir(fname, buf); fileSelect(fullpath, out_dir, out_fname, buf, allow_cancel, true); if ((keysCurrent() & (KEY_L | KEY_R)) && allow_cancel) return; while (keysCurrent() & (KEY_A | KEY_B)); // did we select a file? if so, keep returning to parent calling function if (strlen(out_fname)) return; // we did not select anything, so regenerate the old list num_files = 0; if (buf) ftpGetFileList("/", buf, num_files); else fileGetFileList(startdir, num_files); filePrintFileList(startdir, first_file, sel_file, num_files, allow_cancel); continue; } else { sprintf(out_dir, "%s", startdir); sprintf(out_fname, "%s", fname); while (keysCurrent() & (KEY_A | KEY_B)); return; } } else if (keys & KEY_B) { if (!allow_up) continue; if (buf) FtpChdir("..", buf); return; } else if (keys & (KEY_L | KEY_R)) { if (allow_cancel) { sprintf(out_dir, "%s", startdir); out_fname[0] = 0; return; } } for (int i = 0; i < 5; i++) swiWaitForVBlank(); } }
bool CBlackBox::ReadRecent (const CString &sPath, const CString &sFind, int iLines, TArray<CString> *retLines) // ReadRecent // // Returns the most recent set of lines. { // First we make a list of log files at the given path. TArray<CString> Files; if (!fileGetFileList(sPath, NULL_STR, CString("*.log"), 0, &Files)) return false; // Now sort them in reverse chronological order (we can do this because we // have encoded the date in the name). Files.Sort(DescendingSort); // Now loop until we have filled all the lines (or until we run out of log // files). int iLogFile = 0; int iLinesLeft = iLines; while (iLogFile < Files.GetCount() && iLinesLeft > 0) { // Open the log file for read-only CFileBuffer LogFile; if (!LogFile.OpenReadOnly(Files[iLogFile])) return false; // Parse backwards until we reach the number of lines that we want // or until we reach the beginning of the file. char *pBoF = LogFile.GetPointer(); char *pEoF = pBoF + LogFile.GetLength(); char *pStart = pEoF; while (pStart > pBoF && iLinesLeft > 0) { // Remember the end of the line. char *pLineEnd = pStart; // Go backwards until we hit a line ending while (pStart > pBoF && pStart[-1] != '\n') pStart--; // We're at the beginning of the line so get the whole thing. If // this is a line that we want, then add it to the result. CString sLine(pStart, (int)(pLineEnd - pStart)); if (!sLine.IsEmpty() && (sFind.IsEmpty() || strFind(sLine, sFind) != -1)) { // We add at the beginning because we are reading backwards retLines->Insert(sLine, 0); // We got a line iLinesLeft--; } // Now move backwards to skip the line ending if (pStart > pBoF && pStart[-1] == '\n') pStart--; if (pStart > pBoF && pStart[-1] == '\r') pStart--; } // Next file LogFile.Close(); iLogFile++; } // Done return true; }