261
262
System.err.println("IOError occured when reading list of files");
266
* Converts a File's absolute path to a path relative to the user
267
* (ie start) directory.
269
* @param absolute the File to convert to relative path
270
* @return a File with a path that is relative to the user's directory
271
* @exception Exception if the path cannot be constructed
273
protected File createRelativePath(File absolute) throws Exception {
274
String userPath = m_UserDir.getAbsolutePath() + File.separator;
275
String targetPath = (new File(absolute.getParent())).getPath()
277
String fileName = absolute.getName();
278
StringBuffer relativePath = new StringBuffer();
279
relativePath.append("."+File.separator);
280
// System.err.println("User dir "+userPath);
281
// System.err.println("Target path "+targetPath);
283
// file is in user dir (or subdir)
284
int subdir = targetPath.indexOf(userPath);
286
if (userPath.length() == targetPath.length()) {
287
relativePath.append(fileName);
289
int ll = userPath.length();
290
relativePath.append(targetPath.substring(ll));
291
relativePath.append(fileName);
295
String temp = new String(userPath);
296
while (temp.indexOf(File.separator) != -1) {
297
int ind = temp.indexOf(File.separator);
299
temp = temp.substring(ind+1, temp.length());
302
String targetTemp = new String(targetPath);
303
String userTemp = new String(userPath);
305
while (targetTemp.indexOf(File.separator) != -1) {
306
int ind = targetTemp.indexOf(File.separator);
307
int ind2 = userTemp.indexOf(File.separator);
308
String tpart = targetTemp.substring(0,ind+1);
309
String upart = userTemp.substring(0,ind2+1);
310
if (tpart.compareTo(upart) != 0) {
317
targetTemp = targetTemp.substring(ind+1, targetTemp.length());
318
userTemp = userTemp.substring(ind2+1, userTemp.length());
321
// then target file is probably on another drive (under windows)
322
throw new Exception("Can't construct a path to file relative to user "
325
if (targetTemp.indexOf(File.separator) == -1) {
328
for (int i = 0; i < sepCount - tcount; i++) {
329
relativePath.append(".."+File.separator);
331
relativePath.append(targetTemp + fileName);
333
// System.err.println("new path : "+relativePath.toString());
334
return new File(relativePath.toString());
338
* Converts a File's absolute path to a path relative to the user
339
* (ie start) directory. Includes an additional workaround for Cygwin, which
340
* doesn't like upper case drive letters.
341
* @param absolute the File to convert to relative path
342
* @return a File with a path that is relative to the user's directory
343
* @exception Exception if the path cannot be constructed
345
protected File convertToRelativePath(File absolute) throws Exception {
351
// if we're running windows, it could be Cygwin
352
if (File.separator.equals("\\")) {
353
// Cygwin doesn't like upper case drives -> try lower case drive
355
fileStr = absolute.getPath();
356
fileStr = fileStr.substring(0, 1).toLowerCase()
357
+ fileStr.substring(1);
358
result = createRelativePath(new File(fileStr));
360
catch (Exception e) {
361
// no luck with Cygwin workaround, convert it like it is
362
result = createRelativePath(absolute);
366
result = createRelativePath(absolute);
373
267
* Handle actions when buttons get pressed.