Menu

[424828]: / doc / libfbdoc / CWikiCache.bas  Maximize  Restore  History

Download this file

171 lines (130 with data), 3.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
'' fbdoc - FreeBASIC User's Manual Converter/Generator
'' Copyright (C) 2006-2022 The FreeBASIC development team.
''
'' This program is free software; you can redistribute it and/or modify
'' it under the terms of the GNU General Public License as published by
'' the Free Software Foundation; either version 2 of the License, or
'' (at your option) any later version.
''
'' This program is distributed in the hope that it will be useful,
'' but WITHOUT ANY WARRANTY; without even the implied warranty of
'' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'' GNU General Public License for more details.
''
'' You should have received a copy of the GNU General Public License
'' along with this program; if not, write to the Free Software
'' Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA.
'' CWikiCache - Save/Load raw wiki pages to/from a local dir
''
'' chng: may/2006 written [coderJeff]
'' dec/2006 updated [coderJeff] - using classes
''
#include once "fbdoc_defs.bi"
#include once "fbdoc_string.bi"
#include once "CWikiCache.bi"
#include once "file.bi"
namespace fb.fbdoc
type CWikiCacheCtx_
as zstring ptr localdir = 0
as integer RefreshMode = 0
end type
const cache_ext = ".wakka"
'':::::
constructor CWikiCache _
( _
byval localdir as zstring ptr, _
byval RefreshMode as integer _
)
ctx = new CWikiCacheCtx
ctx->localdir = NULL
ZSet @ctx->localdir, localdir
ctx->RefreshMode = RefreshMode
end constructor
'':::::
destructor CWikiCache _
( _
)
ZFree @ctx->localdir
delete ctx
end destructor
'':::::
function CWikiCache.LoadPage _
( _
byval sPage as zstring ptr, _
byref sBody as string _
) as integer
if( ctx = NULL ) then
return FALSE
end if
if( sPage = NULL ) then
return FALSE
end if
if( len(*sPage) = 0) then
return FALSE
endif
dim as integer h
dim as string sLocalFile
function = FALSE
sBody = ""
sLocalFile = *ctx->localdir + *sPage + cache_ext
if( fileexists( sLocalFile ) ) then
h = freefile
if( open( sLocalFile for binary as #h) = 0 ) then
if( lof(h) > 0 ) then
sBody = space( lof( h ) )
get #h,,sBody
end if
close #h
function = TRUE
end if
end if
end function
'':::::
function CWikiCache.SavePage _
( _
byval sPage as zstring ptr, _
byval sBody as zstring ptr _
) as integer
if( ctx = NULL ) then
return FALSE
end if
if( sPage = NULL ) then
return FALSE
end if
if( len(*sPage) = 0) then
return FALSE
endif
dim as integer h
dim as string sLocalFile
function = FALSE
sLocalFile = *ctx->localdir + *sPage + cache_ext
if( fileexists( sLocalFile ) ) then
kill sLocalFile
end if
h = freefile
if( open(sLocalFile for binary as #h) = 0 ) then
put #h,,*sBody, len(*sBody)
close #h
function = TRUE
end if
end function
'':::::
function CWikiCache.GetRefreshMode _
( _
) as integer
if( ctx = NULL ) then
return FALSE
end if
function = ctx->RefreshMode
end function
'':::::
function CWikiCache.SetRefreshMode _
( _
byval RefreshMode as integer _
) as integer
if( ctx = NULL ) then
return FALSE
end if
ctx->RefreshMode = RefreshMode
end function
end namespace
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.