We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Processing Updater (Read 1527 times)
Processing Updater
Oct 28th, 2007, 10:31am
 
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
Re: Processing Updater
Reply #1 - Oct 28th, 2007, 11:03am
 
hi seltar,
thanks for this contributions, very useful. i just tried it on osx and to get it work there, just replace the double backslashes \\ with one forward slash / . maybe one forward slash even works for windows? dont have a windows machine here, therefore can't test.
best,
andi
Re: Processing Updater
Reply #2 - Oct 28th, 2007, 11:59am
 
Hey andi,

Only glad I can be of help Smiley And thanks for testing it and making it work on a Mac. Hadn't gotten around to checking it out on a mac yet!

best,

seltar
Re: Processing Updater
Reply #3 - Oct 28th, 2007, 10:54pm
 
perhaps simpler, just put libraries in your sketchbook folder, and they'll work with newer releases without having to move anything.

and you should not copy lib/preferences.txt to newer releases--as explained in that file, it's only used as the template, and the actual version that's used is stored elsewhere, and will be picked up by new releases as they are installed.
Re: Processing Updater
Reply #4 - Oct 29th, 2007, 6:37am
 
ah ok, didnt know about the sketchbook solution. very convenient. was just wondering if it would be a good idea to promote this solution of putting 3rd party libraries into the sketchbook folder instead of the libraries folder of the processing app distribution. maybe to keep things organized there can be a libraries folder  in the sketchbook installed by default?

another plus for the sketchbook solution is that if you distribute a 3rd party library with an examples folder contained, examples will be accessible via the sketchbook menu. additionally, when importing a library from the menu bar, the 3rd party libraries will be separated from the default libraries and are contained in their own submenu - sketch/import libraries/libraries
maybe this is convenient not just for me?
best,
andi
Re: Processing Updater
Reply #5 - Oct 29th, 2007, 4:27pm
 
fry wrote on Oct 28th, 2007, 10:54pm:
just put libraries in your sketchbook folder


I had completely overlooked this too - it's terrific, much appreciated.  Smiley
Re: Processing Updater
Reply #6 - Oct 30th, 2007, 2:51pm
 
sojamo wrote on Oct 29th, 2007, 6:37am:
ah ok, didnt know about the sketchbook solution. very convenient. was just wondering if it would be a good idea to promote this solution of putting 3rd party libraries into the sketchbook folder instead of the libraries folder of the processing app distribution. maybe to keep things organized there can be a libraries folder  in the sketchbook installed by default

yes, it's promoted this way in the libraries documentation (libraries/howto.txt)

Libraries live inside the "libraries" folder of the Processing
distribution, however users are encouraged to install "contributed"
libraries in their sketchbook folder, which will prevent them
from having to move their libraries with new Processing releases.

not much else i can do than that. (outside of nagging every  library developer to change their docs)
Re: Processing Updater
Reply #7 - Oct 30th, 2007, 4:34pm
 
thanks ben for clarifying. my excitement probably leads back to my ignorance of not having read the howto.txt, nevertheless happy to have found out. will change the docs.
Page Index Toggle Pages: 1