A simple sketch, that (if it points to the rights folders) will loop through your old processing-folder, and copy over all the libraries that don't exist in the new one, as well as copying over preferences.txt, and loading.gif
Just specify which version you are updating from and to, and where you've put it.
You will get an output with all folders / files that have been copied.
Code:
String path = "c:\\Program Files\\processing-";
String v1 = "0125"; // old version
String v2 = "0132"; // new version
boolean copyPreferences = false; // the newest version has changes to the preferences. be careful with this.
boolean output = false; // turn on to see output
File FolderA, FolderB;
void setup(){
// Set Up Paths
FolderA = new File(path+v1);
FolderB = new File(path+v2);
// Copy All Libraries
if(output){
println(" Copying Libraries from "+FolderA.getAbsolutePath()+" to + "+FolderB.getAbsolutePath()+". ");
println();
}
stepThrough(new File(FolderA.getAbsolutePath()+"\\libraries"),new File(FolderB.getAbsolutePath()+"\\libraries"));
// Copy loading.gif If It Doesn't Match
if(copyIfNotSame("\\lib\\loading.gif")){
println("OK - Loading.gif");
}else{
println("FAILED - Loading.gif");
}
// If Preferences Is To Be Copied
if(copyPreferences){
// Copy preferences.txt If It Doesn't Match
if(copyIfNotSame("\\lib\\preferences.txt")){
println("OK - Preferences");
}else{
println("FAILED - Preferences");
}
}
noLoop();
}
boolean copyIfNotSame(String file)
{
File A = new File(FolderA.getAbsolutePath()+file);
File B = new File(FolderB.getAbsolutePath()+file);
if(!compareFiles(A,B)){
return Copy(A.getAbsolutePath(),B.getAbsolutePath());
}
return false;
}
boolean compareFiles(File A, File B){
if(A.isDirectory() || B.isDirectory()) return false;
try{
FileInputStream inA = new FileInputStream(A);
FileInputStream inB = new FileInputStream(B);
if(inA.available() == inB.available()) return true;
inA.close();
inB.close();
}catch(Exception e){
println(e);
}
return false;
}
void stepThrough(File A, File B)
{
if(!A.isDirectory() || !B.isDirectory()) return;
String[] missing = compareFolders(A,B);
for(int i = 0; i < missing.length; i++){
File source = new File(A.getAbsolutePath()+"\\"+missing[i]);
File dest = new File(B.getAbsolutePath()+"\\"+missing[i]);
if(source.isDirectory()){
if(dest.mkdir()){
stepThrough(source,dest);
}
}else{
if(Copy(source.getAbsolutePath(),dest.getAbsolutePath())){
if(output){
println("OK - "+source.getName());
}
}else{
if(output){
println("FAILED - "+source.getName());
}
}
}
}
}
String[] getFolder(File f)
{
if(!f.isDirectory()) return null;
return f.list();
}
String[] compareFolders(File src, File dest)
{
if(!src.isDirectory() || !dest.isDirectory()) return null;
String[] sSrc = getFolder(src);
String[] sDest = getFolder(dest);
String[] ret = new String[0];
for(int i = 0; i < sSrc.length; i++){
boolean exists = false;
for(int j = 0; j < sDest.length; j++){
if(sSrc[i].equals(sDest[j])) exists = true;
}
if(!exists) ret = append(ret,sSrc[i]);
}
return ret;
}
boolean Copy(String source, String dest){
File inputFile = new File(source);
File outputFile = new File(dest);
try{
FileInputStream in = new FileInputStream(inputFile);
FileOutputStream out = new FileOutputStream(outputFile);
int len;
byte[] buf = new byte[1024];
while ((len = in.read(buf)) > 0)
out.write(buf,0,len);
in.close();
out.close();
return true;
}catch (Exception e){
return false;
}
}
best
seltar