1 |
#define DEBUG_COMMANDLINE_ARGUMENTS // when defined will override supplied commandline args |
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Text; |
5 |
using Enterprise.Logging; |
6 |
using System.Windows.Forms; |
7 |
using System.Diagnostics; |
8 |
using System.IO; |
9 |
using libxmltv.Core; |
10 |
|
11 |
namespace GBPVRProgramDatabaseFixer |
12 |
{ |
13 |
class Program |
14 |
{ |
15 |
static string XMLTV_FILE = ""; |
16 |
static string GBPVR_DATABASE = ""; |
17 |
static bool XMLTV_INSTANCE_CREATED = false; |
18 |
|
19 |
static int LAST_REPORTED_XMLTV_PROGRESS =0; |
20 |
|
21 |
static FileInfo fi_XMLTVFILE; |
22 |
|
23 |
static void CreateLog() |
24 |
{ |
25 |
string log_path = Application.StartupPath; |
26 |
string log_filename = string.Format("{0}.log", typeof(Program).Assembly.GetName().Name); |
27 |
gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All); |
28 |
#if DEBUG |
29 |
LogLevel gLevel = gLog.LogLevel; |
30 |
gLevel |= LogLevel.kLogLevel_VerboseDebug; |
31 |
gLevel |= LogLevel.kLogLevel_Debug; |
32 |
gLog.SetLogLevel(gLevel); |
33 |
#else |
34 |
LogLevel gLevel = LogLevel.kLogLevel_Default; // set the default log level: Info, Warn, Error, Debug |
35 |
// it is OK for kLogLevel_Debug to be set in Release mode ... must of the chatty messages are from kLogLevel_VerboseDebug |
36 |
gLevel &= ~LogLevel.kLogLevel_Debug; // ensure this is not set, ever in release mode |
37 |
gLevel &= ~LogLevel.kLogLevel_VerboseDebug; // ensure this is not set, ever in release mode |
38 |
gLog.SetLogLevel(gLevel); |
39 |
#endif |
40 |
gLog.ReportProgressEvent += new EventHandler<ReportProgressEventArgs>(gLog_ReportProgress); |
41 |
} |
42 |
|
43 |
[Conditional("DEBUG_COMMANDLINE_ARGUMENTS")] |
44 |
static void CreateDebugCommandlineArgs(ref List<string> cargs) |
45 |
{ |
46 |
cargs = new List<string>(); |
47 |
cargs.Add(string.Format("--xmltv_file=\"{0}\"", @"c:\EPG Guide\Guide\tvguide.xml")); |
48 |
cargs.Add(string.Format("--gbprv_db=\"{0}\"", @"c:\Program Files (x86)\Devnz\GBPVR\gbpvr.db3")); |
49 |
} |
50 |
|
51 |
static List<string> CreateCommandlineArgs(string[] args) |
52 |
{ |
53 |
List<string> cargs = new List<string>(args); |
54 |
CreateDebugCommandlineArgs(ref cargs); |
55 |
return cargs; |
56 |
} |
57 |
|
58 |
static void Main(string[] args) |
59 |
{ |
60 |
CreateLog(); |
61 |
var cargs = CreateCommandlineArgs(args); |
62 |
foreach (var carg in cargs) |
63 |
{ |
64 |
if (carg.ToLower().Contains("--xmltv_file=")) |
65 |
{ |
66 |
XMLTV_FILE = carg.Replace("--xmltv_file=", "").Replace("\"",""); |
67 |
gLog.Info.WriteLine("XMLTV FILE: '{0}'", XMLTV_FILE); |
68 |
} |
69 |
else if (carg.ToLower().Contains("--gbprv_db=")) |
70 |
{ |
71 |
GBPVR_DATABASE = carg.Replace("--gbprv_db=", "").Replace("\"", ""); |
72 |
gLog.Info.WriteLine("GBPVR DATABASE: '{0}'", GBPVR_DATABASE); |
73 |
} |
74 |
else |
75 |
{ |
76 |
gLog.Warn.WriteLine("Unknown commandline option: {0}", carg); |
77 |
} |
78 |
} |
79 |
|
80 |
LoadXMLTVFile(); |
81 |
} |
82 |
|
83 |
static void gLog_ReportProgress(object sender, ReportProgressEventArgs e) |
84 |
{ |
85 |
if (LAST_REPORTED_XMLTV_PROGRESS != e.Progress) |
86 |
{ |
87 |
Console.WriteLine("XMLTV: {0} Loading: {1:00}%", fi_XMLTVFILE.Name, e.Progress); |
88 |
LAST_REPORTED_XMLTV_PROGRESS = e.Progress; |
89 |
} |
90 |
} |
91 |
static void LoadXMLTVFile() |
92 |
{ |
93 |
if (string.IsNullOrEmpty(XMLTV_FILE)) |
94 |
{ |
95 |
gLog.Error.WriteLine("XMLTV File is either a null or empty string."); |
96 |
return; |
97 |
} |
98 |
fi_XMLTVFILE = new FileInfo(XMLTV_FILE); |
99 |
if (!fi_XMLTVFILE.Exists) |
100 |
{ |
101 |
gLog.Error.WriteLine("Could not find XMLTV File: {0}", fi_XMLTVFILE.FullName); |
102 |
return; |
103 |
} |
104 |
|
105 |
XMLTV.Create(fi_XMLTVFILE.FullName, new EventHandler<EventArgs>(XMLTV_OnInstanceCreated)); |
106 |
while (!XMLTV_INSTANCE_CREATED) { Application.DoEvents(); } |
107 |
} |
108 |
|
109 |
static void XMLTV_OnInstanceCreated(object sender, EventArgs e) { XMLTV_INSTANCE_CREATED = true; } |
110 |
} |
111 |
} |