Skip to content

Commit

Permalink
- merged most of jrock's changes from his "v0.9 RC3" branch into mast…
Browse files Browse the repository at this point in the history
…er / thx jrock
  • Loading branch information
pulsar-de committed Mar 20, 2022
1 parent a5c2ad3 commit 5918f81
Show file tree
Hide file tree
Showing 9 changed files with 2,511 additions and 1,358 deletions.
3,499 changes: 2,188 additions & 1,311 deletions Announcer.wx.lua

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -35,4 +35,4 @@ use this command:

lua.exe ..\apps\wxluafreeze\wxluafreeze.lua wxluafreeze.exe "Announcer.wx.lua" "Announcer.exe"

*note: there are better ways to do this, but it's the easiest way. (i'am using Notepad++ with integrated Lua/wxLua interpreter and macro shortcuts for "run" and "compile")*
*note: there are better ways to do this, but it's the easiest way. (i'am using Notepad++ with integrated Lua/wxLua interpreter and macro shortcuts for "run" and "compile")*
2 changes: 1 addition & 1 deletion cfg/hub.lua
Expand Up @@ -3,7 +3,7 @@ hub = {
[ "addr" ] = "127.0.0.1",
[ "keyp" ] = "",
[ "name" ] = "Luadch Testhub",
[ "nick" ] = "announcer",
[ "nick" ] = "Announcer",
[ "pass" ] = "test",
[ "port" ] = "5001",

Expand Down
2 changes: 1 addition & 1 deletion cfg/rules.lua
Expand Up @@ -2,7 +2,7 @@ rules = {

[ 1 ] = {

[ "active" ] = false,
[ "active" ] = true,
[ "alibicheck" ] = false,
[ "alibinick" ] = "DUMP",
[ "blacklist" ] = {
Expand Down
27 changes: 14 additions & 13 deletions core/announce.lua
Expand Up @@ -5,7 +5,6 @@
]]--


package.path = package.path .. ";"
.. "././core/?.lua;"
.. "././lib/?/?.lua;"
Expand All @@ -19,8 +18,8 @@ package.cpath = package.cpath .. ";"
.. "././lib/luasec/?/?" .. ".dll" .. ";"
.. "././lib/lfs/?" .. ".dll" .. ";"


local lfs = require( "lfs" )

local alreadysent = log.getreleases( )

local match = function( buf, patternlist, white )
Expand Down Expand Up @@ -48,12 +47,16 @@ local check_for_whitespaces = function( release )
end
end

local check_number_between = function( num, mini, maxi )
num = tonumber( num )
return ( num >= mini and maxi >= num )
end

local directory_has_nfo = function( path )
local lfs_a = lfs.attributes
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path .. "/" .. file
local mode, err = lfs_a( f, "mode" )
local mode, err = lfs.attributes( f, "mode" )
local ext = string.match( file, ".-[^\\/]-%.?([^%.\\/]*)$" )
if mode == "file" and ext == "nfo" then
return true
Expand All @@ -64,18 +67,17 @@ local directory_has_nfo = function( path )
end

local directory_has_valid_sfv = function( path )
local lfs_a = lfs.attributes
for file in lfs.dir(path) do
if file ~= "." and file ~= ".." then
local f = path .. "/" .. file
local mode, err = lfs_a( f, "mode" )
local mode, err = lfs.attributes( f, "mode" )
local ext = string.match( file, ".-[^\\/]-%.?([^%.\\/]*)$" )
if type( err ) == "nil" and mode == "file" and ext == "sfv" then
for line in io.lines(f) do
if string.len( line ) > 0 and not ( string.gsub( line, 1, 1 ) == ";" ) then
local sfv_filename, sfv_checksum = line:match("([^,]+) ([^,]+)")
if type( sfv_filename ) == "string" then
local sfv_mode, sfv_err = lfs_a( path .. "/" .. tostring( sfv_filename ), "mode" )
local sfv_mode, sfv_err = lfs.attributes( path .. "/" .. tostring( sfv_filename ), "mode" )
if type( sfv_err ) == "string" or sfv_mode == "nil" then
return false
end
Expand All @@ -91,10 +93,9 @@ end

local search = function( path, cfg, found )
local count = 0
local lfs_a = lfs.attributes
for release in lfs.dir( path ) do
local f = path .. "/" .. release
local mode, err = lfs_a( f ).mode
local mode, err = lfs.attributes( f ).mode

if ( release ~= "." ) and ( release ~= "..") and ( not announce.blocked[ release ] ) and ( not alreadysent[ release ] ) then
--// blacklist check
Expand All @@ -110,7 +111,7 @@ local search = function( path, cfg, found )
count = count + 1
log.event( "Release: '" .. release .. "' blocked. | Reason: " .. "Whitespaces" )
--// max age check
elseif ( cfg.checkage and cfg.maxage > 0 and age_in_days( lfs_a( f ).modification ) >= cfg.maxage ) then
elseif ( cfg.checkage and cfg.maxage > 0 and age_in_days( lfs.attributes( f ).modification ) >= cfg.maxage ) then
count = count + 1
log.event( "Release: '" .. release .. "' blocked. | Reason: " .. "Max Age" )
--// nfo check
Expand Down Expand Up @@ -160,7 +161,6 @@ announce.update = function( )
local path = cfg.path
path = tostring( path )
local mode, err = lfs.attributes( path, "mode" )

if mode ~= "directory" then
log.event( "Warning: directory '" .. path .. "' is not a directory or does not exist, skipping..." )
elseif ( ( type( cfg.blacklist ) ~= "table" ) or type( cfg.whitelist ) ~= "table" ) then
Expand All @@ -180,7 +180,8 @@ announce.update = function( )
for dir in lfs.dir( path ) do
if ( dir ~= "." ) and ( dir ~= "..") then
local n = tonumber( dir )
if n and ( 0101 <= n ) and ( 1231 >= n ) then -- rough estimate; 1199 is still allowed, though
local d, m = string.match( dir, "(%d%d)(%d%d)" )
if n and check_number_between( m, 1, 31 ) and check_number_between( d, 1, 12 ) then
search( path .. "/" .. dir, cfg, found )
else
log.event( "Warning: directory '" .. dir .. "' fits not in 4 digit day dir scheme, skipping..." )
Expand All @@ -196,6 +197,6 @@ announce.update = function( )
end
local c = 0
for i, k in pairs( found ) do c = c + 1 end
log.event( "...finished. Found: " .. c .. " new releases." )
log.event( "...finished. Found " .. c .. " new releases." )
return found
end
2 changes: 1 addition & 1 deletion core/const.lua
Expand Up @@ -12,4 +12,4 @@ CERT_PATH = "certs/"
LIB_PATH = "lib/"
RES_PATH = "lib/ressources/"

_VERSION = "v0.8.1"
_VERSION = "v0.9.0"
25 changes: 9 additions & 16 deletions core/log.lua
Expand Up @@ -19,38 +19,31 @@ package.cpath = package.cpath .. ";"
.. "././lib/lfs/?" .. ".dll" .. ";"

local lfs = require( "lfs" )
local lfs_a = lfs.attributes

local util = require( CORE_PATH .. "util" )
local util_formatbytes = util.formatbytes
local util_loadtable = util.loadtable

local os_date = os.date
local io_open = io.open

local cfg_tbl = util_loadtable( CFG_PATH .. "cfg.lua" )
local cfg_tbl = util.loadtable( CFG_PATH .. "cfg.lua" )
local maxlogsize = cfg_tbl[ "logfilesize" ] or 2097152

local logfile, content
local releasefile, releases

--// check if logfile reaches the maximum allowable size and if then clear it
local check_filesize = function( file )
local logsize = lfs_a( file ).size or 0
local logsize = lfs.attributes( file ).size or 0
if logsize > maxlogsize then
local f = io_open( file, "w+" ); f:close()
local f = io.open( file, "w+" ); f:close()
if file:find( "logfile" ) then content = "" end
if file:find( "announced" ) then releases = {} end
return true
end
return false
end

local logfile, err = io_open( LOG_PATH .. "logfile.txt", "a+" )
local logfile, err = io.open( LOG_PATH .. "logfile.txt", "a+" )
assert( logfile, "Fail: " .. tostring( err ) )
local content = logfile:read( "*a" )

local releasefile, err = io_open( LOG_PATH .. "announced.txt", "a+" )
local releasefile, err = io.open( LOG_PATH .. "announced.txt", "a+" )
assert( releasefile, "Fail: " .. tostring( err ) )
local releases = { }
for line in releasefile:lines() do releases[ line ] = true end
Expand All @@ -63,27 +56,27 @@ end

log.release = function( buf )
local cleared = false
local timestamp = "[" .. os_date( "%Y-%m-%d/%H:%M:%S" ) .. "] "
local timestamp = "[ " .. os.date( "%Y-%m-%d / %H:%M:%S" ) .. "] "
if check_filesize( LOG_PATH .. "announced.txt" ) then cleared = true end
releases[ buf ] = true
releasefile:write( buf .. "\n" )
releasefile:flush()
if cleared then
logfile:write( timestamp .. "cleared 'announced.txt' because of max logfile size: " .. util_formatbytes( maxlogsize ) .. "\n" )
logfile:write( timestamp .. "cleared 'announced.txt' because of max logfile size: " .. util.formatbytes( maxlogsize ) .. "\n" )
logfile:flush()
end
end

log.event = function( buf )
local cleared = false
local timestamp = "[" .. os_date( "%Y-%m-%d/%H:%M:%S" ) .. "] "
local timestamp = "[ " .. os.date( "%Y-%m-%d / %H:%M:%S" ) .. " ] "
if check_filesize( LOG_PATH .. "logfile.txt" ) then cleared = true end
buf = timestamp .. buf
logfile:write( buf .. "\n" )
logfile:flush()
content = content .. buf
if cleared then
logfile:write( timestamp .. "cleared 'logfile.txt' because of max logfile size: " .. util_formatbytes( maxlogsize ) .. "\n" )
logfile:write( timestamp .. "cleared 'logfile.txt' because of max logfile size: " .. util.formatbytes( maxlogsize ) .. "\n" )
logfile:flush()
end
end
Expand Down
17 changes: 9 additions & 8 deletions core/util.lua
Expand Up @@ -12,8 +12,6 @@ local savetable
local loadtable
local formatbytes

local string_format = string.format

sortserialize = function( tbl, name, file, tab, r )
tab = tab or ""
local temp = { }
Expand All @@ -25,7 +23,7 @@ sortserialize = function( tbl, name, file, tab, r )
table.sort( temp )
local str = tab .. name
if r then
file:write( str .. " {\n\n" )
file:write( str .. "return {\n\n" )
else
file:write( str .. " = {\n\n" )
end
Expand All @@ -49,9 +47,12 @@ end
savetable = function( tbl, name, path )
local file, err = io.open( path, "w+" )
if file then
--file:write( "local " .. name .. "\n\n" )
sortserialize( tbl, name, file, "" )
file:write( "\n\nreturn " .. name )
if not name or name == "" then
sortserialize( tbl, name, file, "", true )
else
sortserialize( tbl, name, file, "" )
file:write( "\n\nreturn " .. name )
end
file:close( )
return true
else
Expand Down Expand Up @@ -151,9 +152,9 @@ formatbytes = function( bytes )
end

if units[ i ] == "B" then
return string_format( "%.0f", bytes ) .. " " .. ( units[ i ] or "?" )
return string.format( "%.0f", bytes ) .. " " .. ( units[ i ] or "?" )
else
return string_format( "%.2f", bytes ) .. " " .. ( units[ i ] or "?" )
return string.format( "%.2f", bytes ) .. " " .. ( units[ i ] or "?" )
end
end

Expand Down

0 comments on commit 5918f81

Please sign in to comment.