package edu.uw.apl.vmvols.model.vmware;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.Comparator;
import java.util.Collections;
import java.util.UUID;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.io.FileUtils;

import edu.uw.apl.vmvols.model.VirtualDisk;
import edu.uw.apl.vmvols.model.VirtualMachine;

/**
 * @author Stuart Maclean
 *
 * To locate the virtual disk(s) in a VMWare vm directory, do this:
 *
 * File theDir = ....
 * boolean b = VMwareVM.isVMware( theDir );
 * if( b ) {
 *   VMwareVM vm = new VMwareVM( theDir );
 *   List<VirtualDisk> disks = vm.getActiveDisks();
 * }
 *
 * An 'active' disk is one which would be written to were the VM to be
 * running.  It is the 'current snapshot'.  This API also supports
 * accessing any 'generation' (Snapshot) of any disk, all the way up
 * the 'base disk' (which has generation 1), which is held in the file
 * VirtualBox created when the VM was first built.  If a VM has never
 * had a Snapshot taken, its active disk(s) and base disk(s) are the
 * same thing.
 *
 * @see VBoxVM
 */
public class VMwareVM extends VirtualMachine {

	static public boolean isVMware( File dir ) {
		if( !dir.isDirectory() )
			return false;

		// TODO: fill this in..
		return false;
	}

	public VMwareVM( File vmDir ) throws IOException {
		baseDisks = new ArrayList<VirtualDisk>();
		log = LogFactory.getLog( getClass() );
		dir = vmDir;
	}

	@Override
	public String getName() {
		return dir.getName();
	}
	
	// the base disks are what we actually maintain...
	@Override
	public List<VirtualDisk> getBaseDisks() {
		return baseDisks;
	}

	// any active disks are derivable from their base disk counterpart...
	@Override
	public List<VirtualDisk> getActiveDisks() {
		List<VirtualDisk> result = new ArrayList<VirtualDisk>();
		for( VirtualDisk vd : baseDisks ) {
			result.add( vd.getActive() );
		}
		return result;
	}

	private final File dir;
	private final List<VirtualDisk> baseDisks;
	private final Log log;

}


// eof
@@ -1114,18 +1114,38 @@
 %0A * 
-VirtualBox
+the VMWare app (Workstation?) 
  cre
@@ -1177,17 +1177,19 @@
 t built.
- 
+%0A *
  If a VM
@@ -1198,19 +1198,16 @@
 as never
-%0A *
  had a S
@@ -1244,24 +1244,27 @@
 (s) and base
+%0A *
  disk(s) are
@@ -1267,19 +1267,16 @@
  are the
-%0A *
  same th

fix typo in VMwareVM comment