From bf1217839dbbcb4c344072de1c68763b37e7914a Mon Sep 17 00:00:00 2001 From: Quinten <67589015+QuintenQVD0@users.noreply.github.com> Date: Sat, 6 May 2023 11:31:33 +0200 Subject: [PATCH] Improve wrapper --- .../swords_'n_Magic_and_Stuff/wrapper | Bin 17736 -> 17784 bytes .../swords_'n_Magic_and_Stuff/wrapper.c | 74 +++++++++++------- 2 files changed, 45 insertions(+), 29 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 0bce0609817198ef56276ff48409e3c9a3626013..29909ad1d2164be05bc25be8c4b4a78a59e5e7e9 100644 GIT binary patch delta 3064 zcmZWr4Qx}_6~5Pw6Wb-&j^j9n(AcyiNegit8cd>@*bpy|iM62CU8Md%R>}(P*3gn| znUXrx4eG0FN;uH96lsaHu0qpPm{*3{v^Yh@$<|h8+8D4@O{YzIS%D=Qpo}JaJLkUl zvaWm5d*|MBzVmy}yZ4U0z-M3J2P$1dE+(F+M%e6N-5a(JyEf|>yco2NmuQo5aPgpR z$fV7NU?UIOr}Y^#!?S#!t303y7by5l@080euXVAxKet~x)zNx!*VfV^_p*6VOt*WM zBAVk{EVTCG#L1RIz+A(B2AyUvY%^Dye$OD;=z*8aA^r%AnuD;ps1nBTwH8(Kg9I~O z6%Z3k(2O4ws{JT^P>hb_=tp8SS=7KEr;%x1*XVQQ@CiHNsLzmqW}{4(BX) zTb_9O(MKPLTZ=EjjpF*q36wc?+@ZmjF>*6|N9T1f*=b|U#Lnt+C87-syZz8v;`K$# zG;SgKztRE>mfXp2fp-zJNE3jIiKapmLOw~d5|}C;NPmMe(gK;jO{p}K^Y5O*(jfTSd#xDrT#j- z`MymV%iqzulqpRK5>d^Jsh$edx#p;DBT0m#K`CRoi9D%!c8^C&TduCc@jz~mO`UX9 z_mk~2I+g61$T>o0ntlskxT@Md(4kg!a)+>JAp0Y)B93(j6H+Sjb3`#o{@b2KQab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vAXTT#BxmT?*1K^cx;M)E4&k1j%R?T$6w zSPo+u7dsyA;r%$;fe)6CzPYycK5w`F**8A_hQ}K~>#L~%zWV(%2mLta;cR_Npr8{f z^sxFlOWeA?L7$Of?*QK4f^p*hYUiignMv*{%2SLE{ef~^_9HJgWbuH~t_hfG7!Tyw z`LW_M6Du(yd>u05kto1Oz-8u02YeE6(+zMp&_??p8gxS>SZQ`3el+N(b#ON5rpNH< zg7<>YV6z4`yUbpagM*vf+Ozskg%Nud4oqYfSy*BB>2_nq41Nd)lz7QB+}iA?-Qat0 zKm7~zKj^1U7{PHJ@QpR}F=%eA_8QA&thN&eWu{fc2}c|EdyPZXXpWnR3dBRQFxS|I zZzHh9&kM$a>*>eg=$1D659n`nd*_kwWc-Lxn(_ALG{zKXK{>7|V&P zX3SYPlh^eey?TGD8v?;Mb^9)t##A=~4$rA}!<#^I3rDZ2^;}n<^Xz&560+FbS7x*0 zK`21fR8H5yCrxh1Hx=QVD>sq2sydrJv}ZKhJVr+=zO&9ex@GHHN{8WxEq>nUR73Lc zGFpv3HDnXawD>te-xLDykr3CRYaI}egvyM4W5@!9S0c~a4&bt}3&tXD2t|3WPw&P) zh(|*pMxCZX3%nAo=ZuCBU@F>1H-dMYpZotWZG2mZJLc139UC3m)<&`W`_1KWWBVE| t8_|F)@U0=vSeqQgTU)T(hFV*=LW9PLzzi~)nl #include -void print_latest_log(const char* log_directory) { +void print_latest_log(const char* log_directory, off_t* last_pos, off_t* last_size) { DIR *dir; struct dirent *entry; time_t latest_time = 0; @@ -39,45 +39,58 @@ void print_latest_log(const char* log_directory) { return; } - printf("\nLatest log file: %s\n", latest_file); - int fd = open(latest_file, O_RDONLY); if (fd < 0) { printf("Error opening file %s\n", latest_file); return; } - 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); + // Get the size of the file + off_t size = lseek(fd, 0, SEEK_END); + + // 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'); } - last_line_printed = (buffer[bytes_read - 1] == '\n'); + } while (bytes_read > 0); + + // If the last line was not printed, print it now + if (!last_line_printed) { + printf("\n"); } - } while (bytes_read > 0); - // If the last line was not printed, print it now - if (!last_line_printed) { - printf("\n"); + // Remember the last position and size that was read + *last_pos = lseek(fd, 0, SEEK_CUR); + *last_size = size; } - close(fd); + } + + int main(int argc, char** argv) { if (argc < 2) { printf("Usage: winewrapper wine_path wine_args exe_path exe_args\n"); @@ -104,12 +117,15 @@ 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); + print_latest_log(log_directory, &last_pos, &last_size); + while (1) { sleep(1); - print_latest_log(log_directory); + print_latest_log(log_directory, &last_pos, &last_size); } kill(pid, SIGTERM);