コード例 #1
0
ファイル: MainDialog.cpp プロジェクト: Aetherdyne/glintercept
void MainDialog::UpdateTokenValues(ConfigToken & updateProfile, const string & searchStr, const string &replaceStr) const
{
  // Get the value array in the token
  uint i;
  vector<string> tokenValues;
  updateProfile.GetArray(updateProfile.GetNumValues(), tokenValues);

  // Loop for all values in the token
  for(i=0; i<tokenValues.size(); i++)
  {
    // Loop and find the token values
    string::size_type findPos = tokenValues[i].find(searchStr);
    while(findPos != string::npos)
    {
      // Replace the string
      tokenValues[i].replace(findPos, searchStr.size(), replaceStr);
      
      // Attempt to find more matches
      findPos = tokenValues[i].find(searchStr, findPos + replaceStr.size());
    }
  }

  // Replace the stored token values
  updateProfile.SetValueArray(tokenValues);

  // Loop for all children
  for(i=0; i<updateProfile.GetNumChildren(); i++) 
  {
    // Recurse
    UpdateTokenValues(*updateProfile.GetChildToken(i), searchStr, replaceStr);
  }
}
コード例 #2
0
ファイル: MainDialog.cpp プロジェクト: Aetherdyne/glintercept
bool MainDialog::GetSaveProfileString(bool copySystemLib, wxString &retString) const
{
  wxStandardPaths stdPaths;

  // Get the current selected profile
  ConfigToken saveProfile;
  if(!GetCurrentProfile(saveProfile))
  {
    wxLogError("No GLIntercept profile selected");
    return false;
  }

  // Get the profile name (if any)
  string profileName = "*Unknown*";
  {
    // Get the profile name if it exists
    const ConfigToken * profileNameToken = saveProfile.GetChildToken("ProfileName");
    if(profileNameToken)
    {
      profileNameToken->Get(profileName);
    }

    // Remove the profile/description tokens
    saveProfile.RemoveChild("ProfileName");
    saveProfile.RemoveChild("ProfileDescription");
  }

  // If copying the OpenGL system library
  if(copySystemLib)
  {
    // Get the input files token (or create it)
    ConfigToken * sourceInputFilesToken = GetCreateChildToken(saveProfile, "InputFiles");
    if(sourceInputFilesToken)
    {
      // Get the system lib token (or create it)
      ConfigToken * syslibToken = GetCreateChildToken(*sourceInputFilesToken, "GLSystemLib");
      if(syslibToken)
      {
        // Set the new override system lib name
        vector<string> newSystemLibName;
        newSystemLibName.push_back("opengl32.orig.dll");

        // Override the existing library name
        syslibToken->SetValueArray(newSystemLibName);
      }
    }
  }
 

  // Replace any string that start with %InstallPath% with the current path
  UpdateTokenValues(saveProfile, "%InstallPath%", stdPaths.GetDataDir().c_str());

  // Generate the config string from the profile
  string stlConfigString;
  for(uint childNum =0;childNum < saveProfile.GetNumChildren(); childNum++)
  {
    //Convert each child back to raw config string data
    const ConfigToken * childData = saveProfile.GetChildToken(childNum);
    if(childData)
    {
      string retString;
      if(ConfigParser::GenerateConfigString(childData, retString))
      {
        stlConfigString += retString;
      }
      else
      {
        wxLogError("Unable to generate GLIntercept configuration file data");
        return false;
      }
    }
  }

  // Add a header comment
  retString.Printf("/*\n*  GLIntercept config file generated by GLIConfig.\n*  Configuration based on profile \"%s\".\n*/\n\n", profileName.c_str());
  retString += stlConfigString.c_str();

  return true;
}