@@ -36,6 +36,7 @@ using namespace std;
3636shrink_t opt_level;
3737bool opt_quiet;
3838bool opt_force;
39+ bool opt_keep_timestamp=false ;
3940
4041enum ftype_t {
4142 ftype_png,
@@ -570,7 +571,18 @@ void rezip_single(const string& file, unsigned long long& total_0, unsigned long
570571 size_0 = file_size (file);
571572
572573 try {
574+ struct stat orig_stat;
575+ const char *filecstr = file.c_str ();
576+ if (opt_keep_timestamp) {
577+ stat (filecstr, &orig_stat);
578+ }
573579 convert_inplace (file);
580+ if (opt_keep_timestamp) {
581+ struct utimbuf utime_buf;
582+ utime_buf.actime = orig_stat.st_atime ; // Set access time
583+ utime_buf.modtime = orig_stat.st_mtime ; // Set modification time
584+ utime (filecstr, &utime_buf);
585+ }
574586 } catch (error_unsupported& e) {
575587 desc = e.desc_get ();
576588 }
@@ -580,7 +592,6 @@ void rezip_single(const string& file, unsigned long long& total_0, unsigned long
580592 } catch (error& e) {
581593 throw e << " on " << file;
582594 }
583-
584595 if (!opt_quiet) {
585596 cout << setw (12 ) << size_0 << setw (12 ) << size_1 << " " ;
586597 if (size_0) {
@@ -630,15 +641,15 @@ struct option long_options[] = {
630641 {" shrink-extra" , 0 , 0 , ' 3' },
631642 {" shrink-insane" , 0 , 0 , ' 4' },
632643 {" iter" , 1 , 0 , ' i' },
633-
644+ { " keep-timestamp " , 0 , 0 , ' k ' },
634645 {" quiet" , 0 , 0 , ' q' },
635646 {" help" , 0 , 0 , ' h' },
636647 {" version" , 0 , 0 , ' V' },
637648 {0 , 0 , 0 , 0 }
638649};
639650#endif
640651
641- #define OPTIONS " zl01234i:fqhV "
652+ #define OPTIONS " zl01234i:kfqhV "
642653
643654void version ()
644655{
@@ -649,7 +660,7 @@ void usage()
649660{
650661 version ();
651662
652- cout << " Usage: advpng [options] [FILES...]" << endl;
663+ cout << " Usage: advdef [options] [FILES...]" << endl;
653664 cout << endl;
654665 cout << " Modes:" << endl;
655666 cout << " " SWITCH_GETOPT_LONG (" -z, --recompress " , " -z" ) " Recompress the specified files" << endl;
@@ -659,6 +670,8 @@ void usage()
659670 cout << " " SWITCH_GETOPT_LONG (" -2, --shrink-normal " , " -2" ) " Compress normal (libdeflate)" << endl;
660671 cout << " " SWITCH_GETOPT_LONG (" -3, --shrink-extra " , " -3" ) " Compress extra (7z)" << endl;
661672 cout << " " SWITCH_GETOPT_LONG (" -4, --shrink-insane " , " -4" ) " Compress extreme (zopfli)" << endl;
673+ cout << " " SWITCH_GETOPT_LONG (" -k, --keep-timestamp" , " -k" ) " Keep the original timestamp" << endl;
674+
662675 cout << " " SWITCH_GETOPT_LONG (" -i N, --iter=N " , " -i" ) " Compress iterations" << endl;
663676 cout << " " SWITCH_GETOPT_LONG (" -f, --force " , " -f" ) " Force the new file also if it's bigger" << endl;
664677 cout << " " SWITCH_GETOPT_LONG (" -q, --quiet " , " -q" ) " Don't print on the console" << endl;
@@ -721,6 +734,9 @@ void process(int argc, char* argv[])
721734 case ' f' :
722735 opt_force = true ;
723736 break ;
737+ case ' k' :
738+ opt_keep_timestamp = true ;
739+ break ;
724740 case ' q' :
725741 opt_quiet = true ;
726742 break ;
0 commit comments