예제 #1
0
void GameSettings::createProfileFolders()
{
     if (!profileOptions)
         return;

    string temp = profileFile("", "", false);
    JFileSystem::GetInstance()->MakeDir(temp);
    temp += "/stats";
    JFileSystem::GetInstance()->MakeDir(temp);
    temp = profileFile(PLAYER_SETTINGS, "", false);
        
    profileOptions->save();
}
예제 #2
0
/**
 * @fn createProfile
 */
QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings)
{
    if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]";
    if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Profile" << profile;

    QString profileTempName = QDir::homePath() + QDir::separator() +
            QString(".cache") + QDir::separator() + QFileInfo(profile).fileName();
    QFile profileFile(profileTempName);
    if (debug) qDebug() << "[NetctlProfile]" << "[createProfile]" << ":" << "Save to" << profileTempName;
    if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text))
        return profileTempName;
    QTextStream out(&profileFile);
    for (int i=0; i<settings.keys().count(); i++) {
        out << settings.keys()[i] << QString("=");
        if ((settings.keys()[i] == QString("BindsToInterfaces")) ||
                (settings.keys()[i] == QString("After")) ||
                (settings.keys()[i] == QString("Address")) ||
                (settings.keys()[i] == QString("Routes")) ||
                (settings.keys()[i] == QString("Address6")) ||
                (settings.keys()[i] == QString("Routes6")) ||
                (settings.keys()[i] == QString("IPCustom")) ||
                (settings.keys()[i] == QString("DNS")) ||
                (settings.keys()[i] == QString("DNSOptions")) ||
                (settings.keys()[i] == QString("ScanFrequencies")) ||
                (settings.keys()[i] == QString("WPAConfigSection")))
            out << QString("(") + settings[settings.keys()[i]] << QString(")") << endl;
        else
            out << settings[settings.keys()[i]] << endl;
    }
    profileFile.close();

    return profileTempName;
}
예제 #3
0
bool MapiProfiles::init()
{
    if (m_initialised) {
        return true;
    }
    QString profilePath(QDir::home().path());
    profilePath.append(QLatin1String("/.openchange/"));
    
    QString profileFile(profilePath);
    profileFile.append(QString::fromLatin1("profiles.ldb"));

    // Check if the store exists.
    QDir path(profilePath);
    if (!path.exists()) {
        if (path.mkpath(profilePath)) {
            error() << "cannot make profile path:" << profilePath;
            return false;
        }
    }
    if (!QFile::exists(profileFile)) {
        if (MAPI_E_SUCCESS != CreateProfileStore(profileFile.toUtf8(), mapi_profile_get_ldif_path())) {
            error() << "cannot create profile store:" << profileFile << mapiError();
            return false;
        }
    }
    if (MAPI_E_SUCCESS != MAPIInitialize(&m_context, profileFile.toLatin1())) {
        error() << "cannot init profile store:" << profileFile << mapiError();
        return false;
    }
    m_initialised = true;
    return true;
}
예제 #4
0
파일: Profiles.cpp 프로젝트: EmuxEvans/vera
Profiles::RuleNameCollection Profiles::getListOfScriptNamesKeys(
  const Vera::Plugins::Profiles::ProfileName & profile)
{
  RuleNameCollection allRules;

  // name of the profile is also the name of the profile file

  const Vera::Plugins::RootDirectory::DirectoryName veraRoot =
          Vera::Plugins::RootDirectory::getRootDirectory();

  std::string fileName(veraRoot + "/profiles/");
  fileName += profile;

  std::ifstream profileFile(fileName.c_str());
  if (profileFile.is_open() == false)
  {
      std::ostringstream ss;
      ss << "Cannot open profile description for profile '" << profile
          << "': "<< strerror(errno);
      throw Vera::Plugins::ProfileError(ss.str());
  }

  std::string line;
  while (getline(profileFile, line))
  {
      if (line.empty() == false && line[0] != '#')
      {
        std::string::size_type pos = line.find("=");
        if (pos != std::string::npos)
        {
            std::string name = line.substr(0, pos);
            std::string value = line.substr(pos + 1);

            if (name == "rule")
            {
              allRules.push_back(value);
            }
        }
      }
  }

  if (profileFile.bad())
  {
      throw std::runtime_error(
          "Cannot read from " + fileName + ": " + strerror(errno));
  }
  profileFile.close();

  return allRules;
}
예제 #5
0
파일: Profiles.cpp 프로젝트: EmuxEvans/vera
Profiles::RuleNameCollection Profiles::getListOfScriptNamesTcl(
  const Vera::Plugins::Profiles::ProfileName & profile)
{
    RuleNameCollection allRules;

    // name of the profile is also the name of the profile file

    const Vera::Plugins::RootDirectory::DirectoryName veraRoot =
            Vera::Plugins::RootDirectory::getRootDirectory();

    std::string fileName(veraRoot + "/profiles/");
    fileName += profile;

    std::ifstream profileFile(fileName.c_str());
    if (profileFile.is_open() == false)
    {
        std::ostringstream ss;
        ss << "Cannot open profile description for profile '" << profile
            << "': "<< strerror(errno);
        throw Vera::Plugins::ProfileError(ss.str());
    }

    Tcl::interpreter interp;
    interp.eval(profileFile);
    if (profileFile.bad())
    {
        throw std::runtime_error(
            "Cannot read from " + fileName + ": " + strerror(errno));
    }

    const Tcl::object ruleList = interp.eval("set rules");

    const size_t ruleListLength = ruleList.length(interp);
    for (size_t i = 0; i != ruleListLength; ++i)
    {
        const Vera::Plugins::Rules::RuleName rName = ruleList.at(interp, i).get();
        allRules.push_back(rName);
    }

    return allRules;
}
예제 #6
0
PRBool
nsProfileMigrator::ImportRegistryProfiles(const nsACString& aAppName)
{
  nsresult rv;

  nsCOMPtr<nsIToolkitProfileService> profileSvc
    (do_GetService(NS_PROFILESERVICE_CONTRACTID));
  NS_ENSURE_TRUE(profileSvc, NS_ERROR_FAILURE);

  nsCOMPtr<nsIProperties> dirService
    (do_GetService("@mozilla.org/file/directory_service;1"));
  NS_ENSURE_TRUE(dirService, NS_ERROR_FAILURE);

  nsCOMPtr<nsILocalFile> regFile;
#ifdef XP_WIN
  rv = dirService->Get(NS_WIN_APPDATA_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  regFile->AppendNative(aAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
#elif defined(XP_MACOSX)
  rv = dirService->Get(NS_MAC_USER_LIB_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  regFile->AppendNative(aAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("Application Registry"));
#elif defined(XP_OS2)
  rv = dirService->Get(NS_OS2_HOME_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  regFile->AppendNative(aAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("registry.dat"));
#elif defined(XP_BEOS)
  rv = dirService->Get(NS_BEOS_SETTINGS_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  regFile->AppendNative(aAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("appreg"));
#else
  rv = dirService->Get(NS_UNIX_HOME_DIR, NS_GET_IID(nsILocalFile),
                       getter_AddRefs(regFile));
  NS_ENSURE_SUCCESS(rv, PR_FALSE);
  nsCAutoString dotAppName;
  ToLowerCase(aAppName, dotAppName);
  dotAppName.Insert('.', 0);
  
  regFile->AppendNative(dotAppName);
  regFile->AppendNative(NS_LITERAL_CSTRING("appreg"));
#endif

  nsCAutoString path;
  rv = regFile->GetNativePath(path);
  NS_ENSURE_SUCCESS(rv, PR_FALSE);

  if (NR_StartupRegistry())
    return PR_FALSE;

  PRBool migrated = PR_FALSE;
  HREG reg = nsnull;
  RKEY profiles = 0;
  REGENUM enumstate = 0;
  char profileName[MAXREGNAMELEN];

  if (NR_RegOpen(path.get(), &reg))
    goto cleanup;

  if (NR_RegGetKey(reg, ROOTKEY_COMMON, "Profiles", &profiles))
    goto cleanup;

  while (!NR_RegEnumSubkeys(reg, profiles, &enumstate,
                            profileName, MAXREGNAMELEN, REGENUM_CHILDREN)) {
#ifdef DEBUG_bsmedberg
    printf("Found profile %s.\n", profileName);
#endif

    RKEY profile = 0;
    if (NR_RegGetKey(reg, profiles, profileName, &profile)) {
      NS_ERROR("Could not get the key that was enumerated.");
      continue;
    }

    char profilePath[MAXPATHLEN];
    if (NR_RegGetEntryString(reg, profile, "directory",
                             profilePath, MAXPATHLEN))
      continue;

    nsCOMPtr<nsILocalFile> profileFile
      (do_CreateInstance("@mozilla.org/file/local;1"));
    if (!profileFile)
      continue;

#if defined (XP_MACOSX)
    rv = profileFile->SetPersistentDescriptor(nsDependentCString(profilePath));
#else
    NS_ConvertUTF8toUTF16 widePath(profilePath);
    rv = profileFile->InitWithPath(widePath);
#endif
    if (NS_FAILED(rv)) continue;

    nsCOMPtr<nsIToolkitProfile> tprofile;
    profileSvc->CreateProfile(profileFile, nsnull,
                              nsDependentCString(profileName),
                              getter_AddRefs(tprofile));
    migrated = PR_TRUE;
  }

cleanup:
  if (reg)
    NR_RegClose(reg);
  NR_ShutdownRegistry();
  return migrated;
}
예제 #7
0
void GameSettings::checkProfile()
{
    if (!globalOptions)
        globalOptions = NEW GameOptions(GLOBAL_SETTINGS);

    //If it doesn't exist, load current profile.
    if (!profileOptions)
    {
        profileOptions = NEW GameOptions(profileFile(PLAYER_SETTINGS, "", false));
        //Backwards compatibility hack for unlocked modes.
        for (int x = Options::BEGIN_AWARDS; x < Options::LAST_NAMED; x++)
        {
            GameOptionAward * goa = dynamic_cast<GameOptionAward *> (globalOptions->get(x));
            if (goa)
            {
                GameOptionAward * dupe = dynamic_cast<GameOptionAward *> (profileOptions->get(x));
                if (dupe && goa->number && !dupe->number)
                    dupe->giveAward();
            }
        }
    }

    //Validation of collection, etc, only happens if the game is up.
    if (theGame == NULL || MTGCollection() == NULL)
        return;

    string pcFile = profileFile(PLAYER_COLLECTION, "", false);
    if (!pcFile.size() || !fileExists(pcFile.c_str()))
    {
        //If we had any default settings, we'd set them here.

        //Create proper directories
        createProfileFolders();
    }

    //Find the set for which we have the most variety
    int setId = -1;
    int maxcards = 0;
    int ok = 0;
    for (int i = 0; i < setlist.size(); i++)
    {
        int value = MTGCollection()->countBySet(i);
        if (value > maxcards)
        {
            maxcards = value;
            setId = i;
        }
        if (options[Options::optionSet(i)].number)
        {
            ok = 1;
            break;
        }
    }
    if (!ok && setId >= 0)
    {
        //Save this set as "unlocked"
        (*profileOptions)[Options::optionSet(setId)] = 1;
        profileOptions->save();

        //Give the player their first deck
        createUsersFirstDeck(setId);
    }
    getStyleMan()->determineActive(NULL, NULL);
}
예제 #8
0
HRESULT ProfileInfo::Read() {
    HRESULT hr = S_OK;

    LFile profileFile(m_csFilename);

    if (!profileFile.Exists())
        hr = E_PM_FILE_NOTEXIST;

    if (SUCCEEDED(hr)) {
        LURESULT lr = profileFile.Open();
        if (lr == LFILE_ERR_OPEN || lr == LFILE_ERR_ALREADY_OPEN)
            hr = E_PM_FILE_OPEN;
    }

    if (SUCCEEDED(hr)) {
        LBuffer fileBuffer(256);

        DWORD dwBytesRead;
        CStringW csLine;
        UINT uiLinesRead = 0;

        // Read BOM (first 2 bytes)
        LURESULT lr = profileFile.ReadRaw(&fileBuffer, 0, 2, &dwBytesRead);
        if (lr != S_OK)
            hr = E_PM_FILE_READ;


        bool bFirstBlock = true;
        if (SUCCEEDED(hr)) {
            do {
                lr = profileFile.ReadRaw(&fileBuffer, 0, fileBuffer.GetSize(), &dwBytesRead);
                if (lr != S_OK)
                    hr = E_PM_FILE_READ;

                if (SUCCEEDED(hr) && bFirstBlock) {
                    WCHAR *pIdent = (WCHAR *)fileBuffer.GetBuffer();
                    if (wcsncmp(pIdent, L"lpp_", 4) != 0)
                        hr = E_PM_WRONG_FORMAT;
                    bFirstBlock = false;
                }

                if (SUCCEEDED(hr)) {
                    WCHAR *pBuffer = (WCHAR *)fileBuffer.GetBuffer();
                    UINT dwCharsRead = dwBytesRead / sizeof(WCHAR);
                    for (int i = 0; i <  dwCharsRead; ++i) {
                        if (pBuffer[i] == L'\n') {
                            CString csKey;
                            CString csValue;
                            //Ignore lines which begins with % or #
                            if (csLine[0] != L'%' && csLine[0] != L'#') {
                                int iBlankPos = csLine.Find(L'=');
                                if (iBlankPos >= 0) {
#ifdef _UNICODE
                                    csKey = csLine.Left(iBlankPos);
                                    csValue = csLine.Right(csLine.GetLength() - (iBlankPos+1));
#else
                                    CStringW csKeyW = csLine.Left(iBlankPos);
                                    int nLen = csKeyW.GetLength();
                                    char *szRet = new char[nLen + 1];
                                    WideCharToMultiByte(CP_ACP, 0, csKeyW, -1, 
                                        szRet, nLen + 1, NULL, NULL);
                                    csKey = szRet;
                                    delete szRet;

                                    CStringW csValueW = csLine.Right(csLine.GetLength() - (iBlankPos+1)); 
                                    nLen = csValueW.GetLength();
                                    szRet = new char[nLen + 1];
                                    WideCharToMultiByte(CP_ACP, 0, csValueW, -1, 
                                        szRet, nLen + 1, NULL, NULL);
                                    csValue = szRet;
                                    delete szRet;
#endif
                                    if (csKey == _T("lpp_id")) {
                                        m_iProfileID = _ttoi64((LPCTSTR)csValue);
                                    } else if (csKey == _T("lpp_version")) {
                                        m_iProfileVersion = _ttoi((LPCTSTR)csValue);
                                    } else if (csKey == _T("lpp_title")) {
                                        m_csTitle = csValue;
                                    } else if (csKey == _T("lpp_type")) {
                                        m_iProfileType = _ttoi((LPCTSTR)csValue);
                                    } else {
                                        m_aKeys.Add(csKey);
                                        m_aValues.Add(csValue);
                                    }
                                }
                            }
                            csLine.Empty();
                        } else {
                            csLine += pBuffer[i];
                        }
                    }
                }

            } while (dwBytesRead == fileBuffer.GetSize());
        }

        profileFile.Close();
    }

    ExtractTargetFormat();
    ExtractStorageDistribution();

    return hr;
}