Skip to content

Commit

Permalink
可能なら過去ログ倉庫からdatを取得できるように設定の再解釈と調整 #12
Browse files Browse the repository at this point in the history
「offlaw2/Rokkaへのアクセス置換時のみHTML変換する」設定を、通常datアクセス時のdat落ち検出時に変換して応答しない(過去ログ倉庫へのアクセスを専ブラに試みさせる)という意味に変更

動作としては、「過去ログをHTMLから変換する」をオンにしたうえで
dat落ち即変換(これまで通り)したい => 「dat落ちを直接HTML変換で応答しない」をオフに
可能なら過去ログ倉庫からdatを取得したい => 「dat落ちを直接HTML変換で応答しない」と「過去ログ倉庫へのアクセス置換する」を両方オン
過去ログ倉庫からdatを取得するがHTML変換はしてほしくない => 「dat落ちを直接HTML変換で応答しない」をオンにし「過去ログ倉庫へのアクセス置換する」をオフにする
  • Loading branch information
onihusube committed Jul 18, 2023
1 parent 9c10997 commit bf06e21
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
24 changes: 11 additions & 13 deletions 2chAPIProxy/DatProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class DatProxy : ViewModels.VMBase
public bool gZipRes { get; set; }
public bool ChunkRes { get; set; }
public bool SocksPoxy { get; set; }
public bool OnlyORPerm { get; set; }
public bool NotReplaceNormalDatAccess { get; set; }
public bool CRReplace { get; set; }
public bool KakolinkPerm { get; set; }
public bool AllUAReplace { get; set; }
Expand Down Expand Up @@ -515,7 +515,7 @@ private bool OtherLinkHTMLTrance(ref Session oSession)
}
});
}
else if (KakolinkPerm && !OnlyORPerm && CheckKakouri2.IsMatch(oSession.fullUrl))
else if (KakolinkPerm && CheckKakouri2.IsMatch(oSession.fullUrl))
{
//kakoリンクのHTML変換応答置換
offlowperm = false;
Expand Down Expand Up @@ -1567,16 +1567,14 @@ private void intervene_in_dat_response(ref Session oSession, bool is2ch, string
case 302:
// dat落ち

// 過去ログ倉庫へのアクセスのレスポンス時で、過去ログ倉庫へのアクセス置換が無効の場合
if (accessing_kakolog && KakolinkPerm == false)
// 過去ログのHTML変換を行うかどうかを判定
bool is_convert = accessing_kakolog switch
{
// 何もしない
return;
}
true => GetHTML && KakolinkPerm, // 過去ログ倉庫で見つからなかった場合 : 過去ログ変換が有効 かつ 過去ログ倉庫へのアクセス置換が有効
false => GetHTML && !NotReplaceNormalDatAccess // 通常datアクセス時にdat落ちの場合 : 過去ログ変換が有効 かつ dat落ち検出時の変換が有効
};

// 過去ログ倉庫へのアクセスを優先させたい場合、ここでHTML変換を行わない方が良い可能性がある?
// ここで変換してしまうと、過去ログ倉庫へのアクセスがそもそも発生しえないため・・・
if (GetHTML && !OnlyORPerm)
if (is_convert)
{
// html変換 and 差分応答
String last = oSession.oRequest.headers["If-Modified-Since"], hrange = oSession.oRequest.headers["Range"];
Expand Down Expand Up @@ -1653,7 +1651,7 @@ private void intervene_in_dat_response(ref Session oSession, bool is2ch, string
}
catch (Exception err)
{
ViewModel.OnModelNotice("datアクセス部でエラーです\n" + err.ToString());
ViewModel.OnModelNotice("dat応答介入時にエラーです\n" + err.ToString());
}
}

Expand Down Expand Up @@ -1824,7 +1822,7 @@ private void GetDat(ref Session oSession, bool is2ch)
if (gZipRes) oSession.utilGZIPResponse();
break;
case HttpStatusCode.NotImplemented:
if (!GetHTML || OnlyORPerm)
if (!GetHTML || NotReplaceNormalDatAccess)
{
oSession.oResponse.headers.HTTPResponseCode = 302;
oSession.oResponse.headers.HTTPResponseStatus = "302 Found";
Expand Down Expand Up @@ -1878,7 +1876,7 @@ private void GetDat(ref Session oSession, bool is2ch)
case HttpStatusCode.InternalServerError:
Byte[] Htmldat = null;
String uri = @"https://" + ch2uri.Groups[1].Value + "." + ch2uri.Groups[2].Value + "/test/read.cgi/" + ch2uri.Groups[3].Value + @"/" + ch2uri.Groups[4].Value + @"/";
if (GetHTML && !OnlyORPerm)
if (GetHTML && !NotReplaceNormalDatAccess)
{
String UA = oSession.oRequest.headers["User-Agent"];
System.Threading.Thread HtmlTranceThread = new System.Threading.Thread(() =>
Expand Down
6 changes: 3 additions & 3 deletions 2chAPIProxy/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:_2chAPIProxy" mc:Ignorable="d" x:Class="_2chAPIProxy.MainWindow"
Title="2chAPIProxy Ver:2023.07.13 nonAPI test" Height="480" Width="640"
Title="2chAPIProxy Ver:2023.07.19 nonAPI test" Height="480" Width="640"
Icon="icon3.ico" WindowStartupLocation="CenterScreen" ResizeMode="CanMinimize" Background="White" d:DataContext="{d:DesignInstance {x:Type local:ViewModel}}">
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+S" Command="{Binding SaveSetting}"/>
Expand Down Expand Up @@ -168,7 +168,7 @@
</Style>
</CheckBox.Style>
</CheckBox>
<CheckBox x:Name="OnlyORPerm" Content="offlaw2/Rokkaへのアクセス置換時のみHTML変換する" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="291,62,0,0" Height="20" IsChecked="{Binding OnlyORPerm, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" ToolTip="HTMLからの過去ログ取得をofflaw2/Rokkaアクセス置換時のみ行います。專ブラが対応していれば、HTMLからの過去ログ取得時のレスのずれが起こらなくなります" Tag="" TabIndex="4">
<CheckBox x:Name="NotReplaceNormalDatAccess" Content="dat落ちを直接HTML変換で応答しない" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="291,37,0,0" Height="20" IsChecked="{Binding NotReplaceNormalDatAccess, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" ToolTip="過去ログ倉庫/offlaw2/RokkaへのアクセスのみをHTML変換で応答します。offlaw2/Rokkaの場合は專ブラが対応していればレスずれが起こらなくなります" Tag="" TabIndex="2">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="FontSize" Value="12px"/>
Expand Down Expand Up @@ -277,7 +277,7 @@
</Popup>
</StackPanel>
</Button>
<CheckBox x:Name="KakolinkPermutation" Content="過去ログ倉庫へのアクセスを置換する" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="291,37,0,0" Height="20" ToolTip="過去ログ倉庫(/kako/を含むリンク)へのアクセスをHTML変換したdatで返します" IsChecked="{Binding KakolinkPermutation, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True}" TabIndex="2">
<CheckBox x:Name="KakolinkPermutation" Content="過去ログ倉庫へのアクセスを置換する" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="291,62,0,0" Height="20" ToolTip="過去ログ倉庫(/kako/を含むリンク)で過去ログが見つからなかった場合にHTML変換したdatで返します" IsChecked="{Binding KakolinkPermutation, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True}" TabIndex="4">
<CheckBox.Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="FontSize" Value="12px"/>
Expand Down
20 changes: 10 additions & 10 deletions 2chAPIProxy/ViewModels/ViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ViewModelImpl()
_KakotoHTML = Setting.KakotoHTML;
_OfflawRokkaPermutation = Setting.OfflawRokkaPermutation;
_AllReturn = Setting.AllReturn;
_OnlyORPerm = Setting.OnlyORPerm;
_NotReplaceNormalDatAccess = Setting.OnlyORPerm;
_ChunkedResponse = Setting.ChunkedResponse;
_SyncEnd = Setting.SyncEnd;
_WANAccess = Setting.WANAccess;
Expand Down Expand Up @@ -193,7 +193,7 @@ public void Init()
DatProxy.SocksPoxy = Socks4aProxy;
DatProxy.gZipRes = gZipResponse;
DatProxy.ChunkRes = ChunkedResponse;
DatProxy.OnlyORPerm = OnlyORPerm;
DatProxy.NotReplaceNormalDatAccess = NotReplaceNormalDatAccess;
DatProxy.CRReplace = CRReplace;
DatProxy.KakolinkPerm = KakolinkPermutation;
DatProxy.AllUAReplace = (UserAgent3 == "") ? (false) : (AllUAReplace);
Expand Down Expand Up @@ -554,8 +554,8 @@ public bool OfflawRokkaPermutation
if (_OfflawRokkaPermutation != value)
{
DatProxy.OfflawRokkaPerm = Setting.OfflawRokkaPermutation = _OfflawRokkaPermutation = value;
if (!value) DatProxy.OnlyORPerm = false;
else DatProxy.OnlyORPerm = OnlyORPerm;
if (!value) DatProxy.NotReplaceNormalDatAccess = false;
else DatProxy.NotReplaceNormalDatAccess = NotReplaceNormalDatAccess;
NoticePropertyChanged("OfflawRokkaPermutation");
}
}
Expand All @@ -576,16 +576,16 @@ public bool AllReturn
}
}

bool _OnlyORPerm;
public bool OnlyORPerm
bool _NotReplaceNormalDatAccess;
public bool NotReplaceNormalDatAccess
{
get { return _OnlyORPerm; }
get { return _NotReplaceNormalDatAccess; }
set
{
if (_OnlyORPerm != value)
if (_NotReplaceNormalDatAccess != value)
{
DatProxy.OnlyORPerm = Setting.OnlyORPerm = _OnlyORPerm = value;
NoticePropertyChanged("OnlyORPerm");
DatProxy.NotReplaceNormalDatAccess = Setting.OnlyORPerm = _NotReplaceNormalDatAccess = value;
NoticePropertyChanged("NotReplaceNormalDatAccess");
}
}
}
Expand Down

0 comments on commit bf06e21

Please sign in to comment.