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));
}
Aggregations