/*
 * Autopsy Forensic Browser
 *
 * Copyright 2013-2017 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.core;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.sendopts.CommandException;
import org.netbeans.spi.sendopts.Env;
import org.netbeans.spi.sendopts.Option;
import org.netbeans.spi.sendopts.OptionProcessor;
import org.openide.util.lookup.ServiceProvider;
import org.sleuthkit.autopsy.coreutils.ModuleSettings;
import org.sleuthkit.autopsy.coreutils.PlatformUtil;

/**
 * This class can be used to add command line options to Autopsy
 * To add more options to autopsy, create a Option variable and add it to the set in getOptions method
 * Do your logic for that option in the process method
 */
@ServiceProvider(service=OptionProcessor.class)
public class AutopsyOptionProcessor extends OptionProcessor {
    
    private static final Logger logger = Logger.getLogger(AutopsyOptionProcessor.class.getName());
    private final Option liveAutopsyOption = Option.optionalArgument('l', "liveAutopsy");
    private final static String PROP_BASECASE = "LBL_BaseCase_PATH";


    @Override
    protected Set<Option> getOptions() {
        Set<Option> set = new HashSet<>();
        set.add(liveAutopsyOption);
        return set;
    }

    @Override
    protected void process(Env env, Map<Option, String[]> values) throws CommandException {
       if(values.containsKey(liveAutopsyOption)){
           try {
               RuntimeProperties.setRunningInTarget(true);
               String[] dir= values.get(liveAutopsyOption);
               String directory = dir == null ? PlatformUtil.getUserDirectory().toString() : dir[0];
               ModuleSettings.setConfigSetting(ModuleSettings.MAIN_SETTINGS, PROP_BASECASE, directory);
           } catch (RuntimeProperties.RuntimePropertiesException ex) {
               logger.log(Level.SEVERE, ex.getMessage(), ex);
           }
       }
    }
    
}

@@ -1724,16 +1724,104 @@
 opsy%22);%0A
+    // @@@ We should centralize where we store this.  It is defined in 2 other places. %0A
     priv
@@ -1881,16 +1881,16 @@
 _PATH%22;%0A
-
 %0A%0A    @O
@@ -2276,16 +2276,92 @@
 (true);%0A
+               %0A               // get the starting folder to store cases in%0A
         
@@ -2376,19 +2376,23 @@
 tring%5B%5D 
-d
+argD
 ir
+s
 = values
@@ -2442,23 +2442,51 @@
 ing 
-directory = d
+startingCaseDir;%0A               if (argD
 ir
+s
  == 
@@ -2494,62 +2494,219 @@
 ull 
-? PlatformUtil.getUserDirectory().toString() : dir%5B0%5D;
+%7C%7C argDirs.length == 0) %7B%0A                   startingCaseDir = PlatformUtil.getUserDirectory().toString();%0A               %7D%0A               else %7B%0A                   startingCaseDir = argDirs%5B0%5D;%0A               %7D
 %0A   
@@ -2798,17 +2798,23 @@
 SE, 
-directory
+startingCaseDir
 );%0A 
@@ -2971,17 +2971,12 @@
   %7D%0A
+
     %7D%0A
-    %0A
 %7D%0A

fix out of bounds exception for live triag drive JIRA-4183