private string ConvertFileName(string name) { char[] array = new char[] { '\\', '/', ':', '*', '?', '"', '<', '>', '|' }; for (int i = 0; i < array.Length; i++) { char oldChar = array[i]; name = name.Replace(oldChar, '_'); } // mark10als string text2 = MainDef.GetInstance()["extend.name.change"]; bool flag = text2 != "0"; if (flag) { name = name.Replace(' ', '_'); name = name.Replace(',', '、'); name = name.Replace(' ', '_'); name = name.Replace('&', '&'); name = name.Replace('%', '%'); } return(name); }
private void SetNextEpgTime() { int hour = DateTime.Now.Hour; string[] arg_34_0 = MainDef.GetInstance()["epg.hour"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <int> list = new List <int>(); string[] array = arg_34_0; for (int i = 0; i < array.Length; i++) { string s = array[i]; list.Add(s.ToInt()); } list.Sort(); list.Add(list[0] + 24); int num = 0; foreach (int current in list) { if (hour < current) { num = current; break; } } this.nextEpgTime = DateTime.Now.Date.AddHours((double)num); Log.Write("次回番組表取得: " + this.nextEpgTime.ToString("M/d HH:mm")); }
private string GetRecPath(string tunername) //引数Tuner名を追加 { //main.defのTuner名毎のrecord.tunerfolderを取得する処理を追加 string arg_26_0; this.list = new PairList(Util.GetUserPath("main.def")); this.list.Load(); if (this.list.IsDefined("record.tunerfolder." + tunername)) { arg_26_0 = MainDef.GetInstance()["record.tunerfolder." + tunername]; } else { arg_26_0 = MainDef.GetInstance()["record.folder"]; } /* * Log.Write("保存フォルダー0:" + tunername); * string arg_26_0 = MainDef.GetInstance()["record.tunerfolder." + tunername]; * int iLength = arg_26_0.Length; * bool flag3 = iLength == 0; * Log.Write("保存フォルダー1:" + arg_26_0); * Log.Write("保存フォルダー2:" + iLength); * if (flag3) * { * arg_26_0 = MainDef.GetInstance()["record.folder"]; * } * Log.Write("保存フォルダー3:" + arg_26_0); */ // mark10als string text2 = MainDef.GetInstance()["record.folder.spare"]; bool flag = text2 != ""; if (flag) { ulong num; ulong num2; ulong num3; bool diskFreeSpaceEx = RecTask.GetDiskFreeSpaceEx(arg_26_0, out num, out num2, out num3); if (diskFreeSpaceEx) { ulong num4 = ulong.Parse(MainDef.GetInstance()["record.folder.spare.use"]); num4 = num4 * 1024uL * 1024uL * 1024uL; bool flag2 = num < num4; if (flag2) { arg_26_0 = text2; } } else { Log.Write("空きディスク容量が取得できませんでした。"); } } string path = this.ConvertFileMacro(MainDef.GetInstance()["record.file"]); string src = Path.Combine(arg_26_0, path); return(this.CheckFilePath(src)); }
public static MainDef GetInstance() { if (MainDef.singleObj == null) { MainDef.singleObj = new MainDef(); } return(MainDef.singleObj); }
private static void LoadDef() { Log.Write("初期化中..."); Util.CopyUserFile(); MainDef.GetInstance().Check(); GenreConv.GetInstance(); TextConv.GetInstance(); EpgWait.GetInstance(); }
public void Enqueue() { List <Service> obj = this.list; lock (obj) { this.list.Clear(); using (Sql sql = new Sql(true)) { string nids = MainDef.GetInstance()["epg.basic"]; if (nids == "") { nids = "-1"; } else { string[] array = nids.Split(new char[] { ',' }); string where = ""; for (int i = 0; i < array.Length; i++) { string s = "(nid = " + array[i]; int sid = EpgWait.GetInstance().GetSid(array[i].ToInt()); if (sid != -1) { s += " and sid = "; s += sid; } s += ")"; where += s; if (i < (array.Length - 1)) { where += " or "; } } sql.Text = "select *, (fsid >> 32) as nid, (fsid & 0xffff) as sid from service where {0} group by nid, driver order by id"; sql.Text = sql.Text.Formatex(new object[] { where }); // Log.Write("sql(basic) = [{0}]".Formatex(new object[]{sql.Text})); this.AddList(sql, true); } sql.Text = "select *, (fsid >> 32) as nid, ((fsid >> 16) & 0xffff) as tsid from service where nid not in ({0}) group by tsid, driver order by id"; sql.Text = sql.Text.Formatex(new object[] { nids }); // Log.Write("sql(ex) = [{0}]".Formatex(new object[]{sql.Text})); this.AddList(sql, false); } this.Enable = (this.list.Count > 0); } }
private void openEpgMenuItem_Click(object sender, EventArgs e) { try { Process.Start(MainDef.GetInstance()["epgurl"]); } catch (Exception ex) { Log.Write("番組表を開けませんでした。[詳細] " + ex.Message); Log.Write(1, ex.StackTrace); } }
public void GetRecordFolderFree() { ulong num; ulong num2; ulong num3; if (WebApi.GetDiskFreeSpaceEx(MainDef.GetInstance()["record.folder"], out num, out num2, out num3)) { this.ret.data1 = num; return; } throw new Exception("録画フォルダの空き容量が取得できませんでした。"); }
public void OnResume() { Log.Write("スリープから復帰しました。"); this.wake.Cancel(); if (MainDef.GetInstance()["autosleep"] != "on") { return; } if (this.GetNextTime() - DateTime.Now < new TimeSpan(0, 3, 0)) { this.sleepTimer.Start(); Log.Write("スリープモードで自動復帰したため、録画後再スリープします。"); return; } Log.Write("自動復帰でないため、再スリープしません。"); }
public void Start() { string text = MainDef.GetInstance()["url"]; Log.Write("Webサーバ受け入れURL: " + text); try { this.listener.Prefixes.Add(text); this.listener.Start(); goto IL_B5; } catch (Exception ex) { string expr_58 = "Webサーバの初期化に失敗しました。この状態では、ブラウザからアクセスできません。アプリケーションを終了してください。[詳細] {0}\n[対策] web.batを実行しましたか?".Formatex(new object[] { ex.Message }); Log.Write(expr_58); Log.Write(1, ex.StackTrace); MessageBox.Show(expr_58, AppData.AppName); return; } IL_77: try { HttpListenerContext context = this.listener.GetContext(); Task.Factory.StartNew(delegate { this.Excute(context); }, TaskCreationOptions.AttachedToParent); } catch (HttpListenerException) { return; } catch (ObjectDisposedException) { return; } IL_B5: if (!this.stop) { goto IL_77; } }
public void Open(bool show) { if (this.IsOpen()) { return; } Ticket ticket = new Ticket("/tvmaid/mutex/tvtest/open/" + this.driverId); try { if (!ticket.GetOwner(0)) { ticket = null; this.WaitOpen(); } else { string str = show ? "" : " /nodshow /min /silent"; Process expr_4A = new Process(); expr_4A.StartInfo.FileName = MainDef.GetInstance()["tvtest"]; expr_4A.StartInfo.Arguments = string.Format("/d \"{0}\"" + str, this.driverPath); // mark10als //WindowStyleにHiddenを指定して、非表示された状態で起動されるようにする expr_4A.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //UseShellExecuteをTrueにする(デフォルトでTrueなので、変更する必要なし) //expr_4A.StartInfo.UseShellExecute = false; expr_4A.StartInfo.UseShellExecute = false; // expr_4A.StartInfo.EnvironmentVariables.Add("DriverId", this.driverId); expr_4A.Start(); expr_4A.WaitForInputIdle(); this.WaitOpen(); } } finally { if (ticket != null) { ticket.Dispose(); } } }
public static Record GetNextRecord(Tuner tuner, Sql sql) { int @int = MainDef.GetInstance().GetInt("record.margin.start"); DateTime dateTime = DateTime.Now + new TimeSpan(0, 0, @int); sql.Text = "select * from record where tuner = '{0}' and status & {2} and start <= {1} and end > {2} order by start limit 1".Formatex(new object[] { tuner.Name, dateTime.Ticks, 1 }); using (DataTable table = sql.GetTable()) { if (table.Read()) { return(new Record(table)); } } return(null); }
private static void CopyPlugin() { try { string basePath = Util.GetBasePath("TvmaidPlugin.tvtp"); string text = Path.Combine(Path.Combine(Path.GetDirectoryName(MainDef.GetInstance()["tvtest"]), "Plugins"), "TvmaidPlugin.tvtp"); if (File.Exists(text) && File.GetLastWriteTime(basePath) == File.GetLastWriteTime(text)) { Log.Write("Tvmaidプラグイン OK"); } else { File.Copy(basePath, text, true); Log.Write("Tvmaidプラグインを更新しました。"); } } catch (Exception ex) { throw new Exception("TVTestのプラグインフォルダに、Tvmaidプラグインをコピーできませんでした。[詳細]" + ex.Message); } }
private void GetFreeTuner(Sql sql) { // mark10als int @int = MainDef.GetInstance().GetInt("record.margin.start"); int @int2 = MainDef.GetInstance().GetInt("record.margin.end"); string text = MainDef.GetInstance()["record.margin.overlap"]; if (text != "0") { sql.Text = "select name from tuner\r\n where\r\n driver in (select driver from service where fsid = {0}) \r\n and\r\n name not in (select tuner from record where {1} < end and {2} > start and status & {3})\r\n order by id".Formatex(new object[] { this.Fsid, (this.StartTime.Ticks - @int), (this.EndTime.Ticks - @int2), 1 }); } else { sql.Text = "select name from tuner\r\n where\r\n driver in (select driver from service where fsid = {0}) \r\n and\r\n name not in (select tuner from record where {1} < end and {2} > start and status & {3})\r\n order by id".Formatex(new object[] { this.Fsid, this.StartTime.Ticks, this.EndTime.Ticks, 1 }); } object data = sql.GetData(); if (data != null) { this.TunerName = (string)data; return; } sql.Text = "select name from tuner\r\n where\r\n driver in (select driver from service where fsid = {0}) \r\n order by id".Formatex(new object[] { this.Fsid }); this.TunerName = (string)sql.GetData(); }
private void PostProcess() { try { string text = MainDef.GetInstance()["postprocess"]; if (this.result.Code == 0 && text != "") { Log.Write("録画後プロセス実行."); // mark10als //Process.Start(text, "\"" + this.recPath + "\""); ProcessStartInfo ppInfo = new ProcessStartInfo(); ppInfo.FileName = text; // 実行するファイル ppInfo.Arguments = "\"" + this.recPath + "\""; ppInfo.CreateNoWindow = false; // コンソール・ウィンドウを開かない ppInfo.UseShellExecute = false; // シェル機能を使用しない Process.Start(ppInfo); } } catch (Exception ex) { Log.Write("録画後プロセスの実行に失敗しました。[詳細] " + ex.Message); Log.Write(1, ex.StackTrace); } }
private void StartAutoRecord(Sql sql) { List <AutoRecord> list = new List <AutoRecord>(); sql.Text = "select * from auto_record where status = 1 and query <> ''"; using (DataTable table = sql.GetTable()) { while (table.Read()) { list.Add(new AutoRecord(table)); } } foreach (AutoRecord current in list) { List <Event> list2 = new List <Event>(); int @int = MainDef.GetInstance().GetInt("record.margin.end"); sql.Text = "select * from event\r\n left join record on event.fsid = record.fsid and event.eid = record.eid\r\n where\r\n event.end > {0} and record.id is null and event.id in ({1})".Formatex(new object[] { (DateTime.Now + new TimeSpan(0, 0, @int)).Ticks, current.Query }); using (DataTable table2 = sql.GetTable()) { while (table2.Read()) { list2.Add(new Event(table2)); } } if (list2.Count > 50) { current.SetEnable(sql, false); Log.Write("自動予約 '{0}' を無効にしました。{1} 件以上ヒットします。条件を見なおしてください。".Formatex(new object[] { current.Name, 50 })); } else { foreach (Event current2 in list2) { // mark10als 最小と最大の自動録画時間のチェック bool flag2 = false; string text = MainDef.GetInstance()["record.minimal.minute"]; bool flag = text != ""; if (flag) { int num = int.Parse(MainDef.GetInstance()["record.minimal.minute"]); num = num * 60; flag2 = current2.Duration < num; } else { flag2 = false; } bool flag4 = false; string text2 = MainDef.GetInstance()["record.maximum.minute"]; bool flag3 = text2 != ""; if (flag3) { int num2 = int.Parse(MainDef.GetInstance()["record.maximum.minute"]); num2 = num2 * 60; flag4 = current2.Duration > num2; } else { flag4 = false; } int disable = 3; bool flag5 = flag2 | flag4; if (flag5) { disable = 0; } new Record { Status = disable, Fsid = current2.Fsid, Eid = current2.Eid, StartTime = current2.Start, Duration = current2.Duration, Title = current2.Title, Auto = current.Id }.Add(sql); } } } }
public void Run() { try { SleepState.Stop(true); this.sql = new Sql(true); this.service = new Service(this.sql, this.record.Fsid); Log.Write(this.tuner.Name + ": 録画を開始します。" + this.record.Title); this.StartRec(); if (this.record.EndTime < DateTime.Now) { throw new Exception("終了時刻が過ぎています。"); } int @int = MainDef.GetInstance().GetInt("record.margin.end"); while (this.record.EndTime - new TimeSpan(0, 0, @int) > DateTime.Now) { if (this.StoppdApp()) { throw new Exception("アプリケーション終了のため、録画を中断します。"); } this.CheckCancel(); this.CheckEvent(); Thread.Sleep(1000); } } catch (Exception ex) { string text = "{0}: 録画に失敗しました。{1}".Formatex(new object[] { this.tuner.Name, ex.Message }); Log.Write(text + " - " + this.record.Title); Log.Write(1, ex.StackTrace); if (this.result != null) { this.result.Code = 1; this.result.Message = text; } } finally { try { this.StopRec(); } catch (Exception ex2) { Log.Write("{0}: 録画終了処理に失敗しました。{1}".Formatex(new object[] { this.tuner.Name, ex2.Message })); Log.Write(1, ex2.StackTrace); } SleepState.Stop(false); this.sql.Dispose(); Log.Write("{0}: 録画終了しました。 - {1}".Formatex(new object[] { this.tuner.Name, this.record.Title })); this.PostProcess(); } }
private static void Main(string[] args) { List <Task> tasks = new List <Task>(); WebServer ws = null; // mark10als // Log.Write(AppData.AppName + " " + AppData.AppVersion); Log.Write(AppData.AppName + " " + AppData.AppVersion + " " + AppData.AppMod); Ticket ticket = new Ticket("/tvmaid/mutex/main"); try { if (!ticket.GetOwner(10000)) { ticket = null; throw new Exception("時間内に二重起動が解消されませんでした。"); } Program.LoadDef(); if (MainDef.GetInstance()["debug"] == "1") { Log.GetInstance().SetLevel(1); Log.Write("debug mode 1 に設定しました。"); } Program.CopyPlugin(); if (args.Length == 1 && args[0] == "-tunerupdate") { Program.UpdateTuner(); } Task item = Task.Factory.StartNew(() => { RecTimer.GetInstance().Run(); }, TaskCreationOptions.AttachedToParent); tasks.Add(item); ws = new WebServer(); item = Task.Factory.StartNew(() => { ws.Start(); }, TaskCreationOptions.AttachedToParent); tasks.Add(item); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TunerMon()); } catch (Exception ex) { string str = ex.Message + ex.StackTrace; MessageBox.Show("このエラーは回復できないため、アプリケーションは終了します。[詳細]" + str, AppData.AppName); } finally { if (ws != null) { ws.Dispose(); } RecTimer.GetInstance().Dispose(); ExitForm form = new ExitForm(30); Task.Factory.StartNew(delegate { Task.WaitAll(tasks.ToArray(), 30000); }).ContinueWith(delegate(Task _) { form.Close(); }, TaskScheduler.FromCurrentSynchronizationContext()); form.ShowDialog(); if (ticket != null) { ticket.Dispose(); } Program.StartNextProcess(); } }