| 1 |
hi_ |
1.1 |
unit Favorite; |
| 2 |
|
|
|
| 3 |
|
|
interface |
| 4 |
|
|
|
| 5 |
|
|
uses |
| 6 |
yoffy |
1.2 |
Messages, SysUtils, Classes, Contnrs, ComCtrls, {HttpApp,} YofUtils, |
| 7 |
h677 |
1.21 |
GikoSystem{, XMLIntf, XMLDoc}, GikoXMLDoc, BoardGroup, windows, |
| 8 |
|
|
MojuUtils; |
| 9 |
hi_ |
1.1 |
{SAX, SAXHelpers, SAXComps, SAXKW;} |
| 10 |
|
|
|
| 11 |
|
|
type |
| 12 |
|
|
TFavoriteFolder = class |
| 13 |
|
|
end; |
| 14 |
|
|
|
| 15 |
|
|
TFavoriteBoardItem = class |
| 16 |
|
|
private |
| 17 |
yoffy |
1.5 |
FItem : TBoard; |
| 18 |
yoffy |
1.7 |
FURL : string; |
| 19 |
yoffy |
1.5 |
FTitle : string; |
| 20 |
yoffy |
1.9 |
function GetItem : TBoard; |
| 21 |
hi_ |
1.1 |
public |
| 22 |
yoffy |
1.7 |
constructor Create( inURL : string; inTitle : string = ''; inItem : TBoard = nil ); |
| 23 |
yoffy |
1.12 |
constructor CreateWithItem( inItem : TBoard ); |
| 24 |
h677 |
1.26 |
destructor Destory; |
| 25 |
yoffy |
1.9 |
property Item : TBoard read GetItem write FItem; |
| 26 |
yoffy |
1.7 |
property URL : string read FURL write FURL; // Item ?????転?長?鼎???足???? URL ???鱈???徹???????辿 |
| 27 |
yoffy |
1.5 |
property Title : string read FTitle write FTitle; |
| 28 |
hi_ |
1.1 |
end; |
| 29 |
|
|
|
| 30 |
|
|
TFavoriteThreadItem = class |
| 31 |
|
|
private |
| 32 |
yoffy |
1.5 |
FItem : TThreadItem; |
| 33 |
yoffy |
1.7 |
FURL : string; |
| 34 |
yoffy |
1.5 |
FTitle : string; |
| 35 |
yoffy |
1.9 |
function GetItem : TThreadItem; |
| 36 |
hi_ |
1.1 |
public |
| 37 |
yoffy |
1.7 |
constructor Create( inURL : string; inTitle : string = ''; inItem : TThreadItem = nil ); |
| 38 |
yoffy |
1.12 |
constructor CreateWithItem( inItem : TThreadItem ); |
| 39 |
h677 |
1.26 |
destructor Destory; |
| 40 |
yoffy |
1.9 |
property Item : TThreadItem read GetItem write FItem; |
| 41 |
yoffy |
1.7 |
property URL : string read FURL write FURL; // Item ?????転?長?鼎???足???? URL ???鱈???徹???????辿 |
| 42 |
yoffy |
1.5 |
property Title : string read FTitle write FTitle; |
| 43 |
hi_ |
1.1 |
end; |
| 44 |
|
|
|
| 45 |
|
|
TFavoriteDM = class(TDataModule) |
| 46 |
|
|
procedure DataModuleDestroy(Sender: TObject); |
| 47 |
|
|
private |
| 48 |
|
|
{ Private ?辿?転 } |
| 49 |
|
|
FStack: TStack; |
| 50 |
|
|
FTreeView: TTreeView; |
| 51 |
|
|
|
| 52 |
|
|
procedure ReadNode(Node: IXMLNode); |
| 53 |
yoffy |
1.2 |
procedure AddSaveString(Node: TTreeNode; SaveList: TStringList); |
| 54 |
|
|
// procedure AddSaveString(Node: TTreeNode; XMLNode: IXMLNode); |
| 55 |
hi_ |
1.1 |
// procedure SAXStartDocument(Sender: TObject); |
| 56 |
|
|
// procedure SAXEndDocument(Sender: TObject); |
| 57 |
|
|
// procedure SAXStartElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString; const Atts: IAttributes); |
| 58 |
|
|
// procedure SAXEndElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString); |
| 59 |
|
|
// procedure SAXCharacters(Sender: TObject; const PCh: SAXString); |
| 60 |
|
|
public |
| 61 |
|
|
{ Public ?辿?転 } |
| 62 |
h677 |
1.27 |
procedure Clear; |
| 63 |
yoffy |
1.7 |
function GetFavoriteFilePath() : String; |
| 64 |
|
|
function SaveFavoriteFile(FileName: String) : Boolean; |
| 65 |
hi_ |
1.1 |
procedure SetFavTreeView(TreeView: TTreeView); |
| 66 |
|
|
procedure ReadFavorite; |
| 67 |
|
|
procedure WriteFavorite; |
| 68 |
h677 |
1.21 |
procedure URLReplace(oldURLs: TStringList; newURLs: TStringList); |
| 69 |
hi_ |
1.1 |
property TreeView: TTreeView read FTreeView; |
| 70 |
|
|
end; |
| 71 |
|
|
|
| 72 |
|
|
var |
| 73 |
|
|
FavoriteDM: TFavoriteDM; |
| 74 |
|
|
const |
| 75 |
|
|
FAVORITE_LINK_NAME = '?????N'; |
| 76 |
|
|
|
| 77 |
|
|
implementation |
| 78 |
|
|
|
| 79 |
yoffy |
1.5 |
uses ExternalBoardManager, ExternalBoardPlugInMain; |
| 80 |
|
|
|
| 81 |
hi_ |
1.1 |
const |
| 82 |
|
|
FAVORITE_ROOT_NAME = '?即?C???端??'; |
| 83 |
|
|
FAVORITE_FILE_NAME = 'Favorite.xml'; |
| 84 |
|
|
|
| 85 |
|
|
{$R *.dfm} |
| 86 |
|
|
|
| 87 |
yoffy |
1.7 |
constructor TFavoriteBoardItem.Create( |
| 88 |
|
|
inURL : string; |
| 89 |
|
|
inTitle : string = ''; |
| 90 |
|
|
inItem : TBoard = nil |
| 91 |
|
|
); |
| 92 |
|
|
begin |
| 93 |
|
|
|
| 94 |
|
|
inherited Create; |
| 95 |
|
|
|
| 96 |
|
|
URL := inURL; |
| 97 |
|
|
Title := inTitle; |
| 98 |
|
|
Item := inItem; |
| 99 |
|
|
|
| 100 |
|
|
end; |
| 101 |
|
|
|
| 102 |
yoffy |
1.12 |
constructor TFavoriteBoardItem.CreateWithItem( |
| 103 |
|
|
inItem : TBoard |
| 104 |
|
|
); |
| 105 |
|
|
begin |
| 106 |
|
|
|
| 107 |
|
|
Create( inItem.URL, inItem.Title, inItem ); |
| 108 |
|
|
|
| 109 |
|
|
end; |
| 110 |
h677 |
1.26 |
destructor TFavoriteBoardItem.Destory; |
| 111 |
|
|
begin |
| 112 |
|
|
if FItem <> nil then |
| 113 |
h677 |
1.41 |
FItem.Free; |
| 114 |
|
|
inherited; |
| 115 |
h677 |
1.26 |
end; |
| 116 |
yoffy |
1.9 |
function TFavoriteBoardItem.GetItem : TBoard; |
| 117 |
yoffy |
1.29 |
var |
| 118 |
|
|
protocol, host, path, document, port, bookmark : string; |
| 119 |
h677 |
1.33 |
BBSID{, BBSKey} : string; |
| 120 |
yoffy |
1.29 |
tmpURL : string; |
| 121 |
h677 |
1.20 |
// category : TCategory; |
| 122 |
yoffy |
1.9 |
begin |
| 123 |
|
|
|
| 124 |
|
|
if FItem = nil then begin |
| 125 |
|
|
FItem := BBSsFindBoardFromURL( URL ); |
| 126 |
yoffy |
1.16 |
if FItem = nil then begin |
| 127 |
yoffy |
1.29 |
tmpURL := URL; |
| 128 |
|
|
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 129 |
|
|
if GikoSys.Is2chHost( host ) then begin |
| 130 |
yoffy |
1.32 |
BBSID := GikoSys.URLToID( tmpURL ); |
| 131 |
yoffy |
1.29 |
FItem := BBSs[ 0 ].FindBBSID( BBSID ); |
| 132 |
yoffy |
1.31 |
if FItem <> nil then |
| 133 |
|
|
URL := FItem.URL; |
| 134 |
yoffy |
1.29 |
end; |
| 135 |
|
|
{ |
| 136 |
yoffy |
1.9 |
// ???????????A???????辿?J?e?S???????????長???直?足?徹?纏 |
| 137 |
yoffy |
1.16 |
FItem := GikoSys.GetUnknownBoard( nil, URL ); |
| 138 |
|
|
FItem.Title := Title; |
| 139 |
yoffy |
1.29 |
} |
| 140 |
yoffy |
1.16 |
end; |
| 141 |
yoffy |
1.9 |
end; |
| 142 |
|
|
|
| 143 |
h677 |
1.41 |
Result := FItem; |
| 144 |
yoffy |
1.9 |
|
| 145 |
|
|
end; |
| 146 |
|
|
|
| 147 |
yoffy |
1.7 |
constructor TFavoriteThreadItem.Create( |
| 148 |
|
|
inURL : string; |
| 149 |
|
|
inTitle : string = ''; |
| 150 |
|
|
inItem : TThreadItem = nil |
| 151 |
|
|
); |
| 152 |
|
|
begin |
| 153 |
|
|
|
| 154 |
|
|
inherited Create; |
| 155 |
h677 |
1.41 |
URL := inURL; |
| 156 |
yoffy |
1.7 |
|
| 157 |
|
|
Title := inTitle; |
| 158 |
|
|
Item := inItem; |
| 159 |
|
|
|
| 160 |
|
|
end; |
| 161 |
|
|
|
| 162 |
yoffy |
1.12 |
constructor TFavoriteThreadItem.CreateWithItem( |
| 163 |
|
|
inItem : TThreadItem |
| 164 |
|
|
); |
| 165 |
|
|
begin |
| 166 |
|
|
|
| 167 |
|
|
Create( inItem.URL, inItem.Title, inItem ); |
| 168 |
|
|
|
| 169 |
h677 |
1.26 |
end; |
| 170 |
|
|
destructor TFavoriteThreadItem.Destory; |
| 171 |
|
|
begin |
| 172 |
|
|
if FItem <> nil then |
| 173 |
|
|
FItem.Free; |
| 174 |
|
|
inherited; |
| 175 |
yoffy |
1.12 |
end; |
| 176 |
|
|
|
| 177 |
yoffy |
1.9 |
function TFavoriteThreadItem.GetItem : TThreadItem; |
| 178 |
|
|
var |
| 179 |
yoffy |
1.17 |
board : TBoard; |
| 180 |
|
|
boardURL : string; |
| 181 |
|
|
browsableURL : string; |
| 182 |
yoffy |
1.29 |
protocol, host, path, document, port, bookmark : string; |
| 183 |
|
|
BBSID, BBSKey : string; |
| 184 |
|
|
tmpURL : string; |
| 185 |
yoffy |
1.9 |
begin |
| 186 |
|
|
|
| 187 |
yoffy |
1.29 |
Result := nil; |
| 188 |
yoffy |
1.9 |
if FItem = nil then begin |
| 189 |
yoffy |
1.29 |
browsableURL := GikoSys.GetBrowsableThreadURL( URL ); |
| 190 |
|
|
boardURL := GikoSys.GetThreadURL2BoardURL( browsableURL ); |
| 191 |
|
|
board := BBSsFindBoardFromURL( boardURL ); |
| 192 |
yoffy |
1.9 |
|
| 193 |
h677 |
1.19 |
if board = nil then begin |
| 194 |
yoffy |
1.29 |
tmpURL := URL; |
| 195 |
|
|
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 196 |
|
|
if GikoSys.Is2chHost( host ) then begin |
| 197 |
|
|
GikoSys.Parse2chURL( tmpURL, path, document, BBSID, BBSKey ); |
| 198 |
|
|
board := BBSs[ 0 ].FindBBSID( BBSID ); |
| 199 |
|
|
end; |
| 200 |
|
|
|
| 201 |
|
|
if board = nil then begin |
| 202 |
|
|
Exit; |
| 203 |
|
|
// ???????????A???????辿?J?e?S???????????長???直?足?徹?纏 |
| 204 |
|
|
//board := GikoSys.GetUnknownBoard( nil, boardURL ) |
| 205 |
|
|
end; |
| 206 |
|
|
end; |
| 207 |
|
|
|
| 208 |
|
|
FItem := board.FindThreadFromURL( browsableURL ); |
| 209 |
yoffy |
1.31 |
|
| 210 |
|
|
if FItem = nil then begin |
| 211 |
|
|
tmpURL := URL; |
| 212 |
|
|
GikoSys.ParseURI( tmpURL, protocol, host, path, document, port, bookmark ); |
| 213 |
|
|
if GikoSys.Is2chHost( host ) then begin |
| 214 |
|
|
GikoSys.Parse2chURL( tmpURL, path, document, BBSID, BBSKey ); |
| 215 |
|
|
FItem := BBSs[ 0 ].FindThreadItem( BBSID, BBSKey + '.dat' ); |
| 216 |
|
|
if FItem <> nil then |
| 217 |
|
|
URL := FItem.URL; |
| 218 |
|
|
end; |
| 219 |
|
|
end; |
| 220 |
yoffy |
1.9 |
|
| 221 |
yoffy |
1.10 |
if FItem = nil then begin |
| 222 |
yoffy |
1.17 |
FItem := TThreadItem.Create( board.BoardPlugIn, browsableURL ); |
| 223 |
yoffy |
1.9 |
|
| 224 |
yoffy |
1.10 |
FItem.Title := Title; |
| 225 |
|
|
board.Add( FItem ); |
| 226 |
|
|
end; |
| 227 |
yoffy |
1.9 |
end; |
| 228 |
|
|
|
| 229 |
|
|
Result := FItem; |
| 230 |
|
|
|
| 231 |
hi_ |
1.1 |
end; |
| 232 |
|
|
|
| 233 |
|
|
procedure TFavoriteDM.DataModuleDestroy(Sender: TObject); |
| 234 |
h677 |
1.28 |
//var |
| 235 |
|
|
// i: Integer; |
| 236 |
hi_ |
1.1 |
begin |
| 237 |
h677 |
1.27 |
{ TreeView.Items.BeginUpdate; |
| 238 |
|
|
for i := TreeView.Items.Count - 1 downto 0 do begin |
| 239 |
|
|
// if TObject(TreeView.Items[i].Data) <> nil then |
| 240 |
|
|
// TObject(TreeView.Items[i].Data).Free; |
| 241 |
|
|
end; |
| 242 |
|
|
TreeView.Items.Clear; |
| 243 |
|
|
TreeView.Items.EndUpdate; |
| 244 |
|
|
} //TreeView.Free; |
| 245 |
|
|
end; |
| 246 |
|
|
procedure TFavoriteDM.Clear; |
| 247 |
|
|
var |
| 248 |
yoffy |
1.38 |
Node : TTreeNode; |
| 249 |
h677 |
1.27 |
begin |
| 250 |
yoffy |
1.38 |
TreeView.Items.BeginUpdate; |
| 251 |
|
|
Node := TreeView.Items.GetFirstNode; |
| 252 |
|
|
while Node <> nil do begin |
| 253 |
|
|
if TObject(Node.Data) <> nil then |
| 254 |
|
|
TObject(Node.Data).Free; |
| 255 |
|
|
Node := Node.GetNext; |
| 256 |
hi_ |
1.1 |
end; |
| 257 |
yoffy |
1.38 |
TreeView.Items.Clear; |
| 258 |
|
|
TreeView.Items.EndUpdate; |
| 259 |
h677 |
1.25 |
//TreeView.Free; |
| 260 |
hi_ |
1.1 |
end; |
| 261 |
|
|
|
| 262 |
|
|
procedure TFavoriteDM.SetFavTreeView(TreeView: TTreeView); |
| 263 |
|
|
begin |
| 264 |
|
|
FTreeView := TreeView; |
| 265 |
|
|
end; |
| 266 |
|
|
|
| 267 |
|
|
procedure TFavoriteDM.ReadFavorite; |
| 268 |
|
|
var |
| 269 |
|
|
FileName: string; |
| 270 |
|
|
XMLDoc: IXMLDocument; |
| 271 |
|
|
XMLNode: IXMLNode; |
| 272 |
|
|
Node: TTreeNode; |
| 273 |
|
|
i: Integer; |
| 274 |
|
|
FavFolder: TFavoriteFolder; |
| 275 |
|
|
LinkExists: Boolean; |
| 276 |
|
|
begin |
| 277 |
yoffy |
1.2 |
|
| 278 |
hi_ |
1.1 |
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 279 |
|
|
|
| 280 |
|
|
FavFolder := TFavoriteFolder.Create; |
| 281 |
|
|
Node := FTreeView.Items.AddChildObject(nil, FAVORITE_ROOT_NAME, FavFolder); |
| 282 |
yoffy |
1.2 |
Node.ImageIndex := 14; |
| 283 |
|
|
Node.SelectedIndex := 14; |
| 284 |
hi_ |
1.1 |
|
| 285 |
|
|
if FileExists(FileName) then begin |
| 286 |
yoffy |
1.2 |
try |
| 287 |
h677 |
1.23 |
XMLDoc := IXMLDocument.Create; |
| 288 |
|
|
//XMLDoc := LoadXMLDocument(FileName); |
| 289 |
|
|
LoadXMLDocument(FileName, XMLDoc); |
| 290 |
yoffy |
1.2 |
XMLNode := XMLDoc.DocumentElement; |
| 291 |
hi_ |
1.1 |
|
| 292 |
yoffy |
1.2 |
FStack := TStack.Create; |
| 293 |
|
|
try |
| 294 |
|
|
FStack.Push(Node); |
| 295 |
|
|
LinkExists := False; |
| 296 |
|
|
if XMLNode.NodeName = 'favorite' then begin |
| 297 |
|
|
for i := 0 to XMLNode.ChildNodes.Count - 1 do begin |
| 298 |
|
|
ReadNode(XMLNode.ChildNodes[i]); |
| 299 |
|
|
if (XMLNode.ChildNodes[i].NodeName = 'folder') and |
| 300 |
|
|
(XMLNode.ChildNodes[i].Attributes['title'] = FAVORITE_LINK_NAME) then begin |
| 301 |
|
|
LinkExists := True; |
| 302 |
|
|
end; |
| 303 |
hi_ |
1.1 |
end; |
| 304 |
|
|
end; |
| 305 |
yoffy |
1.2 |
if not LinkExists then begin |
| 306 |
|
|
FavFolder := TFavoriteFolder.Create; |
| 307 |
|
|
Node := FTreeView.Items.AddChildObject(Node, FAVORITE_LINK_NAME, FavFolder); |
| 308 |
|
|
Node.ImageIndex := 14; |
| 309 |
|
|
Node.SelectedIndex := 14; |
| 310 |
|
|
end; |
| 311 |
|
|
finally |
| 312 |
|
|
FStack.Free; |
| 313 |
h677 |
1.23 |
XMLDoc.Free; |
| 314 |
hi_ |
1.1 |
end; |
| 315 |
yoffy |
1.2 |
except |
| 316 |
hi_ |
1.1 |
end; |
| 317 |
|
|
end; |
| 318 |
|
|
|
| 319 |
yoffy |
1.2 |
{ |
| 320 |
|
|
FavFolder := TFavoriteFolder.Create; |
| 321 |
hi_ |
1.1 |
Node := FTreeView.Items.AddChildObject(nil, FAVORITE_ROOT_NAME, FavFolder); |
| 322 |
|
|
Node.ImageIndex := 12; |
| 323 |
|
|
Node.SelectedIndex := 13; |
| 324 |
|
|
|
| 325 |
|
|
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 326 |
|
|
if not FileExists(FileName) then |
| 327 |
|
|
Exit; |
| 328 |
|
|
|
| 329 |
|
|
FavSAXHandler.OnStartDocument := SAXStartDocument; |
| 330 |
|
|
FavSAXHandler.OnEndDocument := SAXEndDocument; |
| 331 |
|
|
FavSAXHandler.OnStartElement := SAXStartElement; |
| 332 |
|
|
FavSAXHandler.OnStartElement := SAXStartElement; |
| 333 |
|
|
FavSAXHandler.OnEndElement := SAXEndElement; |
| 334 |
|
|
FavSAXHandler.OnCharacters := SAXCharacters; |
| 335 |
|
|
|
| 336 |
|
|
FavSAXReader.Vendor := 'Keith Wood'; |
| 337 |
|
|
FavSAXReader.URL := FileName; |
| 338 |
|
|
FavSAXReader.Parse;} |
| 339 |
|
|
end; |
| 340 |
|
|
|
| 341 |
|
|
procedure TFavoriteDM.ReadNode(Node: IXMLNode); |
| 342 |
|
|
var |
| 343 |
|
|
i: Integer; |
| 344 |
|
|
|
| 345 |
|
|
ParentNode: TTreeNode; |
| 346 |
|
|
CurrentNode: TTreeNode; |
| 347 |
|
|
FavFolder: TFavoriteFolder; |
| 348 |
|
|
FavBoard: TFavoriteBoardItem; |
| 349 |
|
|
FavThread: TFavoriteThreadItem; |
| 350 |
yoffy |
1.7 |
board : TBoard; |
| 351 |
|
|
threadItem : TThreadItem; |
| 352 |
hi_ |
1.1 |
begin |
| 353 |
|
|
if Node.NodeName = 'folder' then begin |
| 354 |
|
|
ParentNode := FStack.Peek; |
| 355 |
|
|
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 356 |
|
|
FavFolder := TFavoriteFolder.Create; |
| 357 |
|
|
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavFolder); |
| 358 |
yoffy |
1.2 |
CurrentNode.ImageIndex := 14; |
| 359 |
|
|
CurrentNode.SelectedIndex := 14; |
| 360 |
yoffy |
1.7 |
CurrentNode.Expanded := Node.Attributes[ 'expanded' ] = 'true'; |
| 361 |
hi_ |
1.1 |
FStack.Push(CurrentNode); |
| 362 |
|
|
end; |
| 363 |
|
|
for i := 0 to Node.ChildNodes.Count - 1 do begin |
| 364 |
|
|
ReadNode(Node.ChildNodes[i]); |
| 365 |
|
|
end; |
| 366 |
|
|
if FStack.Count <> 0 then |
| 367 |
|
|
FStack.Pop; |
| 368 |
|
|
end else if Node.NodeName = 'favitem' then begin |
| 369 |
yoffy |
1.14 |
try |
| 370 |
|
|
ParentNode := FStack.Peek; |
| 371 |
|
|
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 372 |
|
|
if Node.Attributes['favtype'] = 'board' then begin |
| 373 |
yoffy |
1.15 |
FavBoard := nil; |
| 374 |
yoffy |
1.14 |
// ???貼???即?C???端???????????鼎?????? |
| 375 |
|
|
if Length( Node.Attributes[ 'bbs' ] ) > 0 then begin |
| 376 |
|
|
board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] ); |
| 377 |
|
|
if board <> nil then |
| 378 |
|
|
FavBoard := TFavoriteBoardItem.Create( |
| 379 |
|
|
board.URL, Node.Attributes[ 'title' ], board ); |
| 380 |
|
|
end else begin |
| 381 |
|
|
FavBoard := TFavoriteBoardItem.Create( |
| 382 |
yoffy |
1.15 |
Node.Attributes[ 'url' ], Node.Attributes[ 'title' ], nil ); |
| 383 |
yoffy |
1.14 |
end; |
| 384 |
|
|
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavBoard); |
| 385 |
|
|
CurrentNode.ImageIndex := 15; |
| 386 |
|
|
CurrentNode.SelectedIndex := 15; |
| 387 |
|
|
end else if Node.Attributes['favtype'] = 'thread' then begin |
| 388 |
|
|
// ???貼???即?C???端???????????鼎?????? |
| 389 |
|
|
if Length( Node.Attributes[ 'bbs' ] ) > 0 then begin |
| 390 |
|
|
board := BBSsFindBoardFromBBSID( Node.Attributes[ 'bbs' ] ); |
| 391 |
|
|
if board = nil then |
| 392 |
|
|
Exit; |
| 393 |
|
|
|
| 394 |
|
|
if not board.IsThreadDatRead then |
| 395 |
|
|
GikoSys.ReadSubjectFile( board ); |
| 396 |
yoffy |
1.30 |
threadItem := board.FindThreadFromFileName( Node.Attributes[ 'thread' ] ); |
| 397 |
yoffy |
1.14 |
if threadItem = nil then begin |
| 398 |
|
|
threadItem := TThreadItem.Create( |
| 399 |
|
|
board.BoardPlugIn, |
| 400 |
|
|
GikoSys.Get2chBoard2ThreadURL( board, ChangeFileExt( Node.Attributes[ 'thread' ], '' ) ) ); |
| 401 |
|
|
threadItem.Title := Node.Attributes[ 'title' ]; |
| 402 |
|
|
board.Add( threadItem ); |
| 403 |
|
|
end; |
| 404 |
|
|
FavThread := TFavoriteThreadItem.Create( |
| 405 |
|
|
threadItem.URL, Node.Attributes[ 'title' ], threadItem ); |
| 406 |
h677 |
1.23 |
threadItem.Free; |
| 407 |
yoffy |
1.14 |
end else begin |
| 408 |
|
|
FavThread := TFavoriteThreadItem.Create( |
| 409 |
yoffy |
1.15 |
Node.Attributes[ 'url' ], Node.Attributes[ 'title' ], nil ); |
| 410 |
yoffy |
1.7 |
end; |
| 411 |
yoffy |
1.14 |
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Node.Attributes['title'], FavThread); |
| 412 |
|
|
CurrentNode.ImageIndex := 16; |
| 413 |
|
|
CurrentNode.SelectedIndex := 16; |
| 414 |
yoffy |
1.7 |
end; |
| 415 |
hi_ |
1.1 |
end; |
| 416 |
yoffy |
1.14 |
except |
| 417 |
|
|
// ?????A?C?e???長?但?????N?鼎?????添???A?C?e?????e?甜???^?????足???????長 |
| 418 |
hi_ |
1.1 |
end; |
| 419 |
|
|
end; |
| 420 |
|
|
end; |
| 421 |
|
|
|
| 422 |
|
|
procedure TFavoriteDM.WriteFavorite; |
| 423 |
yoffy |
1.2 |
{ |
| 424 |
hi_ |
1.1 |
var |
| 425 |
|
|
FileName: string; |
| 426 |
|
|
// SaveList: TStringList; |
| 427 |
|
|
// i: Integer; |
| 428 |
|
|
// Count: Integer; |
| 429 |
|
|
|
| 430 |
|
|
XMLDoc: IXMLDocument; |
| 431 |
|
|
XMLNode: IXMLNode; |
| 432 |
|
|
// FavoNode: IXMLNode; |
| 433 |
|
|
begin |
| 434 |
yoffy |
1.7 |
XMLDoc := NewXMLDocument; |
| 435 |
hi_ |
1.1 |
XMLDoc.Encoding := 'Shift_JIS'; |
| 436 |
|
|
XMLDoc.StandAlone := 'yes'; |
| 437 |
|
|
XMLNode := XMLDoc.AddChild('favorite'); |
| 438 |
|
|
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 439 |
|
|
AddSaveString(TreeView.Items.GetFirstNode, XMLNode); |
| 440 |
|
|
XMLDoc.SaveToFile(FileName); |
| 441 |
yoffy |
1.2 |
} |
| 442 |
|
|
var |
| 443 |
h677 |
1.42 |
FileName, tmpFileName: string; |
| 444 |
hi_ |
1.1 |
SaveList: TStringList; |
| 445 |
h677 |
1.42 |
|
| 446 |
hi_ |
1.1 |
begin |
| 447 |
|
|
FileName := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 448 |
h677 |
1.42 |
if FileExists(FileName) then begin |
| 449 |
|
|
tmpFileName := GikoSys.GetConfigDir + '~' + FAVORITE_FILE_NAME; |
| 450 |
|
|
if FileExists(tmpFileName) then |
| 451 |
|
|
SysUtils.DeleteFile(tmpFileName); //SysUtils.?????纏??????WinAPI???????長?鼎???????長 |
| 452 |
|
|
RenameFile(FileName, tmpFileName); |
| 453 |
|
|
end; |
| 454 |
hi_ |
1.1 |
SaveList := TStringList.Create; |
| 455 |
|
|
try |
| 456 |
|
|
SaveList.Add('<?xml version="1.0" encoding="Shift_JIS" standalone="yes"?>'); |
| 457 |
|
|
SaveList.Add('<favorite>'); |
| 458 |
yoffy |
1.37 |
AddSaveString(TreeView.Items.GetFirstNode.getFirstChild, SaveList); |
| 459 |
hi_ |
1.1 |
SaveList.Add('</favorite>'); |
| 460 |
|
|
SaveList.SaveToFile(FileName); |
| 461 |
|
|
finally |
| 462 |
|
|
SaveList.Free; |
| 463 |
yoffy |
1.2 |
end; |
| 464 |
hi_ |
1.1 |
end; |
| 465 |
|
|
|
| 466 |
yoffy |
1.2 |
{ |
| 467 |
hi_ |
1.1 |
procedure TFavoriteDM.AddSaveString(Node: TTreeNode; XMLNode: IXMLNode); |
| 468 |
|
|
var |
| 469 |
|
|
i: Integer; |
| 470 |
|
|
// s: string; |
| 471 |
|
|
FavBoard: TFavoriteBoardItem; |
| 472 |
|
|
FavThread: TFavoriteThreadItem; |
| 473 |
|
|
FavNode: IXMLNode; |
| 474 |
|
|
begin |
| 475 |
|
|
for i := 0 to Node.Count - 1 do begin |
| 476 |
|
|
if TObject(Node.Item[i].Data) is TFavoriteFolder then begin |
| 477 |
|
|
FavNode := XMLNode.AddChild('folder'); |
| 478 |
|
|
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 479 |
|
|
AddSaveString(Node.Item[i], FavNode); |
| 480 |
|
|
end else if TObject(Node.Item[i].Data) is TFavoriteBoardItem then begin |
| 481 |
|
|
FavBoard := TFavoriteBoardItem(Node.Item[i].Data); |
| 482 |
|
|
FavNode := XMLNode.AddChild('favitem'); |
| 483 |
|
|
FavNode.Attributes['type'] := '2ch'; |
| 484 |
|
|
FavNode.Attributes['favtype'] := 'board'; |
| 485 |
|
|
FavNode.Attributes['bbs'] := FavBoard.BBSID; |
| 486 |
|
|
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 487 |
|
|
FavNode.Attributes['boardname'] := FavBoard.BoardName; |
| 488 |
|
|
end else if TObject(Node.Item[i].Data) is TFavoriteThreadItem then begin |
| 489 |
|
|
FavThread := TFavoriteThreadItem(Node.Item[i].Data); |
| 490 |
|
|
FavNode := XMLNode.AddChild('favitem'); |
| 491 |
|
|
FavNode.Attributes['type'] := '2ch'; |
| 492 |
|
|
FavNode.Attributes['favtype'] := 'thread'; |
| 493 |
|
|
FavNode.Attributes['bbs'] := FavThread.BBSID; |
| 494 |
|
|
FavNode.Attributes['thread'] := FavThread.ThreadID; |
| 495 |
|
|
FavNode.Attributes['title'] := Node.Item[i].Text; |
| 496 |
|
|
FavNode.Attributes['threadname'] := FavThread.ThreadName; |
| 497 |
|
|
end; |
| 498 |
|
|
end; |
| 499 |
|
|
end; |
| 500 |
yoffy |
1.2 |
} |
| 501 |
hi_ |
1.1 |
|
| 502 |
yoffy |
1.2 |
procedure TFavoriteDM.AddSaveString(Node: TTreeNode; SaveList: TStringList); |
| 503 |
hi_ |
1.1 |
var |
| 504 |
|
|
s: string; |
| 505 |
|
|
FavBoard: TFavoriteBoardItem; |
| 506 |
|
|
FavThread: TFavoriteThreadItem; |
| 507 |
yoffy |
1.37 |
data : Pointer; |
| 508 |
hi_ |
1.1 |
begin |
| 509 |
yoffy |
1.37 |
while Node <> nil do begin |
| 510 |
|
|
data := Node.Data; |
| 511 |
|
|
if TObject(data) is TFavoriteFolder then begin |
| 512 |
|
|
if Node.Expanded then |
| 513 |
|
|
s := Format('<folder title="%s" expanded="true">', [HtmlEncode(Node.Text)]) |
| 514 |
yoffy |
1.7 |
else |
| 515 |
yoffy |
1.37 |
s := Format('<folder title="%s" expanded="false">', [HtmlEncode(Node.Text)]); |
| 516 |
hi_ |
1.1 |
SaveList.Add(s); |
| 517 |
yoffy |
1.37 |
AddSaveString(Node.getFirstChild, SaveList); |
| 518 |
hi_ |
1.1 |
SaveList.Add('</folder>'); |
| 519 |
yoffy |
1.37 |
end else if TObject(data) is TFavoriteBoardItem then begin |
| 520 |
|
|
FavBoard := TFavoriteBoardItem(data); |
| 521 |
yoffy |
1.5 |
s := Format('<favitem type="2ch" favtype="board" url="%s" title="%s"/>', |
| 522 |
yoffy |
1.37 |
[HtmlEncode( FavBoard.URL ), HtmlEncode(Node.Text)]); |
| 523 |
hi_ |
1.1 |
SaveList.Add(s); |
| 524 |
yoffy |
1.37 |
end else if TObject(data) is TFavoriteThreadItem then begin |
| 525 |
|
|
FavThread := TFavoriteThreadItem(data); |
| 526 |
yoffy |
1.5 |
s := Format('<favitem type="2ch" favtype="thread" url="%s" title="%s"/>', |
| 527 |
yoffy |
1.37 |
[HtmlEncode( FavThread.URL ), HtmlEncode(Node.Text)]); |
| 528 |
hi_ |
1.1 |
SaveList.Add(s); |
| 529 |
|
|
end; |
| 530 |
yoffy |
1.37 |
Node := Node.getNextSibling; |
| 531 |
hi_ |
1.1 |
end; |
| 532 |
yoffy |
1.2 |
end; |
| 533 |
hi_ |
1.1 |
|
| 534 |
|
|
{ |
| 535 |
|
|
procedure TFavoriteDM.SAXStartDocument(Sender: TObject); |
| 536 |
|
|
begin |
| 537 |
|
|
FStack := TStack.Create; |
| 538 |
|
|
FStack.Push(FTreeView.Items.GetFirstNode); |
| 539 |
|
|
end; |
| 540 |
|
|
|
| 541 |
|
|
procedure TFavoriteDM.SAXEndDocument(Sender: TObject); |
| 542 |
|
|
begin |
| 543 |
|
|
FStack.Free; |
| 544 |
|
|
end; |
| 545 |
|
|
|
| 546 |
|
|
procedure TFavoriteDM.SAXStartElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString; |
| 547 |
|
|
const Atts: IAttributes); |
| 548 |
|
|
var |
| 549 |
|
|
FavType: string; |
| 550 |
|
|
ParentNode: TTreeNode; |
| 551 |
|
|
CurrentNode: TTreeNode; |
| 552 |
|
|
FavFolder: TFavoriteFolder; |
| 553 |
|
|
FavBoard: TFavoriteBoardItem; |
| 554 |
|
|
FavThread: TFavoriteThreadItem; |
| 555 |
|
|
begin |
| 556 |
|
|
if QName = 'folder' then begin |
| 557 |
|
|
ParentNode := FStack.Peek; |
| 558 |
|
|
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 559 |
|
|
FavFolder := TFavoriteFolder.Create; |
| 560 |
|
|
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavFolder); |
| 561 |
|
|
CurrentNode.ImageIndex := 12; |
| 562 |
|
|
CurrentNode.SelectedIndex := 13; |
| 563 |
|
|
FStack.Push(CurrentNode); |
| 564 |
|
|
end; |
| 565 |
|
|
end else if QName = 'favitem' then begin |
| 566 |
|
|
ParentNode := FStack.Peek; |
| 567 |
|
|
if TObject(ParentNode.Data) is TFavoriteFolder then begin |
| 568 |
|
|
FavType := Atts.getValue('favtype'); |
| 569 |
|
|
if FavType = 'board' then begin |
| 570 |
|
|
FavBoard := TFavoriteBoardItem.Create; |
| 571 |
|
|
FavBoard.BBSID := Atts.getValue('bbs'); |
| 572 |
|
|
FavBoard.BoardName := Atts.getValue('boardname'); |
| 573 |
|
|
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavBoard); |
| 574 |
|
|
CurrentNode.ImageIndex := 14; |
| 575 |
|
|
CurrentNode.SelectedIndex := 15; |
| 576 |
|
|
end else if FavType = 'thread' then begin |
| 577 |
|
|
FavThread := TFavoriteThreadItem.Create; |
| 578 |
|
|
FavThread.BBSID := Atts.getValue('bbs'); |
| 579 |
|
|
FavThread.ThreadID := Atts.getValue('thread'); |
| 580 |
|
|
FavThread.ThreadName := Atts.getValue('threadname'); |
| 581 |
|
|
CurrentNode := FTreeView.Items.AddChildObject(ParentNode, Atts.getValue('title'), FavThread); |
| 582 |
|
|
CurrentNode.ImageIndex := 16; |
| 583 |
|
|
CurrentNode.SelectedIndex := 17; |
| 584 |
|
|
end; |
| 585 |
|
|
end; |
| 586 |
|
|
end; |
| 587 |
|
|
end; |
| 588 |
|
|
|
| 589 |
|
|
procedure TFavoriteDM.SAXEndElement(Sender: TObject; const NamespaceURI, LocalName, QName: SAXString); |
| 590 |
|
|
begin |
| 591 |
|
|
if QName = 'folder' then begin |
| 592 |
|
|
if FStack.Count <> 0 then |
| 593 |
|
|
FStack.Pop; |
| 594 |
|
|
end; |
| 595 |
|
|
end; |
| 596 |
|
|
|
| 597 |
|
|
procedure TFavoriteDM.SAXCharacters(Sender: TObject; const PCh: SAXString); |
| 598 |
|
|
begin |
| 599 |
|
|
// |
| 600 |
|
|
end; |
| 601 |
|
|
} |
| 602 |
h677 |
1.4 |
function TFavoriteDM.SaveFavoriteFile(FileName: String) : Boolean; |
| 603 |
|
|
var |
| 604 |
|
|
FavoriteFilePath: string; |
| 605 |
yoffy |
1.7 |
tempStringList: TStringList; |
| 606 |
h677 |
1.4 |
begin |
| 607 |
h677 |
1.36 |
WriteFavorite; |
| 608 |
h677 |
1.4 |
FavoriteFilePath := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 609 |
|
|
|
| 610 |
|
|
if FileExists( FavoriteFilePath ) then begin |
| 611 |
yoffy |
1.7 |
tempStringList := TStringList.Create; |
| 612 |
h677 |
1.4 |
try |
| 613 |
yoffy |
1.7 |
tempStringList.LoadFromFile( FavoriteFilePath ); |
| 614 |
|
|
tempStringList.SaveToFile( FileName ); |
| 615 |
h677 |
1.4 |
finally |
| 616 |
yoffy |
1.7 |
tempStringList.Free; |
| 617 |
h677 |
1.4 |
end; |
| 618 |
yoffy |
1.7 |
Result := true; |
| 619 |
h677 |
1.4 |
end else begin |
| 620 |
yoffy |
1.7 |
Result := false; |
| 621 |
h677 |
1.21 |
end; |
| 622 |
|
|
end; |
| 623 |
|
|
|
| 624 |
|
|
procedure TFavoriteDM.URLReplace(oldURLs: TStringList; newURLs: TStringList); |
| 625 |
|
|
var |
| 626 |
yoffy |
1.39 |
i : Integer; |
| 627 |
yoffy |
1.34 |
tmpURL: string; |
| 628 |
h677 |
1.21 |
oldHost: string; |
| 629 |
|
|
oldBoardName: string; |
| 630 |
|
|
newHost: string; |
| 631 |
|
|
newBoardName: string; |
| 632 |
yoffy |
1.34 |
tempString: string; |
| 633 |
|
|
favBoard : TFavoriteBoardItem; |
| 634 |
|
|
favThread : TFavoriteThreadItem; |
| 635 |
|
|
favorites : TTreeNodes; |
| 636 |
yoffy |
1.39 |
Node : TTreeNode; |
| 637 |
h677 |
1.21 |
begin |
| 638 |
|
|
|
| 639 |
yoffy |
1.34 |
// ???|?転?纏??thread???泥???添??URL???`?F?b?N?直?????巽?但?????????鼎?叩???纏?????B |
| 640 |
|
|
favorites := FavoriteDM.FTreeView.Items; |
| 641 |
|
|
for i := 0 to oldURLs.Count - 1 do begin |
| 642 |
h677 |
1.21 |
try |
| 643 |
yoffy |
1.34 |
tmpURL := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1); |
| 644 |
|
|
oldHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) ); |
| 645 |
|
|
oldBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/'; |
| 646 |
|
|
tmpURL := Copy(newURLs[i], 1, Length(newURLs[i]) -1); |
| 647 |
|
|
newHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) ); |
| 648 |
|
|
newBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/'; |
| 649 |
h677 |
1.33 |
|
| 650 |
yoffy |
1.39 |
Node := favorites.GetFirstNode.getFirstChild; |
| 651 |
|
|
while Node <> nil do begin |
| 652 |
yoffy |
1.34 |
try |
| 653 |
yoffy |
1.39 |
if TObject( Node.Data ) is TFavoriteBoardItem then begin |
| 654 |
|
|
favBoard := TFavoriteBoardItem( Node.Data ); |
| 655 |
yoffy |
1.34 |
if favBoard = nil then continue; |
| 656 |
|
|
tempString := favBoard.URL; |
| 657 |
|
|
if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin |
| 658 |
|
|
tempString := StringReplace(tempString, oldHost, newHost,[]); |
| 659 |
|
|
favBoard.URL := tempString; |
| 660 |
|
|
end; |
| 661 |
yoffy |
1.39 |
end else if TObject( Node.Data ) is TFavoriteThreadItem then begin |
| 662 |
|
|
favThread := TFavoriteThreadItem( Node.Data ); |
| 663 |
yoffy |
1.34 |
if favThread = nil then continue; |
| 664 |
|
|
tempString := favThread.URL; |
| 665 |
|
|
if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin |
| 666 |
|
|
tempString := StringReplace(tempString, oldHost, newHost,[]); |
| 667 |
|
|
favThread.URL := tempString; |
| 668 |
h677 |
1.33 |
end; |
| 669 |
|
|
end; |
| 670 |
yoffy |
1.34 |
except |
| 671 |
|
|
end; |
| 672 |
yoffy |
1.39 |
Node := Node.GetNext; |
| 673 |
yoffy |
1.34 |
end; |
| 674 |
|
|
except |
| 675 |
h677 |
1.21 |
end; |
| 676 |
yoffy |
1.7 |
end; |
| 677 |
yoffy |
1.34 |
|
| 678 |
h677 |
1.4 |
end; |
| 679 |
|
|
|
| 680 |
|
|
function TFavoriteDM.GetFavoriteFilePath() : String; |
| 681 |
|
|
begin |
| 682 |
|
|
Result := GikoSys.GetConfigDir + FAVORITE_FILE_NAME; |
| 683 |
|
|
end; |
| 684 |
|
|
|
| 685 |
hi_ |
1.1 |
end. |