/[xmltv_parser]/trunk/xmltv_parser/main.cs
ViewVC logotype

Diff of /trunk/xmltv_parser/main.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/xmltv_parser/main.cs	2013/03/17 03:57:57	227
+++ trunk/xmltv_parser/main.cs	2013/03/22 16:41:42	248
@@ -23,14 +23,45 @@
 
     public partial class main : Form
     {
+        const long MAX_LOG_FILESIZE_IN_BYTES = 250000; //250kb max
+        void TruncateLogFile(FileInfo log_file)
+        {
+            if (!log_file.Exists)
+            {
+                gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+            }
+            else
+            {
+                if (log_file.Length > MAX_LOG_FILESIZE_IN_BYTES)
+                {
+                    string match = string.Format("{0}.*", log_file.Name);
+                    var files = Directory.GetFiles(log_file.Directory.FullName, match).ToList();
+                    files.RemoveAt(0);
+                    files.TrimExcess();
+                    int count = files.Count;
+                    if (log_file.Exists)
+                    {
+                        File.Copy(log_file.FullName, string.Format("{0}.{1}", log_file.FullName, count));
+                    }
+                    gLog.CreateLog(log_file.FullName, true, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+                }
+                else
+                {
+                    gLog.CreateLog(log_file.FullName, false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+                }
+            }
+        }
+
         public main()
         {
             InitializeComponent();
             ListViewSorter Sorter = new ListViewSorter();
             //lstPrograms.ListViewItemSorter = Sorter;
+
             string log_path = Application.StartupPath;
             string log_filename = string.Format("{0}.log", typeof(main).Assembly.GetName().Name);
-            gLog.CreateLog(string.Format(@"{0}\{1}", log_path, log_filename), false, LogLevel.kLogLevel_All_NoProgress, new EventHandler<LoggerOnFlushEventArgs>(Log_OnFlush));
+            FileInfo log_file = new FileInfo(string.Format(@"{0}\{1}", log_path, log_filename));
+            TruncateLogFile(log_file);            
 #if DEBUG
             LogLevel gLevel = gLog.LogLevel;
 #if DISABLE_DEBUG_MODE_KLOGLEVEL_VERBOSE_DEBUG
@@ -373,6 +404,7 @@
             object data = XMLTV.CreateBindingSourceFromData(XMLTV.GetPrograms(), out data_type);
             XMLTV.CreateFilterFromDataSource(ref data, column, txtFilterText.Text);
             dataGrid.DataSource = data;
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
         }
         private RadioButton GetSelectedFilteringControl()
         {
@@ -469,6 +501,7 @@
             XMLTV.CreateSorterFromDataSource(ref data, Descending, column);
             dataGrid.DataSource = data;
             ToggleDescedning();
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
         }
         private RadioButton GetSelectedSortControl()
         {
@@ -495,6 +528,11 @@
         }
         #endregion
 
+        private void dataGrid_Click(object sender, EventArgs e)
+        {
+            dataGrid_SelectionChanged(dataGrid, new EventArgs());
+        }
+
        
     }
 }

 

  ViewVC Help
Powered by ViewVC 1.1.22