Search in sources :

Example 1 with LocaleUtilEncodingException

use of com.biglybt.core.internat.LocaleUtilEncodingException in project BiglyBT by BiglySoftware.

the class DiskManagerImpl method deleteDataFileContents.

private static void deleteDataFileContents(TOTorrent torrent, String torrent_save_dir, String torrent_save_file, boolean force_no_recycle) throws TOTorrentException, UnsupportedEncodingException, LocaleUtilEncodingException {
    LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
    TOTorrentFile[] files = torrent.getFiles();
    String root_path = torrent_save_dir + File.separator + torrent_save_file + File.separator;
    boolean delete_if_not_in_dir = COConfigurationManager.getBooleanParameter("File.delete.include_files_outside_save_dir");
    for (int i = 0; i < files.length; i++) {
        byte[][] path_comps = files[i].getPathComponents();
        String path_str = root_path;
        for (int j = 0; j < path_comps.length; j++) {
            try {
                String comp = locale_decoder.decodeString(path_comps[j]);
                comp = FileUtil.convertOSSpecificChars(comp, j != path_comps.length - 1);
                path_str += (j == 0 ? "" : File.separator) + comp;
            } catch (UnsupportedEncodingException e) {
                Debug.out("file - unsupported encoding!!!!");
            }
        }
        File file = new File(path_str);
        File linked_file = FMFileManagerFactory.getSingleton().getFileLink(torrent, i, file);
        boolean delete;
        if (linked_file == file) {
            delete = true;
        } else {
            try {
                if (delete_if_not_in_dir || linked_file.getCanonicalPath().startsWith(new File(root_path).getCanonicalPath())) {
                    file = linked_file;
                    delete = true;
                } else {
                    delete = false;
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
                delete = false;
            }
        }
        if (delete && file.exists() && !file.isDirectory()) {
            try {
                FileUtil.deleteWithRecycle(file, force_no_recycle);
            } catch (Exception e) {
                Debug.out(e.toString());
            }
        }
    }
    TorrentUtils.recursiveEmptyDirDelete(new File(torrent_save_dir, torrent_save_file));
}
Also used : TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) LocaleUtilDecoder(com.biglybt.core.internat.LocaleUtilDecoder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) CacheFile(com.biglybt.core.diskmanager.cache.CacheFile) File(java.io.File) LocaleUtilEncodingException(com.biglybt.core.internat.LocaleUtilEncodingException) CacheFileManagerException(com.biglybt.core.diskmanager.cache.CacheFileManagerException) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) DownloadManagerException(com.biglybt.core.download.DownloadManagerException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)1 CacheFileManagerException (com.biglybt.core.diskmanager.cache.CacheFileManagerException)1 DownloadManagerException (com.biglybt.core.download.DownloadManagerException)1 LocaleUtilDecoder (com.biglybt.core.internat.LocaleUtilDecoder)1 LocaleUtilEncodingException (com.biglybt.core.internat.LocaleUtilEncodingException)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)1 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1