Skip to content

Commit

Permalink
Merge pull request #4 from LeoChen98/Development
Browse files Browse the repository at this point in the history
1. 新增了“任务列表保存”功能,现在程序退出时会自动保存任务列表,启动时自动加载任务列表了。
2. 修复了任务开始条件为“开播时开始”且“不重复”时任务仍会重复的bug。
  • Loading branch information
LeoChen98 committed Dec 23, 2018
2 parents 0b6f940 + 38c6997 commit 0e477d0
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 10 deletions.
3 changes: 3 additions & 0 deletions AutoLiveRecorder/AutoLiveRecorder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Windows.Forms" />
Expand Down
73 changes: 69 additions & 4 deletions AutoLiveRecorder/Class/Bas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -58,6 +61,7 @@ public static void Exit()
return;
}
}
SaveTasks();
Environment.Exit(0);
}

Expand Down Expand Up @@ -163,7 +167,7 @@ public static object GetJsonValueByKey(string JsonStr, string Keys, int step = 0
Dictionary<string, object> p = serializer.Deserialize<Dictionary<string, object>>(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<object> results = new List<object>();
Expand All @@ -174,7 +178,7 @@ public static object GetJsonValueByKey(string JsonStr, string Keys, int step = 0
return results;
}
else
if (p[Key].GetType() == typeof(Dictionary<string, object>) && step < TolStep - 1)
if (p[Key]?.GetType() == typeof(Dictionary<string, object>) && step < TolStep - 1)
{
Dictionary<string, object> di = (Dictionary<string, object>)p[Key];
return GetJsonValueByKey(di, Keys, step + 1);
Expand Down Expand Up @@ -203,7 +207,7 @@ public static object GetJsonValueByKey(Dictionary<string, object> 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<object> results = new List<object>();
Expand All @@ -214,7 +218,7 @@ public static object GetJsonValueByKey(Dictionary<string, object> JsonObject, st
return results;
}
else
if (JsonObject[Key].GetType() == typeof(Dictionary<string, object>) && step < TolStep - 1)
if (JsonObject[Key]?.GetType() == typeof(Dictionary<string, object>) && step < TolStep - 1)
{
Dictionary<string, object> di = (Dictionary<string, object>)JsonObject[Key];
return GetJsonValueByKey(di, Keys, step + 1);
Expand All @@ -230,6 +234,67 @@ public static object GetJsonValueByKey(Dictionary<string, object> JsonObject, st
}
}

/// <summary>
/// 读取任务列表
/// </summary>
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<string, object> 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);
}
}
}

/// <summary>
/// 保存任务列表
/// </summary>
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
}
}
14 changes: 12 additions & 2 deletions AutoLiveRecorder/Class/Cls_WorkListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,17 @@ public string RoomTitle
/// </summary>
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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions AutoLiveRecorder/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
3 changes: 3 additions & 0 deletions AutoLiveRecorder/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
{
//初始化托盘图标
NotifyIcon.NotifyIcon_Init();

//读取任务列表
Bas.LoadTasks();
}

#endregion Private Methods
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## 开发计划
Expand Down
6 changes: 5 additions & 1 deletion ReleaseHistory.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 0e477d0

Please sign in to comment.