All pastes #497385 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-19 20:37 UTC
rendered paste body
Index: azureus2/org/gudy/azureus2/ui/swt/OpenTorrentWindow.java
===================================================================
RCS file: /cvsroot/azureus/azureus2/org/gudy/azureus2/ui/swt/OpenTorrentWindow.java,v
retrieving revision 1.89
diff -u -r1.89 OpenTorrentWindow.java
--- azureus2/org/gudy/azureus2/ui/swt/OpenTorrentWindow.java	18 May 2007 22:57:09 -0000	1.89
+++ azureus2/org/gudy/azureus2/ui/swt/OpenTorrentWindow.java	19 May 2007 20:36:04 -0000
@@ -27,6 +27,7 @@
 import java.io.*;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 
@@ -2501,7 +2502,7 @@
 			if (sDestFileName != null) {
 				return new File(sDestFileName);
 			} else {
-				return new File(sDestDir, sFullFileName);
+				return new File(parent.sDestDir, sFullFileName);
 			}
 		}
 
@@ -2534,21 +2535,114 @@
 
 		return (sDefDir == "") ? null : sDefDir;
 	}
+	
+	private class FreeSpaceItem {
+		
+		public FreeSpaceItem(File root)
+		{
+			this.root = root;
+		}
+		
+		long bytestoConsume = 0;
+		long freeSpace = 0;
+		final File root;
+	}
 
 	private void updateSize() {
+		/*
+		 * determine space consumed by all files per partition
+		 */		
+		final File[] FSroots = File.listRoots();
+		final HashMap partitionItems = new HashMap();
+		String diskFreeInfo = "";
+		boolean filesTooBig = false;
+		
+		for(int i = 0;i<torrentList.size();i++)
+		{
+			TorrentInfo tor = (TorrentInfo)torrentList.get(i);
+			TorrentFileInfo[] files = tor.getFiles();
+			for(int j = 0;j<files.length;j++)
+			{
+				TorrentFileInfo file = files[j];
+				try
+				{
+					/* 
+					 * reduce each file to its partition root
+					 * code requires java 1.6 methods 
+					 */
+					File root = file.getDestFile().getAbsoluteFile().getParentFile();
+					while(true)
+					{
+						final File next = root.getParentFile();
+						boolean rootReached = false;
+						if(next == null || next.equals(root) || next.getUsableSpace() != root.getUsableSpace())
+							rootReached = true;
+						for(int k = 0;k<FSroots.length;k++)
+							if(FSroots[k].equals(root))
+								rootReached = true;
+						if(rootReached)
+							break;
+						root = next;
+					}
+					
+					FreeSpaceItem partition = (FreeSpaceItem)partitionItems.get(root);
+					if(partition == null)
+					{
+						partition = new FreeSpaceItem(root);
+						partition.freeSpace = root.getUsableSpace();
+						partitionItems.put(root, partition);
+					}
+					partition.bytestoConsume += file.lSize;
+				} catch (NoSuchMethodError e)
+				{
+					// non-java 1.6 
+				}
+			}
+		}
+		
+		// build string
+		if(partitionItems.size() > 0)
+		{
+			Iterator it = partitionItems.values().iterator();
+			while(it.hasNext())
+			{
+				FreeSpaceItem part = (FreeSpaceItem)it.next();
+				diskFreeInfo +=
+					MessageText.getString(
+							"OpenTorrentWindow.diskUsage",
+							new String[] {
+								part.root.getPath(),
+								DisplayFormatters.formatByteCountToKiBEtc(part.bytestoConsume),
+								DisplayFormatters.formatByteCountToKiBEtc(part.freeSpace)}
+							);
+		
+				if(part.bytestoConsume > part.freeSpace)
+					filesTooBig = true;
+			}
+		}
+
+		
+		
+		/*
+		 * determine info for selected torrents only
+		 */
 		long totalSize = 0;
 		long checkedSize = 0;
 
+		
 		for (int i = 0; i < dataFiles.size(); i++) {
 			TorrentFileInfo file = (TorrentFileInfo) dataFiles.get(i);
 
 			totalSize += file.lSize;
-
+			
 			if (file.bDownload) {
 				checkedSize += file.lSize;
 			}
 		}
-
+		
+		
+		
+		// build string and set label
 		if (totalSize == 0) {
 			dataFileTableLabel.setText("");
 		} else {
@@ -2556,8 +2650,9 @@
 					"OpenTorrentWindow.filesInfo", new String[] {
 						DisplayFormatters.formatByteCountToKiBEtc(checkedSize),
 						DisplayFormatters.formatByteCountToKiBEtc(totalSize)
-					}));
+					})+diskFreeInfo);
 		}
+		dataFileTableLabel.setForeground(filesTooBig ? Colors.colorError : null);
 		dataFileTableLabel.update();
 		dataFileTableLabel.getParent().getParent().layout(true, true);
 	}
Index: azureus2/org/gudy/azureus2/internat/MessagesBundle.properties
===================================================================
RCS file: /cvsroot/azureus/azureus2/org/gudy/azureus2/internat/MessagesBundle.properties,v
retrieving revision 1.815
diff -u -r1.815 MessagesBundle.properties
--- azureus2/org/gudy/azureus2/internat/MessagesBundle.properties	18 May 2007 19:25:52 -0000	1.815
+++ azureus2/org/gudy/azureus2/internat/MessagesBundle.properties	19 May 2007 20:36:04 -0000
@@ -2148,6 +2150,8 @@
 ConfigView.section.ipfilter.enable.descriptionCache.tooltip=When disabled, descriptions will not be remembered
 
 OpenTorrentWindow.filesInfo=%1 of %2 will be downloaded.
+OpenTorrentWindow.diskUsage=\n%1\t%2 of %3 
+
 ConfigView.label.openmytorrents=Open 'My Torrents' on startup
 ConfigView.section.style.DNDalwaysInIncomplete=Always show torrents with 'Do Not Download' files in Incomplete section of My Torrents