package com.atolsystems.atolutilities.tools;
import com.atolsystems.atolutilities.AFileChooser;
import com.atolsystems.atolutilities.AFileUtilities;
import com.atolsystems.atolutilities.AStringUtilities;
import com.atolsystems.atolutilities.ATextScreenOutput;
import com.atolsystems.atolutilities.LoggingWindow;
import java.io.File;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.util.Random;
/**
*
* @author seb
*/
public class UnSvn {
static void showHelpAndExit(int exitStatus){
System.out.print("UnSvn utility\n"+
"Remove all .svn folders from sub directories of <topFolderName>\n"+
"Usage: UnSvn <topFolderName>\n"
);
System.exit(exitStatus);
}
public static void main(String[] args) throws IOException {
File topFolder;
boolean guiMode=false;
if(1!=args.length){
guiMode=true;
topFolder=AFileChooser.askForDirectory("Choose folder to 'UnSvnize'", false);
if(null==topFolder)
showHelpAndExit(-1);
topFolder=topFolder.getCanonicalFile();
}else{
topFolder = (new File(args[0])).getCanonicalFile();
}
ATextScreenOutput logWin = null;
if(guiMode){
logWin= new ATextScreenOutput(null, false, true);
logWin.setVisible(true);
logWin.appendAndScroll("Processing "+topFolder+"\n");
}
unsvn(topFolder);
if(guiMode){
logWin.appendAndScroll("done");
}else{
System.exit(0);
}
}
static int level=0;
private static void unsvn(File file) throws IOException {
if(file.isFile())
return;
else if(file.getName().equals(".svn"))
AFileUtilities.removeDirectory(file);
else{
for(int i=0;i<level;i++)
System.out.print(" ");
System.out.println("open "+file.getCanonicalPath());
level++;
File[] list=file.listFiles();
for(int i=0;i<list.length;i++)
unsvn(list[i]);
level--;
for(int i=0;i<level;i++)
System.out.print(" ");
System.out.println("close "+file.getCanonicalPath());
}
}
}