1using System.Globalization;
23 public string Title =
string.Empty;
27 public string Time =
string.Empty;
35 public string Name =
string.Empty;
81 string url =
string.Format(
94 ex => {
Log.
Warning($
"Failed processing Update check. Reason: {ex.Message}"); }
105 delegate(
byte[] result) {
107 string motdLastDownloadedData =
UnpackMotd(result);
112 catch (Exception ex) {
113 Log.
Warning($
"Failed processing MOTD string. Reason: {ex.Message}");
116 delegate(Exception error) {
Log.
Warning($
"Failed downloading MOTD. Reason: {error.Message}"); }
161 using (MemoryStream stream =
new(data)) {
162 return new StreamReader(stream).ReadToEnd();
169 int num = dataString.IndexOf(
"<Motd");
171 throw new InvalidOperationException(
"Invalid MOTD data string.");
173 int num2 = dataString.IndexOf(
"</Motd>");
182 foreach (XElement item2
in xElement.Elements()) {
187 message.Lines.Add(item);
194 catch (Exception ex) {
195 Log.
Warning($
"Failed extracting MOTD string. Reason: {ex.Message}");
201 int num = dataString.IndexOf(
"<Motd2");
203 throw new InvalidOperationException(
"Invalid MOTD2 data string.");
205 int num2 = dataString.IndexOf(
"</Motd2>");
211 string languageType = !
ModsManager.
Configs.TryGetValue(
"Language", out
string config) ?
"zh-CN" : config;
212 foreach (XElement item
in xElement.Elements()) {
213 if (item.Name.LocalName ==
"Bulletin") {
214 XAttribute title = item.Attribute(
"Title");
218 XAttribute enTitle = item.Attribute(
"EnTitle");
219 if (enTitle ==
null) {
222 XAttribute time = item.Attribute(
"Time");
226 XElement content = item.Element(
"Content");
227 if (content ==
null) {
230 XElement enContent = item.Element(
"EnContent");
231 if (enContent ==
null) {
236 EnTitle = enTitle.Value,
237 Time = $
"{languageType}${time.Value}",
238 Content = content.Value,
239 EnContent = enContent.Value
249 failure(
new InvalidOperationException(
"Internet connection is unavailable."));
252 Dictionary<string, string> header =
new() { {
"Content-Type",
"application/x-www-form-urlencoded" } };
255 "https://m.schub.top/com/api/zh/setnotice",
266 int num = dataString.IndexOf(
"<Motd3");
268 throw new InvalidOperationException(
"Invalid MOTD3 data string.");
270 int num2 = dataString.IndexOf(
"</Motd3>");
277 foreach (XElement item
in xElement.Elements()) {
278 if (item.Name.LocalName ==
"FilterMod") {
279 XAttribute name = item.Attribute(
"Name");
283 XAttribute packageName = item.Attribute(
"PackageName");
284 if (packageName ==
null) {
287 XAttribute version = item.Attribute(
"Version");
288 if (version ==
null) {
291 XAttribute filterAPIVersion = item.Attribute(
"FilterAPIVersion");
292 if (filterAPIVersion ==
null) {
297 PackageName = packageName.Value,
298 Version = version.Value,
299 FilterAPIVersion = filterAPIVersion.Value,
300 Explanation = item.Value
309 string time =
m_bulletin.Time.Contains(
'$') ?
m_bulletin.Time.Split(
'$', StringSplitOptions.RemoveEmptyEntries)[1] :
string.Empty;
310 if (!
string.IsNullOrEmpty(time)) {
327 delegate(
string inputTitle) {
332 contentLabel.
Text.Replace(
"\n",
"[n]"),
334 delegate(
string inputContent) {
335 if (!
string.IsNullOrEmpty(inputTitle)
336 && !
string.IsNullOrEmpty(inputContent)) {
337 titleLabel.Text = inputTitle;
338 contentLabel.Text = inputContent.Replace(
"[n]",
"\n");
340 m_bulletin.Title = titleLabel.
Text;
341 m_bulletin.Content = contentLabel.
Text;
344 m_bulletin.EnTitle = titleLabel.
Text;
345 m_bulletin.EnContent = contentLabel.
Text;
350 m_bulletin.Time = $
"{languageType}${DateTime.Now}";
353 delegate(
TextBoxWidget textBox) { textBox.Text = textBox.
Text.Replace(
"\n",
"[n]"); }
365 foreach (XElement item
in xElement.Elements()) {
366 if (item.Name.LocalName ==
"Bulletin") {
368 XAttribute titleAttribute = item.Attribute(
"Title");
369 if (titleAttribute !=
null) {
370 titleAttribute.Value = titleLabel.
m_text;
372 XAttribute contentAttribute = item.Attribute(
"Content");
373 if (contentAttribute !=
null) {
374 contentAttribute.Value = contentLabel.
m_text;
378 XAttribute enTitleAttribute = item.Attribute(
"EnTitle");
379 if (enTitleAttribute !=
null) {
380 enTitleAttribute.Value = titleLabel.
m_text;
382 XAttribute enContentAttribute = item.Attribute(
"EnContent");
383 if (enContentAttribute !=
null) {
384 enContentAttribute.Value = contentLabel.
m_text;
387 XAttribute timeAttribute = item.Attribute(
"Time");
388 if (timeAttribute !=
null) {
389 timeAttribute.Value = DateTime.Now.ToString(CultureInfo.InvariantCulture);
395 newDownloadedData += xElement.ToString();
402 delegate(
byte[] data) {
405 bool success = result[0].GetInt32() == 200;
406 string msg = success ?
"公告已更新,建议重启游戏检查效果" : result[1].GetString();
412 delegate(Exception e) {
420 bulletinDialog.m_editButton.IsVisible =
m_isAdmin;
421 bulletinDialog.m_updateButton.IsVisible =
m_isAdmin;
425 catch (Exception ex) {
426 Log.
Warning($
"Failed ShowBulletin. Reason: {ex.Message}");
431 string languageType = !
ModsManager.
Configs.TryGetValue(
"Language", out
string value) ?
"zh-CN" : value;
432 return languageType ==
"zh-CN";
436 string languageType = !
ModsManager.
Configs.TryGetValue(
"Language", out
string value) ?
"zh-CN" : value;
static void Information(object message)
static void Warning(object message)
CancellableProgress Progress
static void HideDialog(Dialog dialog)
static void ShowDialog(ContainerWidget parentWidget, Dialog dialog)
static readonly JsonDocumentOptions DefaultJsonOptions
static string LName()
当前设置中的语言的标识符,如果是在加载完成后获取语言,建议改用CurrentLanguageName
static Action MessageOfTheDayUpdated
static void LoadFilterMods(string dataString)
static Bulletin m_bulletin
static bool IsCNLanguageType()
static JsonDocument UpdateResult
static void ShowBulletin()
static List< FilterMod > FilterModAll
static string GetMotdUrl()
static bool CanDownloadMotd
static void ForceRedownload()
static string UnpackMotd(byte[] data)
static bool CanShowBulletin
static Message MessageOfTheDay
static void UpdateVersion()
static Message ParseMotd(string dataString)
static void LoadBulletin(string dataString)
static void SaveBulletin(string dataString, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
static void DownloadMotd()
static double MotdUpdatePeriodHours
static string MotdUpdateUrl
static string MotdUpdateCheckUrl
static string BulletinTime
static string ScpboxAccessToken
static DateTime MotdLastUpdateTime
static string MotdLastDownloadedData
static string SerializationVersion
static string LastLaunchedVersion
static string PlatformString
static void Post(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, Stream data, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
static bool IsInternetConnectionAvailable()
static MemoryStream UrlParametersToStream(Dictionary< string, string > values)
static void Get(string address, Dictionary< string, string > parameters, Dictionary< string, string > headers, CancellableProgress progress, Action< byte[]> success, Action< Exception > failure)
static string APIVersionString
static Dictionary< string, string > Configs
static object GetAttributeValue(XElement node, string attributeName, Type type)
static XElement LoadXmlFromString(string data, bool throwOnError)