add an updater (#9)
* add an updator * change update branch * make updater work * change update branch * make work * add new line * add exception log + clean up
This commit is contained in:
parent
43911d0c81
commit
5228a2eb6c
10 changed files with 131 additions and 28 deletions
|
@ -25,6 +25,9 @@ LANG=日本語
|
|||
26=基本
|
||||
27=なし
|
||||
|
||||
30=Webサービスでエラーが発生しました。
|
||||
31=コンテンツデータのアップデート中にエラーが発生しました。
|
||||
|
||||
99=ドユーティー・コンテンツ・プラグイン {0}
|
||||
|
||||
101=WAVEファイルを選んでください
|
||||
|
|
|
@ -25,6 +25,9 @@ LANG=한국어(액토즈)
|
|||
26=기본
|
||||
27=없음
|
||||
|
||||
30=웹 요청중 에러 발생
|
||||
31=임무 데이터 업데이트중 에러 발생
|
||||
|
||||
99=듀티 콘텐츠 플러그인 {0}
|
||||
|
||||
101=소리 파일을 선택하세요
|
||||
|
|
|
@ -25,6 +25,9 @@ LANG=한국어
|
|||
26=기본
|
||||
27=없음
|
||||
|
||||
30=웹 요청중 에러 발생
|
||||
31=임무 데이터 업데이트중 에러 발생
|
||||
|
||||
99=듀티 콘텐츠 플러그인 {0}
|
||||
|
||||
101=소리 파일을 선택하세요
|
||||
|
|
15
DcContent.cs
15
DcContent.cs
|
@ -54,16 +54,18 @@ namespace DutyContent
|
|||
// group
|
||||
public class Group
|
||||
{
|
||||
public string Version { get; set; }
|
||||
public decimal Version { get; set; }
|
||||
public string Language { get; set; }
|
||||
public string DisplayLanguage { get; set; }
|
||||
public Dictionary<int, Roulette> Roulettes { get; set; }
|
||||
public Dictionary<int, Instance> Instances { get; set; }
|
||||
public Dictionary<int, Area> Areas { get; set; }
|
||||
}
|
||||
|
||||
//
|
||||
public static string Version { get; private set; }
|
||||
public static decimal Version { get; private set; } = 0;
|
||||
public static string Language { get; private set; }
|
||||
public static string DisplayLanguage { get; private set; }
|
||||
public static IReadOnlyDictionary<int, Roulette> Roulettes { get; private set; } = new Dictionary<int, Roulette>();
|
||||
public static IReadOnlyDictionary<int, Instance> Instances { get; private set; } = new Dictionary<int, Instance>();
|
||||
public static IReadOnlyDictionary<int, Area> Areas { get; private set; } = new Dictionary<int, Area>();
|
||||
|
@ -92,12 +94,17 @@ namespace DutyContent
|
|||
|
||||
|
||||
// parse json
|
||||
private static bool Fill(string json)
|
||||
public static bool Fill(string json)
|
||||
{
|
||||
Group data = JsonConvert.DeserializeObject<Group>(json);
|
||||
|
||||
Dictionary<int, Fate> fates = new Dictionary<int, Fate>();
|
||||
|
||||
var version = data.Version;
|
||||
var language = data.Language;
|
||||
|
||||
if (version > Version || language != Language)
|
||||
{
|
||||
foreach (var area in data.Areas)
|
||||
{
|
||||
foreach (var fate in area.Value.Fates)
|
||||
|
@ -122,10 +129,12 @@ namespace DutyContent
|
|||
|
||||
Version = data.Version;
|
||||
Language = data.Language;
|
||||
DisplayLanguage = data.DisplayLanguage;
|
||||
Roulettes = data.Roulettes;
|
||||
Instances = data.Instances;
|
||||
Areas = data.Areas;
|
||||
Fates = fates;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -105,6 +105,8 @@
|
|||
<Compile Include="ThirdParty\LineDb.cs" />
|
||||
<Compile Include="ThirdParty\NativeMethods.cs" />
|
||||
<Compile Include="ThirdParty\ThreadWorker.cs" />
|
||||
<Compile Include="ThirdParty\WebApi.cs" />
|
||||
<Compile Include="Updater.cs" />
|
||||
<Compile Include="WorkerAct.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -25,6 +25,9 @@ LANG=English
|
|||
26=Default
|
||||
27=None
|
||||
|
||||
30=Error requesting web service
|
||||
31=Error while updating duty/FATE Data
|
||||
|
||||
99=DutyContent Plugin {0}
|
||||
|
||||
101=Select wave file
|
||||
|
|
|
@ -7,6 +7,7 @@ using System.Drawing;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -46,6 +47,15 @@ namespace DutyContent.Tab
|
|||
|
||||
if (cboDispLang.SelectedIndex < 0)
|
||||
cboDispLang.SelectedIndex = 0;
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Updater.CheckNewVersion();
|
||||
Thread.Sleep(30 * 60 * 1000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void RefreshLocale()
|
||||
|
|
|
@ -43,7 +43,7 @@ namespace DutyContent.Tab
|
|||
public void PluginInitialize()
|
||||
{
|
||||
//
|
||||
lblCurrentDataSet.Text = DcContent.Language;
|
||||
lblCurrentDataSet.Text = DcContent.DisplayLanguage;
|
||||
|
||||
//
|
||||
var lang = MakeDutyLangList();
|
||||
|
@ -534,11 +534,14 @@ namespace DutyContent.Tab
|
|||
|
||||
if (!string.IsNullOrWhiteSpace(l) && !l.Equals(DcConfig.Duty.Language) && DcContent.ReadContent(l))
|
||||
{
|
||||
UpdateFates();
|
||||
|
||||
lblCurrentDataSet.Text = DcContent.Language;
|
||||
lblCurrentDataSet.Text = DcContent.DisplayLanguage;
|
||||
|
||||
SaveConfig();
|
||||
|
||||
Updater.CheckNewVersion();
|
||||
|
||||
UpdateFates();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
42
ThirdParty/WebApi.cs
vendored
Normal file
42
ThirdParty/WebApi.cs
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Cache;
|
||||
using System.Text;
|
||||
|
||||
namespace DutyContent
|
||||
{
|
||||
internal static class WebApi
|
||||
{
|
||||
internal static string Request(string urlfmt, params object[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
var url = string.Format(urlfmt, args);
|
||||
|
||||
ServicePointManager.Expect100Continue = true;
|
||||
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
|
||||
ServicePointManager.DefaultConnectionLimit = 9999;
|
||||
|
||||
var request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.UserAgent = "DFA";
|
||||
request.Timeout = 10000;
|
||||
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
|
||||
using (var response = (HttpWebResponse)request.GetResponse())
|
||||
{
|
||||
var encoding = Encoding.GetEncoding(response.CharacterSet);
|
||||
|
||||
using (var responseStream = response.GetResponseStream())
|
||||
using (var reader = new StreamReader(responseStream, encoding))
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MesgLog.Ex(ex, 30);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
25
Updater.cs
Normal file
25
Updater.cs
Normal file
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DutyContent
|
||||
{
|
||||
internal class Updater
|
||||
{
|
||||
internal static void CheckNewVersion()
|
||||
{
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = WebApi.Request($"https://raw.githubusercontent.com/kshman/DutyContent/main/Data/DcDuty-{DcContent.Language}.json");
|
||||
DcContent.Fill(json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MesgLog.Ex(ex, 31);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue