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.
IndexProgramming Questions & HelpPrograms › Sketch for updating to new version of processing
Page Index Toggle Pages: 1
Sketch for updating to new version of processing (Read 780 times)
Sketch for updating to new version of processing
Mar 29th, 2006, 10:16pm
 
Unpack the new version of processing to wherever you usually put the new version of processing.. change the folders and version-numbers in the code to match your own

this will copy all files and folder from the "libraries"-filder in the old version of processing to the new version of processing, including lib\loading.gif

-seltar

Quote:


String v1 = "0110";
String v2 = "0111";
File FolderA, FolderB;

void setup(){
 size(200, 200);
 FolderA = new File("c:\\Program Files\\processing-"+v1+"-expert");
 FolderB = new File("c:\\Program Files\\processing-"+v2+"-expert");
 stepThrough(new File(FolderA.getAbsolutePath()+"\\libraries"),new File(FolderB.getAbsolutePath()+"\\libraries"));
 if(!compareFiles(new File(FolderA.getAbsolutePath()+"\\lib\\loading.gif"),new File(FolderB.getAbsolutePath()+"\\lib\\loading.gif"))) Copy(FolderA.getAbsolutePath()+"\\lib\\loading.gif",FolderB.getAbsolutePath()+"\\lib\\loading.gif");
 noLoop();
}

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{
     Copy(source.getAbsolutePath(),dest.getAbsolutePath());
   }
 }
}

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;
}

void 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();
   println("Copied");
 }catch (Exception e){
   println("Not Copied");
 }
}
Page Index Toggle Pages: 1