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"); }
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; }
// show the setup dialog public void ShowPlugin() { //open .exe file to avoid data conflicts during import Process nproc = new Process(); ProcessStartInfo procstartinfo = new ProcessStartInfo(); if (File.Exists(@"plugins\process\BackupSettingsMP.exe") == true) { procstartinfo.FileName = @"plugins\process\BackupSettingsMP.exe"; procstartinfo.Arguments = "MP1_Client"; } else { // get actual plugin directory InstallPaths instpaths = new InstallPaths(); //define new instance for folder detection //autodetect paths instpaths.GetInstallPaths(); string DIR_Plugins = instpaths.DIR_Plugins; procstartinfo.FileName = DIR_Plugins + @"\process\BackupSettingsMP.exe"; procstartinfo.Arguments = "MP1_Client"; } nproc.StartInfo = procstartinfo; try { nproc.Start(); } catch { MessageBox.Show("Could not open " + procstartinfo.FileName, "Error"); } }
public void Start(IController controller) { Log.Debug("BackupSettingsServer: Plugin BackupSettings active"); events = GlobalServiceProvider.Instance.Get<ITvServerEvent>(); events.OnTvServerEvent += new TvServerEventHandler(events_OnTvServerEvent); TvBusinessLayer layer = new TvBusinessLayer(); Setting setting = null; //get debug setting setting = layer.GetSetting("Backup_SettingsSetup_debug", "false"); if (setting.Value.ToLower() == "true") { DEBUG = true; } else { DEBUG = false; } //get next backup time _NextBackup = DateTime.Now.AddDays(30);//add one month default _RecordingFlagTime = DateTime.Now.AddHours(1.0); //add 1 hour to give time for setup setting = layer.GetSetting("Backup_SettingsNextBackup", DateTime.Now.ToString("yyyy-MM-dd_HH:mm", System.Globalization.CultureInfo.InvariantCulture)); try { _NextBackup = DateTime.ParseExact(setting.Value, "yyyy-MM-dd_HH:mm", System.Globalization.CultureInfo.InvariantCulture); } catch (Exception exc) { Log.Error("NextBackup failed with exception: " + exc.Message); } //is host name stored in database for BackupSettingsMP2? setting = layer.GetSetting("BackupSettings_MachineName", "NONE"); if (setting.Value != System.Environment.MachineName.ToString()) { setting.Value = System.Environment.MachineName.ToString(); setting.Persist(); } //Get TV_USER_FOLDER TV_USER_FOLDER = layer.GetSetting("BackupSettings_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 instpaths.GetInstallPaths(); TV_USER_FOLDER = instpaths.TV_USER_FOLDER; 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 BackupSettings"); Log.Debug(@" TV server user folder does not exist - using C:\MediaPortal BackupSettings"); TV_USER_FOLDER = @"C:\MediaPortal BackupSettings"; if (Directory.Exists(TV_USER_FOLDER) == false) Directory.CreateDirectory(TV_USER_FOLDER + @"\BackupSettings"); } //store new TV_USER_FOLDER setting = layer.GetSetting("BackupSettings_TV_USER_FOLDER", "NOT_FOUND"); setting.Value = TV_USER_FOLDER; setting.Persist(); } //enable textmessages from other classes by starting filewatchers if (Directory.Exists(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR) == true) { if (File.Exists(TV_USER_FOLDER + @"\"+BACKUPSETTING_TV_DIR + @"\" + POSTPROCESSING_FILE) == true) //delete old corrupt file { File.Delete(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + POSTPROCESSING_FILE); Log.Debug("BackupSettings Server: File " + TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + POSTPROCESSING_FILE + " deleted"); } ImportWatcher.Path = TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR; ImportWatcher.Created += new FileSystemEventHandler(importpostprocessing); ImportWatcher.Filter = POSTPROCESSING_FILE; ImportWatcher.EnableRaisingEvents = true; WATCHERACTIVE = true; Log.Debug("BackupSettings Server: Importwatcher activated for " + ImportWatcher.Path + "\\" + ImportWatcher.Filter); if (File.Exists(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + AUTO_EXPORT_FILE) == true) //delete old corrupt file { File.Delete(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + AUTO_EXPORT_FILE); Log.Debug("BackupSettings Server: File " + TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + AUTO_EXPORT_FILE + " deleted"); } AutomatedExport.Path = TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR; AutomatedExport.Created += new FileSystemEventHandler(AutomatedExportProcessing); AutomatedExport.Filter = AUTO_EXPORT_FILE; AutomatedExport.EnableRaisingEvents = true; Log.Debug("BackupSettings Server: AutomatedExport activated for " + AutomatedExport.Path + "\\" + AutomatedExport.Filter); if (File.Exists(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + SCHEDULED_EXPORT_FILE) == true) //delete old corrupt file { File.Delete(TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + SCHEDULED_EXPORT_FILE); Log.Debug("BackupSettings Server: File " + TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + @"\" + SCHEDULED_EXPORT_FILE + " deleted"); } ScheduledExport.Path = TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR; ScheduledExport.Created += new FileSystemEventHandler(ScheduledExportProcessing); ScheduledExport.Filter = SCHEDULED_EXPORT_FILE; ScheduledExport.EnableRaisingEvents = true; Log.Debug("BackupSettings Server: AutomatedExport activated for " + ScheduledExport.Path + "\\" + ScheduledExport.Filter); } else { Log.Debug("BackupSettings Server Error: Importwatcher/AutomatedExport could not be started because directory " + @"\" + TV_USER_FOLDER + @"\" + BACKUPSETTING_TV_DIR + " does not exist"); } //start pollingthread runpolling = true; System.Threading.Thread th = new System.Threading.Thread(startpolling); th.IsBackground = true; th.Start(); //Log.Debug("Polling thread starting"); }
static void Main(string[] args) { //check for single instance Process current = Process.GetCurrentProcess(); Process[] allnamedprocesses = Process.GetProcessesByName(current.ProcessName); int k = allnamedprocesses.Length; if (k > 1) { //MessageBox.Show("More than one single instance running ("+k.ToString()+") - aborting","Error"); return; } //setup bool install = false; bool uninstall = false; bool killserver = false; for (int i = 0; i < args.Length; i++) { if (args[i].ToLower() == "-install") { install = true; } else if (args[i].ToLower() == "-uninstall") { uninstall = true; } else if (args[i].ToLower() == "-killtvserveronmyownrisk") { killserver = true; } } InstallPaths instpaths = new InstallPaths(); //define new instance for folder detection instpaths.GetInstallPaths(); string licensefile = "license.txt"; if (File.Exists(licensefile) == false) { //Log.Debug("Current folder is " + installdirectory + "\n"); causes exception licensefile = System.Environment.CurrentDirectory + @"\license.txt";// 1st try in current directory if (File.Exists(licensefile) == false) { //2nd try mpi installer licensefile = instpaths.MP_USER_FOLDER + @"\Installer\TvWishList\license.txt"; if (File.Exists(licensefile) == false) { //3rd try in %Installer% licensefile = System.Environment.CurrentDirectory + @"\%Installer%\TvWishList\license.txt"; if (File.Exists(licensefile) == false) { MessageBox.Show("License file " + licensefile + " not found - aborting installation", "Installation Error"); return; } } } } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new License(licensefile)); Application.Run(new InstallSetup(install, uninstall,killserver)); }