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=基本
|
26=基本
|
||||||
27=なし
|
27=なし
|
||||||
|
|
||||||
|
30=Webサービスでエラーが発生しました。
|
||||||
|
31=コンテンツデータのアップデート中にエラーが発生しました。
|
||||||
|
|
||||||
99=ドユーティー・コンテンツ・プラグイン {0}
|
99=ドユーティー・コンテンツ・プラグイン {0}
|
||||||
|
|
||||||
101=WAVEファイルを選んでください
|
101=WAVEファイルを選んでください
|
||||||
|
|
|
@ -25,6 +25,9 @@ LANG=한국어(액토즈)
|
||||||
26=기본
|
26=기본
|
||||||
27=없음
|
27=없음
|
||||||
|
|
||||||
|
30=웹 요청중 에러 발생
|
||||||
|
31=임무 데이터 업데이트중 에러 발생
|
||||||
|
|
||||||
99=듀티 콘텐츠 플러그인 {0}
|
99=듀티 콘텐츠 플러그인 {0}
|
||||||
|
|
||||||
101=소리 파일을 선택하세요
|
101=소리 파일을 선택하세요
|
||||||
|
|
|
@ -25,6 +25,9 @@ LANG=한국어
|
||||||
26=기본
|
26=기본
|
||||||
27=없음
|
27=없음
|
||||||
|
|
||||||
|
30=웹 요청중 에러 발생
|
||||||
|
31=임무 데이터 업데이트중 에러 발생
|
||||||
|
|
||||||
99=듀티 콘텐츠 플러그인 {0}
|
99=듀티 콘텐츠 플러그인 {0}
|
||||||
|
|
||||||
101=소리 파일을 선택하세요
|
101=소리 파일을 선택하세요
|
||||||
|
|
59
DcContent.cs
59
DcContent.cs
|
@ -54,16 +54,18 @@ namespace DutyContent
|
||||||
// group
|
// group
|
||||||
public class Group
|
public class Group
|
||||||
{
|
{
|
||||||
public string Version { get; set; }
|
public decimal Version { get; set; }
|
||||||
public string Language { get; set; }
|
public string Language { get; set; }
|
||||||
|
public string DisplayLanguage { get; set; }
|
||||||
public Dictionary<int, Roulette> Roulettes { get; set; }
|
public Dictionary<int, Roulette> Roulettes { get; set; }
|
||||||
public Dictionary<int, Instance> Instances { get; set; }
|
public Dictionary<int, Instance> Instances { get; set; }
|
||||||
public Dictionary<int, Area> Areas { 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 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, 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, Instance> Instances { get; private set; } = new Dictionary<int, Instance>();
|
||||||
public static IReadOnlyDictionary<int, Area> Areas { get; private set; } = new Dictionary<int, Area>();
|
public static IReadOnlyDictionary<int, Area> Areas { get; private set; } = new Dictionary<int, Area>();
|
||||||
|
@ -92,40 +94,47 @@ namespace DutyContent
|
||||||
|
|
||||||
|
|
||||||
// parse json
|
// parse json
|
||||||
private static bool Fill(string json)
|
public static bool Fill(string json)
|
||||||
{
|
{
|
||||||
Group data = JsonConvert.DeserializeObject<Group>(json);
|
Group data = JsonConvert.DeserializeObject<Group>(json);
|
||||||
|
|
||||||
Dictionary<int, Fate> fates = new Dictionary<int, Fate>();
|
Dictionary<int, Fate> fates = new Dictionary<int, Fate>();
|
||||||
|
|
||||||
foreach (var area in data.Areas)
|
var version = data.Version;
|
||||||
|
var language = data.Language;
|
||||||
|
|
||||||
|
if (version > Version || language != Language)
|
||||||
{
|
{
|
||||||
foreach (var fate in area.Value.Fates)
|
foreach (var area in data.Areas)
|
||||||
{
|
{
|
||||||
try
|
foreach (var fate in area.Value.Fates)
|
||||||
{
|
{
|
||||||
fate.Value.Area = area.Value;
|
try
|
||||||
fates.Add(fate.Key, fate.Value);
|
{
|
||||||
}
|
fate.Value.Area = area.Value;
|
||||||
catch (NullReferenceException /*nex*/)
|
fates.Add(fate.Key, fate.Value);
|
||||||
{
|
}
|
||||||
MesgLog.E(7, fate.Key);
|
catch (NullReferenceException /*nex*/)
|
||||||
return false;
|
{
|
||||||
}
|
MesgLog.E(7, fate.Key);
|
||||||
catch (Exception ex)
|
return false;
|
||||||
{
|
}
|
||||||
MesgLog.Ex(ex, 8);
|
catch (Exception ex)
|
||||||
return false;
|
{
|
||||||
|
MesgLog.Ex(ex, 8);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Version = data.Version;
|
Version = data.Version;
|
||||||
Language = data.Language;
|
Language = data.Language;
|
||||||
Roulettes = data.Roulettes;
|
DisplayLanguage = data.DisplayLanguage;
|
||||||
Instances = data.Instances;
|
Roulettes = data.Roulettes;
|
||||||
Areas = data.Areas;
|
Instances = data.Instances;
|
||||||
Fates = fates;
|
Areas = data.Areas;
|
||||||
|
Fates = fates;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,8 @@
|
||||||
<Compile Include="ThirdParty\LineDb.cs" />
|
<Compile Include="ThirdParty\LineDb.cs" />
|
||||||
<Compile Include="ThirdParty\NativeMethods.cs" />
|
<Compile Include="ThirdParty\NativeMethods.cs" />
|
||||||
<Compile Include="ThirdParty\ThreadWorker.cs" />
|
<Compile Include="ThirdParty\ThreadWorker.cs" />
|
||||||
|
<Compile Include="ThirdParty\WebApi.cs" />
|
||||||
|
<Compile Include="Updater.cs" />
|
||||||
<Compile Include="WorkerAct.cs" />
|
<Compile Include="WorkerAct.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -25,6 +25,9 @@ LANG=English
|
||||||
26=Default
|
26=Default
|
||||||
27=None
|
27=None
|
||||||
|
|
||||||
|
30=Error requesting web service
|
||||||
|
31=Error while updating duty/FATE Data
|
||||||
|
|
||||||
99=DutyContent Plugin {0}
|
99=DutyContent Plugin {0}
|
||||||
|
|
||||||
101=Select wave file
|
101=Select wave file
|
||||||
|
|
|
@ -7,6 +7,7 @@ using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
@ -46,6 +47,15 @@ namespace DutyContent.Tab
|
||||||
|
|
||||||
if (cboDispLang.SelectedIndex < 0)
|
if (cboDispLang.SelectedIndex < 0)
|
||||||
cboDispLang.SelectedIndex = 0;
|
cboDispLang.SelectedIndex = 0;
|
||||||
|
|
||||||
|
Task.Factory.StartNew(() =>
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
Updater.CheckNewVersion();
|
||||||
|
Thread.Sleep(30 * 60 * 1000);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshLocale()
|
public void RefreshLocale()
|
||||||
|
|
|
@ -43,7 +43,7 @@ namespace DutyContent.Tab
|
||||||
public void PluginInitialize()
|
public void PluginInitialize()
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
lblCurrentDataSet.Text = DcContent.Language;
|
lblCurrentDataSet.Text = DcContent.DisplayLanguage;
|
||||||
|
|
||||||
//
|
//
|
||||||
var lang = MakeDutyLangList();
|
var lang = MakeDutyLangList();
|
||||||
|
@ -534,11 +534,14 @@ namespace DutyContent.Tab
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(l) && !l.Equals(DcConfig.Duty.Language) && DcContent.ReadContent(l))
|
if (!string.IsNullOrWhiteSpace(l) && !l.Equals(DcConfig.Duty.Language) && DcContent.ReadContent(l))
|
||||||
{
|
{
|
||||||
UpdateFates();
|
|
||||||
|
|
||||||
lblCurrentDataSet.Text = DcContent.Language;
|
lblCurrentDataSet.Text = DcContent.DisplayLanguage;
|
||||||
|
|
||||||
SaveConfig();
|
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