Skip to content

Commit

Permalink
Monakeyの即時保存処理 #6
Browse files Browse the repository at this point in the history
  • Loading branch information
onihusube committed May 26, 2022
1 parent 9040b03 commit 875e562
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 25 deletions.
5 changes: 3 additions & 2 deletions 2chAPIProxy/DatProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using _2chAPIProxy.APIMediator;
using System.Security.Cryptography;
using System.Threading;
using System.ComponentModel;

namespace _2chAPIProxy
{
Expand All @@ -22,7 +23,7 @@ class IPAuthData
public String nonce = "";
}

public class DatProxy
public class DatProxy : ViewModels.VMBase
{
Dictionary<String, String> Cookie = new Dictionary<string, string>();
Dictionary<String, IPAuthData> AuthIPList = new Dictionary<string, IPAuthData>();
Expand Down Expand Up @@ -996,7 +997,7 @@ public string Monakey
}
else
{
monakey = value;
_ = SetProperty(ref monakey, value, nameof(Monakey));
}
}
}
Expand Down
54 changes: 31 additions & 23 deletions 2chAPIProxy/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ public void Init()
DatProxy.HtmlConverter.IsHttpsReplace = _ReplaceHttpsLink;
DatProxy.HtmlConverter.IsExternalConverterUse = _CEExternalRead;

// Monakeyの即時保存処理
DatProxy.PropertyChanged += (sender, e) =>
{
if (e.PropertyName == nameof(DatProxy.Monakey))
{
// Monakeyを保存
Setting.Monakey = DatProxy.Monakey;
SaveSettings();
}
};

//エラー通知用コールバック登録
DatProxy.APIMediator.PropertyChanged += (sender, e) =>
{
Expand Down Expand Up @@ -348,6 +359,16 @@ private void HtmlConverter_PropertyChanged(object sender, PropertyChangedEventAr
throw new NotImplementedException();
}

private void SaveSettings()
{
XmlSerializer xser = new XmlSerializer(typeof(AppSetting));
using (StreamWriter sw = new StreamWriter("./settings.xml", false, Encoding.UTF8))
{
xser.Serialize(sw, Setting);
}
Setting.change = false;
}

public void BeforeShutdown()
{
using (TaskTrayIcon)
Expand All @@ -371,17 +392,10 @@ public void BeforeShutdown()
}
catch (ArgumentException) { }
}

// Monakeyが更新されてたら保存
if (Setting.Monakey != DatProxy.Monakey) Setting.Monakey = DatProxy.Monakey;

if (Setting.change)
{
XmlSerializer xser = new XmlSerializer(typeof(AppSetting));
using (StreamWriter sw = new StreamWriter("./settings.xml", false, Encoding.UTF8))
{
xser.Serialize(sw, Setting);
}
SaveSettings();
}
System.Windows.Application.Current.Shutdown();
}
Expand Down Expand Up @@ -1303,14 +1317,12 @@ public RelayCommand<String> OnClick
}
}));
});
XmlSerializer xser = new XmlSerializer(typeof(AppSetting));
using (StreamWriter sw = new StreamWriter("./settings.xml", false, Encoding.UTF8))
{
xser.Serialize(sw, Setting);
Setting.change = false;
SystemLog = "現在の設定を保存しました。";
this.PopupVisible = true;
}
// 無条件設定保存と通知
SaveSettings();
SystemLog = "現在の設定を保存しました。";
this.PopupVisible = true;
// Monakeyをリセット
DatProxy.ResetMonakey();
break;
Expand Down Expand Up @@ -1428,13 +1440,9 @@ public RelayCommand SaveSetting
{
if (_SaveSetting == null) _SaveSetting = new RelayCommand(() =>
{
XmlSerializer xser = new XmlSerializer(typeof(AppSetting));
using (StreamWriter sw = new StreamWriter("./settings.xml", false, Encoding.UTF8))
{
xser.Serialize(sw, Setting);
Setting.change = false;
SystemLog = "現在の設定を保存しました。";
}
// 無条件設定保存と通知
SaveSettings();
SystemLog = "現在の設定を保存しました。";
// Monakeyをリセット
DatProxy.ResetMonakey();
Expand Down
51 changes: 51 additions & 0 deletions doc/書き込み新仕様関連.md
Original file line number Diff line number Diff line change
Expand Up @@ -1163,4 +1163,55 @@ Content-Encoding:
Content-Type:text/html; charset=Shift_JIS
Date:Sun, 24 Apr 2022 09:26:42 GMT
Server:cloudflare
```


# 失敗(鍵の有効期限が切れています)

2022/05/27、鍵の期限切れパターンはこっち?

```
オリジナルリクエストヘッダ
Host:egg.5ch.net
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language:ja,en-US;q=0.7,en;q=0.3
Accept-Encoding:gzip, deflate
Referer:http://egg.5ch.net/test/read.cgi/software/1652008003/
Upgrade-Insecure-Requests:1
Content-Type:application/x-www-form-urlencoded
Content-Length:158
Connection:keep-alive
リクエストヘッダ
Referer:https://egg.5ch.net/test/read.cgi/software/1652008003/
X-PostSig:93a1a370926e9ceb8bca8e829847faefff9675155c2106cf249ab52b12d7dcac
X-APIKey:8yoeAcaLXiEY1FjEuJBKgkPxirkDqn
X-PostNonce:1653578637.547
X-MonaKey:b1fd22457df0fc0d096dbeb719f15a006449599cb5d181e0d90bdc382c91f964
X-2ch-UA:2chMate/0.8.10.153
User-Agent:Monazilla/1.00 2chMate/0.8.10.153 Dalvik/2.1.0 (Linux; U; Android 11; SC-52B Build/RP1A.200720.012; 60)
Accept-Encoding:gzip
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:egg.5ch.net
Content-Length:175
レスポンスヘッダ
Connection:close
X-InqID:egg/71178b84c8b7fcc9;
X-Robots-Tag:noindex;
X-Chx-Error:E3324 Expired key.;
X-PostPlace:software/1652008003
X-RONIN-Stat:NONE
X-Condition:0/0
X-Proc-Time:0.017456 sec.
X-BBx-Stat:180.60.38.129, NONE
Vary:Accept-Encoding
CF-Cache-Status:DYNAMIC
Expect-CT:max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
CF-RAY:71178b84c8b7fcc9-KIX
Content-Encoding:
Content-Type:text/html; charset=Shift_JIS
Date:Thu, 26 May 2022 15:29:13 GMT
Server:cloudflare
```

0 comments on commit 875e562

Please sign in to comment.