mirror of https://github.com/zlatinb/muwire
Make FileUnsharedEvent a batch event
parent
29e002f8f1
commit
948ab9d3c0
|
@ -52,7 +52,7 @@ class FilesModel {
|
|||
|
||||
void onFileUnsharedEvent(FileUnsharedEvent e) {
|
||||
guiThread.invokeLater {
|
||||
sharedFiles.remove(e.unsharedFile)
|
||||
sharedFiles.removeAll(e.unsharedFiles)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class FilesView extends BasicWindow {
|
|||
contentPanel.setLayoutManager(new GridLayout(4))
|
||||
|
||||
Button unshareButton = new Button("Unshare", {
|
||||
core.eventBus.publish(new FileUnsharedEvent(unsharedFile : sf))
|
||||
core.eventBus.publish(new FileUnsharedEvent(unsharedFiles : new SharedFile[]{sf}))
|
||||
MessageDialog.showMessageDialog(textGUI, "File Unshared", "Unshared "+sf.getFile().getName(), MessageDialogButton.OK)
|
||||
} )
|
||||
Button addCommentButton = new Button("Add Comment", {
|
||||
|
|
|
@ -284,14 +284,16 @@ class CollectionManager {
|
|||
}
|
||||
|
||||
synchronized void onFileUnsharedEvent(FileUnsharedEvent e) {
|
||||
InfoHash infoHash = new InfoHash(e.unsharedFile.getRoot())
|
||||
Set<FileCollection> affected = fileRootToCollections.get(infoHash)
|
||||
if (affected == null || affected.isEmpty()) {
|
||||
return
|
||||
}
|
||||
affected.each { c ->
|
||||
diskIO.execute({delete(c)} as Runnable)
|
||||
eventBus.publish(new CollectionUnsharedEvent(collection : c))
|
||||
for (SharedFile sf : e.unsharedFiles) {
|
||||
InfoHash infoHash = sf.getRootInfoHash()
|
||||
Set<FileCollection> affected = fileRootToCollections.get(infoHash)
|
||||
if (affected == null || affected.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
affected.each { c ->
|
||||
diskIO.execute({ delete(c) } as Runnable)
|
||||
eventBus.publish(new CollectionUnsharedEvent(collection: c))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class DirectoryWatcher {
|
|||
log.fine("deleted entry $f")
|
||||
SharedFile sf = fileManager.fileToSharedFile.get(f)
|
||||
if (sf != null)
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFile : sf, deleted : true))
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFiles : new SharedFile[]{sf}, deleted : true))
|
||||
else if (watchedDirectoryManager.isWatched(f))
|
||||
eventBus.publish(new DirectoryUnsharedEvent(directory : f, deleted : true))
|
||||
else
|
||||
|
|
|
@ -132,7 +132,11 @@ class FileManager {
|
|||
}
|
||||
|
||||
void onFileUnsharedEvent(FileUnsharedEvent e) {
|
||||
SharedFile sf = e.unsharedFile
|
||||
for(SharedFile sharedFile : e.unsharedFiles)
|
||||
unshareFile(sharedFile, e.deleted)
|
||||
}
|
||||
|
||||
private void unshareFile(SharedFile sf, boolean deleted) {
|
||||
InfoHash infoHash = new InfoHash(sf.getRoot())
|
||||
SharedFile[] existing = rootToFiles.get(infoHash)
|
||||
if (existing != null) {
|
||||
|
@ -149,7 +153,7 @@ class FileManager {
|
|||
|
||||
fileToSharedFile.remove(sf.file)
|
||||
positiveTree.remove(sf.file)
|
||||
if (!e.deleted && negativeTree.fileToNode.containsKey(sf.file.getParentFile())) {
|
||||
if (!deleted && negativeTree.fileToNode.containsKey(sf.file.getParentFile())) {
|
||||
negativeTree.add(sf.file,null)
|
||||
saveNegativeTree()
|
||||
}
|
||||
|
@ -258,22 +262,23 @@ class FileManager {
|
|||
negativeTree.remove(e.directory)
|
||||
saveNegativeTree()
|
||||
if (!e.deleted) {
|
||||
List<SharedFile> unsharedFiles = new ArrayList<>()
|
||||
e.directory.listFiles().each {
|
||||
if (it.isDirectory())
|
||||
eventBus.publish(new DirectoryUnsharedEvent(directory : it))
|
||||
else {
|
||||
SharedFile sf = fileToSharedFile.get(it)
|
||||
if (sf != null)
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFile : sf))
|
||||
unsharedFiles.add(sf)
|
||||
}
|
||||
}
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFiles : unsharedFiles.toArray(new SharedFile[0])))
|
||||
} else {
|
||||
def cb = new DirDeletionCallback()
|
||||
positiveTree.traverse(e.directory, cb)
|
||||
positiveTree.remove(e.directory)
|
||||
cb.unsharedFiles.each {
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFile : it, deleted: true))
|
||||
}
|
||||
eventBus.publish(new FileUnsharedEvent()unsharedFiles: cb.unsharedFiles.toArray(new SharedFile[0]),
|
||||
deleted: true)
|
||||
cb.subDirs.each {
|
||||
eventBus.publish(new DirectoryUnsharedEvent(directory : it, deleted : true))
|
||||
}
|
||||
|
|
|
@ -4,6 +4,6 @@ import com.muwire.core.Event
|
|||
import com.muwire.core.SharedFile
|
||||
|
||||
class FileUnsharedEvent extends Event {
|
||||
SharedFile unsharedFile
|
||||
SharedFile[] unsharedFiles
|
||||
boolean deleted
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ class HasherService {
|
|||
}
|
||||
|
||||
void onFileUnsharedEvent(FileUnsharedEvent evt) {
|
||||
hashed.remove(evt.unsharedFile.file)
|
||||
hashed.removeAll(evt.unsharedFiles)
|
||||
}
|
||||
|
||||
void onDirectoryUnsharedEvent(DirectoryUnsharedEvent evt) {
|
||||
|
|
|
@ -80,12 +80,17 @@ class PersisterFolderService extends BasePersisterService {
|
|||
* @param unsharedEvent
|
||||
*/
|
||||
void onFileUnsharedEvent(FileUnsharedEvent unsharedEvent) {
|
||||
def jsonPath = getJsonPath(unsharedEvent.unsharedFile)
|
||||
for(SharedFile sharedFile : unsharedEvent.unsharedFiles)
|
||||
unshareFile(sharedFile)
|
||||
}
|
||||
|
||||
private void unshareFile(SharedFile sharedFile) {
|
||||
def jsonPath = getJsonPath(sharedFile)
|
||||
def jsonFile = jsonPath.toFile()
|
||||
if(jsonFile.isFile()){
|
||||
jsonFile.delete()
|
||||
}
|
||||
def hashListPath = getHashListPath(unsharedEvent.unsharedFile)
|
||||
def hashListPath = getHashListPath(sharedFile)
|
||||
def hashListFile = hashListPath.toFile()
|
||||
if (hashListFile.isFile())
|
||||
hashListFile.delete()
|
||||
|
|
|
@ -195,9 +195,7 @@ class WatchedDirectoryManager {
|
|||
|
||||
Set<File> deletedFiles = new HashSet<>(cb.files)
|
||||
deletedFiles.removeAll(filesOnFS)
|
||||
deletedFiles.each {
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFile : fileManager.getFileToSharedFile().get(it), deleted : true))
|
||||
}
|
||||
eventBus.publish(new FileUnsharedEvent(unsharedFiles: deletedFiles.toArray(new SharedFile[0]), deleted: true))
|
||||
Set<File> deletedDirs = new HashSet<>(cb.dirs)
|
||||
deletedDirs.removeAll(dirsOnFS)
|
||||
deletedDirs.each {
|
||||
|
|
|
@ -154,7 +154,7 @@ class FileManagerTest {
|
|||
manager.onFileLoadedEvent new FileLoadedEvent(loadedFile : sf1)
|
||||
manager.onFileLoadedEvent new FileLoadedEvent(loadedFile : sf2)
|
||||
|
||||
manager.onFileUnsharedEvent new FileUnsharedEvent(deleted : true, unsharedFile: sf2)
|
||||
manager.onFileUnsharedEvent new FileUnsharedEvent(deleted : true, unsharedFiles: new SharedFile[]{sf2})
|
||||
|
||||
manager.onSearchEvent new SearchEvent(searchHash : ih.getRoot())
|
||||
Thread.sleep(20)
|
||||
|
@ -175,7 +175,7 @@ class FileManagerTest {
|
|||
SharedFile sf2 = new SharedFile(f2, ih2.getRoot(), 0)
|
||||
manager.onFileLoadedEvent new FileLoadedEvent(loadedFile: sf2)
|
||||
|
||||
manager.onFileUnsharedEvent new FileUnsharedEvent(deleted : true, unsharedFile: sf2)
|
||||
manager.onFileUnsharedEvent new FileUnsharedEvent(deleted : true, unsharedFiles: new SharedFile[]{sf2})
|
||||
|
||||
// 1 match left
|
||||
manager.onSearchEvent new SearchEvent(searchTerms: ["c"])
|
||||
|
@ -202,7 +202,7 @@ class FileManagerTest {
|
|||
sf1.setComment(comment)
|
||||
|
||||
manager.onFileLoadedEvent(new FileLoadedEvent(loadedFile : sf1))
|
||||
manager.onFileUnsharedEvent(new FileUnsharedEvent(unsharedFile : sf1, deleted : true))
|
||||
manager.onFileUnsharedEvent(new FileUnsharedEvent(unsharedFiles : new SharedFile[]{sf1}, deleted : true))
|
||||
|
||||
File f2 = new File("MuWire-0.6.0.AppImage")
|
||||
InfoHash ih2 = InfoHash.fromHashList(new byte[64])
|
||||
|
|
|
@ -455,6 +455,7 @@ class MainFrameController {
|
|||
def sfs = view.selectedSharedFiles()
|
||||
if (sfs == null)
|
||||
return
|
||||
List<SharedFile> toUnshare = new ArrayList<>()
|
||||
sfs.each { SharedFile sf ->
|
||||
|
||||
if (view.settings.collectionWarning) {
|
||||
|
@ -475,9 +476,9 @@ class MainFrameController {
|
|||
return
|
||||
}
|
||||
}
|
||||
|
||||
core.eventBus.publish(new FileUnsharedEvent(unsharedFile : sf))
|
||||
toUnshare.add(sf)
|
||||
}
|
||||
core.eventBus.publish(new FileUnsharedEvent(unsharedFiles : toUnshare.toArray(new SharedFile[0])))
|
||||
}
|
||||
|
||||
@ControllerAction
|
||||
|
|
|
@ -538,60 +538,66 @@ class MainFrameModel {
|
|||
|
||||
void onFileUnsharedEvent(FileUnsharedEvent e) {
|
||||
runInsideUIAsync {
|
||||
allSharedFiles.remove(e.unsharedFile)
|
||||
synchronized (allSharedFiles) {
|
||||
allSharedFiles.removeAll(e.unsharedFiles)
|
||||
}
|
||||
loadedFiles = allSharedFiles.size()
|
||||
|
||||
boolean wasVisible = shared.remove(e.unsharedFile)
|
||||
|
||||
DefaultMutableTreeNode dmtn = fileToNode.remove(e.unsharedFile)
|
||||
if (dmtn != null) {
|
||||
|
||||
if (wasVisible) {
|
||||
Object[] path = dmtn.getUserObjectPath()
|
||||
DefaultMutableTreeNode otherNode = treeRoot
|
||||
for (int i = 1; i < path.length; i ++) {
|
||||
Object o = path[i]
|
||||
DefaultMutableTreeNode next = null
|
||||
for (int j = 0; j < otherNode.childCount; j ++) {
|
||||
if (otherNode.getChildAt(j).getUserObject() == o) {
|
||||
next = otherNode.getChildAt(j)
|
||||
break
|
||||
for (SharedFile sharedFile : e.unsharedFiles) {
|
||||
boolean wasVisible = shared.remove(sharedFile)
|
||||
|
||||
DefaultMutableTreeNode dmtn = fileToNode.remove(sharedFile)
|
||||
if (dmtn != null) {
|
||||
|
||||
if (wasVisible) {
|
||||
Object[] path = dmtn.getUserObjectPath()
|
||||
DefaultMutableTreeNode otherNode = treeRoot
|
||||
for (int i = 1; i < path.length; i++) {
|
||||
Object o = path[i]
|
||||
DefaultMutableTreeNode next = null
|
||||
for (int j = 0; j < otherNode.childCount; j++) {
|
||||
if (otherNode.getChildAt(j).getUserObject() == o) {
|
||||
next = otherNode.getChildAt(j)
|
||||
break
|
||||
}
|
||||
}
|
||||
if (next == null)
|
||||
throw new IllegalStateException()
|
||||
otherNode = next
|
||||
}
|
||||
while (true) {
|
||||
def parent = otherNode.getParent()
|
||||
otherNode.removeFromParent()
|
||||
if (parent.getChildCount() == 0) {
|
||||
otherNode = parent
|
||||
} else
|
||||
break
|
||||
}
|
||||
if (next == null)
|
||||
throw new IllegalStateException()
|
||||
otherNode = next
|
||||
}
|
||||
while(true) {
|
||||
def parent = otherNode.getParent()
|
||||
otherNode.removeFromParent()
|
||||
if (parent.getChildCount() == 0) {
|
||||
otherNode = parent
|
||||
} else
|
||||
|
||||
List<File> unshared = new ArrayList<>()
|
||||
while (true) {
|
||||
def parent = dmtn.getParent()
|
||||
parent.remove(dmtn)
|
||||
if (parent == allFilesTreeRoot)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
List<File> unshared = new ArrayList<>()
|
||||
while (true) {
|
||||
def parent = dmtn.getParent()
|
||||
parent.remove(dmtn)
|
||||
if (parent == allFilesTreeRoot)
|
||||
if (parent.getChildCount() == 0) {
|
||||
File file = parent.getUserObject().file
|
||||
if (core.watchedDirectoryManager.isWatched(file))
|
||||
unshared.add(file)
|
||||
dmtn = parent
|
||||
continue
|
||||
}
|
||||
break
|
||||
if (parent.getChildCount() == 0) {
|
||||
File file = parent.getUserObject().file
|
||||
if (core.watchedDirectoryManager.isWatched(file))
|
||||
unshared.add(file)
|
||||
dmtn = parent
|
||||
continue
|
||||
}
|
||||
break
|
||||
if (!unshared.isEmpty()) {
|
||||
File unsharedRoot = unshared.get(unshared.size() - 1)
|
||||
core.eventBus.publish(new DirectoryUnsharedEvent(directory: unsharedRoot))
|
||||
}
|
||||
}
|
||||
if (!unshared.isEmpty()) {
|
||||
File unsharedRoot = unshared.get( unshared.size() -1 )
|
||||
core.eventBus.publish(new DirectoryUnsharedEvent(directory : unsharedRoot))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
view.refreshSharedFiles()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue