*/
public static int checkCardDir(final Shell parent, final Folder f)
{
int res = C_OK;
final Attribut a1 = ((FolderDescription) f.getDescription()).getCardDescription().find(AttrType.T_Image);
if (a1 != null)
{
final int attrIdx = ((FolderDescription) f.getDescription()).getCardDescription().getAttributList().indexOf(a1);
// Keep previous dialog -> Keep memory of last directory
if (_dd == null)
{
_dd = new DirectoryDialog(parent);
}
final String fndir = _dd.open();
final List<DeltaMMFile> lstDelta = new LinkedList<DeltaMMFile>();
if (fndir != null)
{
try
{
new ProgressMonitorDialog(parent).run(true, false, new IRunnableWithProgress()
{
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
{
File fdir = new File(fndir);
File[] tabMMFile = fdir.listFiles();
monitor.beginTask("Checking", tabMMFile.length);
List<File> lstMMFile = new ArrayList<File>(tabMMFile.length);
for (File fic : tabMMFile)
{
if (Attribut.isImageExtension(fic))
{
lstMMFile.add(fic);
}
}
// Check card images files status
monitor.subTask("Card checking");
for (Card cd : f.getLstCard())
{
AttrFile ai = (AttrFile) cd.getValue(attrIdx);
if (ai != null)
{
String absCardFileName = ai.getAbsolutePath();
File foundMMFile = null;
for (Iterator<File> itfic = lstMMFile.iterator(); itfic.hasNext() && (foundMMFile == null);)
{
File floc = itfic.next();
if (absCardFileName.equals(floc.getAbsolutePath()))
{
foundMMFile = floc;
itfic.remove();
}
}
if (foundMMFile == null)
{
// Suggest Card Deletion
DeltaMMFile dlt = new DeltaMMFile(cd, attrIdx, FileStatus.MISSING);
lstDelta.add(dlt);
}
else
{
// Check Last modification Date and size
Date dateBase = ai.getLastModificationDate();
// Get the actual file last modification date
long lmd = foundMMFile.lastModified();
if (dateBase.getTime() < lmd)
{
// Suggest Card Update
DeltaMMFile dlt = new DeltaMMFile(cd, attrIdx, FileStatus.UPDATED);
dlt.setFoundFic(foundMMFile);
lstDelta.add(dlt);
}
else
{
// Nothing to do with the card, it's up to date
}
}
} // Else the card has a non valued AttrFile
}
monitor.subTask("New File Importation");
// If the list of read files is not empty, it means that some MM files are not recorded
// in the database ==> Suggest to create them
for (File fic : lstMMFile)
{
DeltaMMFile dlt = new DeltaMMFile(fic);
dlt.setFoundFic(fic);
AttrImage imgAttr = (AttrImage) a1.create(Application.getDataStore(), fic);
if (imgAttr != null)
{
dlt.setAttrFile(imgAttr);
}