1.12.0 Redirected log path: some files created in standard path (2 Viewers)

Owlsroost

Development Group
  • Team MediaPortal
  • October 28, 2008
    5,540
    5,038
    Cambridge
    United Kingdom United Kingdom
    Country flag
    This is what the C++ code looks like:

    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:

    regeszter

    Retired Team Member
  • Premium Supporter
  • October 29, 2005
    5,335
    4,954
    Hungary Hungary
    Can the watchdog.exe use any non default log source path?
     

    morpheus_xx

    Lead Dev MP2
  • Team MediaPortal
  • March 24, 2007
    11,487
    7,020
    Germany Germany
    Country flag
    Just found this thread. We already have a different solution for dealing with config/log folders for DirectShow filters, which doesn't depend on registry, but a config next to the filter. It was implemented by @FreakyJ for some (if not all?) TVE related filters.

    The reason to avoid registry was, that the filter can be used in both MP1 and MP2. MP2 loads it from filename and doesn't require registration. Avoiding registry entries also avoids conflicts between different configuration for MP1 and MP2. So I suggest to look at the solution, it's maybe not 100% complete, but works very well already. @FreakyJ can you point to the commit for the changes, please?
     

    HTPCSourcer

    MP2 Product Manager
  • Team MediaPortal
  • May 16, 2008
    11,431
    2,334
    Germany Germany
    Country flag
    Regarding restart.vbs, if I read this code correctly then the logpath definition should be replaced by the respective "Skin" information from mediaportaldirs.xml

    Code:
    Set Shell         = CreateObject("WScript.Shell")
    Set Shell2        = CreateObject("Shell.Application")
    Set objFolder     = Shell2.Namespace(ssfCOMMONAPPDATA)
    Set objFolderItem = objFolder.Self
    
    logpath           = objFolderItem.Path & "\Team MediaPortal\MediaPortal\log\"
    lognew            = logpath + "\" + Wscript.ScriptName + ".log"
    logold            = logpath + "\" + Wscript.ScriptName + ".bak"
    Any other change required? If not, I will start making my first steps towards Powershell processing of XML files...
     

    regeszter

    Retired Team Member
  • Premium Supporter
  • October 29, 2005
    5,335
    4,954
    Hungary Hungary
    Any other change required? If not, I will start making my first steps towards Powershell processing of XML files...
    Do not forget that this file is in Program Files\Team MediaPortal, and it needs elevated rights to change any files in that directory.

    If you have any c# skill, you may try to create a section in the configure.exe to changing the log directories (a GUI for the mediaportaldirs.xml).
     

    HTPCSourcer

    MP2 Product Manager
  • Team MediaPortal
  • May 16, 2008
    11,431
    2,334
    Germany Germany
    Country flag
    Do not forget that this file is in Program Files\Team MediaPortal, and it needs elevated rights to change any files in that directory.
    I think there is a misunderstanding. I don't plan to change any files in the protected path but I would just redirect the output that the script creates when triggered by the Watchdog.

    I would check for the existence of mediaportaldirs.xml in the user's local "Documents/Team MediaPortal" directory, and if there read the path in the xml to define "logpath" in the vbs script.

    If you have any c# skill
    Not specially, nothing but general knowledge of several languages
     

    HTPCSourcer

    MP2 Product Manager
  • Team MediaPortal
  • May 16, 2008
    11,431
    2,334
    Germany Germany
    Country flag
    One other thing that I noticed is that MediaPortal will crash if the skin folder is not immediately available after resume.

    The server is running LightsOut and a resuming client will also wake the server from its standby state. Depending on how long this lasts, MP will not find the redirected skin folder and "folds". Interestingly, shared paths such as music and pictures are no problem as there seems to be in-built logic to just discard those unavailable shares.

    ONe can of course delay the MP startup after resume but it would be more elegant to wait for the remote path to become available.
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    horned_reaper Errors in FH log ... Fanart Handler 1
    catavolt [WiP] When changing theme in my skins, I always get this error message in logs MediaPortal 1 9
    horned_reaper MediaPortal configuration error log message General Support 1
    horned_reaper MiniDisplayStatus error log messages General Support 7
    horned_reaper [solved] GUITextureManager Load2 log error messages Fanart Handler 1
    horned_reaper MediaPortal.LastFM.LastFMException error log message General Support 1
    doskabouter Exceptions found due to improved logging General Support 11
    ajs Can't log in to MyGet Online Facilities 4
    HTPCSourcer Media Accessor is flooding logs with files from attached monitor MediaPortal 2 9
    F Audio render and font error in my logs General Support 2
    HTPCSourcer [fixed] [MP2-815] User not logged in when resuming from standby MediaPortal 2 17
    T No TV after updating Windows 10 to latest Version 1903 / OS build 18362.175 (logs attached) General Support 2
    T [solved] "Unable To Play" (Videos) rears it's head again. Logs not possible... WatchDog error attached!! :( General Support 1
    T Get this error message on attempted re-install...LOGS inc. General Support 4
    HTPCSourcer [solved] Can't log in to Wiki Online Facilities 3
    N [Question] How come when I build WIP_2.2.1 the logged version number is 2.1.1711.10774? MediaPortal 2 1
    J Trying out MP 1 again, have some questions and a few log files Newcomers Forum 5
    Terra [Rejected] Log Media Anonymization/Masking Feature Requests 4
    T Mp 1.20 won't play .265 hdr capable file......settings problem? logs inc. Watch / Listen Media 0
    CyberSimian Inappropriate error messages in the log file MediaPortal 1 0
    S MP restarts after 10-30 sec - how to read error logs General Support 1
    J Use IP address of NAS in network path for Recorded TV General Support 8
    Similar threads






















    Top Bottom