All pastes #497776 Raw Edit

Someone

public text v1 · immutable
·published 2007-05-20 01:59 UTC
rendered paste body
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	20 May 2007 01:58:08 -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  
 
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	20 May 2007 01:58:08 -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;
 
@@ -509,6 +510,7 @@
 				}
 				cmbDataDir.redraw();
 				cmbDataDir.update();
+				updateSize();
 			}
 		});
 
@@ -1201,6 +1203,7 @@
 				} // for i
 
 				checkSeedingMode();
+				updateSize();
 			}
 		});
 
@@ -1589,6 +1592,7 @@
 		} // for i
 
 		checkSeedingMode();
+		updateSize();
 	}
 
 	/**
@@ -2501,7 +2505,7 @@
 			if (sDestFileName != null) {
 				return new File(sDestFileName);
 			} else {
-				return new File(sDestDir, sFullFileName);
+				return new File(parent.sDestDir, sFullFileName);
 			}
 		}
 
@@ -2534,21 +2538,109 @@
 
 		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;
+
+		// code requires java 1.6 methods
+		try
+		{
+			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];
+					if(!file.bDownload)
+						continue;
+
+					// reduce each file to its partition root
+					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
+		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 +2648,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);
 	}