Changeset 307 for trunk/src/org/expeditee/gui/FrameIO.java
- Timestamp:
- 09/16/08 16:29:27 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/FrameIO.java
r306 r307 128 128 MessageBay.supressMessages(true); 129 129 // loading automatically caches the frame is caching is turned on 130 Load UnknownPath(framename, false);130 LoadFromDisk(framename, null, false); 131 131 MessageBay.supressMessages(false); 132 132 } … … 150 150 151 151 public static Frame LoadFrame(String frameName) { 152 return LoadFrame(frameName, false); 153 } 154 155 public static Frame LoadFrame(String frameName, boolean ignoreAnnotations) { 152 return LoadFrame(frameName, null, false); 153 } 154 155 public static Frame LoadFrame(String frameName, String path) { 156 return LoadFrame(frameName, path, false); 157 } 158 159 public static Frame LoadFrame(String frameName, String path, 160 boolean ignoreAnnotations) { 156 161 if (!isValidFrameName(frameName)) 157 162 return null; … … 168 173 Logger.Log(Logger.SYSTEM, Logger.LOAD, "Loading " + frameName 169 174 + " from disk."); 170 return LoadUnknownPath(frameName, ignoreAnnotations); 175 176 return LoadFromDisk(frameName, path, ignoreAnnotations); 171 177 } 172 178 … … 174 180 String fullPath = FrameIO.getFrameFullPathName(PUBLIC_PATH, frameName); 175 181 182 if(fullPath == null) 183 return null; 184 176 185 File frameFile = new File(fullPath); 177 186 if (frameFile.exists() && frameFile.canRead()) { … … 185 194 } 186 195 187 private static Frame Load UnknownPath(String framename,196 private static Frame LoadFromDisk(String framename, String knownPath, 188 197 boolean ignoreAnnotations) { 189 198 Frame loaded = null; 190 199 191 for (String path : UserSettings.FrameDirs) { 192 loaded = LoadFrame(path, framename); 193 if (loaded != null) { 194 break; 195 } 196 } 197 200 if (knownPath != null) { 201 loaded = LoadKnowPath(knownPath, framename); 202 } else { 203 204 for (String path : UserSettings.FrameDirs) { 205 loaded = LoadKnowPath(path, framename); 206 if (loaded != null) { 207 break; 208 } 209 } 210 } 211 198 212 if (loaded == null && FrameShare.getInstance() != null) { 199 loaded = FrameShare.getInstance().loadFrame(framename );213 loaded = FrameShare.getInstance().loadFrame(framename, knownPath); 200 214 } 201 215 … … 321 335 } 322 336 323 private static Frame Load Frame(String path, String frameName) {337 private static Frame LoadKnowPath(String path, String frameName) { 324 338 String fullPath = getFrameFullPathName(path, frameName); 325 339 if (fullPath == null) … … 386 400 // loop until a frame that exists is found 387 401 for (; num >= 0; num--) { 388 Frame f = LoadFrame(name + num );402 Frame f = LoadFrame(name + num, current.getPath()); 389 403 if (f != null) 390 404 return f; … … 415 429 // read the maximum from the INF file 416 430 try { 417 max = ReadINF(current.getPath(), current.getFramesetName() );431 max = ReadINF(current.getPath(), current.getFramesetName(), false); 418 432 } catch (IOException ioe) { 419 433 MessageBay.errorMessage("Error loading INF file for frameset '" … … 424 438 // loop until a frame that exists is found 425 439 for (; num <= max; num++) { 426 Frame f = LoadFrame(name + num );440 Frame f = LoadFrame(name + num, current.getPath()); 427 441 if (f != null) 428 442 return f; … … 454 468 int max; 455 469 try { 456 max = ReadINF(path, framesetName );470 max = ReadINF(path, framesetName, false); 457 471 } catch (IOException ioe) { 458 472 MessageBay.errorMessage("Error loading INF file for frameset '" … … 463 477 // loop backwards until a frame that exists is found 464 478 for (int num = max; num > 0; num--) { 465 Frame f = LoadFr ame(framesetName + num);479 Frame f = LoadFromDisk(framesetName + num, path, false); 466 480 if (f != null) 467 481 return f; … … 610 624 // read the next number from the INF file 611 625 try { 612 next = ReadINF(destFramesetZero.getPath(), frameset );626 next = ReadINF(destFramesetZero.getPath(), frameset, true); 613 627 } catch (IOException ioe) { 614 628 ioe.printStackTrace(); … … 626 640 Logger.Log(Logger.SYSTEM, Logger.TDFC, "Creating new frame: " 627 641 + template.getName() + " from TDFC"); 628 629 // update INF file630 try {631 WriteINF(template.getPath(), frameset, frameset + next);632 } catch (IOException ioe) {633 ioe.printStackTrace();634 Logger.Log(ioe);635 }636 642 637 643 template.setOwner(UserSettings.Username); … … 822 828 _Cache.remove(toSave.getName().toLowerCase()); 823 829 int nextnum = ReadINF(toSave.getPath(), toSave 824 .getFramesetName() ) + 1;830 .getFramesetName(), false) + 1; 825 831 SuspendCache(); 826 832 Frame original = LoadFrame(toSave.getName()); … … 851 857 int orignum = original.getNumber(); 852 858 int nextnum = ReadINF(toSave.getPath(), toSave 853 .getFramesetName() ) + 1;859 .getFramesetName(), false) + 1; 854 860 855 861 original.setFrameNumber(nextnum); … … 885 891 886 892 // check that the INF file is not out of date 887 int last = ReadINF(toSave.getPath(), toSave.getFramesetName()); 893 int last = ReadINF(toSave.getPath(), toSave.getFramesetName(), 894 false); 888 895 if (last <= toSave.getNumber()) 889 896 WriteINF(toSave.getPath(), toSave.getFramesetName(), toSave … … 947 954 * the INF. 948 955 */ 949 private static int ReadINF(String path, String frameset) throws IOException { 956 public static int ReadINF(String path, String frameset, boolean update) 957 throws IOException { 950 958 assert (!frameset.endsWith(".")); 951 952 // read INF953 BufferedReader reader;954 959 try { 955 reader = new BufferedReader(new FileReader(path 956 + frameset.toLowerCase() + File.separator + INF_FILENAME)); 960 // read INF 961 BufferedReader reader; 962 try { 963 // Check on the local drive 964 reader = new BufferedReader(new FileReader(path 965 + frameset.toLowerCase() + File.separator 966 + INF_FILENAME)); 967 } catch (Exception e) { 968 reader = new BufferedReader(new FileReader(path 969 + frameset.toLowerCase() + File.separator 970 + frameset.toLowerCase() + ".inf")); 971 } 972 String inf = reader.readLine(); 973 reader.close(); 974 975 int next = Conversion.getFrameNumber(inf); 976 // update INF file 977 if (update) { 978 try { 979 WriteINF(path, frameset, frameset + (next + 1)); 980 } catch (IOException ioe) { 981 ioe.printStackTrace(); 982 Logger.Log(ioe); 983 } 984 } 985 return next; 957 986 } catch (Exception e) { 958 reader = new BufferedReader(new FileReader(path 959 + frameset.toLowerCase() + File.separator 960 + frameset.toLowerCase() + ".inf")); 961 } 962 String inf = reader.readLine(); 963 reader.close(); 964 965 return Conversion.getFrameNumber(inf); 987 } 988 989 // Check peers 990 return FrameShare.getInstance().getInfNumber(path, frameset, update); 966 991 } 967 992 … … 975 1000 * Any exception encountered by the BufferedWriter. 976 1001 */ 977 p rivatestatic void WriteINF(String path, String frameset, String frameName)1002 public static void WriteINF(String path, String frameset, String frameName) 978 1003 throws IOException { 979 assert (!frameset.endsWith(".")); 980 981 path += frameset.toLowerCase() + File.separator + INF_FILENAME; 982 983 BufferedWriter writer = new BufferedWriter(new FileWriter(path)); 984 writer.write(frameName); 985 writer.close(); 1004 try { 1005 assert (!frameset.endsWith(".")); 1006 1007 path += frameset.toLowerCase() + File.separator + INF_FILENAME; 1008 1009 BufferedWriter writer = new BufferedWriter(new FileWriter(path)); 1010 writer.write(frameName); 1011 writer.close(); 1012 } catch (Exception e) { 1013 1014 } 986 1015 } 987 1016 … … 1090 1119 1091 1120 try { 1092 num = ReadINF(zero.getPath(), frameset );1121 num = ReadINF(zero.getPath(), frameset, false); 1093 1122 } catch (IOException e) { 1094 1123 // TODO Auto-generated catch block … … 1368 1397 try { 1369 1398 nextNum = ReadINF(PUBLIC_PATH, Conversion 1370 .getFramesetName(frameName) ) + 1;1399 .getFramesetName(frameName), false) + 1; 1371 1400 } catch (IOException e) { 1372 1401 e.printStackTrace(); … … 1399 1428 "Your version was renamed " + newName, peerName); 1400 1429 } 1401 1402 // Save the new version 1403 try { 1404 FileWriter fw = new FileWriter(file); 1405 String nextLine = null; 1406 while ((nextLine = packetContents.readLine()) != null) { 1407 fw.write(nextLine + '\n'); 1408 } 1409 fw.flush(); 1410 fw.close(); 1411 MessageBay.displayMessage("Saved remote frame: " + frameName); 1412 } catch (IOException e) { 1413 e.printStackTrace(); 1414 } 1415 } else { 1416 MessageBay 1417 .errorMessage("Recieved request for unknown public frame: " 1418 + frameName); 1419 } 1430 } 1431 1432 // Save the new version 1433 try { 1434 FileWriter fw = new FileWriter(file); 1435 String nextLine = null; 1436 while ((nextLine = packetContents.readLine()) != null) { 1437 fw.write(nextLine + '\n'); 1438 } 1439 fw.flush(); 1440 fw.close(); 1441 MessageBay.displayMessage("Saved remote frame: " + frameName); 1442 } catch (IOException e) { 1443 MessageBay.errorMessage("Error remote saving " + frameName + ": " 1444 + e.getMessage()); 1445 e.printStackTrace(); 1446 } 1447 // } else { 1448 // 1449 // 1450 // 1451 // MessageBay 1452 // .errorMessage("Recieved save request for unknown public frame: " 1453 // + frameName); 1454 // } 1420 1455 } 1421 1456
Note:
See TracChangeset
for help on using the changeset viewer.