Ejemplo n.º 1
0
static void FileGetLines(File& file, /*out*/ std::vector<STRING>& lines)
{
    lines.clear();
    string line;
    while (!file.IsEOF())
    {
        file.GetLine(line);
        PushBackString(lines, line);
    }
}
Ejemplo n.º 2
0
	JSONFileNode::JSONFileNode(const std::string& name, JsonOpenType t)
	{
		File f;
		switch (t) {
		case JsonOpenType::ReadFromFile:
			f.Open(name, OpenType::Read);
			mJsonString = f.GetLine(EOF);
			break;
		case JsonOpenType::ReadFromBinary:
			f.Open(name, OpenType::ReadBinary);
			mJsonString = f.GetBinaryString();
			break;
		}

		bool hasError = mDocument.Parse<0>(mJsonString.c_str()).HasParseError();
		assert(!hasError && "Json string parsing error!");
	}
Ejemplo n.º 3
0
/** @brief parses the save file and fills histories (does't load any snapshot)
  */
bool Session::Load()
{
  File Save;
  const string& savePath = STORY_DIR + SLASH + BookName + SLASH
                           + Filename + SESSION_EXT;
  if (!Disk::Exists(savePath) || !Save.Read(savePath)) {
    LOG(savePath + " - save file missing");
    return false;
  }

  string buffer;
  Save.GetLine(buffer); // session name:
  Save.GetLine(Name);
  Save.GetLine(buffer); // book title:
  Save.GetLine(BookName);
  Save.GetLine(buffer);
  Save.GetLine(buffer); // steps taken:
  Save.GetLine(buffer); // #
  Save.GetLine(buffer);

  // queue
  while (Save.GetLine(buffer)) {
    QueueHistory.push_back(buffer);
  }

  // assets
  Save.GetLine(buffer); // asset states:
  Save.GetLine(buffer); // #
  Save.GetLine(buffer);
  while (Save.GetLine(buffer)) {
    string historyEntry = buffer;
    while (Save.GetLine(buffer)) {
      historyEntry += "\n";
      historyEntry += buffer;
    }
    AssetsHistory.push_back(historyEntry);
  }

  // values
  Save.GetLine(buffer); // tracked values:
  Save.GetLine(buffer); // #
  // resize the array to fit all the values tracked
  ValuesHistories.resize(IntoSizeT(buffer));
  Save.GetLine(buffer);
  while (Save.GetLine(buffer)) {
    string indexBuffer;
    Save.GetLine(indexBuffer);
    cszt index = IntoSizeT(indexBuffer);
    ValuesHistoryNames[buffer] = IntoSizeT(index);
    while (Save.GetLine(buffer)) {
      ValuesHistories[index].push_back(buffer);
    }
  }

  // changes
  while (Save.GetLine(buffer)) {
    cszt pos = FindCharacter(buffer, VALUE_SEPARATOR);
    const string& valueIndex = CutString(buffer, 0, pos);
    const string& changeIndex = CutString(buffer, pos + 1);
    cszt_pair change(IntoSizeT(valueIndex), IntoSizeT(changeIndex));
    ValuesChanges.push_back(change);
  }

  // snapshots
  while (Save.GetLine(buffer)) {
    cszt pos = FindCharacter(buffer, VALUE_SEPARATOR);
    cszt pos2 = FindCharacter(buffer, VALUE_SEPARATOR, pos + 1);
    const string& queueIndex = CutString(buffer, 0, pos);
    const string& assetIndex = CutString(buffer, pos + 1, pos2);
    const string& changeIndex = CutString(buffer, pos2 + 1);
    const Snapshot loadedSnapshot(IntoSizeT(queueIndex),
                                  IntoSizeT(assetIndex),
                                  IntoSizeT(changeIndex));
    Snapshots.push_back(loadedSnapshot);
  }

  // bookmarks
  while (Save.GetLine(buffer)) {
    cszt index = IntoSizeT(buffer);
    string bookmarkDescription;
    while (Save.GetLine(buffer)) {
      bookmarkDescription += buffer;
    }
    Bookmarks[index].Description = bookmarkDescription;
  }

  // repeat last snapshot
  LoadSnapshot(Snapshots.size() - 1);
  return true;
}