Exemplo n.º 1
0
 /**
  * Change a playlist name
  *
  * @param plfOld
  * @param sNewName
  * @return new playlist
  */
 public Playlist changePlaylistFileName(Playlist plfOld, String sNewName) throws JajukException {
   synchronized (PlaylistManager.getInstance().getLock()) {
     // 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());
     plfNew.setProperties(plfOld.getProperties()); // transfert all
     // properties
     // (inc id and
     // name)
     plfNew.setProperty(XML_ID, sNewId); // reset new id and name
     plfNew.setProperty(XML_NAME, sNewName); // reset new id and name
     // check file name and extension
     if (plfNew.getName().lastIndexOf('.') != plfNew.getName().indexOf('.') // just
         // one
         // '.'
         || !(Util.getExtension(ioNew).equals(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 {
       plfOld.getFio().renameTo(ioNew);
     } catch (Exception e) {
       throw new JajukException(134);
     }
     // OK, remove old file and register this new file
     hmItems.remove(plfOld.getID());
     if (!hmItems.containsKey(sNewId)) {
       hmItems.put(sNewId, plfNew);
     }
     // change directory reference
     plfNew.getDirectory().changePlaylistFile(plfOld, plfNew);
     return plfNew;
   }
 }
Exemplo n.º 2
0
 /** Delete a playlist */
 public void removePlaylistFile(Playlist plf) {
   synchronized (PlaylistManager.getInstance().getLock()) {
     String sFileToDelete =
         plf.getDirectory().getFio().getAbsoluteFile().toString()
             + java.io.File.separatorChar
             + plf.getName();
     java.io.File fileToDelete = new java.io.File(sFileToDelete);
     if (fileToDelete.exists()) {
       fileToDelete.delete();
       // check that file has been really deleted (sometimes, we get no
       // exception)
       if (fileToDelete.exists()) {
         Log.error("131", new JajukException(131));
         Messages.showErrorMessage(131);
         return;
       }
     }
     plf.getDirectory().removePlaylistFile(plf);
     // remove playlist
     removeItem(plf.getID());
   }
 }