@@ -209,10 +209,18 @@ public void start(){
209209 }else {
210210 this .pool .execute (new ListenerThreadTCP ());
211211 }
212- String log = logListener ();
212+ String log = logListener ("yyyy-MM-dd HH.mm.ss" , this :: getMax , SMOD2_LOG_FILE );
213213 if (log != null ) {
214- this .pool .execute (new LogListener (log , Integer .parseInt (serverProp .getProperty (SMOD2_LOG_INTERVAL ,"2000" ))));
214+ this .pool .execute (new LogListener (log , Integer .parseInt (serverProp .getProperty (SMOD2_LOG_INTERVAL ,"2000" )), "yyyy-MM-dd HH.mm.ss" , this :: getMax , SMOD2_LOG_FILE ));
215215 }
216+ String log1 = logListener ("yyyy-MM-dd_HH_mm" ,(format , x1 , x2 ) -> getMultiSCPMax (format ,x1 ,x2 ,"MA" ),"multi-admin.log" );
217+ if (log1 != null ){
218+ this .pool .execute (new LogListener (log1 ,Integer .parseInt (serverProp .getProperty (SMOD2_LOG_INTERVAL ,"2000" )),"yyyy-MM-dd_HH_mm" ,(format , x1 , x2 ) -> getMultiSCPMax (format ,x1 ,x2 ,"MA" ),"multi-admin.log" ));
219+ this .pool .execute (new LogListener (log1 ,Integer .parseInt (serverProp .getProperty (SMOD2_LOG_INTERVAL ,"2000" )),"yyyy-MM-dd_HH_mm" ,(format , x1 , x2 ) -> getMultiSCPMax (format ,x1 ,x2 ,"SCP" ),"multi-admin.log" ));
220+ }
221+
222+
223+
216224 if (Boolean .parseBoolean (serverProp .getProperty (GITHUB ))) {
217225 this .pool .execute (new GithubConnectThread ());
218226 }
@@ -222,6 +230,35 @@ public void start(){
222230 this .startSuccessTime = new Date ().getTime ();
223231 }
224232
233+ private int getMax (SimpleDateFormat format ,File x1 ,File x2 ){
234+ try {
235+ String name1 = x1 .getName ().substring ("Round" .length ()).trim ();
236+ String name2 = x2 .getName ().substring ("Round" .length ()).trim ();
237+ Date date1 = format .parse (name1 );
238+ Date date2 = format .parse (name2 );
239+
240+ return (int )(date2 .getTime ()-date1 .getTime ());
241+ }catch (Exception e ){
242+ Utils .printException (e );
243+ }
244+ return 0 ;
245+ }
246+
247+ private int getMultiSCPMax (SimpleDateFormat format ,File x1 ,File x2 ,String str ){
248+ try {
249+ String name1 = x1 .getName ().replace ("_" +str +"_output_log.txt" ,"" );
250+ String name2 = x2 .getName ().replace ("_" +str +"_output_log.txt" ,"" );
251+ Date date1 = format .parse (name1 );
252+ Date date2 = format .parse (name2 );
253+
254+ return (int )(date2 .getTime ()-date1 .getTime ());
255+ }catch (Exception e ){
256+ Utils .printException (e );
257+ }
258+
259+ return 0 ;
260+ }
261+
225262 public <T > T sendGetPacket (GetPacket packet ,Class <T > type ){
226263 return type .cast (packet .send ());
227264 }
@@ -706,11 +743,18 @@ private class LogListener implements Runnable {
706743 private long lastKnownPosition = 0 ;
707744 private boolean shouldIRun = true ;
708745 private File crunchifyFile ;
746+ private String timeFormat ;
747+
748+ private Max max ;
709749
750+ private String fileProperty ;
710751
711- public LogListener (String file ,int myInterval ) {
752+ public LogListener (String file ,int myInterval , String timeFormat , Max max , String prop ) {
712753 this .crunchifyRunEveryNSeconds = myInterval ;
713754 this .crunchifyFile = new File (file );
755+ this .timeFormat = timeFormat ;
756+ this .max = max ;
757+ this .fileProperty = prop ;
714758 }
715759
716760 private void printLine (String message ) {
@@ -732,7 +776,7 @@ public void run() {
732776 while (shouldIRun ) {
733777 Thread .sleep (crunchifyRunEveryNSeconds );
734778
735- String log = logListener ();
779+ String log = logListener (timeFormat , max , fileProperty );
736780
737781 if (!"same" .equals (log )){
738782 if (log !=null ) {
@@ -817,10 +861,10 @@ private void startConsoleCommand() throws IOException{
817861
818862 private File [] beforeFile ;
819863
820- private String logListener (){
821- String serverProps = serverProp .getProperty (SMOD2_LOG_FILE );
864+ private String logListener (String timeFormat , Max max , String fileProperty ){
865+ String serverProps = serverProp .getProperty (fileProperty );
822866 File file = new File (serverProps );
823- SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH.mm.ss" );
867+ SimpleDateFormat format = new SimpleDateFormat (timeFormat );
824868 if (file .exists ()){
825869 File [] files = file .listFiles ();
826870 if (files !=null ) {
@@ -832,20 +876,8 @@ private String logListener(){
832876 }
833877 }
834878 File lastFile = Arrays .stream (files )
835- .filter (x ->x .getName ().endsWith (".log" ))
836- .sorted ((x1 ,x2 )->{
837- try {
838- String name1 = x1 .getName ().substring ("Round" .length ()).trim ();
839- String name2 = x2 .getName ().substring ("Round" .length ()).trim ();
840- Date date1 = format .parse (name1 );
841- Date date2 = format .parse (name2 );
842-
843- return (int )(date2 .getTime ()-date1 .getTime ());
844- }catch (Exception e ){
845- Utils .printException (e );
846- }
847- return 0 ;
848- }).collect (Collectors .toList ()).get (0 );
879+ .filter (x ->x .getName ().endsWith (".log" )||x .getName ().endsWith (".txt" ))
880+ .sorted ((x1 ,x2 )->max .getMax (format ,x1 ,x2 )).collect (Collectors .toList ()).get (0 );
849881 //Round 2019-07-10 08.47.31
850882 return lastFile .toString ();
851883
@@ -855,5 +887,11 @@ private String logListener(){
855887 return null ;
856888 }
857889
890+ interface Max {
891+
892+
893+ int getMax (SimpleDateFormat format ,File x1 ,File x2 );
894+
895+ }
858896
859897}
0 commit comments