--- C:/Users/Hugheth/AppData/Local/Temp/jQuery.-rev9946.svn009.tmp.js	Tue Jul 21 11:02:27 2009
+++ C:/Subversion/core/jquery/plugins/jQuery.twFile.js	Tue Jul 21 11:02:53 2009
@@ -1,4 +1,4 @@
-/*
+﻿/*
 jQuery.twFile.js
 
 jQuery plugin for loading a file and saving data to a file
@@ -43,6 +43,40 @@
 				return this.currentDriver.copyFile(dest,source);
 			else
 				return false;
+		},
+		getFilePath: function(filePath){	// helper function to retrieve requested file's path
+			// If blank then assume the file requested is the current file
+			if(!filePath){
+				filePath = document.location.href;
+			}
+			filePath = unescape(filePath);		// Unescape the filePath
+			// Remove any location or query part of the URL
+			var hashPos = filePath.indexOf("#");
+			var argPos = filePath.indexOf("?");
+			var nPos = Math.min((hashPos+1) ? hashPos : filePath.length, (argPos+1) ? argPos : filePath.length);
+			var info = filePath.substr(nPos);
+			filePath = filePath.substr(0,nPos);
+			// Convert file://localhost/ to file:///
+			if(filePath.indexOf("file://localhost/") == 0)
+			filePath = "file://" + filePath.substr(16);
+			// Convert to a native file format
+			if(filePath.charAt(9) == ":") // pc local file
+				filePath = filePath.substr(8).replace(new RegExp("/","g"),"\\");
+			else if(filePath.indexOf("file://///") == 0) // FireFox pc network file
+				filePath = "\\\\" + filePath.substr(10).replace(new RegExp("/","g"),"\\");
+			else if(filePath.indexOf("file:///") == 0) // mac/unix local file
+				filePath = filePath.substr(7);
+			else if(filePath.indexOf("file:/") == 0) // mac/unix local file
+				filePath = filePath.substr(5);
+			else if(filePath.indexOf("//") == 0) // pc network file
+				filePath = "\\\\" + filePath.substr(7).replace(new RegExp("/","g"),"\\");
+			// If relative then append pathname
+			if(filePath.indexOf("/")!=0&&(filePath.indexOf(":")==-1||filePath.indexOf(":")>2)){
+				var brPos = document.location.pathname.lastIndexOf("/");
+				filePath = "file://" + document.location.pathname.substr(0,brPos) + "/" + filePath;
+			}
+			// Return filePath
+			return filePath;
 		}
 	});
 
@@ -186,7 +220,7 @@
 					out.close();
 					return true;
 				} catch(ex) {
-					alert("Exception while attempting to save\n\n" + ex);
+					//# alert("Exception while attempting to save\n\n" + ex);
 					return false;
 				}
 			}
@@ -210,7 +244,7 @@
 			var r;
 			try {
 				if(document.applets["TiddlySaver"]) {
-					r = document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8");
+					r = document.applets["TiddlySaver"].loadFile(filePath,"UTF-8");
 					return (r === undefined || r === null) ? null : String(r);
 				}
 			} catch(ex) {
@@ -220,7 +254,7 @@
 		saveFile: function(filePath,content) {
 			try {
 				if(document.applets["TiddlySaver"])
-					return document.applets["TiddlySaver"].saveFile(javaUrlToFilename(filePath),"UTF-8",content);
+					return document.applets["TiddlySaver"].saveFile(filePath,"UTF-8",content);
 			} catch(ex) {
 			}
 			return null;
@@ -238,7 +272,7 @@
 			var r;
 			var content = [];
 			try {
-				r = new java.io.BufferedReader(new java.io.FileReader(javaUrlToFilename(filePath)));
+				r = new java.io.BufferedReader(new java.io.FileReader(filePath));
 				var line;
 				while((line = r.readLine()) != null)
 					content.push(new String(line));
@@ -250,7 +284,7 @@
 		},
 		saveFile: function(filePath,content) {
 			try {
-				var s = new java.io.PrintStream(new java.io.FileOutputStream(javaUrlToFilename(filePath)));
+				var s = new java.io.PrintStream(new java.io.FileOutputStream(filePath));
 				s.print(content);
 				s.close();
 			} catch(ex) {
@@ -260,14 +294,4 @@
 		}
 	}
 
-	// Private utilities
-
-	function javaUrlToFilename(url) {
-		var f = "//localhost";
-		if(url.indexOf(f) == 0)
-			return url.substring(f.length);
-		var i = url.indexOf(":");
-		return i > 0 ? url.substring(i-1) : url;
-	}
-
 })(jQuery);

