@@ -19,7 +19,8 @@ enum logType_s {
1919new logType_s: ca_log_type,
2020 logLevel_s: ca_log_level = logLevel_Debug,
2121 g_logsPath[PLATFORM_MAX_PATH],
22- bool: ca_update_notify
22+ bool: ca_update_notify,
23+ ca_log_autodelete_time
2324
2425new const LOG_FOLDER[] = " ChatAdditions"
2526
@@ -76,6 +77,8 @@ public plugin_init() {
7677 g_fwdClientVoice = CreateMultiForward (" CA_Client_Voice" , ET_STOP, FP_CELL, FP_CELL)
7778 g_fwdClientChangeName = CreateMultiForward (" CA_Client_ChangeName" , ET_STOP, FP_CELL, FP_STRING)
7879
80+ CheckAutoDelete ()
81+
7982 CA_Log (logLevel_Debug, " Chat Additions: Core initialized!" )
8083
8184 set_task_ex (6 .274 , " _OnConfigsExecuted" )
@@ -91,12 +94,70 @@ public _OnConfigsExecuted() {
9194 CheckUpdate ()
9295}
9396
97+ CheckAutoDelete () {
98+ if (ca_log_autodelete_time > 0 ) {
99+ if (dir_exists (g_logsPath)) {
100+ new logFile[PLATFORM_MAX_PATH]
101+ new dirHandle
102+ new subDirectory[PLATFORM_MAX_PATH]
103+ new deleteTime
104+
105+ deleteTime = get_systime () - (ca_log_autodelete_time * 60 * 60 * 24 )
106+
107+ dirHandle = open_dir (g_logsPath, logFile, charsmax (logFile))
108+
109+ if (dirHandle) {
110+ while (next_file (dirHandle, logFile, charsmax (logFile))) {
111+ if (logFile[0 ] == ' .' )
112+ continue
113+
114+ if (containi (logFile, " .log" ) == - 1 ) {
115+ formatex (subDirectory, charsmax (subDirectory), " %s /%s " , g_logsPath, logFile)
116+
117+ ReadFolder (deleteTime, subDirectory)
118+
119+ continue
120+ }
121+ }
122+ close_dir (dirHandle)
123+ }
124+ }
125+ }
126+ }
127+
128+ ReadFolder (deleteTime, logPath[]) {
129+ new logFile[PLATFORM_MAX_PATH]
130+ new dirHandle = open_dir (logPath, logFile, charsmax (logFile))
131+ new fileTime
132+
133+ if (dirHandle) {
134+ do
135+ {
136+ if (logFile[0 ] == ' .' ) {
137+ continue
138+ }
139+
140+ if (containi (logFile, " .log" ) != - 1 ) {
141+ fileTime = 0
142+ format (logFile, charsmax (logFile), " %s /%s " , logPath, logFile)
143+
144+ fileTime = GetFileTime (logFile, FileTime_Created)
145+ if (fileTime < deleteTime) {
146+ unlink (logFile)
147+ }
148+ }
149+ } while (next_file (dirHandle, logFile, charsmax (logFile)))
150+ }
151+ close_dir (dirHandle)
152+ }
153+
94154Create_CVars () {
155+
95156 bind_pcvar_num (create_cvar (" ca_log_type" , " 1" ,
96157 .description = fmt (" Log file type\n \
97158 0 = log to common amxx log file (logs/L*.log)\n \
98159 1 = log to plugins folder (logs/%s /[plugin name]/L*.log)\n \
99- 2 = silent log to plugins folder (logs/%s /[plugin name]/L*.log)" , LOG_FOLDER),
160+ 2 = silent log to plugins folder (logs/%s /[plugin name]/L*.log)" , LOG_FOLDER, LOG_FOLDER ),
100161 .has_min = true , .min_val = 0 .0 ,
101162 .has_max = true , .max_val = float (_LogToDirSilent)
102163 ),
@@ -118,6 +179,15 @@ Create_CVars() {
118179 ),
119180 ca_update_notify
120181 )
182+
183+ bind_pcvar_num (create_cvar (" ca_log_autodelete_time" , " 7" ,
184+ .description = " The time in days after which the log files should be deleted.\n \
185+ 0 - The logs won't be deleted.\n \
186+ > 0 - The logs will be deleted at the time inserted." ,
187+ .has_min = true , .min_val = 0 .0
188+ ),
189+ ca_log_autodelete_time
190+ )
121191}
122192
123193public plugin_natives () {
0 commit comments