#!/bin/sh

# This gets run after ROX-Session is loaded and running as your session
# manager, before Login is run.
#
# It is used to run ROX-Filer. If this process terminates, ROX-Session will
# offer to rerun it.
#
# $1 is the ROX-Session application directory.
#
# If you want to modify this file, you should first copy it as
# <Choices>/ROX-Session/RunROX so that upgrading ROX-Session will not overwrite
# your changes. This also allows per-user modifications.

if [ ! -n "$XDG_CONFIG_DIRS" ]; then
	XDG_CONFIG_DIRS=/etc/xdg
fi
if [ ! -n "$XDG_CONFIG_HOME" ]; then
	XDG_CONFIG_HOME="$HOME/.config"
fi
IFS=":"

# Load ROX-Filer with a panel and a pinboard set up.
for DIR in $XDG_CONFIG_HOME $XDG_CONFIG_DIRS; do
  PANEL="$DIR/rox.sourceforge.net/ROX-Filer/pan_Default"
  if [ -f "$PANEL" ]; then
    break;
  fi;
  PANEL="";
done

if [ -z "$PANEL" ]; then
  "$1/SetupPanel" "$1" "$XDG_CONFIG_HOME"
fi

# -n is needed to stop the filer going into the background, causing
# ROX-Session to offer to restart it... (-S turns on -n automatically)

# Try to run it though Zero Install...
if [ -x "`which 0launch`" ]; then
    exec 0launch http://rox.sourceforge.net/2005/interfaces/ROX-Filer -S
fi

# Fallback to a manual installation
exec rox -S
