1.12.0 - Redirected log path: some files created in standard path | Page 5

Discussion in 'Archive' started by HTPCSourcer, August 9, 2015.

  1. Owlsroost
    • Team MediaPortal

    Owlsroost Development Group

    Joined:
    October 28, 2008
    Messages:
    5,537
    Likes Received:
    2,829
    Location:
    Cambridge
    Ratings:
    +4,131 / 1
    Home Country:
    United Kingdom United Kingdom
    Show System Specs
    This is what the C++ code looks like:

    Code (Text):
    1.  
    2. LONG LogWriteRegistryKeyString(HKEY hKey, LPCTSTR& lpSubKey, LPCTSTR& data)
    3. {
    4.   LONG result = RegSetValueEx(hKey, lpSubKey, 0, REG_SZ, (LPBYTE)data, _tcslen(data) * sizeof(TCHAR));
    5.  
    6.   return result;
    7. }
    8.  
    9. LONG LogReadRegistryKeyString(HKEY hKey, LPCTSTR& lpSubKey, LPCTSTR& data)
    10. {
    11.   DWORD dwSize = MAX_PATH * sizeof(TCHAR);
    12.   DWORD dwType = REG_SZ;
    13.   LONG result = RegQueryValueEx(hKey, lpSubKey, NULL, &dwType, (PBYTE)data, &dwSize);
    14.  
    15.   if (result != ERROR_SUCCESS)
    16.   {
    17.     if (result == ERROR_FILE_NOT_FOUND)
    18.     {
    19.       //create default value
    20.       result = LogWriteRegistryKeyString(hKey, lpSubKey, data);
    21.     }
    22.   }
    23.  
    24.   return result;
    25. }
    26.  
    27. void LogPath(TCHAR* dest, TCHAR* name)
    28. {
    29.   CAutoLock lock(&m_logFileLock);
    30.   HKEY hKey;
    31.   //Try to read logging folder path from registry
    32.   LONG result = RegCreateKeyEx(HKEY_CURRENT_USER, _T("Software\\Team MediaPortal\\Client Common"), 0, NULL,
    33.                                     REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL);                                
    34.   if (result == ERROR_SUCCESS)
    35.   {
    36.     //Get default log folder path
    37.     TCHAR folder[MAX_PATH];
    38.     SHGetSpecialFolderPath(NULL,folder,CSIDL_COMMON_APPDATA,FALSE);
    39.     TCHAR logFolder[MAX_PATH];
    40.     _stprintf(logFolder, _T("%s\\Team Mediaportal\\MediaPortal\\log"), folder);
    41.  
    42.     //Read log folder path from registry (or write default path into registry if key doesn't exist)
    43.     LPCTSTR logFolderC = logFolder;
    44.     LPCTSTR logFolderPath = _T("LogFolderPath");
    45.     result = LogReadRegistryKeyString(hKey, logFolderPath, logFolderC);
    46.  
    47.     if (result == ERROR_SUCCESS)
    48.     {
    49.       //Get full log file path
    50.       _stprintf(dest, _T("%s\\TsReader.%s"), logFolderC, name);
    51.     }
    52.   }
    53.  
    54.   if (result != ERROR_SUCCESS)
    55.   {
    56.     //Fall back to default log folder path
    57.     TCHAR folder[MAX_PATH];
    58.     SHGetSpecialFolderPath(NULL,folder,CSIDL_COMMON_APPDATA,FALSE);
    59.     //Get full log file path
    60.     _stprintf(dest, _T("%s\\Team Mediaportal\\MediaPortal\\log\\TsReader.%s"), folder, name);
    61.   }
    62. }
    63.  
    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: August 23, 2015
    • Like Like x 1
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. regeszter
    • Premium Supporter

    regeszter Retired Team Member

    Joined:
    October 29, 2005
    Messages:
    5,335
    Likes Received:
    2,863
    Ratings:
    +5,152 / 18
    Home Country:
    Hungary Hungary
    Can the watchdog.exe use any non default log source path?
     
  4. Sebastiii
    • Team MediaPortal

    Sebastiii Development Group

    Joined:
    November 12, 2007
    Messages:
    16,297
    Likes Received:
    6,249
    Gender:
    Male
    Location:
    France
    Ratings:
    +10,270 / 9
    Home Country:
    France France
    Show System Specs
    That a good question :) that's need to be tested or maybe already written in wiki :)
     
  5. morpheus_xx
    • Team MediaPortal

    morpheus_xx Lead Dev MP2

    Joined:
    March 24, 2007
    Messages:
    11,090
    Likes Received:
    4,766
    Ratings:
    +6,826 / 11
    Home Country:
    Germany Germany
    Show System Specs
    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?
     
    • Like Like x 2
    • Thank You! Thank You! x 1
  6. FreakyJ
    • Team MediaPortal

    FreakyJ Development Group

    Joined:
    July 25, 2010
    Messages:
    4,021
    Likes Received:
    839
    Gender:
    Male
    Ratings:
    +1,424 / 1
    Home Country:
    Germany Germany
  7. HTPCSourcer
    • Team MediaPortal
    • Administrator

    HTPCSourcer MP2 Product Manager

    Joined:
    May 16, 2008
    Messages:
    10,811
    Likes Received:
    1,126
    Gender:
    Male
    Ratings:
    +2,411 / 22
    Home Country:
    Germany Germany
    Show System Specs
    Yes. Option 3 correctly pulls the client logs from the redirected path.
     
    • Thank You! Thank You! x 2
  8. HTPCSourcer
    • Team MediaPortal
    • Administrator

    HTPCSourcer MP2 Product Manager

    Joined:
    May 16, 2008
    Messages:
    10,811
    Likes Received:
    1,126
    Gender:
    Male
    Ratings:
    +2,411 / 22
    Home Country:
    Germany Germany
    Show System Specs
    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 (Winbatch):
    1. Set Shell         = CreateObject("WScript.Shell")
    2. Set Shell2        = CreateObject("Shell.Application")
    3. Set objFolder     = Shell2.Namespace(ssfCOMMONAPPDATA)
    4. Set objFolderItem = objFolder.Self
    5.  
    6. logpath           = objFolderItem.Path & "\Team MediaPortal\MediaPortal\log\"
    7. lognew            = logpath + "\" + Wscript.ScriptName + ".log"
    8. logold            = logpath + "\" + Wscript.ScriptName + ".bak"
    Any other change required? If not, I will start making my first steps towards Powershell processing of XML files...
     
    • Like Like x 1
  9. regeszter
    • Premium Supporter

    regeszter Retired Team Member

    Joined:
    October 29, 2005
    Messages:
    5,335
    Likes Received:
    2,863
    Ratings:
    +5,152 / 18
    Home Country:
    Hungary Hungary
    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).
     
  10. HTPCSourcer
    • Team MediaPortal
    • Administrator

    HTPCSourcer MP2 Product Manager

    Joined:
    May 16, 2008
    Messages:
    10,811
    Likes Received:
    1,126
    Gender:
    Male
    Ratings:
    +2,411 / 22
    Home Country:
    Germany Germany
    Show System Specs
    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.

    Not specially, nothing but general knowledge of several languages
     
  11. HTPCSourcer
    • Team MediaPortal
    • Administrator

    HTPCSourcer MP2 Product Manager

    Joined:
    May 16, 2008
    Messages:
    10,811
    Likes Received:
    1,126
    Gender:
    Male
    Ratings:
    +2,411 / 22
    Home Country:
    Germany Germany
    Show System Specs
    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.
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!