/**
  * The refresh itself.
  *
  * @param bDeepScan whether it is a deep refresh request or only fast
  * @param bManual whether it is a manual refresh or auto
  * @param dirsToRefresh list of the directory to refresh, null if all of them
  * @return true if some changes occurred in device
  */
 boolean refreshCommand(
     final boolean bDeepScan, final boolean bManual, List<Directory> dirsToRefresh) {
   try {
     // Check if this device is mounted (useful when called by
     // automatic refresh)
     if (!isMounted()) {
       return false;
     }
     // Check that device is still available
     boolean readyToMount = checkDevice();
     if (!readyToMount) {
       return false;
     }
     bAlreadyRefreshing = true;
     // reporter is already set in case of manual refresh
     if (reporter == null) {
       reporter = new RefreshReporter(this);
     }
     // Notify the reporter of the actual refresh startup
     reporter.refreshStarted();
     lDateLastRefresh = System.currentTimeMillis();
     // check Jajuk is not exiting because a refresh cannot start in
     // this state
     if (ExitService.isExiting()) {
       return false;
     }
     int iNbFilesBeforeRefresh = FileManager.getInstance().getElementCount();
     int iNbDirsBeforeRefresh = DirectoryManager.getInstance().getElementCount();
     int iNbPlaylistsBeforeRefresh = PlaylistManager.getInstance().getElementCount();
     if (bDeepScan && Log.isDebugEnabled()) {
       Log.debug("Starting refresh of device : " + this);
     }
     // Create a directory for device itself and scan files to allow
     // files at the root of the device
     final Directory top = DirectoryManager.getInstance().registerDirectory(this);
     if (!getDirectories().contains(top)) {
       addDirectory(top);
     }
     // Start actual scan
     List<Directory> dirs = null;
     if (dirsToRefresh == null) {
       // No directory specified ? refresh the top directory
       dirs = new ArrayList<Directory>(1);
       dirs.add(top);
     } else {
       dirs = dirsToRefresh;
     }
     for (Directory dir : dirs) {
       scanRecursively(dir, bDeepScan);
     }
     // Force a GUI refresh if new files or directories discovered or have been
     // removed
     if (((FileManager.getInstance().getElementCount() - iNbFilesBeforeRefresh) != 0)
         || ((DirectoryManager.getInstance().getElementCount() - iNbDirsBeforeRefresh) != 0)
         || ((PlaylistManager.getInstance().getElementCount() - iNbPlaylistsBeforeRefresh) != 0)) {
       return true;
     }
     return false;
   } catch (final Exception e) {
     // and regular ones logged
     Log.error(e);
     return false;
   } finally {
     // make sure to unlock refreshing even if an error occurred
     bAlreadyRefreshing = false;
     // reporter is null if mount is not mounted due to early return
     if (reporter != null) {
       // Notify the reporter of the actual refresh startup
       reporter.done();
       // Reset the reporter as next time, it could be another type
       reporter = null;
     }
   }
 }