From 9c08f3fd5ef42c32765c732da43ce08cbc9eddbd Mon Sep 17 00:00:00 2001 From: Quinten <67589015+QuintenQVD0@users.noreply.github.com> Date: Sat, 6 May 2023 11:38:55 +0200 Subject: [PATCH] wrapper use time and not size --- .../swords_'n_Magic_and_Stuff/wrapper | Bin 17784 -> 17784 bytes .../swords_'n_Magic_and_Stuff/wrapper.c | 79 +++++++++--------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/game_eggs/steamcmd_servers/swords_'n_Magic_and_Stuff/wrapper b/game_eggs/steamcmd_servers/swords_'n_Magic_and_Stuff/wrapper index 29909ad1d2164be05bc25be8c4b4a78a59e5e7e9..dc959e19edd2d38aa7e0fd37c49ba270a18afaac 100644 GIT binary patch delta 1199 zcmZ8fTS!z<6g_7~ZM1Y|%t!X}K}1oRy%mxg>eA^&Wla&)M+JTO6Bd35P9sbfx7+P? z8Y&`?3j2w&rX&R)DLGnEx1Sio0sFgUCX~ixqo=*kb^P$cWuLRx+H0?~&xu{4u}iec zK~r015c#!)+_al!or&xlstR;OD<0oCd9UU0ykq5E)gjaNHpBTPnGmL@pOvBf7k}-3 zw{;*Ba%x-YkPu9LSt3Jl35Ku|Ls_QPTVU9HF^(j~WC5Q^ob{0e%8kri+Q-eziX)P$ z*BdCHuQO+%c=#3Sm|?8egPSE}G1Sk1n#D=7%WVY8l$dW3w3HiFi9vy-Rd4X%>@|MN zN)OY^D?!^5ZioxU(z!-Z$9bg{b6{pdh<3CvWn}^?RHZ-Q>nAk@lMJS!YUz~f z4pgnNROMJSho<=ZTP>jv;JXYMVP!-nblvzVgr)%Q!bS;PRU!djggCE6fu_O6r0lk{ z`Ft|cH>OpuW?FjLatX1M23mo9J9I^}=0)hhwB$KJz-?*VFT`Li%5;JZrgD&>DhA|a zy|lqJ#Q+P4_xwXw62l}ldPo|y3@@|XfDCj6WU6Jh)v^%?iF!*eYdC3VhiMKl-P_Cb-8h+n$w3CdvejX$?Cae*opAyf zgVDb3Q_lSJs7E}9cIo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swords_'n_Magic_and_Stuff/wrapper.c b/game_eggs/steamcmd_servers/swords_'n_Magic_and_Stuff/wrapper.c index 7c94477b..c38eadb5 100644 --- a/game_eggs/steamcmd_servers/swords_'n_Magic_and_Stuff/wrapper.c +++ b/game_eggs/steamcmd_servers/swords_'n_Magic_and_Stuff/wrapper.c @@ -8,7 +8,7 @@ #include #include -void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_size) { +void print_latest_log(const char* log_directory, off_t* last_pos, time_t* last_time) { DIR *dir; struct dirent *entry; time_t latest_time = 0; @@ -39,58 +39,57 @@ void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_si return; } + if (latest_time <= *last_time) { + return; + } + int fd = open(latest_file, O_RDONLY); if (fd < 0) { printf("Error opening file %s\n", latest_file); return; } - // Get the size of the file - off_t size = lseek(fd, 0, SEEK_END); + // Move the file pointer to the last printed position + lseek(fd, *last_pos, SEEK_SET); - // Check if the file size has increased since the last read - if (size > *last_size) { - // Move the file pointer to the beginning of the file - lseek(fd, 0, SEEK_SET); - - char buffer[4096]; - int bytes_read; - int last_line_printed = 0; // Flag to check whether we have printed the last line - do { - bytes_read = read(fd, buffer, sizeof(buffer)); - if (bytes_read > 0) { - // Check if the last character is a newline - if (buffer[bytes_read - 1] == '\n') { - fwrite(buffer, 1, bytes_read, stdout); - fflush(stdout); - } else { - // If the last character is not a newline, add one - char* temp = (char*) malloc(bytes_read + 1); - memcpy(temp, buffer, bytes_read); - temp[bytes_read] = '\n'; - fwrite(temp, 1, bytes_read + 1, stdout); - fflush(stdout); - free(temp); - } - last_line_printed = (buffer[bytes_read - 1] == '\n'); + char buffer[4096]; + int bytes_read; + int last_line_printed = 0; // Flag to check whether we have printed the last line + do { + bytes_read = read(fd, buffer, sizeof(buffer)); + if (bytes_read > 0) { + // Check if the last character is a newline + if (buffer[bytes_read - 1] == '\n') { + fwrite(buffer, 1, bytes_read, stdout); + fflush(stdout); + } else { + // If the last character is not a newline, add one + char* temp = (char*) malloc(bytes_read + 1); + memcpy(temp, buffer, bytes_read); + temp[bytes_read] = '\n'; + fwrite(temp, 1, bytes_read + 1, stdout); + fflush(stdout); + free(temp); } - } while (bytes_read > 0); - - // If the last line was not printed, print it now - if (!last_line_printed) { - printf("\n"); + last_line_printed = (buffer[bytes_read - 1] == '\n'); } + } while (bytes_read > 0); - // Remember the last position and size that was read - *last_pos = lseek(fd, 0, SEEK_CUR); - *last_size = size; + // If the last line was not printed, print it now + if (!last_line_printed) { + printf("\n"); } - close(fd); + // Remember the last position and time that was read + *last_pos = lseek(fd, 0, SEEK_CUR); + *last_time = latest_time; + + close(fd); } + int main(int argc, char** argv) { if (argc < 2) { printf("Usage: winewrapper wine_path wine_args exe_path exe_args\n"); @@ -116,13 +115,13 @@ int main(int argc, char** argv) { } sleep(30); - + off_t last_pos = 0; off_t last_size = 0; char* log_directory = "/home/container/SNM2020/Saved/Logs"; print_latest_log(log_directory, &last_pos, &last_size); - + while (1) { sleep(1); print_latest_log(log_directory, &last_pos, &last_size); @@ -131,4 +130,4 @@ int main(int argc, char** argv) { kill(pid, SIGTERM); return 0; -} +} \ No newline at end of file