-- vim:set ft=lua: dofile(mg.script_name:gsub('[^\\/]*$','')..'util.lua') ct=CreateContentBuilder(GZIP_THRESHOLD_BYTE) ct:Append([=[ 設定/PlugIn設定 - EDCB

設定/PlugIn設定

]=]) --設定ファイルについてのメタ情報(JSONの配列をコンマで任意の数並べた形式)を解析する function ParseSettingArrays(s) local i,r=1,{} while s:find('^%[',i) do i=i+1 local a={} while true do local v=nil if s:find('^false',i) then v=false i=i+5 elseif s:find('^true',i) then v=true i=i+4 elseif s:find('^"',i) then --文字列 i=i+1 local t='' while i<=#s do if s:find('^"',i) then v=t i=i+1 break elseif s:find('^\\.',i) then i=i+1 end t=t..s:sub(i,i) i=i+1 end else local n=s:match('^%-?[0-9]+',i) if n then --数値 i=i+#n n=tonumber(n) if n and n==math.floor(n) and n>=-2147483648 and n<=2147483647 then v=n end end end if v==nil then return nil end a[#a+1]=v if s:find('^%],',i) then i=i+2 break end if not s:find('^,',i) then return nil end i=i+1 end if r.body then if type(a[1])~='number' then return nil end if a[1]%8==0 then --設定項目 if #a<5 or type(a[2])~='string' or type(a[3])~='string' or type(a[4])~='string' then return nil end r.body[#r.body+1]={sub=math.floor(a[1]/8)%4,section=a[2],key=a[3],desc=a[4],def=a[5]} if type(a[5])=='number' then --数値の設定項目 if type(a[6])~='number' or type(a[7])~='number' then return nil end r.body[#r.body].min=a[6] r.body[#r.body].max=a[7] end elseif a[1]%8==1 then --ラベル項目 if type(a[2])~='string' then return nil end r.body[#r.body+1]={sub=math.floor(a[1]/8)%4,label=a[2]} end else if type(a[2])~='string' or type(a[3])~='number' then return nil end r.head={desc=a[2],utf=a[3]%2==1} r.body={} end end return r.body and r or nil end post=AssertPost() mode=GetVarInt(post or mg.request_info.query_string,'mode',1,2) or 1 if post and not ALLOW_SETTING then post=nil ct:Append('
変更は許可されていません
\n') end item=mg.get_var(post or mg.request_info.query_string,'item') or '' itemList=EnumPlugInFileName(mode==1 and 'RecName' or 'Write') setting=nil for i,v in ipairs(itemList) do if v==item then f=edcb.io.open(EdcbModulePath()..(mode==1 and '\\RecName\\' or '\\Write\\')..v,'rb') if f then --埋め込まれた設定ファイルについてのメタ情報を取り出す buf=(' '):rep(65536) while #buf==65536 do buf=buf..(f:read(65536) or '') setting=buf:match('%[(%["setting%-59c4d329%-ba81%-4054%-9f4d%-d1900653338a",.-)%[""%]%]') if setting then setting=ParseSettingArrays(setting:gsub('%c','')) break end buf=buf:sub(65537) end f:close() end break end end if post and setting then if setting.head.utf then --設定ファイルがまだないか空のときバイト順マークを書き込む f=edcb.io.open(EdcbModulePath()..(mode==1 and '\\RecName\\' or '\\Write\\')..item..'.ini','ab') if f then if f:seek('end')==0 then f:write('\xff\xfe') end f:close() end end for i,v in ipairs(setting.body) do if v.section and mg.get_var(post,'k-'..i)=='['..v.section..']'..v.key then val=GetVarInt(post,'c-'..i)==1 if type(v.def)=='number' then val=math.min(math.max(val and GetVarInt(post,'v-'..i) or 0,v.min),v.max) elseif type(v.def)=='string' then val=(val and mg.get_var(post,'v-'..i) or ''):gsub('%c','') end edcb.WritePrivateProfile(v.section,v.key,val,(mode==1 and 'RecName\\' or 'Write\\')..item..'.ini') end end ct:Append('
変更しました
\n') end edcb.htmlEscape=15 ct:Append([=[
]=]) if setting then ct:Append([=[ 【]=]..EdcbHtmlEscape(setting.head.desc)..[=[】
]=]) sub=0 for i,v in ipairs(setting.body) do ct:Append(v.sub>=2 and sub<2 and '\n
\n' or v.sub<2 and sub>=2 and '\n
\n' or '
\n') sub=v.sub if v.section then --次の項目がenabled-on-checkedなサブ項目になるときは常にチェックボックスを作る check=sub<2 and i<#setting.body and setting.body[i+1].sub==3 val=edcb.GetPrivateProfile(v.section,v.key,v.def,(mode==1 and 'RecName\\' or 'Write\\')..item..'.ini') ct:Append(' ') elseif type(v.def)=='number' then ct:Append((check and Checkbox(val~='0') or ' type="hidden" value="1"')..'>'..EdcbHtmlEscape(v.desc)..'\n ' ..'') else ct:Append((check and Checkbox(val~='') or ' type="hidden" value="1"')..'>'..EdcbHtmlEscape(v.desc)..'' ..(check and '\n
' or '
\n ') ..''..(check and '
' or '')) end else --ラベル項目 ct:Append(' '..EdcbHtmlEscape(v.label)) end end ct:Append((sub>=2 and '\n
\n' or '
\n')..[=[
]=]) elseif item~='' then ct:Append([=[ ・設定項目がないかメタ情報のないPlugInです。 ]=]) end ct:Append([=[ ]=]) ct:Finish() mg.write(ct:Pop(Response(200,'text/html','utf-8',ct.len)..(ct.gzip and 'Content-Encoding: gzip\r\n' or '')..'\r\n'))