diff --git a/AutoLiveRecorder/AutoLiveRecorder.csproj b/AutoLiveRecorder/AutoLiveRecorder.csproj index 4f06497..592956a 100644 --- a/AutoLiveRecorder/AutoLiveRecorder.csproj +++ b/AutoLiveRecorder/AutoLiveRecorder.csproj @@ -47,6 +47,9 @@ + + + diff --git a/AutoLiveRecorder/Class/Bas.cs b/AutoLiveRecorder/Class/Bas.cs index 90641fb..eea5933 100644 --- a/AutoLiveRecorder/Class/Bas.cs +++ b/AutoLiveRecorder/Class/Bas.cs @@ -3,8 +3,11 @@ using System.Collections.Generic; using System.IO; using System.Net; +using System.Runtime.Serialization.Json; +using System.Text; using System.Text.RegularExpressions; using System.Web.Script.Serialization; +using System.Windows; namespace AutoLiveRecorder { @@ -58,6 +61,7 @@ public static void Exit() return; } } + SaveTasks(); Environment.Exit(0); } @@ -163,7 +167,7 @@ public static object GetJsonValueByKey(string JsonStr, string Keys, int step = 0 Dictionary p = serializer.Deserialize>(JsonStr); if (p.ContainsKey(Key)) { - if (p[Key].GetType() == typeof(ArrayList) && step < TolStep - 1) + if (p[Key]?.GetType() == typeof(ArrayList) && step < TolStep - 1) { ArrayList al = (ArrayList)p[Key]; List results = new List(); @@ -174,7 +178,7 @@ public static object GetJsonValueByKey(string JsonStr, string Keys, int step = 0 return results; } else - if (p[Key].GetType() == typeof(Dictionary) && step < TolStep - 1) + if (p[Key]?.GetType() == typeof(Dictionary) && step < TolStep - 1) { Dictionary di = (Dictionary)p[Key]; return GetJsonValueByKey(di, Keys, step + 1); @@ -203,7 +207,7 @@ public static object GetJsonValueByKey(Dictionary JsonObject, st int TolStep = Keys.Split('/').Length; if (JsonObject.ContainsKey(Key)) { - if (JsonObject[Key].GetType() == typeof(ArrayList) && step < TolStep - 1) + if (JsonObject[Key]?.GetType() == typeof(ArrayList) && step < TolStep - 1) { ArrayList al = (ArrayList)JsonObject[Key]; List results = new List(); @@ -214,7 +218,7 @@ public static object GetJsonValueByKey(Dictionary JsonObject, st return results; } else - if (JsonObject[Key].GetType() == typeof(Dictionary) && step < TolStep - 1) + if (JsonObject[Key]?.GetType() == typeof(Dictionary) && step < TolStep - 1) { Dictionary di = (Dictionary)JsonObject[Key]; return GetJsonValueByKey(di, Keys, step + 1); @@ -230,6 +234,67 @@ public static object GetJsonValueByKey(Dictionary JsonObject, st } } + /// + /// 读取任务列表 + /// + public static void LoadTasks() + { + if (File.Exists("tasks.txt")) + { + FileStream fs = new FileStream(Properties.Settings.Default.SavePath + "\tasks.json", FileMode.Open); + StreamReader reader = new StreamReader(fs); + string json = reader.ReadToEnd(); + fs.Close(); + + ArrayList al = (ArrayList)GetJsonValueByKey(json, "tasks"); + foreach (Dictionary i in al) + { + Cls_WorkListItem c = new Cls_WorkListItem(); + + c.Frequency = GetJsonValueByKey(i, "Frequency")?.ToString(); + c.Host = GetJsonValueByKey(i, "Host").ToString(); + c.IsRecordDanmu = (bool)GetJsonValueByKey(i, "IsRecordDanmu"); + c.IsRepeat = (bool)GetJsonValueByKey(i, "IsRepeat"); + c.IsSupportDanmu = (bool)GetJsonValueByKey(i, "IsSupportDanmu"); + c.IsTranslateAfterCompleted = (bool)GetJsonValueByKey(i, "IsTranslateAfterCompleted"); + c.Platform = (Cls_WorkListItem.PlatformType)GetJsonValueByKey(i, "Platform"); + c.RoomStatus = (int)GetJsonValueByKey(i, "RoomStatus"); + c.RoomTitle = GetJsonValueByKey(i, "RoomTitle").ToString(); + c.Roomid = GetJsonValueByKey(i, "Roomid").ToString(); + c.StartMode = (Cls_WorkListItem.StartModeType)GetJsonValueByKey(i, "StartMode"); + c.StartTime = DateTime.Parse(GetJsonValueByKey(i, "StartTime")?.ToString()); + c.StartTime = c.StartTime.AddHours(8); + c.Status = (Cls_WorkListItem.StatusCode)GetJsonValueByKey(i, "Status"); + c.URL = GetJsonValueByKey(i, "URL").ToString(); + + c.SettingFinished(); + + TaskList.Add(c); + ((MainWindow)Application.Current.MainWindow).WorkList.AddTask(c); + } + } + } + + /// + /// 保存任务列表 + /// + public static void SaveTasks() + { + DataContractJsonSerializer jser = new DataContractJsonSerializer(TaskList.GetType()); + using (MemoryStream ms = new MemoryStream()) + { + jser.WriteObject(ms, TaskList); + StringBuilder sb = new StringBuilder(); + sb.Append(Encoding.UTF8.GetString(ms.ToArray())); + string json = sb.ToString(); + json = "{\"tasks\":" + json + "}"; + byte[] bjson = Encoding.UTF8.GetBytes(json); + FileStream fs = File.Open(Properties.Settings.Default.SavePath + "\tasks.json", FileMode.OpenOrCreate); + fs.Write(bjson, 0, bjson.Length); + fs.Close(); + } + } + #endregion Public Methods } } \ No newline at end of file diff --git a/AutoLiveRecorder/Class/Cls_WorkListItem.cs b/AutoLiveRecorder/Class/Cls_WorkListItem.cs index dcda329..de59f85 100644 --- a/AutoLiveRecorder/Class/Cls_WorkListItem.cs +++ b/AutoLiveRecorder/Class/Cls_WorkListItem.cs @@ -452,7 +452,17 @@ public string RoomTitle /// public DateTime StartTime { - get { return _StartTime; } + get + { + if (_StartTime == new DateTime()) + { + return new DateTime(1970, 1, 1, 8, 0, 0); + } + else + { + return _StartTime; + } + } set { _StartTime = value; @@ -667,7 +677,7 @@ private void ArrangeFile() } } tmpFileList.Clear(); - if (StartMode == StartModeType.WhenStart || (StartMode == StartModeType.WhenStart && IsRepeat) || (StartMode == StartModeType.WhenTime && !Frequency.Contains("仅一次"))) + if ((StartMode == StartModeType.WhenStart && IsRepeat) || (StartMode == StartModeType.WhenTime && !Frequency.Contains("仅一次"))) Status = StatusCode.Waiting; else Status = StatusCode.Finished; diff --git a/AutoLiveRecorder/Properties/AssemblyInfo.cs b/AutoLiveRecorder/Properties/AssemblyInfo.cs index 53cdc4b..28aa7aa 100644 --- a/AutoLiveRecorder/Properties/AssemblyInfo.cs +++ b/AutoLiveRecorder/Properties/AssemblyInfo.cs @@ -40,6 +40,6 @@ // 主版本 次版本 生成号 修订号 // // 可以指定所有值,也可以使用以下所示的 "*" 预置版本号和修订号 方法是按如下所示使用“*”: : [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.2.19")] -[assembly: AssemblyFileVersion("2.0.2.19")] +[assembly: AssemblyVersion("2.0.3.20")] +[assembly: AssemblyFileVersion("2.0.3.20")] [assembly: Guid("b3481a0e-1d11-4a78-a059-64bb9dd7f1c0")] \ No newline at end of file diff --git a/AutoLiveRecorder/Windows/MainWindow.xaml.cs b/AutoLiveRecorder/Windows/MainWindow.xaml.cs index 86bf9fa..8cc16cd 100644 --- a/AutoLiveRecorder/Windows/MainWindow.xaml.cs +++ b/AutoLiveRecorder/Windows/MainWindow.xaml.cs @@ -318,6 +318,9 @@ private void Window_Loaded(object sender, RoutedEventArgs e) { //初始化托盘图标 NotifyIcon.NotifyIcon_Init(); + + //读取任务列表 + Bas.LoadTasks(); } #endregion Private Methods diff --git a/README.md b/README.md index 4410fa0..6c4a24c 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ ## 下载地址 -[![Downloads](https://img.shields.io/badge/%E4%B8%8B%E8%BD%BD%E8%BD%AF%E4%BB%B6@2.0.2.19-484K-brightgreen.svg)](https://github.com/LeoChen98/AutoLiveRecorder/releases/download/2.0.2.19/AutoLiveRecorder.exe) +[![Downloads](https://img.shields.io/badge/%E4%B8%8B%E8%BD%BD%E8%BD%AF%E4%BB%B6@2.0.3.20-485K-brightgreen.svg)](https://github.com/LeoChen98/AutoLiveRecorder/releases/download/2.0.3.20/AutoLiveRecorder.exe) [![PassedDownloads](https://img.shields.io/badge/%E8%BF%87%E5%BE%80%E7%89%88%E6%9C%AC-release-blue.svg)](https://github.com/LeoChen98/AutoLiveRecorder/releases) ## 开发计划 diff --git a/ReleaseHistory.md b/ReleaseHistory.md index 03ca9a9..b267429 100644 --- a/ReleaseHistory.md +++ b/ReleaseHistory.md @@ -1,4 +1,8 @@ -# 2.0.2.19 release +# 2.0.3.20 release +1. 新增了“任务列表保存”功能,现在程序退出时会自动保存任务列表,启动时自动加载任务列表了。 +2. 修复了任务开始条件为“开播时开始”且“不重复”时任务仍会重复的bug。 + +# 2.0.2.19 release 1. 优化了“检查更新”模块的显示。 # 2.0.1.18 release