Exemplo n.º 1
0
 /**
  * Change a playlist name.
  *
  * @param plfOld DOCUMENT_ME
  * @param sNewName DOCUMENT_ME
  * @return new playlist
  * @throws JajukException the jajuk exception
  */
 public synchronized Playlist changePlaylistFileName(Playlist plfOld, String sNewName)
     throws JajukException {
   // check given name is different
   if (plfOld.getName().equals(sNewName)) {
     return plfOld;
   }
   // check if this file still exists
   if (!plfOld.getFIO().exists()) {
     throw new JajukException(135);
   }
   java.io.File ioNew =
       new java.io.File(
           plfOld.getFIO().getParentFile().getAbsolutePath() + java.io.File.separator + sNewName);
   // recalculate file ID
   plfOld.getDirectory();
   String sNewId = PlaylistManager.createID(sNewName, plfOld.getDirectory());
   // create a new playlist (with own fio and sAbs)
   Playlist plfNew = new Playlist(sNewId, sNewName, plfOld.getDirectory());
   // Transfer all properties (id and name)
   // We use a shallow copy of properties to avoid any properties share between
   // two items
   plfNew.setProperties(plfOld.getShallowProperties());
   plfNew.setProperty(Const.XML_ID, sNewId); // reset new id and name
   plfNew.setProperty(Const.XML_NAME, sNewName); // reset new id and name
   // check file name and extension
   if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
       // one
       // '.'
       || !(UtilSystem.getExtension(ioNew).equals(Const.EXT_PLAYLIST))) { // check
     // extension
     Messages.showErrorMessage(134);
     throw new JajukException(134);
   }
   // check if future file exists (under windows, file.exists
   // return true even with different case so we test file name is
   // different)
   if (!ioNew.getName().equalsIgnoreCase(plfOld.getName()) && ioNew.exists()) {
     throw new JajukException(134);
   }
   // try to rename file on disk
   try {
     boolean result = plfOld.getFIO().renameTo(ioNew);
     if (!result) {
       throw new IOException();
     }
   } catch (Exception e) {
     throw new JajukException(134, e);
   }
   // OK, remove old file and register this new file
   removeItem(plfOld);
   registerItem(plfNew);
   return plfNew;
 }
 /**
  * Walk through all Playlists and remove the ones for the current device.
  *
  * @param dirsToRefresh list of the directory to refresh, null if all of them
  * @return true if there was any playlist removed
  */
 private boolean cleanPlaylist(List<Directory> dirsToRefresh) {
   boolean bChanges = false;
   final List<Playlist> plfiles = PlaylistManager.getInstance().getPlaylists();
   for (final Playlist plf : plfiles) {
     // check if it is a playlist located inside refreshed directory
     if (dirsToRefresh != null) {
       boolean checkIt = false;
       for (Directory directory : dirsToRefresh) {
         if (plf.hasAncestor(directory)) {
           checkIt = true;
         }
       }
       // This item is not in given directories, just continue
       if (!checkIt) {
         continue;
       }
     }
     if (!ExitService.isExiting()
         && plf.getDirectory().getDevice().equals(this)
         && plf.isReady()
         && !plf.getFIO().exists()) {
       PlaylistManager.getInstance().removeItem(plf);
       Log.debug("Removed: " + plf);
       if (reporter != null) {
         reporter.notifyFileOrPlaylistDropped();
       }
       bChanges = true;
     }
   }
   return bChanges;
 }