1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/**
* Title: ProAlign<p>
* Description: <p>
* Copyright: Copyright (c) Ari Loytynoja<p>
* License: GNU GENERAL PUBLIC LICENSE<p>
* @see http://www.gnu.org/copyleft/gpl.html
* Company: ULB<p>
* @author Ari Loytynoja
* @version 1.0
*/
package proalign;
import java.io.File;
import java.io.IOException;
/**
* Reads and writes a file for user settings
*/
public class UserSettings {
String filepath;
File file;
UserSettings() {
ProAlign.log("UserSettings");
if(System.getProperty("os.name").startsWith("Windows")){
filepath = "proalign.ini";
} else {
filepath = ".proalignrc";
}
file = new File(filepath);
}
// Read existing settings
String[] readSettings() {
String[] userdata = new String[3];
String str = new String();
if(file.exists()) {
try {
InFile dataIn = new InFile(filepath);
if((str = dataIn.readLine())!=null) {
if(new File(str).isDirectory()){
userdata[0] = str;
}
}
if((str = dataIn.readLine())!=null) {
if(new File(str).isFile()){
userdata[1] = str;
}
}
if((str = dataIn.readLine())!=null) {
if(new File(str).isDirectory()){
userdata[2] = str;
}
}
dataIn.close();
} catch (IOException ie) { }
}
return userdata;
}
// Write current settings
void writeSettings(String[] userdata) {
if(file.exists()) {
try {
file.delete();
} catch (Exception ie) { }
}
try {
OutFile dataOut = new OutFile(filepath);
dataOut.println(userdata[0]); // ProAlign data
dataOut.println(userdata[1]); // ProAlign ClustalW
dataOut.println(userdata[2]); // temp
dataOut.close();
} catch (IOException ie) { }
}
}
|