/* * Read the update.status file and sets isApplying to true if * the status is set to applying * * @param updateDirPath The directory where update.status is stored * @param isApplying Out parameter for specifying if the status * is set to applying or not. * @return TRUE if the information was filled. */ static BOOL IsStatusApplying(LPCWSTR updateDirPath, BOOL &isApplying) { isApplying = FALSE; WCHAR updateStatusFilePath[MAX_PATH + 1]; wcscpy(updateStatusFilePath, updateDirPath); if (!PathAppendSafe(updateStatusFilePath, L"update.status")) { LOG(("Warning: Could not append path for update.status file\n")); return FALSE; } nsAutoHandle statusFile(CreateFileW(updateStatusFilePath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, NULL)); if (INVALID_HANDLE_VALUE == statusFile) { LOG(("Warning: Could not open update.status file\n")); return FALSE; } char buf[32] = { 0 }; DWORD read; if (!ReadFile(statusFile, buf, sizeof(buf), &read, NULL)) { LOG(("Warning: Could not read from update.status file\n")); return FALSE; } LOG(("updater.exe returned status: %s\n", buf)); const char kApplying[] = "applying"; isApplying = strncmp(buf, kApplying, sizeof(kApplying) - 1) == 0; return TRUE; }
void BaczekKPAI::DumpStatus() { std::string tmpName = std::string(statusName)+".tmp"; ofstream statusFile(tmpName.c_str()); // dump map size, frame number, etc int frame = cb->GetCurrentFrame(); statusFile << "frame " << frame << "\n" << "map " << map.w << " " << map.h << "\n"; // dump known geovents statusFile << "geovents\n"; BOOST_FOREACH(float3 geo, geovents) { statusFile << "\t" << geo.x << " " << geo.z << "\n"; } // dump units int unitids[MAX_UNITS]; // dump known friendly units statusFile << "units friendly\n"; int num = cb->GetFriendlyUnits(unitids); std::vector<float3> friends; friends.reserve(num); for (int i = 0; i<num; ++i) { int id = unitids[i]; float3 pos = cb->GetUnitPos(id); const UnitDef* ud = cb->GetUnitDef(id); assert(ud); // print owner char *ownerstr; if (cb->GetUnitTeam(id) == cb->GetMyTeam()) { ownerstr = "mine"; } else { ownerstr = "allied"; } statusFile << "\t" << ud->name << " " << id << " " << pos.x << " " << pos.y << " " << pos.z << " " << ownerstr << "\n"; friends.push_back(pos); } // dump known enemy units statusFile << "units enemy\n"; num = cheatcb->GetEnemyUnits(unitids); std::vector<float3> enemies; enemies.reserve(num); for (int i = 0; i<num; ++i) { int id = unitids[i]; float3 pos = cheatcb->GetUnitPos(id); const UnitDef* ud = cheatcb->GetUnitDef(id); assert(ud); statusFile << "\t" << ud->name << " " << id << " " << pos.x << " " << pos.y << " " << pos.z << "\n"; enemies.push_back(pos); } // dump influence map statusFile << "influence map\n"; statusFile << influence->mapw << " " << influence->maph << "\n"; for (int y=0; y<influence->maph; ++y) { for (int x=0; x<influence->mapw; ++x) { statusFile << influence->map[x][y] << " "; } statusFile << "\n"; } // dump other stuff statusFile.close(); unlink(statusName); rename(tmpName.c_str(), statusName); //python->DumpStatus(frame, geovents, friends, enemies); }
int createFile(char *name, enum fileTypes type, securityIdType securityID) { int i; unsigned int catalogBlock; // if no filename give, return error if ( name == 0 ) { return ERROR_BAD_VALUE; } // if the root directory is invalid, return error if ( rootDir == 0 ) { return ERROR_INIT; } // if the file already exists, return error if ( statusFile(name, 0) == 0 ) { return ERROR_FILE_EXISTS; } // find the first empty directory entry for ( i = 0; i < masterBlocks->mblock0.dirEntriesPerBlock; ++i ) { if ( rootDir->entry[i].name[0] == 0) { strncpy(rootDir->entry[i].name, name, MAX_FILENAME_LEN); rootDir->entry[i].fileSize = 0; rootDir->entry[i].fileType = type; rootDir->entry[i].securityID = securityID; rootDir->entry[i].othersPermissions = 0; // now allocate a block for its first catalog block if (findFreeBlock(&catalogBlock) == 0 ) { eraseBlock(catalogBlock); setBlockInUse(catalogBlock); rootDir->entry[i].firstCatalogBlock = catalogBlock; } else { return ERROR_NO_BLOCKS; } rootDir->numEntries++; return NO_ERROR; } // if strcmp } // for return ERROR_MAX_EXCEEDED; }
int makeMemoryFile(char *name, unsigned int address, unsigned int length, char accessType, securityIdType securityID ) { int i; unsigned int catalogBlock; struct { unsigned int address; unsigned int size; char accessType; } *memoryFileInfo; // if no filename give, return error if ( name == 0 ) { return ERROR_BAD_VALUE; } // if the root directory is invalid, return error if ( rootDir == 0 ) { return ERROR_INIT; } // if the file already exists, return error if ( statusFile(name, 0) == 0 ) { return ERROR_FILE_EXISTS; } // find the first empty directory entry for ( i = 0; i < rootDir->maxEntries; ++i ) { if ( rootDir->entry[i].name[0] == 0) { strncpy(rootDir->entry[i].name, name, MAX_FILENAME_LEN); rootDir->entry[i].fileSize = length; rootDir->entry[i].fileType = 0x3 + accessType; rootDir->entry[i].securityID = securityID; rootDir->entry[i].othersPermissions = 0; // now allocate a block for its first catalog block if (findFreeBlock(&catalogBlock) == 0 ) { eraseBlock(catalogBlock); setBlockInUse(catalogBlock); rootDir->entry[i].firstCatalogBlock = catalogBlock; } else { return ERROR_NO_BLOCKS; } rootDir->numEntries++; readBlock(catalogBlock, (void **)&memoryFileInfo); memoryFileInfo->address = address; memoryFileInfo->size = length; memoryFileInfo->accessType = accessType; writeBlock(memoryFileInfo, catalogBlock); return NO_ERROR; } // if strcmp } // for return ERROR_MAX_EXCEEDED; }