public frmProgress(epgConfig config) { Application.EnableVisualStyles(); InitializeComponent(); sdJson2mxf.backgroundWorker = backgroundWorker1; backgroundWorker1.WorkerReportsProgress = true; backgroundWorker1.RunWorkerAsync(config); }
public frmProgress(epgConfig config) { Application.EnableVisualStyles(); InitializeComponent(); progressBarStage.Maximum = (sdJson2mxf.sdJson2Mxf.Stages.Length + 1) * 100; sdJson2mxf.sdJson2Mxf.BackgroundWorker = backgroundWorker1; backgroundWorker1.WorkerReportsProgress = true; backgroundWorker1.RunWorkerAsync(config); }
public frmXmltvConfig(ref epgConfig config) { InitializeComponent(); localConfig = config; ckChannelNumbers.Checked = config.XmltvIncludeChannelNumbers; ckChannelLogos.Checked = !string.IsNullOrEmpty(config.XmltvIncludeChannelLogos) && (config.XmltvIncludeChannelLogos != "false"); ckLocalLogos.Checked = (config.XmltvIncludeChannelLogos == "local") || (config.XmltvIncludeChannelLogos == "substitute"); ckUrlLogos.Checked = (config.XmltvIncludeChannelLogos == "url") || !ckLocalLogos.Checked; ckSubstitutePath.Checked = (config.XmltvIncludeChannelLogos == "substitute"); txtSubstitutePath.Text = config.XmltvLogoSubstitutePath; ckXmltvFillerData.Checked = config.XmltvAddFillerData; ckLogos_CheckedChanged(ckChannelLogos, null); }
static int Main(string[] args) { // setup catch to fatal program crash AppDomain.CurrentDomain.UnhandledException += MyUnhandledException; Application.ThreadException += MyThreadException; // establish file/folder locations Logger.Initialize("Media Center", "EPG123"); EstablishFileFolderPaths(); // create a mutex and keep alive until program exits using (Mutex mutex = new Mutex(true, "Global\\" + appGuid)) { bool showGui = true; bool import = false; bool match = false; bool showProgress = false; epgConfig config = null; // only evaluate arguments if a configuration file exists, otherwise open the gui if (File.Exists(Helper.Epg123CfgPath) && (args != null)) { for (int i = 0; i < args.Length; ++i) { switch (args[i].ToLower()) { case "-update": showGui = false; break; case "-p": showProgress = true; break; default: return(-1); } } } // check for an instance already running if (!mutex.WaitOne(3000, false)) { if (!showGui) { Logger.WriteMessage("==============================================================================="); Logger.WriteError("An instance of EPG123 is already running. Aborting update."); Logger.WriteMessage("==============================================================================="); Logger.Close(); return(-1); } else { MessageBox.Show("An instance of EPG123 is already running.", "Initialization Aborted"); Logger.Close(); return(0); } } // open the configuration GUI if needed if (showGui) { Logger.WriteMessage("==============================================================================="); Logger.WriteMessage(string.Format(" Activating the epg123 configuration GUI. version {0}", Helper.epg123Version)); Logger.WriteMessage("==============================================================================="); frmMain cfgForm = new frmMain(); cfgForm.ShowDialog(); Logger.Close(); if (!cfgForm.Execute) { mutex.ReleaseMutex(); return(0); } Logger.Initialize("Media Center", "EPG123"); config = cfgForm.config; import = cfgForm.import; match = cfgForm.match; } // prevent machine from entering sleep mode uint prevThreadState = NativeMethods.SetThreadExecutionState((uint)ExecutionFlags.ES_CONTINUOUS | (uint)ExecutionFlags.ES_SYSTEM_REQUIRED | (uint)ExecutionFlags.ES_AWAYMODE_REQUIRED); Logger.WriteMessage("==============================================================================="); Logger.WriteMessage(string.Format(" Beginning epg123 update execution. version {0}", Helper.epg123Version)); Logger.WriteMessage("==============================================================================="); // bring in the configuration if (config == null) { try { using (StreamReader stream = new StreamReader(Helper.Epg123CfgPath, Encoding.Default)) { XmlSerializer serializer = new XmlSerializer(typeof(epgConfig)); TextReader reader = new StringReader(stream.ReadToEnd()); config = (epgConfig)serializer.Deserialize(reader); reader.Close(); } } catch (IOException ex) { Logger.WriteError(string.Format("Failed to open configuration file during initialization due to IO exception. message: {0}", ex.Message)); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); mutex.ReleaseMutex(); return(-1); } catch (Exception ex) { Logger.WriteError(string.Format("Failed to open configuration file during initialization with unknown exception. message: {0}", ex.Message)); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); mutex.ReleaseMutex(); return(-1); } } // let's do this DateTime startTime = DateTime.UtcNow - TimeSpan.FromMinutes(1.0); NotifyIcon notifyIcon = new NotifyIcon() { Text = "EPG123\nDownloading and building guide listings...", Icon = Properties.Resources.EPG123_download }; notifyIcon.Visible = true; if (showGui || showProgress) { frmProgress build = new frmProgress(config); build.ShowDialog(); } else { sdJson2mxf.Build(config); } notifyIcon.Visible = false; notifyIcon.Dispose(); // close the logger and restore power/sleep settings Logger.WriteVerbose(string.Format("epg123 update execution time was {0}.", DateTime.UtcNow - startTime - TimeSpan.FromMinutes(1.0))); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); // did a Save&Execute from GUI ... perform import and automatch as well if requested if (sdJson2mxf.success && import) { // verify output file exists if (!File.Exists(Helper.Epg123MxfPath) || !File.Exists(Helper.Epg123ClientExePath)) { mutex.ReleaseMutex(); return(-1); } // epg123client ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "epg123Client.exe", Arguments = "-i \"" + Helper.Epg123MxfPath + "\"" + (match ? " -match" : string.Empty) + (showGui ? " -p" : string.Empty), RedirectStandardOutput = true, RedirectStandardError = true, UseShellExecute = false, CreateNoWindow = true }; Process proc = Process.Start(startInfo); proc.WaitForExit(); } mutex.ReleaseMutex(); return(0); } }
public static void Build(epgConfig configuration) { string errString = string.Empty; // initialize schedules direct API sdAPI.Initialize("EPG123", epg123Version); // copy configuration to local variable config = configuration; // initialize event buffer Logger.WriteInformation(string.Format("Beginning EPG123 update execution. {0:u}", DateTime.Now.ToUniversalTime())); Logger.WriteVerbose(string.Format("DaysToDownload: {0} , TheTVDBNumbers : {1} , PrefixEpisodeTitle: {2} , PrefixEpisodeDescription : {3} , AppendEpisodeDesc: {4} , OADOverride : {5} , TMDbCoverArt: {6} , IncludeSDLogos : {7} , AutoAddNew: {8} , CreateXmltv: {9} , ModernMediaUiPlusSupport: {10}", config.DaysToDownload, config.TheTVDBNumbers, config.PrefixEpisodeTitle, config.PrefixEpisodeDescription, config.AppendEpisodeDesc, config.OADOverride, config.TMDbCoverArt, config.IncludeSDLogos, config.AutoAddNew, config.CreateXmltv, config.ModernMediaUiPlusSupport)); // populate station prefixes to suppress if (config.SuppressStationEmptyWarnings == null) { suppressedPrefixes = new List <string>(defaultSuppressedPrefixes.Split(',')); } else { suppressedPrefixes = new List <string>(config.SuppressStationEmptyWarnings.Split(',')); } // login to Schedules Direct and build the mxf file if (sdAPI.sdGetToken(config.UserAccount.LoginName, config.UserAccount.PasswordHash, ref errString)) { // check server status sdUserStatusResponse susr = sdAPI.sdGetStatus(); if (susr == null) { return; } else if (susr.SystemStatus[0].Status.ToLower().Equals("offline")) { Logger.WriteError("Schedules Direct server is offline. Aborting update."); return; } // check for latest version and update the display name that shows in About Guide sdClientVersionResponse scvr = sdAPI.sdCheckVersion(); if ((scvr != null) && !string.IsNullOrEmpty(scvr.Version)) { sdMxf.Providers[0].DisplayName += " v" + epg123Version; if (epg123Version != scvr.Version) { sdMxf.Providers[0].DisplayName += string.Format(" (v{0} Available)", scvr.Version); BrandLogo.updateAvailable = true; } } // make sure cache directory exists if (!Directory.Exists(Helper.Epg123CacheFolder)) { Directory.CreateDirectory(Helper.Epg123CacheFolder); } // initialize tmdb api tmdbAPI.Initialize(false); // prepopulate keyword groups initializeKeywordGroups(); // read all image links archived in file getImageArchive(); // read all included and excluded station from configuration populateIncludedExcludedStations(config.StationID); // if all components of the mxf file have been successfully created, save the file if (success = buildLineupServices() && serviceCountSafetyCheck() && getAllScheduleEntryMd5s(config.DaysToDownload) && buildAllProgramEntries() && buildAllGenericSeriesInfoDescriptions() && buildAllExtendedSeriesDataForUiPlus() && getAllMoviePosters() && getAllSeriesImages() && buildKeywords() && writeMxf()) { // create the xmltv file if desired if (config.CreateXmltv && CreateXmltvFile()) { writeXmltv(); ++processedObjects; reportProgress(); } // save the image links writeImageArchive(); // create the ModernMedia UI+ json file if desired if (config.ModernMediaUiPlusSupport) { ModernMediaUiPlus.WriteModernMediaUiPlusJson(config.ModernMediaUiPlusJsonFilepath ?? null); ++processedObjects; reportProgress(); } // clean the cache folder of stale data cleanCacheFolder(); Logger.WriteVerbose(string.Format("Downloaded and processed {0} of data from Schedules Direct.", sdAPI.TotalDownloadBytes)); Logger.WriteVerbose(string.Format("Generated .mxf file contains {0} services, {1} series, {2} programs, and {3} people with {4} image links.", sdMxf.With[0].Services.Count, sdMxf.With[0].SeriesInfos.Count, sdMxf.With[0].Programs.Count, sdMxf.With[0].People.Count, sdMxf.With[0].GuideImages.Count)); Logger.WriteInformation("Completed EPG123 update execution. SUCCESS."); } else { Logger.WriteError("Failed to create MXF file. Exiting."); } } else { Logger.WriteError(string.Format("Failed to retrieve token from Schedules Direct. message: {0}", errString)); } }
private static int Main(string[] args) { // setup catch to fatal program crash AppDomain.CurrentDomain.UnhandledException += MyUnhandledException; Application.ThreadException += MyThreadException; // establish file/folder locations Logger.Initialize("Media Center", "EPG123"); Helper.EstablishFileFolderPaths(); bool import, match, showProgress; import = match = showProgress = false; var showGui = true; epgConfig config = null; // only evaluate arguments if a configuration file exists, otherwise open the gui if (File.Exists(Helper.Epg123CfgPath) && args != null) { foreach (var t in args) { switch (t.ToLower()) { case "-update": showGui = false; break; case "-p": showProgress = true; break; default: return(-1); } } } // create a mutex and keep alive until program exits using (var mutex = Helper.GetProgramMutex($"Global\\{AppGuid}", !showGui)) { // check for an instance already running if (mutex == null) { return(-1); } Logger.WriteMessage("==============================================================================="); Logger.WriteMessage($" {(showGui ? "Activating the epg123 configuration GUI." : "Beginning epg123 update execution.")} version {Helper.Epg123Version}"); Logger.WriteMessage("==============================================================================="); Logger.WriteMessage($"*** {Helper.GetOsDescription()} ***"); Logger.WriteMessage($"*** {Helper.GetWmcDescription()} ***"); // open the configuration GUI if needed if (showGui) { var cfgForm = new frmMain(); cfgForm.ShowDialog(); Logger.Close(); if (!cfgForm.Execute) { mutex.ReleaseMutex(); GC.Collect(); if (!cfgForm.RestartAsAdmin) { return(0); } var startInfo = new ProcessStartInfo { FileName = Helper.Epg123ExePath, WorkingDirectory = Helper.ExecutablePath, UseShellExecute = true, Verb = "runas" }; Process.Start(startInfo); return(0); } Logger.Initialize("Media Center", "EPG123"); config = cfgForm.Config; import = config.AutoImport; match = config.Automatch; } // prevent machine from entering sleep mode var prevThreadState = NativeMethods.SetThreadExecutionState((uint)ExecutionFlags.ES_CONTINUOUS | (uint)ExecutionFlags.ES_SYSTEM_REQUIRED | (uint)ExecutionFlags.ES_AWAYMODE_REQUIRED); // bring in the configuration if (config == null) { try { using (var stream = new StreamReader(Helper.Epg123CfgPath, Encoding.Default)) { var serializer = new XmlSerializer(typeof(epgConfig)); TextReader reader = new StringReader(stream.ReadToEnd()); config = (epgConfig)serializer.Deserialize(reader); reader.Close(); } } catch (IOException ex) { Logger.WriteError($"Failed to open configuration file during initialization due to IO exception. message: {ex.Message}"); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); mutex.ReleaseMutex(); GC.Collect(); return(-1); } catch (Exception ex) { Logger.WriteError($"Failed to open configuration file during initialization with unknown exception. message: {ex.Message}"); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); mutex.ReleaseMutex(); GC.Collect(); return(-1); } } // let's do this Helper.SendPipeMessage("Downloading|Initializing..."); var startTime = DateTime.UtcNow; if (showGui || showProgress) { var build = new frmProgress(config); build.ShowDialog(); } else { sdJson2mxf.sdJson2Mxf.Build(config); if (!sdJson2mxf.sdJson2Mxf.Success) { Logger.WriteError("Failed to create MXF file. Exiting."); } } // close the logger and restore power/sleep settings Logger.WriteVerbose($"epg123 update execution time was {DateTime.UtcNow - startTime}."); Logger.Close(); NativeMethods.SetThreadExecutionState(prevThreadState | (uint)ExecutionFlags.ES_CONTINUOUS); // did a Save&Execute from GUI ... perform import and automatch as well if requested if (!sdJson2mxf.sdJson2Mxf.Success) { return(-1); } if (import) { // verify output file exists if (!File.Exists(Helper.Epg123MxfPath) || !File.Exists(Helper.Epg123ClientExePath)) { mutex.ReleaseMutex(); GC.Collect(); return(-1); } // epg123client var startInfo = new ProcessStartInfo() { FileName = "epg123Client.exe", Arguments = "-i \"" + Helper.Epg123MxfPath + "\" -nogc -noverify -p" + (match ? " -match" : string.Empty), UseShellExecute = false, CreateNoWindow = true }; var proc = Process.Start(startInfo); proc?.WaitForExit(); } return(0); } }