package _VisualDVM.Passes.All;
import Common.Passes.Pass;
import _VisualDVM.Global;
import _VisualDVM.GlobalData.FileObject.DirInfo;
import _VisualDVM.GlobalData.FileObject.DirInfosDataSet;
import _VisualDVM.Utils;

import java.io.File;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
public class GetOldBugReports extends Pass<DirInfosDataSet> {
    @Override
    protected boolean canStart(Object... args) throws Exception {
        target = new DirInfosDataSet();
        return true;
    }
    @Override
    protected boolean needsAnimation() {
        return true;
    }
    @Override
    protected void body() throws Exception {
        File downloadsDirectory = Global.visualiser.getDownloadsDirectory();
        File[] files = downloadsDirectory.listFiles(pathname -> pathname.isDirectory() && pathname.getName().toLowerCase().startsWith("bugreport_"));
        if (files != null) {
            //---
            Calendar c = new GregorianCalendar();
            c.setTimeInMillis(System.currentTimeMillis());
            c.add(Calendar.MONTH, -Global.normalProperties.BugReportsAgeLimit);
            Date date = c.getTime();
            long border = date.getTime();
            //--
            for (File file : files) {
                ShowMessage2(file.getName());
                long mdate = Utils.getNewestFileDate(file);
                if (mdate <= border) {
                    DirInfo d = new DirInfo(file, mdate);
                    target.put(d.getPK(), d);
                }
            }
        }
    }
}
