This is what the C++ code looks like:
Basically it calls 'RegCreateKeyEx' to find out if the key 'HKEY_CURRENT_USER\Software\Team MediaPortal\Client Common' exists and create it if it doesn't.
Then it calls 'RegQueryValueEx' to get the 'LogFolderPath' value - if that value doesn't exist it creates it using 'RegSetValueEx' (with the default path value).
So I guess doing something similar on the C# should work, except that since MP is going to be the 'master' here, it can just overwrite the 'LogFolderPath' value with whatever is in MediaPortalDirs.xml each time (on MP startup ?)
(Ignoring the problem of accessing the registry from .NET of course - http://stackoverflow.com/questions/1470770/accessing-the-windows-registry-using-net )
Code:
LONG LogWriteRegistryKeyString(HKEY hKey, LPCTSTR& lpSubKey, LPCTSTR& data)
{
LONG result = RegSetValueEx(hKey, lpSubKey, 0, REG_SZ, (LPBYTE)data, _tcslen(data) * sizeof(TCHAR));
return result;
}
LONG LogReadRegistryKeyString(HKEY hKey, LPCTSTR& lpSubKey, LPCTSTR& data)
{
DWORD dwSize = MAX_PATH * sizeof(TCHAR);
DWORD dwType = REG_SZ;
LONG result = RegQueryValueEx(hKey, lpSubKey, NULL, &dwType, (PBYTE)data, &dwSize);
if (result != ERROR_SUCCESS)
{
if (result == ERROR_FILE_NOT_FOUND)
{
//create default value
result = LogWriteRegistryKeyString(hKey, lpSubKey, data);
}
}
return result;
}
void LogPath(TCHAR* dest, TCHAR* name)
{
CAutoLock lock(&m_logFileLock);
HKEY hKey;
//Try to read logging folder path from registry
LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Team MediaPortal\\Client Common"), 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);
if (result == ERROR_SUCCESS)
{
//Get default log folder path
TCHAR folder[MAX_PATH];
SHGetSpecialFolderPath(NULL,folder,CSIDL_COMMON_APPDATA,FALSE);
TCHAR logFolder[MAX_PATH];
_stprintf(logFolder, _T("%s\\Team Mediaportal\\MediaPortal\\log"), folder);
//Read log folder path from registry (or write default path into registry if key doesn't exist)
LPCTSTR logFolderC = logFolder;
LPCTSTR logFolderPath = _T("LogFolderPath");
result = LogReadRegistryKeyString(hKey, logFolderPath, logFolderC);
if (result == ERROR_SUCCESS)
{
//Get full log file path
_stprintf(dest, _T("%s\\TsReader.%s"), logFolderC, name);
}
}
if (result != ERROR_SUCCESS)
{
//Fall back to default log folder path
TCHAR folder[MAX_PATH];
SHGetSpecialFolderPath(NULL,folder,CSIDL_COMMON_APPDATA,FALSE);
//Get full log file path
_stprintf(dest, _T("%s\\Team Mediaportal\\MediaPortal\\log\\TsReader.%s"), folder, name);
}
}
Basically it calls 'RegCreateKeyEx' to find out if the key 'HKEY_CURRENT_USER\Software\Team MediaPortal\Client Common' exists and create it if it doesn't.
Then it calls 'RegQueryValueEx' to get the 'LogFolderPath' value - if that value doesn't exist it creates it using 'RegSetValueEx' (with the default path value).
So I guess doing something similar on the C# should work, except that since MP is going to be the 'master' here, it can just overwrite the 'LogFolderPath' value with whatever is in MediaPortalDirs.xml each time (on MP startup ?)
(Ignoring the problem of accessing the registry from .NET of course - http://stackoverflow.com/questions/1470770/accessing-the-windows-registry-using-net )
Last edited: