Example #1
0
// Create CDDB file
bool Dbase::Write(const Cddb::Album& album)
{
    CachePut(album);

    const QString genre = !album.discGenre.isEmpty() ?
        album.discGenre.toLower().toUtf8() : "misc";

    LOG(VB_MEDIA, LOG_INFO, "WriteDB " + genre +
        QString(" %1 ").arg(album.discID,0,16) +
        album.artist + " / " + album.title);

    if (QDir(GetDB()).mkpath(genre))
    {
        QFile file(GetDB() + '/' + genre + '/' + 
            QString::number(album.discID,16));
        if (file.open(QIODevice::WriteOnly | QIODevice::Text))
        {
            QTextStream(&file) << album;
            return true;
        }
        else
            LOG(VB_GENERAL, LOG_ERR, "Cddb can't write " + file.fileName());
    }
    else
        LOG(VB_GENERAL, LOG_ERR, "Cddb can't mkpath " + GetDB() + '/' + genre);
    return false;
}
Example #2
0
PCTSTR CAbstractSettings::RegistryGet (HKEY hkey, PCTSTR pszKey) {
	DWORD dwType;
	union {
		TCHAR sz[MAX_PATH];
		DWORD dw;
	} data;
	DWORD dwSize = sizeof (data);
	HRESULT hr;
	if ((hr = RegGetValue (hkey, NULL, pszKey, RRF_RT_REG_DWORD | RRF_RT_REG_SZ, &dwType, &data, &dwSize)) != ERROR_SUCCESS) {
		LOGDEBUG (TEXT ("Couldn't read registry key ") << pszKey << TEXT (", error ") << hr);
	} else {
		switch (dwType) {
		case REG_DWORD :
			dwSize = data.dw;
			StringCbPrintf (data.sz, sizeof (data.sz), TEXT ("%d"), dwSize);
			/* drop through */
		case REG_SZ :
			return CachePut (pszKey, data.sz);
		default :
			LOGWARN (TEXT ("Unexpected type ") << dwType << TEXT (" in registry value ") << pszKey);
			break;
		}
	}
	return NULL;
}
Example #3
0
// search local database for genre/discID
bool Dbase::Search(Cddb::Album& a, const QString& genre, const Cddb::discid_t discID)
{
    if (CacheGet(a, genre, discID))
        return true;

    QFile file(GetDB() + '/' + genre.toLower() + '/' + QString::number(discID,16));
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        a = QTextStream(&file).readAll();
        a.discGenre = genre.toLower();
        a.discID = discID;
        LOG(VB_MEDIA, LOG_INFO, QString("LocalCDDB matched %1 ").arg(discID,0,16) +
            genre + " to " + a.artist + " / " + a.title);

        CachePut(a);

        return true;
    }
    return false;
}
Example #4
0
// search local database for discID
bool Dbase::Search(Cddb::Matches& res, const Cddb::discid_t discID)
{
    res.matches.clear();
    res.discID = discID;

    if (CacheGet(res, discID))
        return true;

    QFileInfoList list = QDir(GetDB()).entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
    for (QFileInfoList::const_iterator it = list.begin(); it != list.end(); ++it)
    {
        QString genre = it->baseName();

        QFileInfoList ids = QDir(it->canonicalFilePath()).entryInfoList(QDir::Files);
        for (QFileInfoList::const_iterator it2 = ids.begin(); it2 != ids.end(); ++it2)
        {
            if (it2->baseName().toUInt(nullptr,16) == discID)
            {
                QFile file(it2->canonicalFilePath());
                if (file.open(QIODevice::ReadOnly | QIODevice::Text))
                {
                    Cddb::Album a(QTextStream(&file).readAll());
                    a.discGenre = genre;
                    a.discID = discID;
                    LOG(VB_MEDIA, LOG_INFO, QString("LocalCDDB found %1 in ").
                        arg(discID,0,16) + genre + " : " +
                        a.artist + " / " + a.title);

                    CachePut(a);
                    res.matches.push_back(Cddb::Match(genre,discID,a.artist,a.title));
                }

            }
        }
    }
    return res.matches.size() > 0;
}
Example #5
0
CAbstractSettings::CAbstractSettings () {
	m_pCache = NULL;
	TCHAR szSettingsLocation[256];
	if (!GetSettingsLocation (szSettingsLocation, sizeof (szSettingsLocation))) {
		LOGWARN (TEXT ("Couldn't get settings location, error ") << GetLastError ());
		return;
	}
#ifdef _WIN32
	m_hkeyGlobal = NULL;
	m_hkeyLocal = NULL;
	HKEY hkey;
	LOGDEBUG ("Opening registry keys");
	HRESULT hr;
	if ((hr = RegOpenKeyEx (HKEY_LOCAL_MACHINE, TEXT ("SOFTWARE"), 0, KEY_READ, &hkey)) == ERROR_SUCCESS) {
		if ((hr = RegOpenKeyEx (hkey, szSettingsLocation, 0, KEY_READ, &m_hkeyGlobal)) != ERROR_SUCCESS) {
			LOGDEBUG ("Couldn't find machine global configuration settings, error " << hr);
		}
		RegCloseKey (hkey);
	} else {
		LOGWARN ("Couldn't open HKEY_LOCAL_MACHINE\\SOFTWARE registry key, error " << hr);
	}
	if ((hr = RegOpenKeyEx (HKEY_CURRENT_USER, TEXT ("SOFTWARE"), 0, KEY_READ, &hkey)) == ERROR_SUCCESS) {
		if ((hr = RegOpenKeyEx (hkey, szSettingsLocation, 0, KEY_READ, &m_hkeyLocal)) != ERROR_SUCCESS) {
			LOGDEBUG ("Couldn't find user local configuration settings, error " << hr);
		}
		RegCloseKey (hkey);
	} else {
		LOGWARN ("Couldn't open HKEY_CURRENT_USER\\Software registry key, error " << hr);
	}
#else /* ifdef _WIN32 */
#ifndef DEFAULT_CONFIG_FOLDER
#define DEFAULT_CONFIG_FOLDER	"/etc/"
#endif /* ifndef DEFAULT_CONFIG_FOLDER */
#ifndef DEFAULT_CONFIG_BASE
#define DEFAULT_CONFIG_BASE		"/usr/local"
#endif /* ifndef DEFAULT_CONFIG_BASE */
	FILE *f = _OpenSettings (szSettingsLocation, getenv ("HOME"), TEXT (DEFAULT_CONFIG_FOLDER));
	if (!f) {
		f = _OpenSettings (szSettingsLocation, TEXT (DEFAULT_CONFIG_BASE), TEXT (DEFAULT_CONFIG_FOLDER));
		if (!f) {
			f = _OpenSettings (szSettingsLocation, TEXT (""), TEXT (DEFAULT_CONFIG_FOLDER));
			if (!f) {
				LOGWARN (TEXT ("Couldn't open configuration file"));
				return;
			}
		}
	}
	int nLine = 0;
	while (fgets (szSettingsLocation, sizeof (szSettingsLocation), f)) {
		nLine++;
		TCHAR *psz = szSettingsLocation;
		while (isspace (*psz)) psz++;
		if (!*psz || (*psz == '#') || !strtok (psz, "\r\n")) continue;
		TCHAR *pszKey = strtok (psz, "=");
		if (!pszKey) {
			// This shouldn't happen
			LOGFATAL (TEXT ("Bad line ") << nLine);
			continue;
		}
		TCHAR *pszValue = strtok (NULL, "");
		if (!pszValue) {
			LOGWARN (TEXT ("Bad line ") << nLine);
			continue;
		}
		LOGDEBUG (TEXT ("Key=") << pszKey << TEXT (", Value=") << pszValue);
		CachePut (pszKey, pszValue);
	}
	fclose (f);
	LOGDEBUG (TEXT ("Configuration file read, ") << nLine << TEXT (" lines"));
#endif /* ifdef _WIN32 */
}