Example #1
0
        public void Start(IController controller)
#endif
        
        {            
            try
            {
                Log.Info("TvWishList started");

                SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
                SystemEvents.SessionEnded += new SessionEndedEventHandler(SystemEvents_SessionEnded);

                events = GlobalServiceProvider.Instance.Get<ITvServerEvent>();
                events.OnTvServerEvent += new TvServerEventHandler(events_OnTvServerEvent);

                TvBusinessLayer layer = new TvBusinessLayer();
                Setting setting = null; 
                //set BUSY = false
                setting = layer.GetSetting("TvWishList_BUSY", "false");
                setting.Value = "false";
                setting.Persist();

                

                setting = layer.GetSetting("TvWishList_Debug", "false");
                Log.Info("setting DEBUG MODE = " + setting.Value);
                

                DEBUG = false;
                Boolean.TryParse(setting.Value, out DEBUG);
                Log.DebugValue = DEBUG;

                Log.Info("DEBUG MODE = " + DEBUG.ToString());

                //unlock pluginversion
                setting = layer.GetSetting("TvWishList_LockingPluginname", "NONE");
                setting.Value = "NONE";
                setting.Persist();

                //write Tv version
                setting = layer.GetSetting("TvWishList_TvServerVersion", "0.0.0.0");
                setting.Value = Version;
                setting.Persist();
                Log.Debug("TvVersion = "+Version);


                //is host name stored in database for TvWishListMP?
                setting = layer.GetSetting("TvWishList_MachineName", "NONE");
                Log.Debug("TvServer Machine Name="+setting.Value);
                if (setting.Value != System.Environment.MachineName.ToString())
                {
                    setting.Value = System.Environment.MachineName.ToString();
                    setting.Persist();
                    Log.Debug("Overwriting TvServer Machine Name To " + setting.Value);
                }

                //save pipename for Tvserver2
                setting = layer.GetSetting("TvWishList_PipeName", "NONE");
                Log.Debug("TvWishList_PipeName=" + setting.Value);
#if (MPTV2)
                setting.Value = "MP2TvWishListPipe";
#else
                setting.Value = "TvWishListPipe";
#endif
                setting.Persist();
                

                TV_USER_FOLDER = layer.GetSetting("TvWishList_TV_USER_FOLDER", "NOT_FOUND").Value;
                if ((File.Exists(TV_USER_FOLDER + @"\TvService.exe") == true) || (Directory.Exists(TV_USER_FOLDER) == false))
                {
                    //autodetect paths
                    InstallPaths instpaths = new InstallPaths();  //define new instance for folder detection
#if (MPTV2) //Native MP2 Tv server
                    instpaths.GetInstallPathsMP2();
                    TV_USER_FOLDER = instpaths.TV2_USER_FOLDER;
#else
                    instpaths.GetInstallPaths();
                    TV_USER_FOLDER = instpaths.TV_USER_FOLDER;
#endif
                    Logdebug("TV server user folder detected at " + TV_USER_FOLDER); 

                    if ((File.Exists(TV_USER_FOLDER + @"\TvService.exe") == true) || (Directory.Exists(TV_USER_FOLDER) == false))
                    {
                        Log.Error(@" TV server user folder does not exist - using C:\MediaPortal\TvWishList");
                        Logdebug(@" TV server user folder does not exist - using C:\MediaPortal\TvWishList");
                        TV_USER_FOLDER = @"C:\MediaPortal";
                        if (Directory.Exists(TV_USER_FOLDER) == false)
                            Directory.CreateDirectory(TV_USER_FOLDER + @"\TvWishList");
                    }
                    else
                    {//store found TV_USER_FOLDER
                        setting = layer.GetSetting("TvWishList_TV_USER_FOLDER", "NOT_FOUND");
                        setting.Value = TV_USER_FOLDER;
                        setting.Persist();
                    }
                }

                


                _RecordingFlagTime = DateTime.Now.AddHours(1.0); //add 1 hour to give time for setup
                _NextEpgTime = DateTime.Now.AddHours(1.0); //add 1 hour to give time for setup
                setting = layer.GetSetting("TvWishList_NextEpgDate", _NextEpgTime.ToString("yyyy-MM-dd_HH:mm", System.Globalization.CultureInfo.InvariantCulture));
                try
                {
                    _NextEpgTime = DateTime.ParseExact(setting.Value, "yyyy-MM-dd_HH:mm", System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception exc)
                {
                    Log.Error("NextEpgDate reading failed with exception: " + exc.Message);
                }
                Log.Debug("Start(IController controller):  _NextEpgTime=" + _NextEpgTime.ToString());



                

                /*
                // lock next time for receive mail for upcoming startups if Tvserver is being restarted after each standby
                setting = layer.GetSetting("TvWishList_SetEpgTime", "false");
                setting.Value = "false";
                setting.Persist();*/


                epgwatchclass = new EpgParser();

                if (epgwatchclass == null)
                {
                    Log.Error("EpgParser could not be initiated - aborting operation");
                    return;
                }
                else
                {
                    epgwatchclass.newlabelmessage += new setuplabelmessage(SendServerPipeMessage);
                    Logdebug("EpgParser initiated");
                }
                
                //start pollingthread
                runpolling = true;
                System.Threading.Thread th = new System.Threading.Thread(startpolling);
                th.IsBackground = true;
                th.Start();
                Logdebug("Polling thread starting");
                

                /*
                // activate filewatcher for active command
                try
                {
                    filewatcherstartepg = TV_USER_FOLDER + @"\TvWishList\StartEPGsearch.txt";
                    if (File.Exists(filewatcherstartepg) == true)
                    {
                        File.Delete(filewatcherstartepg);
                    }

                    filewatcherfinishedepg = TV_USER_FOLDER + @"\TvWishList\FinishedEPGsearch.txt";
                    if (File.Exists(filewatcherfinishedepg) == true)
                    {
                        File.Delete(filewatcherfinishedepg);
                    }

                    FileInfo myfileinfo = new FileInfo(filewatcherstartepg);
                    StartEPGsearch.Path = myfileinfo.DirectoryName;
                    StartEPGsearch.Created += new FileSystemEventHandler(StartEPGsearchFilewatcher);
                    StartEPGsearch.Filter = myfileinfo.Name;
                    StartEPGsearch.EnableRaisingEvents = true;
                    Logdebug("file watcher StartEPGsearch enabled");
                }
                catch (Exception ex)
                {
                    Log.Error("Error in starting StartEPGsearch File watcher: Exception message was " + ex.Message);
                    return;

                }*/

                // activate filewatcher for setupTvStarted
                try
                {
                    filewatcherSetupTvStarted = TV_USER_FOLDER + @"\TvWishList\SetupTvStarted.txt";
                    if (File.Exists(filewatcherSetupTvStarted) == true)
                    {
                        File.Delete(filewatcherSetupTvStarted);
                    }

                    FileInfo myfileinfo = new FileInfo(filewatcherSetupTvStarted);
                    SetupTvStarted.Path = myfileinfo.DirectoryName;
                    SetupTvStarted.Created += new FileSystemEventHandler(SetupTvStartedFilewatcher);
                    SetupTvStarted.Filter = myfileinfo.Name;
                    SetupTvStarted.EnableRaisingEvents = true;
                    Logdebug("file watcher SetupTvStarted enabled");
                }
                catch (Exception ex)
                {
                    Log.Error("Error in starting SetupTvStarted File watcher: Exception message was " + ex.Message);
                    return;

                }


                // activate filewatcher for NextEpgCheck
                try
                {
                    filewatcherNextEpgCheck = TV_USER_FOLDER + @"\TvWishList\NextEpgCheck.txt";
                    if (File.Exists(filewatcherNextEpgCheck) == true)
                    {
                        File.Delete(filewatcherNextEpgCheck);
                    }

                    FileInfo myfileinfo = new FileInfo(filewatcherNextEpgCheck);
                    NextEpgCheck.Path = myfileinfo.DirectoryName;
                    NextEpgCheck.Created += new FileSystemEventHandler(NextEpgCheckFilewatcher);
                    NextEpgCheck.Filter = myfileinfo.Name;
                    NextEpgCheck.EnableRaisingEvents = true;
                    Logdebug("file watcher NextEpgCheck enabled");
                }
                catch (Exception ex)
                {
                    Log.Error("Error in starting NextEpgCheck File watcher: Exception message was " + ex.Message);
                    return;

                }
                
                //startpipeserver and listen for commands
                StartServer();

            }
            catch (Exception ex)
            {
                Log.Debug("Error in starting TvWishList: Exception message was " + ex.Message);
                return;

            }
            Log.Debug("TvWishList start completed");


            
        }
Example #2
0
        private static string GetFileName(LogType logType)
        {

            switch (logType)
            {
                case LogType.Debug:
                case LogType.Info:
#if (MP11 || MP12)
                    string Path1 = String.Format(@"{0}\Team MediaPortal\MediaPortal", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\TvWishListMP.log", Path1);
#elif (MP2)
                    InstallPaths instpaths1 = new InstallPaths();  //define new instance for folder detection
                    instpaths1.GetInstallPathsMP2();
                    return String.Format(@"{0}\TvWishListMP2.log", instpaths1.DIR_MP2_LOG);
#elif (MPTV2)
                    InstallPaths instpaths1 = new InstallPaths();  //define new instance for folder detection
                    instpaths1.GetInstallPathsMP2();
                    return String.Format(@"{0}\TvWishListMP2.log", instpaths1.DIR_SV2_LOG);
#else
                    string Path1 = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\TvWishList.log", Path1);
#endif

                case LogType.Error:
#if (MP11 || MP12)
                    string Path2 = String.Format(@"{0}\Team MediaPortal\MediaPortal", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\error.log", Path2);
#elif (MP2)
                    InstallPaths instpaths2 = new InstallPaths();  //define new instance for folder detection
                    instpaths2.GetInstallPathsMP2();
                    return String.Format(@"{0}\ClientError.log", instpaths2.DIR_MP2_LOG);
#elif (MPTV2)
                    InstallPaths instpaths2 = new InstallPaths();  //define new instance for folder detection
                    instpaths2.GetInstallPathsMP2();
                    return String.Format(@"{0}\Error_TvWishListMP2.log", instpaths2.DIR_SV2_LOG);
#else
                    string Path2 = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\error.log", Path2);
#endif


                default:
#if (MP11 || MP12)
                    string Path3 = String.Format(@"{0}\Team MediaPortal\MediaPortal", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\TvWishListMP.log", Path3);
#elif (MP2)
                    InstallPaths instpaths3 = new InstallPaths();  //define new instance for folder detection
                    instpaths3.GetInstallPathsMP2();
                    return String.Format(@"{0}\TvWishListMP2.log", instpaths3.DIR_MP2_LOG);
#elif (MPTV2)
                    InstallPaths instpaths3 = new InstallPaths();  //define new instance for folder detection
                    instpaths3.GetInstallPathsMP2();
                    return String.Format(@"{0}\TvWishListMP2.log", instpaths3.DIR_SV2_LOG);
#else
                    string Path3 = String.Format(@"{0}\Team MediaPortal\MediaPortal TV Server", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
                    return String.Format(@"{0}\log\TvWishList.log", Path3);
#endif
            }
        }
        public bool ReadLanguageFile()
        {
            Log.Debug("ReadLanguageFile started");
            TvBusinessLayer layer = new TvBusinessLayer();
            Setting setting = null;
            setting = layer.GetSetting("TvWishList_TV_USER_FOLDER", "NOT_DEFINED");



            string TV_USER_FOLDER;
            TV_USER_FOLDER = layer.GetSetting("TvWishList_TV_USER_FOLDER", "NOT_FOUND").Value;
            if ((File.Exists(TV_USER_FOLDER + @"\TvService.exe") == true) || (Directory.Exists(TV_USER_FOLDER) == false))
            {
                //autodetect paths
                InstallPaths instpaths = new InstallPaths();  //define new instance for folder detection
#if (MPTV2) //Native MP2 Tv server
                instpaths.GetInstallPathsMP2();
                TV_USER_FOLDER = instpaths.TV2_USER_FOLDER;
#else
                    instpaths.GetInstallPaths();
                    TV_USER_FOLDER = instpaths.TV_USER_FOLDER;
#endif
                Log.Debug("TV server user folder detected at " + TV_USER_FOLDER);

                if ((File.Exists(TV_USER_FOLDER + @"\TvService.exe") == true) || (Directory.Exists(TV_USER_FOLDER) == false))
                {
                    Log.Error(@" TV server user folder does not exist - using C:\MediaPortal\TvWishList");
                    Log.Debug(@" TV server user folder does not exist - using C:\MediaPortal\TvWishList");
                    TV_USER_FOLDER = @"C:\MediaPortal";
                    if (Directory.Exists(TV_USER_FOLDER) == false)
                        Directory.CreateDirectory(TV_USER_FOLDER + @"\TvWishList");
                }
                else
                {//store found TV_USER_FOLDER
                    setting = layer.GetSetting("TvWishList_TV_USER_FOLDER", "NOT_FOUND");
                    setting.Value = TV_USER_FOLDER;
                    setting.Persist();
                }
            }





            if (Directory.Exists(setting.Value) == false)
            {
                Log.Error("Error: TV User Folder is not defined - cannot use language file");
                return false;
            }

            string foldername = setting.Value + @"\TvWishList\Languages\";

            setting = layer.GetSetting("TvWishList_LanguageFile", "strings_en.xml");

            string filename = foldername + setting.Value;
            if (File.Exists(filename) == false)
            {
                Log.Error("Could not find language file " + filename);
                filename = foldername + "strings_en.xml";                
                Log.Error("Switching to English default language file " + filename);
            }

            Log.Debug("Language file is " + filename);

            try
            {
                //read inputfile
                string[] inputlines = File.ReadAllLines(filename);
                Log.Debug(inputlines.Length.ToString()+" Lines read");
                int minimum = 0;
                int maximum = 0;
                int offset = 0;
                int offsetMinimum = 0;
                int offsetMaximum = 0;

                //process each line
                foreach (string line in inputlines)
                {
                    string myline = line.Replace("\t", string.Empty); //replace tab

                    //global replacements
                    if ((myline.Contains("<!-- TVSERVER VECTORSIZE="))||(myline.Contains("<!--TVSERVER VECTORSIZE=")))
                    {
                        myline = myline.Replace("<!-- TVSERVER VECTORSIZE=", string.Empty);
                        myline = myline.Replace("<!--TVSERVER VECTORSIZE=", string.Empty);
                        myline = myline.Replace("-->", string.Empty);

                        int size = 0;
                        int.TryParse(myline, out size);
                        Log.Debug("size = " + size.ToString());

                        Language = new string[size];

                        for (int i = 0; i < size; i++)
                        {
                            Language[i] = String.Empty;
                        }

                        //define at least true and false
                        try
                        {
                            Language[4000] = "true";
                            Language[4001] = "false";
                        }
                        catch //do nothing
                        {
                            Log.Error("Error in default initialization of true and false");
                        }
                        

                    }
                    else if ((myline.Contains("<!-- TVSERVER USE FROM=")) || (myline.Contains("<!--TVSERVER USE FROM=")) )
                    {
                        myline = myline.Replace("<!-- TVSERVER USE FROM=", string.Empty);
                        myline = myline.Replace("<!--TVSERVER USE FROM=", string.Empty);
                        myline = myline.Replace("-->", string.Empty);
                        myline = myline.Replace("OFFSET_FROM=", "\n"); //order is important
                        myline = myline.Replace("OFFSET_TO=", "\n");
                        myline = myline.Replace("TO=", "\n");
                        //myline = myline.Replace("OFFSET=", "\n");
                        
                        string[] tokenarray = myline.Split('\n');
                        if (tokenarray.Length != 4)
                        {
                            Log.Error("Invalid tv server command " + line.Replace("{","_") + " - cannot use language files");
                            return false;
                        }


                        minimum = 0;
                        int.TryParse(tokenarray[0], out minimum);
                        Log.Debug(" new minimum=" + minimum.ToString());
                        maximum = 0;
                        int.TryParse(tokenarray[1], out maximum);
                        Log.Debug(" new maximum=" + maximum.ToString());
                        offsetMinimum = 0;
                        int.TryParse(tokenarray[2], out offsetMinimum);
                        Log.Debug(" new offsetMinimum=" + offsetMinimum.ToString());
                        offsetMaximum = 0;
                        int.TryParse(tokenarray[3], out offsetMaximum);
                        Log.Debug(" new offsetMaximum=" + offsetMaximum.ToString());
                        offset = minimum - offsetMinimum;
                        Log.Debug(" new offset=" + offset.ToString());
                    }
                    else if (myline.Contains("<String id=\""))  // <String id="1107">Mehr</String> 
                    {
                        try
                        {
                            //remove leading spaces
                            int leadingSpaces = 0;
                            for (int i = 0; i < myline.Length; i++)
                            {
                                if (myline[i] == ' ')
                                {
                                    leadingSpaces++;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            //textoutput("leadingSpaces=" + leadingSpaces.ToString());
                            myline = myline.Substring(leadingSpaces, myline.Length - leadingSpaces);//remove leading spaces

                            //remove trailing spaces
                            int trailingSpaces = 0;
                            for (int i = myline.Length - 1; i >= 0; i--)
                            {
                                if (myline[i] == ' ')
                                {
                                    trailingSpaces++;
                                }
                                else
                                {
                                    break;
                                }
                            }
                            //textoutput("trailingSpaces=" + trailingSpaces.ToString());
                            myline = myline.Substring(0, myline.Length - trailingSpaces);

                            myline = myline.Substring(12, myline.Length - 12);  //remove beginning comment and <String id=" 

                            

                            //now extract the numbers till the next "
                            int digits = 0;
                            for (int i = 0; i < myline.Length; i++)
                            {
                                if (myline[i] == '"')
                                {
                                    break;
                                }
                                else
                                {
                                    digits++;
                                }
                            }
                            //Log.Debug("digits=" + digits.ToString());

                            string digitString = myline.Substring(0, digits);
                            //Log.Debug("digitString=" + digitString);

                            if (myline.Length >= digits)
                                myline = myline.Substring(digits, myline.Length - digits);

                            myline = myline.Replace("\">", ""); //remove ending

                            

                            myline = myline.Replace("</String>", ""); //remove ending 

                            string valueString = myline;

                            
                            //Debug
                            //string output = valueString.Replace("{", "_");
                            //output = output.Replace("}", "_");
                            //Log.Debug("output ="+output);


                            int number = 0;
                            int.TryParse(digitString, out number);

                            //Log.Debug("number=" + number.ToString());

                            if ((number >= minimum) && (number <= maximum))
                            {
                                number = number - offset;
                                Language[number] = valueString;

                                
                                //Debug
                                //string output2 = Language[number].Replace("{", "_");
                                //output2 = output2.Replace("}", "_");                               
                                //Log.Debug("language[" + number.ToString() + "]=" + output2);
                            }

                        }
                        catch (Exception exc)
                        {
                            string output = line.Replace("{", "_");
                            output = output.Replace("}", "_");
                            Log.Error("Error: could not read string " + output + " Exception was " + exc.Message);
                        }

                    }//end expression


                }//end foreach line
            }
            catch (Exception exc)
            {
                Log.Error("Error: could not read language file " + filename + " Exception was " + exc.Message);
                return false;
            }


            



            Log.Debug("Language file read");
            return true;

        }
Example #4
0
 public void HelpButton()
 {
     Log.Debug("ConfigMain_GUI: Help() started");
     //Help
     Process proc = new Process();
     ProcessStartInfo procstartinfo = new ProcessStartInfo();
     procstartinfo.FileName = "TvWishList.pdf";
     InstallPaths instpaths = new InstallPaths();
     instpaths.GetInstallPathsMP2();
     instpaths.GetMediaPortalDirsMP2();
     procstartinfo.WorkingDirectory = instpaths.DIR_MP2_Plugins + @"\TvWishListMP2";
     proc.StartInfo = procstartinfo;
     try
     {
         proc.Start();
     }
     catch
     {
         Log.Error("Could not open " + procstartinfo.WorkingDirectory + "\\" + procstartinfo.FileName, "Error");
     }
 }